diff --git a/smash/web/forms.py b/smash/web/forms.py index 5033f1a17bbe6bc25d2f637d828be90c010799c8..768a5e8fa550c2d30b7e0757e17e6e0b1427638c 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -146,7 +146,6 @@ 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/models/appointment.py b/smash/web/models/appointment.py index 62e42d9a1c242016e56a428c9c812a6ba69e45cd..bebf0265dd09b873abc9920bceb918e5d29df565 100644 --- a/smash/web/models/appointment.py +++ b/smash/web/models/appointment.py @@ -45,7 +45,8 @@ class Appointment(models.Model): verbose_name='Location', ) visit = models.ForeignKey(Visit, - verbose_name='Visit ID' + verbose_name='Visit ID', + editable=False, ) comment = models.TextField(max_length=1024, verbose_name='Comment', @@ -62,7 +63,6 @@ class Appointment(models.Model): status = models.CharField(max_length=20, choices=APPOINTMENT_STATUS_CHOICES.items(), verbose_name='Status', - editable=False, default=APPOINTMENT_STATUS_SCHEDULED ) diff --git a/smash/web/templates/appointments/edit.html b/smash/web/templates/appointments/edit.html index 24c4c735fb823bb911ebd78139d9e9a065b150be..d3a791917844e91ea074c3a4f978f7a1e2c3fb97 100644 --- a/smash/web/templates/appointments/edit.html +++ b/smash/web/templates/appointments/edit.html @@ -51,26 +51,10 @@ </div> {% if field.errors %} - <span class="help-block"> - {{ field.errors }} - </span> + <span class="help-block">{{ field.errors }}</span> {% endif %} </div> {% endfor %} - <div class="col-md-6 form-group"> - <label for="{# TODO #}" class="col-sm-4 control-label"> - Status: - </label> - <div class="btn-group-vertical col-sm-8"> - <label class="btn btn-primary">{{ appointment.status }}</label> - <a href="{% url 'web.views.appointment_mark' id 'finished' %}" - class="btn btn-warning btn-block">Mark as finished</a> - <a href="{% url 'web.views.appointment_mark' id 'cancelled' %}" - class="btn btn-warning btn-block">Mark as cancelled</a> - <a href="{% url 'web.views.appointment_mark' id 'no_show' %}" - class="btn btn-warning btn-block">Mark as no show</a> - </div> - </div> </div><!-- /.box-body --> diff --git a/smash/web/tests/test_AppointmentEditForm.py b/smash/web/tests/test_AppointmentEditForm.py index e4b9bee916d6acce768325ebc86d24e6ca30a253..d81a31bb363ce921b68dd6161fe45d37fe61b6a7 100644 --- a/smash/web/tests/test_AppointmentEditForm.py +++ b/smash/web/tests/test_AppointmentEditForm.py @@ -22,23 +22,23 @@ class AppointmentEditFormTests(TestCase): 'location': location.id, 'datetime_when': "2020-01-01", } - - 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.sample_data_with_status = self.sample_data + self.sample_data_with_status['status'] = 'NO_SHOW' + add_form = AppointmentAddForm(user=self.user, data=self.sample_data) + add_form.instance.visit_id = self.visit.id self.appointment = add_form.save() def test_validation(self): - form = AppointmentEditForm(user=self.user, data=self.sample_data) + form = AppointmentEditForm(user=self.user, data=self.sample_data_with_status) self.assertTrue(form.is_valid()) def test_no_visit_field(self): - form = AppointmentEditForm(user=self.user, data=self.sample_data) + form = AppointmentEditForm(user=self.user, data=self.sample_data_with_status) 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) + form = AppointmentEditForm(user=self.user, data=self.sample_data_with_status) self.assertFalse(form.is_valid()) self.assertTrue("location" in form.errors) diff --git a/smash/web/tests/test_view_appointments.py b/smash/web/tests/test_view_appointments.py index e92bb096b1c4fe7431c03527d0daefe83c9ca1f8..1cbbf13890a52f851d7907e364223ceed8f4874d 100644 --- a/smash/web/tests/test_view_appointments.py +++ b/smash/web/tests/test_view_appointments.py @@ -29,6 +29,7 @@ class AppointmentsViewTests(TestCase): appointment = create_appointment(visit, when=datetime.datetime.now()) create_worker(self.user, True) new_comment = 'new comment' + new_status = appointment.APPOINTMENT_STATUS_NO_SHOW new_last_name = "new last name" form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment") form_subject = SubjectEditForm(instance=subject, prefix="subject") @@ -40,6 +41,7 @@ class AppointmentsViewTests(TestCase): if value is not None: form_data['subject-{}'.format(key)] = value form_data["appointment-comment"] = new_comment + form_data["appointment-status"] = new_status form_data["subject-last_name"] = new_last_name response = self.client.post( reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) @@ -47,34 +49,5 @@ class AppointmentsViewTests(TestCase): updated_appointment = Appointment.objects.filter(id=appointment.id)[0] updated_subject = Subject.objects.filter(id=subject.id)[0] self.assertEqual(new_comment, updated_appointment.comment) + self.assertEqual(new_status, updated_appointment.status) self.assertEqual(new_last_name, updated_subject.last_name) - - def test_mark_as_finished(self): - subject = create_subject() - visit = create_visit(subject) - appointment = create_appointment(visit) - response = self.client.get( - reverse('web.views.appointment_mark', kwargs={'id': appointment.id, 'as_what': 'finished'})) - self.assertEqual(response.status_code, 302) - update_appointment = Appointment.objects.filter(id=appointment.id)[0] - self.assertEqual(update_appointment.status, Appointment.APPOINTMENT_STATUS_FINISHED) - - def test_mark_as_cancelled(self): - subject = create_subject() - visit = create_visit(subject) - appointment = create_appointment(visit) - response = self.client.get( - reverse('web.views.appointment_mark', kwargs={'id': appointment.id, 'as_what': 'cancelled'})) - self.assertEqual(response.status_code, 302) - update_appointment = Appointment.objects.filter(id=appointment.id)[0] - self.assertEqual(update_appointment.status, Appointment.APPOINTMENT_STATUS_CANCELLED) - - def test_mark_as_no_show(self): - subject = create_subject() - visit = create_visit(subject) - appointment = create_appointment(visit) - response = self.client.get( - reverse('web.views.appointment_mark', kwargs={'id': appointment.id, 'as_what': 'no_show'})) - self.assertEqual(response.status_code, 302) - update_appointment = Appointment.objects.filter(id=appointment.id)[0] - self.assertEqual(update_appointment.status, Appointment.APPOINTMENT_STATUS_NO_SHOW) diff --git a/smash/web/urls.py b/smash/web/urls.py index 0d0d0b6356aa8491e0119076ce6637bde3693adf..6392138cb655cb16ce445ab0f1511f12b6824431 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -25,13 +25,10 @@ urlpatterns = [ name='web.views.unfinished_appointments'), url(r'^appointments/details/(?P<id>\d+)$', views.appointment.appointment_details, name='web.views.appointment_details'), - url(r'^appointments/add/(?P<id>\d+)$', views.appointment.appointment_add, name='web.views.appointment_add'), + url(r'^appointments/add/(?P<visit_id>\d+)$', views.appointment.appointment_add, name='web.views.appointment_add'), url(r'^appointments/edit/(?P<id>\d+)$', views.appointment.appointment_edit, name='web.views.appointment_edit'), url(r'^appointments/edit_datetime/(?P<id>\d+)$', views.appointment.appointment_edit_datetime, name='web.views.appointment_edit_datetime'), - url(r'^appointments/mark/(?P<id>\d+)/(?P<as_what>[A-z]+)$', views.appointment.appointment_mark, - name='web.views.appointment_mark'), - url(r'^visits$', views.visit.visits, name='web.views.visits'), url(r'^visits/exceeded$', views.visit.exceeded_visits, name='web.views.exceeded_visits'), url(r'^visits/unfinished$', views.visit.unfinished_visits, name='web.views.unfinished_visits'), diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 471f33c293d3feb5a39e46127f18d9e6de7d946d..0f1380359af3acbc48f8b7dd08b5c72d1565dbf5 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -1,29 +1,15 @@ # coding=utf-8 -from django.forms import HiddenInput from django.shortcuts import get_object_or_404, redirect from notifications import get_today_midnight_date, get_filter_locations, get_calendar_full_appointments, \ get_unfinished_appointments -from . import e500_error, wrap_response +from . import wrap_response from ..forms import AppointmentDetailForm, AppointmentAddForm, AppointmentEditForm, SubjectEditForm from ..models import Appointment __author__ = 'Valentin Grouès' -def appointment_mark(request, id, as_what): - appointment = get_object_or_404(Appointment, id=id) - if as_what == 'finished': - appointment.mark_as_finished() - elif as_what == 'cancelled': - appointment.mark_as_cancelled() - elif as_what == 'no_show': - appointment.mark_as_no_show() - else: - return e500_error(request) - return redirect('web.views.visit_details', id=appointment.visit.id) - - def appointments(request): approaching_list = Appointment.objects.filter( datetime_when__gt=get_today_midnight_date(), @@ -56,20 +42,19 @@ def appointment_details(request, id): return wrap_response(request, 'appointments/details.html', {'form': form}) -def appointment_add(request, id): +def appointment_add(request, visit_id): full_list = get_calendar_full_appointments(request.user) if request.method == 'POST': form = AppointmentAddForm(request.POST, request.FILES, user=request.user) - form.fields['visit'].widget = HiddenInput() if form.is_valid(): + form.instance.visit_id = visit_id form.save() - return redirect('web.views.visit_details', id=id) + return redirect('web.views.visit_details', id=visit_id) else: - form = AppointmentAddForm(initial={'visit': id}, user=request.user) - form.fields['visit'].widget = HiddenInput() + form = AppointmentAddForm(user=request.user) return wrap_response(request, 'appointments/add.html', - {'form': form, 'visitID': id, 'full_appointment_list': full_list}) + {'form': form, 'visitID': visit_id, 'full_appointment_list': full_list}) def appointment_edit(request, id):