diff --git a/smash/web/templates/doctors/index.html b/smash/web/templates/doctors/index.html index 2e14e5095e8127daabdb0038b548a5f6a14460cf..2011cf349b9daa10ac4f039893a863814e3e46fe 100644 --- a/smash/web/templates/doctors/index.html +++ b/smash/web/templates/doctors/index.html @@ -117,7 +117,7 @@ <a href="{% url 'web.views.worker_disable' worker.id %}" class="btn btn-block btn-warning">DISABLE</a> {% else %} - YES + <span class="btn btn-block btn-danger" disabled>YES</span> {% endif %} </td> {% endif %} diff --git a/smash/web/templates/visits/add.html b/smash/web/templates/visits/add.html index 4c93ee497b56c5d68886deb070115662d1fa3e05..9ab44bbc466f899e7bf50ebd78a798ea1d7c0ca3 100644 --- a/smash/web/templates/visits/add.html +++ b/smash/web/templates/visits/add.html @@ -72,6 +72,10 @@ <script> var default_visit_duration_in_months = parseInt("{{default_visit_duration}}"); visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']"), default_visit_duration_in_months); + $('form').submit(function(event){ + $('button[type=submit]').prop('disabled', true); + }); + </script> {% include "includes/datepicker.js.html" %} diff --git a/smash/web/views/visit.py b/smash/web/views/visit.py index 77625043f21147bc3c9b0e3cc314a9925120c2de..b6fb34ad39ec964f5c45a37e5a32d4148cea9136 100644 --- a/smash/web/views/visit.py +++ b/smash/web/views/visit.py @@ -2,7 +2,7 @@ import logging from django.shortcuts import get_object_or_404, redirect - +from django.contrib import messages from notifications import waiting_for_appointment from web.models.study_visit_list import VISIT_LIST_GENERIC, VISIT_LIST_MISSING_APPOINTMENTS, \ VISIT_LIST_APPROACHING_WITHOUT_APPOINTMENTS, VISIT_LIST_APPROACHING_FOR_MAIL_CONTACT, VISIT_LIST_EXCEEDED_TIME, \ @@ -55,6 +55,10 @@ def visit_details(request, id): else: visit_form = VisitDetailForm(instance=displayed_visit) + visit_form.fields['subject'].choices = [(displayed_visit.subject.id, displayed_visit.subject)] + visit_form.fields['subject'].initial = (displayed_visit.subject.id, displayed_visit.subject) + visit_form.fields['subject'].widget.attrs['readonly'] = True + visit_finished = displayed_visit.is_finished visit_id = displayed_visit.id study_subject = displayed_visit.subject @@ -95,18 +99,28 @@ def visit_mark(request, id, as_what): def visit_add(request, subject_id=-1): + subjects = StudySubject.objects.filter(id=subject_id) + subject = None + if len(subjects) > 0: + subject = subjects[0] + if Visit.objects.filter(subject=subject, is_finished=False).count() > 0: + messages.add_message(request, messages.WARNING, 'The subject has unfinished visits, please, finish them before adding new visits.') + return redirect('web.views.subject_visit_details', id=subject_id) + if request.method == 'POST': form = VisitAddForm(request.POST, request.FILES) args = {'form': form} + if request.POST['subject'] != subject_id: + messages.add_message(request, messages.WARNING, u'The subject is invalid. Must be {}'.format(subject)) + return wrap_response(request, 'visits/add.html', args) if form.is_valid(): visit = form.save() return redirect('web.views.visit_details', visit.id) else: - subjects = StudySubject.objects.filter(id=subject_id) - subject = None - if len(subjects) > 0: - subject = subjects[0] form = VisitAddForm(initial={'subject': subject}) + form.fields['subject'].choices = [(subject_id, subject)] + form.fields['subject'].initial = (subject_id, subject) + form.fields['subject'].widget.attrs['readonly'] = True args = {'form': form, 'default_visit_duration': subject.study.default_visit_duration_in_months} return wrap_response(request, 'visits/add.html', args)