From 0faff66dd30dc9e31a2a66be0edf6853eb693200 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 13 Dec 2017 11:19:18 +0100 Subject: [PATCH] contact attempt forms extracted to separate file --- smash/web/forms/__init__.py | 3 +- smash/web/forms/contact_attempt_forms.py | 49 ++++++++++++++++++++++++ smash/web/forms/forms.py | 45 +--------------------- smash/web/views/contact_attempt.py | 4 +- 4 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 smash/web/forms/contact_attempt_forms.py diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index ed536d27..6081d81e 100644 --- a/smash/web/forms/__init__.py +++ b/smash/web/forms/__init__.py @@ -1,7 +1,8 @@ from worker_form import WorkerForm from forms import VisitDetailForm, \ - VisitAddForm, ContactAttemptForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ + VisitAddForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ AvailabilityEditForm, HolidayAddForm +from contact_attempt_forms import ContactAttemptForm, ContactAttemptEditForm from appointment_form import AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm from study_subject_forms import StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm from subject_forms import SubjectAddForm, SubjectEditForm, SubjectDetailForm diff --git a/smash/web/forms/contact_attempt_forms.py b/smash/web/forms/contact_attempt_forms.py new file mode 100644 index 00000000..b91cd78c --- /dev/null +++ b/smash/web/forms/contact_attempt_forms.py @@ -0,0 +1,49 @@ +from django import forms +from django.forms import ModelForm + +from web.forms.forms import DATETIMEPICKER_DATE_ATTRS + +from web.models import ContactAttempt, Worker + + +class ContactAttemptForm(ModelForm): + datetime_when = forms.DateTimeField(label='When? (YYYY-MM-DD HH:MM)', + widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) + ) + + class Meta: + model = ContactAttempt + fields = '__all__' + + def __init__(self, *args, **kwargs): + user = kwargs.pop('user', None) + if user is None: + raise TypeError("User not defined") + self.user = Worker.get_by_user(user) + if self.user is None: + raise TypeError("Worker not defined for: " + user.username) + subject = kwargs.pop('subject', None) + super(ContactAttemptForm, self).__init__(*args, **kwargs) + self.fields['subject'].initial = subject.id + self.fields['subject'].disabled = True + self.fields['worker'].initial = self.user + + +class ContactAttemptEditForm(ModelForm): + datetime_when = forms.DateTimeField(label='When? (YYYY-MM-DD HH:MM)', + widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) + ) + + class Meta: + model = ContactAttempt + fields = '__all__' + + def __init__(self, *args, **kwargs): + user = kwargs.pop('user', None) + if user is None: + raise TypeError("User not defined") + self.user = Worker.get_by_user(user) + if self.user is None: + raise TypeError("Worker not defined for: " + user.username) + super(ContactAttemptEditForm, self).__init__(*args, **kwargs) + self.fields['subject'].disabled = True \ No newline at end of file diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py index 4774526f..d50b2d9e 100644 --- a/smash/web/forms/forms.py +++ b/smash/web/forms/forms.py @@ -5,7 +5,7 @@ from django import forms from django.forms import ModelForm, Form from django.utils.dates import MONTHS -from web.models import StudySubject, Worker, Visit, AppointmentType, ContactAttempt, Availability, Holiday +from web.models import StudySubject, Worker, Visit, AppointmentType, Availability, Holiday from web.models.constants import SUBJECT_TYPE_CHOICES """ @@ -88,49 +88,6 @@ class VisitAddForm(ModelForm): self.add_error('datetime_end', "End date must be after start date") -class ContactAttemptForm(ModelForm): - datetime_when = forms.DateTimeField(label='When? (YYYY-MM-DD HH:MM)', - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) - ) - - class Meta: - model = ContactAttempt - fields = '__all__' - - def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - if user is None: - raise TypeError("User not defined") - self.user = Worker.get_by_user(user) - if self.user is None: - raise TypeError("Worker not defined for: " + user.username) - subject = kwargs.pop('subject', None) - super(ContactAttemptForm, self).__init__(*args, **kwargs) - self.fields['subject'].initial = subject.id - self.fields['subject'].disabled = True - self.fields['worker'].initial = self.user - - -class ContactAttemptEditForm(ModelForm): - datetime_when = forms.DateTimeField(label='When? (YYYY-MM-DD HH:MM)', - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) - ) - - class Meta: - model = ContactAttempt - fields = '__all__' - - def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - if user is None: - raise TypeError("User not defined") - self.user = Worker.get_by_user(user) - if self.user is None: - raise TypeError("Worker not defined for: " + user.username) - super(ContactAttemptEditForm, self).__init__(*args, **kwargs) - self.fields['subject'].disabled = True - - class KitRequestForm(Form): start_date = forms.DateField(label="From date", widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"), diff --git a/smash/web/views/contact_attempt.py b/smash/web/views/contact_attempt.py index 6694bc41..f4e7c14a 100644 --- a/smash/web/views/contact_attempt.py +++ b/smash/web/views/contact_attempt.py @@ -1,8 +1,8 @@ from django.shortcuts import redirect, get_object_or_404 +from web.forms import ContactAttemptForm, ContactAttemptEditForm +from web.models import StudySubject, ContactAttempt from . import wrap_response -from ..forms import ContactAttemptForm, ContactAttemptEditForm -from ..models import StudySubject, ContactAttempt def contact_add(request, subject_id): -- GitLab