Skip to content
Snippets Groups Projects
Commit d1c934aa authored by Valentin Groues's avatar Valentin Groues :eyes:
Browse files

display appointment status as select - #69

parent 66426b81
No related branches found
No related tags found
1 merge request!23display appointment status as select field - #69
Pipeline #
......@@ -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']
......
......@@ -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
)
......
......@@ -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 -->
......
......@@ -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)
......@@ -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)
......@@ -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'),
......
# 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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment