diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..41432b74e56c6ac250f4f182d9654a39f6f7f772 --- /dev/null +++ b/smash/web/forms/__init__.py @@ -0,0 +1,11 @@ +from forms import WorkerAddForm, \ + WorkerEditForm, AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, \ + ContactAttemptForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ + AvailabilityEditForm, HolidayAddForm +from study_subject_forms import StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm +from subject_forms import SubjectAddForm, SubjectEditForm, SubjectDetailForm + +__all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, WorkerAddForm, WorkerEditForm, + AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, + ContactAttemptForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, + AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm] diff --git a/smash/web/forms.py b/smash/web/forms/forms.py similarity index 63% rename from smash/web/forms.py rename to smash/web/forms/forms.py index 2b50d8ba57e22de782dde8cbb113038cb629c391..76b196785782e284bc84f33cb71cf26669600908 100644 --- a/smash/web/forms.py +++ b/smash/web/forms/forms.py @@ -1,17 +1,14 @@ import datetime import logging -import re from collections import OrderedDict from django import forms from django.forms import ModelForm, Form from django.utils.dates import MONTHS -from models import Study, StudyColumns -from web.models import Subject, StudySubject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, \ - AppointmentTypeLink, \ +from web.models import StudySubject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, AppointmentTypeLink, \ Availability, Holiday -from web.models.constants import SUBJECT_TYPE_CHOICES, SCREENING_NUMBER_PREFIXES_FOR_TYPE, COUNTRY_OTHER_ID +from web.models.constants import SUBJECT_TYPE_CHOICES from web.views.notifications import get_filter_locations """ @@ -42,38 +39,6 @@ APPOINTMENT_TYPES_FIELD_POSITION = 1 logger = logging.getLogger(__name__) -def validate_subject_nd_number(self, cleaned_data): - if self.study.columns.nd_number: - nd_number = cleaned_data['nd_number'] - if nd_number != "": - if re.match('ND[0-9][0-9][0-9][0-9]', nd_number) is None: - self.add_error('nd_number', "Invalid ND number") - else: - subjects_from_db = StudySubject.objects.filter(nd_number=nd_number, study=self.study) - if subjects_from_db: - if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): - self.add_error('nd_number', "ND number already in use") - - -def validate_subject_country(self, cleaned_data): - if cleaned_data['country'].id == COUNTRY_OTHER_ID: - self.add_error('country', "Select valid country") - - -def validate_subject_resign_reason(self, cleaned_data): - if cleaned_data['resigned'] and cleaned_data['resign_reason'] == '': - self.add_error('resign_reason', "Resign reason cannot be empty") - - -def validate_subject_mpower_number(self, cleaned_data): - if self.study.columns.mpower_id: - if cleaned_data['mpower_id'] != "": - subjects_from_db = StudySubject.objects.filter(mpower_id=cleaned_data['mpower_id']) - if subjects_from_db: - if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): - self.add_error('mpower_id', "mPower number already in use") - - def get_worker_from_args(kwargs): user = kwargs.pop('user', None) if user is None: @@ -84,182 +49,6 @@ def get_worker_from_args(kwargs): return result -def get_study_from_args(kwargs): - study = kwargs.pop('study', None) - if study is None: - raise TypeError("Study not defined") - return study - - -def prepare_study_subject_fields(fields, study): - if study.columns.default_location: - fields['default_location'].required = True - else: - del fields['default_location'] - - if study.columns.type: - fields['type'].required = True - else: - del fields['type'] - - if not study.columns.nd_number: - del fields['nd_number'] - - if not study.columns.datetime_contact_reminder: - del fields['datetime_contact_reminder'] - - if not study.columns.postponed: - del fields['postponed'] - - if not study.columns.flying_team: - del fields['flying_team'] - - if not study.columns.mpower_id: - del fields['mpower_id'] - - if not study.columns.comments: - del fields['comments'] - - if not study.columns.referral: - del fields['referral'] - - if not study.columns.diagnosis: - del fields['diagnosis'] - - if not study.columns.year_of_diagnosis: - del fields['year_of_diagnosis'] - - if not study.columns.information_sent: - del fields['information_sent'] - - if not study.columns.pd_in_family: - del fields['pd_in_family'] - - if not study.columns.resigned and 'resigned' in fields: - del fields['resigned'] - - if not study.columns.resign_reason and 'resign_reason' in fields: - del fields['resign_reason'] - - -def validate_subject_screening_number(self, cleaned_data): - if self.study.columns.resign_reason: - subjects_from_db = StudySubject.objects.filter(screening_number=cleaned_data["screening_number"], - study=self.study) - if len(subjects_from_db) > 0: - self.add_error('screening_number', "Screening number already in use") - - -class StudySubjectAddForm(ModelForm): - datetime_contact_reminder = forms.DateTimeField(label="Contact on", - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), - required=False - ) - - class Meta: - model = StudySubject - fields = '__all__' - exclude = ['resigned', 'resign_reason'] - - def __init__(self, *args, **kwargs): - self.user = get_worker_from_args(kwargs) - self.study = get_study_from_args(kwargs) - - super(ModelForm, self).__init__(*args, **kwargs) - prepare_study_subject_fields(fields=self.fields, study=self.study) - - def save(self, commit=True): - self.instance.study_id = self.study.id - return super(ModelForm, self).save(commit) - - def build_screening_number(self, cleaned_data): - screening_number = cleaned_data.get('screening_number', None) - if not screening_number: - prefix_screening_number = self.get_prefix_screening_number() - if prefix_screening_number is not None: - screening_number = get_new_screening_number(prefix_screening_number) - return screening_number - - def clean(self): - cleaned_data = super(StudySubjectAddForm, self).clean() - screening_number = self.build_screening_number(cleaned_data) - if screening_number is not None and self.study.columns.screening_number: - cleaned_data['screening_number'] = screening_number - validate_subject_screening_number(self, cleaned_data) - validate_subject_nd_number(self, cleaned_data) - validate_subject_mpower_number(self, cleaned_data) - return cleaned_data - - def get_prefix_screening_number(self): - default_location = self.cleaned_data.get('default_location', None) - screening_number_prefix = None - if default_location is not None and default_location.prefix: - screening_number_prefix = default_location.prefix - else: - subject_type = self.cleaned_data.get('type', None) - if subject_type is not None: - screening_number_prefix = SCREENING_NUMBER_PREFIXES_FOR_TYPE[subject_type] - if screening_number_prefix is None: - return None - prefix_screening_number = screening_number_prefix + "-" - return prefix_screening_number - - -def get_new_screening_number(screening_number_prefix): - result_number = 0 - subjects = StudySubject.objects.filter(screening_number__contains=screening_number_prefix) - for subject in subjects: - screening_numbers = subject.screening_number.split(";") - for screening_number in screening_numbers: - screening_number = screening_number.strip() - if screening_number.startswith(screening_number_prefix): - number = screening_number[len(screening_number_prefix):] - try: - result_number = max(result_number, int(number)) - except ValueError: - pass - - return screening_number_prefix + str(result_number + 1).zfill(3) - - -class StudySubjectDetailForm(ModelForm): - class Meta: - model = StudySubject - fields = '__all__' - - -class StudySubjectEditForm(ModelForm): - datetime_contact_reminder = forms.DateTimeField(label="Contact on", - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), - required=False - ) - - def __init__(self, *args, **kwargs): - was_resigned = kwargs.get('was_resigned', False) - if 'was_resigned' in kwargs: - kwargs.pop('was_resigned') - super(StudySubjectEditForm, self).__init__(*args, **kwargs) - instance = getattr(self, 'instance', None) - if instance and instance.id: - self.fields['screening_number'].widget.attrs['readonly'] = True - if instance and instance.study_id: - self.study = Study.objects.filter(id=instance.study_id)[0] - else: - self.study = Study(columns=StudyColumns()) - - if was_resigned: - self.fields['resigned'].disabled = True - - def clean(self): - validate_subject_nd_number(self, self.cleaned_data) - validate_subject_mpower_number(self, self.cleaned_data) - validate_subject_resign_reason(self, self.cleaned_data) - - class Meta: - model = StudySubject - fields = '__all__' - - class WorkerAddForm(ModelForm): class Meta: model = Worker @@ -596,48 +385,3 @@ class HolidayAddForm(ModelForm): availabilities = worker.availability_set.all() for availability in availabilities: validate_availability_conflict(self, self.cleaned_data, availability) - - -class SubjectAddForm(ModelForm): - date_born = forms.DateField(label="Date of birth", - widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"), - required=False - ) - - class Meta: - model = Subject - fields = '__all__' - exclude = ['dead'] - - def clean(self): - cleaned_data = super(SubjectAddForm, self).clean() - validate_subject_country(self, cleaned_data) - return cleaned_data - - -class SubjectEditForm(ModelForm): - date_born = forms.DateField(label="Date of birth", - widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"), - required=False - ) - - def __init__(self, *args, **kwargs): - was_dead = kwargs.get('was_dead', False) - if 'was_dead' in kwargs: - kwargs.pop('was_dead') - super(SubjectEditForm, self).__init__(*args, **kwargs) - if was_dead: - self.fields['dead'].disabled = True - - def clean(self): - validate_subject_country(self, self.cleaned_data) - - class Meta: - model = Subject - fields = '__all__' - - -class SubjectDetailForm(ModelForm): - class Meta: - model = Subject - fields = '__all__' diff --git a/smash/web/forms/study_subject_forms.py b/smash/web/forms/study_subject_forms.py new file mode 100644 index 0000000000000000000000000000000000000000..93debc5b236001b458f1cef28af722f5914d60ea --- /dev/null +++ b/smash/web/forms/study_subject_forms.py @@ -0,0 +1,217 @@ +import re + +from django import forms +from django.forms import ModelForm + +from web.forms.forms import DATETIMEPICKER_DATE_ATTRS, get_worker_from_args +from web.models import StudySubject, Study, StudyColumns +from web.models.constants import SCREENING_NUMBER_PREFIXES_FOR_TYPE + + +class StudySubjectAddForm(ModelForm): + datetime_contact_reminder = forms.DateTimeField(label="Contact on", + widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), + required=False + ) + + class Meta: + model = StudySubject + fields = '__all__' + exclude = ['resigned', 'resign_reason'] + + def __init__(self, *args, **kwargs): + self.user = get_worker_from_args(kwargs) + self.study = get_study_from_args(kwargs) + + super(ModelForm, self).__init__(*args, **kwargs) + prepare_study_subject_fields(fields=self.fields, study=self.study) + + def save(self, commit=True): + self.instance.study_id = self.study.id + return super(ModelForm, self).save(commit) + + def build_screening_number(self, cleaned_data): + screening_number = cleaned_data.get('screening_number', None) + if not screening_number: + prefix_screening_number = self.get_prefix_screening_number() + if prefix_screening_number is not None: + screening_number = get_new_screening_number(prefix_screening_number) + return screening_number + + def clean(self): + cleaned_data = super(StudySubjectAddForm, self).clean() + screening_number = self.build_screening_number(cleaned_data) + if screening_number is not None and self.study.columns.screening_number: + cleaned_data['screening_number'] = screening_number + validate_subject_screening_number(self, cleaned_data) + validate_subject_nd_number(self, cleaned_data) + validate_subject_mpower_number(self, cleaned_data) + return cleaned_data + + def get_prefix_screening_number(self): + default_location = self.cleaned_data.get('default_location', None) + screening_number_prefix = None + if default_location is not None and default_location.prefix: + screening_number_prefix = default_location.prefix + else: + subject_type = self.cleaned_data.get('type', None) + if subject_type is not None: + screening_number_prefix = SCREENING_NUMBER_PREFIXES_FOR_TYPE[subject_type] + if screening_number_prefix is None: + return None + prefix_screening_number = screening_number_prefix + "-" + return prefix_screening_number + + +def get_new_screening_number(screening_number_prefix): + result_number = 0 + subjects = StudySubject.objects.filter(screening_number__contains=screening_number_prefix) + for subject in subjects: + screening_numbers = subject.screening_number.split(";") + for screening_number in screening_numbers: + screening_number = screening_number.strip() + if screening_number.startswith(screening_number_prefix): + number = screening_number[len(screening_number_prefix):] + try: + result_number = max(result_number, int(number)) + except ValueError: + pass + + return screening_number_prefix + str(result_number + 1).zfill(3) + + +class StudySubjectDetailForm(ModelForm): + class Meta: + model = StudySubject + fields = '__all__' + + +class StudySubjectEditForm(ModelForm): + datetime_contact_reminder = forms.DateTimeField(label="Contact on", + widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), + required=False + ) + + def __init__(self, *args, **kwargs): + was_resigned = kwargs.get('was_resigned', False) + if 'was_resigned' in kwargs: + kwargs.pop('was_resigned') + super(StudySubjectEditForm, self).__init__(*args, **kwargs) + instance = getattr(self, 'instance', None) + if instance and instance.id: + self.fields['screening_number'].widget.attrs['readonly'] = True + if instance and instance.study_id: + self.study = Study.objects.filter(id=instance.study_id)[0] + else: + self.study = Study(columns=StudyColumns()) + + if was_resigned: + self.fields['resigned'].disabled = True + + prepare_study_subject_fields(fields=self.fields, study=self.study) + + def clean(self): + validate_subject_nd_number(self, self.cleaned_data) + validate_subject_mpower_number(self, self.cleaned_data) + validate_subject_resign_reason(self, self.cleaned_data) + + class Meta: + model = StudySubject + fields = '__all__' + + +def get_study_from_args(kwargs): + study = kwargs.pop('study', None) + if study is None: + raise TypeError("Study not defined") + return study + + +def prepare_study_subject_fields(fields, study): + if study.columns.default_location: + fields['default_location'].required = True + else: + del fields['default_location'] + + if study.columns.type: + fields['type'].required = True + else: + del fields['type'] + + if not study.columns.screening_number: + del fields['screening_number'] + + if not study.columns.nd_number: + del fields['nd_number'] + + if not study.columns.datetime_contact_reminder: + del fields['datetime_contact_reminder'] + + if not study.columns.postponed: + del fields['postponed'] + + if not study.columns.flying_team: + del fields['flying_team'] + + if not study.columns.mpower_id: + del fields['mpower_id'] + + if not study.columns.comments: + del fields['comments'] + + if not study.columns.referral: + del fields['referral'] + + if not study.columns.diagnosis: + del fields['diagnosis'] + + if not study.columns.year_of_diagnosis: + del fields['year_of_diagnosis'] + + if not study.columns.information_sent: + del fields['information_sent'] + + if not study.columns.pd_in_family: + del fields['pd_in_family'] + + if not study.columns.resigned and 'resigned' in fields: + del fields['resigned'] + + if not study.columns.resign_reason and 'resign_reason' in fields: + del fields['resign_reason'] + + +def validate_subject_screening_number(self, cleaned_data): + if self.study.columns.resign_reason: + subjects_from_db = StudySubject.objects.filter(screening_number=cleaned_data["screening_number"], + study=self.study) + if len(subjects_from_db) > 0: + self.add_error('screening_number', "Screening number already in use") + + +def validate_subject_nd_number(self, cleaned_data): + if self.study.columns.nd_number: + nd_number = cleaned_data['nd_number'] + if nd_number != "": + if re.match('ND[0-9][0-9][0-9][0-9]', nd_number) is None: + self.add_error('nd_number', "Invalid ND number") + else: + subjects_from_db = StudySubject.objects.filter(nd_number=nd_number, study=self.study) + if subjects_from_db: + if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): + self.add_error('nd_number', "ND number already in use") + + +def validate_subject_resign_reason(self, cleaned_data): + if self.study.columns.resigned and self.study.columns.resign_reason: + if cleaned_data['resigned'] and cleaned_data['resign_reason'] == '': + self.add_error('resign_reason', "Resign reason cannot be empty") + + +def validate_subject_mpower_number(self, cleaned_data): + if self.study.columns.mpower_id: + if cleaned_data['mpower_id'] != "": + subjects_from_db = StudySubject.objects.filter(mpower_id=cleaned_data['mpower_id']) + if subjects_from_db: + if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): + self.add_error('mpower_id', "mPower number already in use") diff --git a/smash/web/forms/subject_forms.py b/smash/web/forms/subject_forms.py new file mode 100644 index 0000000000000000000000000000000000000000..008ab88238188f249a20755f215103846a57f11c --- /dev/null +++ b/smash/web/forms/subject_forms.py @@ -0,0 +1,56 @@ +from django import forms +from django.forms import ModelForm + +from web.models import Subject +from web.models.constants import COUNTRY_OTHER_ID +from web.forms.forms import DATEPICKER_DATE_ATTRS + + +def validate_subject_country(self, cleaned_data): + if cleaned_data['country'].id == COUNTRY_OTHER_ID: + self.add_error('country', "Select valid country") + + +class SubjectAddForm(ModelForm): + date_born = forms.DateField(label="Date of birth", + widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"), + required=False + ) + + class Meta: + model = Subject + fields = '__all__' + exclude = ['dead'] + + def clean(self): + cleaned_data = super(SubjectAddForm, self).clean() + validate_subject_country(self, cleaned_data) + return cleaned_data + + +class SubjectEditForm(ModelForm): + date_born = forms.DateField(label="Date of birth", + widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"), + required=False + ) + + def __init__(self, *args, **kwargs): + was_dead = kwargs.get('was_dead', False) + if 'was_dead' in kwargs: + kwargs.pop('was_dead') + super(SubjectEditForm, self).__init__(*args, **kwargs) + if was_dead: + self.fields['dead'].disabled = True + + def clean(self): + validate_subject_country(self, self.cleaned_data) + + class Meta: + model = Subject + fields = '__all__' + + +class SubjectDetailForm(ModelForm): + class Meta: + model = Subject + fields = '__all__' diff --git a/smash/web/models/configuration_item.py b/smash/web/models/configuration_item.py index 37db0488bb25d9b370e567f3acc5445d7ebe2a8e..cdaa6fbbabdabbd8c082e1ed41f3eaeb6c736ce8 100644 --- a/smash/web/models/configuration_item.py +++ b/smash/web/models/configuration_item.py @@ -8,6 +8,9 @@ from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE, class ConfigurationItem(models.Model): + class Meta: + app_label = 'web' + type = models.CharField(max_length=50, verbose_name='Type', editable=False diff --git a/smash/web/tests/forms/test_StudySubjectAddForm.py b/smash/web/tests/forms/test_StudySubjectAddForm.py index 6efd5c311d50663df0bd3374fdd484a6b4d1314f..2b71231dd637a4171325d50c10de614907b154d4 100644 --- a/smash/web/tests/forms/test_StudySubjectAddForm.py +++ b/smash/web/tests/forms/test_StudySubjectAddForm.py @@ -1,6 +1,7 @@ import logging -from web.forms import StudySubjectAddForm, get_new_screening_number +from web.forms.study_subject_forms import get_new_screening_number +from web.forms import StudySubjectAddForm from web.models.constants import SUBJECT_TYPE_CHOICES_CONTROL from web.tests import LoggedInWithWorkerTestCase from web.tests.functions import create_study_subject, create_subject, get_test_study, create_empty_study diff --git a/smash/web/tests/view/test_appointments.py b/smash/web/tests/view/test_appointments.py index 97f26eb5c7abae165eb7f89d2766c299f9245e35..c187af91ed8d55d33f861d6f956cb998e3663946 100644 --- a/smash/web/tests/view/test_appointments.py +++ b/smash/web/tests/view/test_appointments.py @@ -3,12 +3,11 @@ import logging from django.urls import reverse -from web.forms import AppointmentEditForm, StudySubjectEditForm, SubjectEditForm +from web.forms import AppointmentEditForm, SubjectEditForm, StudySubjectEditForm from web.models import Appointment, StudySubject from web.tests import LoggedInTestCase from web.tests.functions import create_study_subject, create_visit, create_appointment, create_worker, \ - create_flying_team, \ - format_form_field + create_flying_team, format_form_field from web.views.notifications import get_today_midnight_date logger = logging.getLogger(__name__) diff --git a/smash/web/tests/view/test_subjects.py b/smash/web/tests/view/test_subjects.py index 7d47368cf3555ca41201b74a0e29a785cf7d69ec..cf9d49777f4ebd58988db0c48c3e8df2d6eb509e 100644 --- a/smash/web/tests/view/test_subjects.py +++ b/smash/web/tests/view/test_subjects.py @@ -3,7 +3,7 @@ import logging from django.urls import reverse -from web.forms import StudySubjectAddForm, StudySubjectEditForm, SubjectEditForm, SubjectAddForm +from web.forms import SubjectAddForm, SubjectEditForm, StudySubjectAddForm, StudySubjectEditForm from web.models import MailTemplate, StudySubject from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, SUBJECT_TYPE_CHOICES_PATIENT, \ COUNTRY_AFGHANISTAN_ID, COUNTRY_OTHER_ID, MAIL_TEMPLATE_CONTEXT_SUBJECT diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index e7f08ea311fe1581c2c1363606c0842f11f572a2..938e713058cbd8ce402bf708122e81d489bfd728 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -7,8 +7,8 @@ from django.core.exceptions import ValidationError from django.shortcuts import get_object_or_404, redirect from . import wrap_response -from ..forms import AppointmentDetailForm, AppointmentAddForm, AppointmentEditForm, StudySubjectEditForm, \ - SubjectEditForm +from ..forms import AppointmentDetailForm, AppointmentAddForm, AppointmentEditForm, SubjectEditForm, \ + StudySubjectEditForm from ..models import Appointment, StudySubject, MailTemplate APPOINTMENT_LIST_GENERIC = "GENERIC" diff --git a/smash/web/views/subject.py b/smash/web/views/subject.py index 7542d73b9c497070bc82b3a6e58d21cb19347ee1..e12ba130aba71f0e5fca221dae809b68d0bb22ba 100644 --- a/smash/web/views/subject.py +++ b/smash/web/views/subject.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 StudySubjectAddForm, StudySubjectEditForm, VisitDetailForm, SubjectEditForm, SubjectAddForm +from ..forms import VisitDetailForm,SubjectAddForm, SubjectEditForm, StudySubjectAddForm, StudySubjectEditForm from ..models import StudySubject, MailTemplate, Worker, Study from ..models.constants import GLOBAL_STUDY_ID @@ -27,7 +27,8 @@ def subjects(request): def subject_add(request): study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0] if request.method == 'POST': - study_subject_form = StudySubjectAddForm(request.POST, request.FILES, prefix="study_subject", user=request.user, study=study) + study_subject_form = StudySubjectAddForm(request.POST, request.FILES, prefix="study_subject", user=request.user, + study=study) subject_form = SubjectAddForm(request.POST, request.FILES, prefix="subject") if study_subject_form.is_valid() and subject_form.is_valid(): @@ -79,7 +80,8 @@ def subject_edit(request, id): # check if subject was marked as dead or resigned if subject_form.cleaned_data['dead'] and not was_dead: study_subject.subject.mark_as_dead() - if study_subject_form.cleaned_data['resigned'] and not was_resigned: + if study_subject.study.columns.resigned \ + and study_subject_form.cleaned_data['resigned'] and not was_resigned: study_subject.mark_as_resigned() messages.success(request, "Modifications saved") if '_continue' in request.POST: diff --git a/smash/web/views/visit.py b/smash/web/views/visit.py index 253270a4afe020cb5efaaccbc9654a4c1882f4b6..0dd67c3b3f67cabb631f9b08ee00359081b1694a 100644 --- a/smash/web/views/visit.py +++ b/smash/web/views/visit.py @@ -7,7 +7,7 @@ from notifications import get_active_visits_with_missing_appointments, get_unfin get_approaching_visits_without_appointments, get_approaching_visits_for_mail_contact, get_exceeded_visits, \ waiting_for_appointment from . import wrap_response -from ..forms import VisitDetailForm, StudySubjectDetailForm, VisitAddForm, SubjectDetailForm +from ..forms import VisitDetailForm, VisitAddForm, SubjectDetailForm, StudySubjectDetailForm from ..models import Visit, Appointment, StudySubject, MailTemplate logger = logging.getLogger(__name__)