From a4c114154b4747cb77ba6534f5272e69e515373f Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 5 Jun 2018 16:19:51 +0200 Subject: [PATCH] edit study form --- smash/web/forms/__init__.py | 3 +- smash/web/forms/study_forms.py | 18 ++++++ smash/web/templates/sidebar.html | 1 + smash/web/templates/study/edit.html | 95 +++++++++++++++++++++++++++++ smash/web/urls.py | 6 ++ smash/web/views/__init__.py | 6 +- smash/web/views/study.py | 35 +++++++++++ 7 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 smash/web/forms/study_forms.py create mode 100644 smash/web/templates/study/edit.html create mode 100644 smash/web/views/study.py diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 99186b1c..870db428 100644 --- a/smash/web/forms/__init__.py +++ b/smash/web/forms/__init__.py @@ -1,3 +1,4 @@ +from study_forms import StudyEditForm from worker_form import WorkerForm from forms import VisitDetailForm, \ VisitAddForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ @@ -12,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] + VoucherTypePriceForm, VoucherForm, StudyEditForm] diff --git a/smash/web/forms/study_forms.py b/smash/web/forms/study_forms.py new file mode 100644 index 00000000..7c245dd1 --- /dev/null +++ b/smash/web/forms/study_forms.py @@ -0,0 +1,18 @@ +import logging + +from django.forms import ModelForm + +from web.models import Study + +logger = logging.getLogger(__name__) + + +class StudyEditForm(ModelForm): + + def __init__(self, *args, **kwargs): + super(StudyEditForm, self).__init__(*args, **kwargs) + + class Meta: + model = Study + fields = '__all__' + exclude = ['columns', 'notification_parameters'] diff --git a/smash/web/templates/sidebar.html b/smash/web/templates/sidebar.html index 9a811637..1816f05c 100644 --- a/smash/web/templates/sidebar.html +++ b/smash/web/templates/sidebar.html @@ -86,6 +86,7 @@ <li><a href="{% url 'web.views.voucher_types' %}">Voucher types</a></li> <li><a href="{% url 'web.views.workers' 'VOUCHER_PARTNER' %}">Voucher partners</a></li> <li><a href="{% url 'web.views.workers' 'HEALTH_PARTNER' %}">Health partners</a></li> + <li><a href="{% url 'web.views.edit_study' study_id %}">Study</a></li> </ul> </li> diff --git a/smash/web/templates/study/edit.html b/smash/web/templates/study/edit.html new file mode 100644 index 00000000..ddc7d176 --- /dev/null +++ b/smash/web/templates/study/edit.html @@ -0,0 +1,95 @@ +{% extends "_base.html" %} +{% load static %} +{% load filters %} + +{% block styles %} + {{ block.super }} + <!-- DataTables --> + <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}"> + + {% include "includes/datepicker.css.html" %} + {% include "includes/datetimepicker.css.html" %} +{% endblock styles %} + +{% block ui_active_tab %}'subjects'{% endblock ui_active_tab %} +{% block page_header %}Edit subject{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Edit subject information{% endblock %} + +{% block breadcrumb %} + {% include "subjects/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} + + {% block content %} + <div class="row"> + <p class="col-lg-3 pull-left"> + <a href="javascript:history.back(1)" class="btn btn-block btn-default">Go back (discard changes)</a> + </p> + </div> + <div class="row"> + <div class="col-md-12"> + <div class="box box-success"> + <form method="post" action="" enctype="multipart/form-data" class="form-horizontal"> + {% csrf_token %} + + <div class="box-header with-border"> + <h3>Study</h3> + </div> + <div class="box-body"> + <div class="col-md-12"> + + {% for field in study_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> + </div> + <div class="col-sm-4"> + <button id="save-and-continue" type="button" class="btn btn-block btn-success">Save and + Continue + </button> + </div> + <div class="col-sm-4"> + <a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default" + onclick="history.back()">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div><!-- /.box --> + </div><!-- /.col-md-12 --> + </div><!-- /.row --> + + {% endblock %} + + +{% endblock maincontent %} + +{% block scripts %} + {{ block.super }} + + <script src="{% static 'AdminLTE/plugins/datatables/jquery.dataTables.min.js' %}"></script> + <script src="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.min.js' %}"></script> + + {% include "includes/datepicker.js.html" %} + {% include "includes/datetimepicker.js.html" %} +{% endblock scripts %} diff --git a/smash/web/urls.py b/smash/web/urls.py index ff3f13a9..be3b72f6 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -225,6 +225,12 @@ urlpatterns = [ url(r'^statistics$', views.statistics.statistics, name='web.views.statistics'), + #################### + # STUDY # + #################### + + url(r'^study/(?P<study_id>\d+)/edit', views.study.study_edit, name='web.views.edit_study'), + #################### # EXPORT # #################### diff --git a/smash/web/views/__init__.py b/smash/web/views/__init__.py index e3e10f31..ea4b446f 100644 --- a/smash/web/views/__init__.py +++ b/smash/web/views/__init__.py @@ -1,9 +1,9 @@ # coding=utf-8 from django.conf import settings from django.shortcuts import redirect, render -from django.utils.decorators import method_decorator from django.views.generic.base import ContextMixin +from web.models.constants import GLOBAL_STUDY_ID from notifications import get_notifications from ..models import Worker @@ -47,7 +47,8 @@ def extend_context(params, request): final_params.update({ 'person': person, 'role': role, - 'notifications': notifications + 'notifications': notifications, + 'study_id': GLOBAL_STUDY_ID }) return final_params @@ -83,3 +84,4 @@ import voucher_type_price import redcap import rooms import uploaded_files +import study diff --git a/smash/web/views/study.py b/smash/web/views/study.py new file mode 100644 index 00000000..35061b0d --- /dev/null +++ b/smash/web/views/study.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import logging + +from django.contrib import messages +from django.shortcuts import redirect, get_object_or_404 + +from . import wrap_response +from ..forms import StudyEditForm +from ..models import Study + +logger = logging.getLogger(__name__) + + +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() : + study_form.save() + messages.success(request, "Modifications saved") + if '_continue' in request.POST: + return redirect('web.views.edit_study', study_id=study.id) + return redirect('web.views.appointments') + else: + messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.') + else: + study_form = StudyEditForm(instance=study, prefix="study") + + return wrap_response(request, 'study/edit.html', { + 'study_form': study_form, + # 'subject_form': subject_form, + # 'study_subject': study_subject, + # 'contact_attempts': contact_attempts, + # 'mail_templates': MailTemplate.get_subject_mail_templates(languages) + }) -- GitLab