diff --git a/smash/web/forms.py b/smash/web/forms.py index d1b4f2b7afa452499322314ead0cb253cdaa9c95..35a319b8b2e49255efa9947ccc8c4682347f8d74 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -145,6 +145,7 @@ class AppointmentEditForm(ModelForm): raise TypeError("Worker not defined for: " + user.username) super(ModelForm, self).__init__(*args, **kwargs) + self.fields.pop('visit') def clean_location(self): location = self.cleaned_data['location'] diff --git a/smash/web/tests/test_AppointmentEditForm.py b/smash/web/tests/test_AppointmentEditForm.py index 23e816d981853a7a4c70f894c2f44f71bc38e7d2..e4b9bee916d6acce768325ebc86d24e6ca30a253 100644 --- a/smash/web/tests/test_AppointmentEditForm.py +++ b/smash/web/tests/test_AppointmentEditForm.py @@ -19,18 +19,23 @@ class AppointmentEditFormTests(TestCase): self.sample_data = {'first_name': 'name', 'length': '50', - 'visit': self.visit.id, 'location': location.id, 'datetime_when': "2020-01-01", } - add_form = AppointmentAddForm(user=self.user, data=self.sample_data) + self.sample_data_with_visit = self.sample_data + self.sample_data_with_visit['visit'] = self.visit.id + add_form = AppointmentAddForm(user=self.user, data=self.sample_data_with_visit) self.appointment = add_form.save() def test_validation(self): form = AppointmentEditForm(user=self.user, data=self.sample_data) self.assertTrue(form.is_valid()) + def test_no_visit_field(self): + form = AppointmentEditForm(user=self.user, data=self.sample_data) + self.assertNotIn('visit', form.fields) + def test_validation_invalid_location(self): self.sample_data['location'] = create_location(name="xxx").id form = AppointmentEditForm(user=self.user, data=self.sample_data) diff --git a/smash/web/views.py b/smash/web/views.py index a18ece4b4ae19e6526c51240afd9398b37a69cbf..989dd33c6190687c41bd808cadc8a6ae00fdd7be 100644 --- a/smash/web/views.py +++ b/smash/web/views.py @@ -717,11 +717,6 @@ def appointment_edit(request, id): if appointment_form.is_valid() and subject_form.is_valid(): appointment_form.save() subject_form.save() - - data = appointment_form.cleaned_data - vis = data['visit'] - get_object_or_404(Visit, id=vis.id) - return redirect(appointments) else: appointment_form = AppointmentEditForm(instance=the_appointment, user=request.user, prefix="appointment")