diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 99186b1cc4900b521e0d35da9727beff58ee5c20..870db4289f913056bb81ae28fd2fbd411473d969 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 0000000000000000000000000000000000000000..7c245dd14ff05842eead2058224ecfe4cde4e95d --- /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 9a811637183b6d7b95a6446b249fe91cfba9419a..1816f05cdc961a653d62180b1805e846dec2ac06 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 0000000000000000000000000000000000000000..ddc7d176e5e7451f4fb8d9b6624ecc2113e770fc --- /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 ff3f13a912ccad5c56f589b19fefa808f8d0c49f..be3b72f6d5387724f56698e420b967aa857a69a0 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 e3e10f3171d3085795180a820c611940bac8250b..ea4b446f84fe402a7b2abbbd9c082040646ea121 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 0000000000000000000000000000000000000000..35061b0d9428e94a13050a21edb23876c17d2b3f --- /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) + })