From b2da009c97ff1dffa720ffefee71129a0b32acb1 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 5 Jun 2018 16:39:54 +0200 Subject: [PATCH] possibiity to configure study notification set --- smash/web/forms/__init__.py | 4 ++-- smash/web/forms/study_forms.py | 12 +++++++++++- smash/web/templates/study/edit.html | 25 +++++++++++++++++++++++++ smash/web/views/study.py | 11 ++++++++--- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 870db428..c89dd25a 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 7c245dd1..38910317 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 ddc7d176..373f6035 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 35061b0d..8a91ed24 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) -- GitLab