From bf75dbbd3aca6aadcb36424da9768a070a64e272 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 13 Dec 2017 10:53:15 +0100 Subject: [PATCH] common functionality between forms extracted --- smash/web/forms/appointment_form.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/smash/web/forms/appointment_form.py b/smash/web/forms/appointment_form.py index 40038af8..f5be3a8e 100644 --- a/smash/web/forms/appointment_form.py +++ b/smash/web/forms/appointment_form.py @@ -8,26 +8,24 @@ from web.models import Appointment, Worker, AppointmentTypeLink, AppointmentType from web.views.notifications import get_filter_locations -class AppointmentDetailForm(ModelForm): +class AppointmentForm(ModelForm): + datetime_when = forms.DateTimeField(label='Appointment on', + widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) + ) + + +class AppointmentDetailForm(AppointmentForm): class Meta: model = Appointment fields = '__all__' - datetime_when = forms.DateTimeField(label='Appointment on (YYYY-MM-DD HH:MM)', - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) - ) - -class AppointmentEditForm(ModelForm): +class AppointmentEditForm(AppointmentForm): class Meta: model = Appointment fields = '__all__' exclude = ['appointment_types'] - datetime_when = forms.DateTimeField(label='Appointment on (YYYY-MM-DD HH:MM)', - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) - ) - def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) if user is None: @@ -87,15 +85,11 @@ class AppointmentEditForm(ModelForm): return appointment -class AppointmentAddForm(ModelForm): +class AppointmentAddForm(AppointmentForm): class Meta: model = Appointment exclude = ['status', 'appointment_types'] - datetime_when = forms.DateTimeField(label='Appointment on (YYYY-MM-DD HH:MM)', - widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) - ) - def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) if user is None: @@ -132,4 +126,4 @@ class AppointmentAddForm(ModelForm): for appointment_type in appointment_types: appointment_type_link = AppointmentTypeLink(appointment=appointment, appointment_type=appointment_type) appointment_type_link.save() - return appointment \ No newline at end of file + return appointment -- GitLab