diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 870db4289f913056bb81ae28fd2fbd411473d969..c89dd25a7d2bef66ead08ae6459501ef80feeba9 100644 --- a/smash/web/forms/__init__.py +++ b/smash/web/forms/__init__.py @@ -1,4 +1,4 @@ -from study_forms import StudyEditForm +from study_forms import StudyEditForm, StudyNotificationParametersEditForm from worker_form import WorkerForm from forms import VisitDetailForm, \ VisitAddForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ @@ -13,4 +13,4 @@ __all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, Wo AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, ContactAttemptAddForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm, VoucherTypeForm, - VoucherTypePriceForm, VoucherForm, StudyEditForm] + VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm] diff --git a/smash/web/forms/study_forms.py b/smash/web/forms/study_forms.py index 7c245dd14ff05842eead2058224ecfe4cde4e95d..38910317ba1963d6b48d97582661e3ffd5fcb18c 100644 --- a/smash/web/forms/study_forms.py +++ b/smash/web/forms/study_forms.py @@ -2,7 +2,7 @@ import logging from django.forms import ModelForm -from web.models import Study +from web.models import Study, StudyNotificationParameters logger = logging.getLogger(__name__) @@ -16,3 +16,13 @@ class StudyEditForm(ModelForm): model = Study fields = '__all__' exclude = ['columns', 'notification_parameters'] + + +class StudyNotificationParametersEditForm(ModelForm): + + def __init__(self, *args, **kwargs): + super(StudyNotificationParametersEditForm, self).__init__(*args, **kwargs) + + class Meta: + model = StudyNotificationParameters + fields = '__all__' diff --git a/smash/web/templates/study/edit.html b/smash/web/templates/study/edit.html index ddc7d176e5e7451f4fb8d9b6624ecc2113e770fc..373f60354cfa568a7589cd0771fb8c1f550a7374 100644 --- a/smash/web/templates/study/edit.html +++ b/smash/web/templates/study/edit.html @@ -60,6 +60,31 @@ </div> </div><!-- /.box-body --> + <div class="box-header with-border"> + <h3>Notifications</h3> + </div> + <div class="box-body"> + <div class="col-md-12"> + + {% for field in notifications_form %} + <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> + <label for="{# TODO #}" class="col-sm-4 control-label"> + {{ field.label }} + </label> + + <div class="col-sm-8"> + {{ field|add_class:'form-control' }} + </div> + + {% if field.errors %} + <span class="help-block"> {{ field.errors }} </span> + {% endif %} + </div> + {% endfor %} + + </div> + </div><!-- /.box-body --> + <div class="box-footer"> <div class="col-sm-4"> <button type="submit" class="btn btn-block btn-success">Save</button> diff --git a/smash/web/views/study.py b/smash/web/views/study.py index 35061b0d9428e94a13050a21edb23876c17d2b3f..8a91ed245cdbdd6e84fc173b030e7b5de27c9755 100644 --- a/smash/web/views/study.py +++ b/smash/web/views/study.py @@ -5,7 +5,7 @@ from django.contrib import messages from django.shortcuts import redirect, get_object_or_404 from . import wrap_response -from ..forms import StudyEditForm +from ..forms import StudyEditForm, StudyNotificationParametersEditForm from ..models import Study logger = logging.getLogger(__name__) @@ -15,8 +15,12 @@ def study_edit(request, study_id): study = get_object_or_404(Study, id=study_id) if request.method == 'POST': study_form = StudyEditForm(request.POST, request.FILES, instance=study, prefix="study") - if study_form.is_valid() : + notifications_form = StudyNotificationParametersEditForm(request.POST, request.FILES, + instance=study.notification_parameters, + prefix="notifications") + if study_form.is_valid() and notifications_form.is_valid(): study_form.save() + notifications_form.save() messages.success(request, "Modifications saved") if '_continue' in request.POST: return redirect('web.views.edit_study', study_id=study.id) @@ -25,10 +29,11 @@ def study_edit(request, study_id): messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.') else: study_form = StudyEditForm(instance=study, prefix="study") + notifications_form = StudyNotificationParametersEditForm(instance=study.notification_parameters, prefix="notifications") return wrap_response(request, 'study/edit.html', { 'study_form': study_form, - # 'subject_form': subject_form, + 'notifications_form': notifications_form, # 'study_subject': study_subject, # 'contact_attempts': contact_attempts, # 'mail_templates': MailTemplate.get_subject_mail_templates(languages)