diff --git a/smash/web/api_views/appointment.py b/smash/web/api_views/appointment.py index 331c331c50b6cecc4f17070235448222c07d7dda..4951cbb738bfc7f8167ab43e8f88bab99dc99480 100644 --- a/smash/web/api_views/appointment.py +++ b/smash/web/api_views/appointment.py @@ -7,7 +7,6 @@ from django.urls import reverse from django.utils import timezone from web.models import Appointment -from web.views import e500_error from web.views.appointment import APPOINTMENT_LIST_GENERIC, APPOINTMENT_LIST_UNFINISHED, APPOINTMENT_LIST_APPROACHING from web.views.notifications import get_filter_locations, \ get_today_midnight_date, \ @@ -44,42 +43,38 @@ def get_appointments(request, type, min_date, max_date): @login_required def appointments(request, type): - try: - # id of the query from dataTable: https://datatables.net/manual/server-side - draw = int(request.GET.get("draw", "-1")) + # id of the query from dataTable: https://datatables.net/manual/server-side + draw = int(request.GET.get("draw", "-1")) - start = int(request.GET.get("start", "0")) - length = int(request.GET.get("length", "10")) + start = int(request.GET.get("start", "0")) + length = int(request.GET.get("length", "10")) - min_date = request.GET.get("start_date", None) - max_date = request.GET.get("end_date", None) + min_date = request.GET.get("start_date", None) + max_date = request.GET.get("end_date", None) - if min_date is not None: - length = 1000000000 + if min_date is not None: + length = 1000000000 - all_appointments = get_appointments(request, type, min_date, max_date) + all_appointments = get_appointments(request, type, min_date, max_date) - count = all_appointments.count() + count = all_appointments.count() - sliced_subjects = all_appointments[start:(start + length)] + sliced_subjects = all_appointments[start:(start + length)] - result_appointments = sliced_subjects + result_appointments = sliced_subjects - count_filtered = all_appointments.count() + count_filtered = all_appointments.count() - data = [] - for appointment in result_appointments: - data.append(serialize_appointment(appointment)) + data = [] + for appointment in result_appointments: + data.append(serialize_appointment(appointment)) - return JsonResponse({ - "draw": draw, - "recordsTotal": count, - "recordsFiltered": count_filtered, - "data": data, - }) - except: - logger.exception("Problem with getting appointments") - return e500_error(request) + return JsonResponse({ + "draw": draw, + "recordsTotal": count, + "recordsFiltered": count_filtered, + "data": data, + }) def serialize_appointment(appointment): @@ -94,11 +89,12 @@ def serialize_appointment(appointment): phone_numbers = ", ".join(filter(None, [study_subject.subject.phone_number, study_subject.subject.phone_number_2, study_subject.subject.phone_number_3])) - appointment_types = ", ".join([unicode(type) for type in appointment.appointment_types.all()]) + appointment_types = ", ".join( + [unicode(appointment_type) for appointment_type in appointment.appointment_types.all()]) else: title = appointment.comment - type = ", ".join([type.code for type in appointment.appointment_types.all()]) + appointment_type = ", ".join([appointment_type.code for appointment_type in appointment.appointment_types.all()]) time = "" if appointment.datetime_when is not None: time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M') @@ -118,7 +114,7 @@ def serialize_appointment(appointment): "screening_number": screening_number, "phone_number": phone_numbers, "appointment_types": appointment_types, - "type": type, + "type": appointment_type, "datetime_when": time, "datetime_until": until, "comment": appointment.comment, diff --git a/smash/web/static/js/appointment.js b/smash/web/static/js/appointment.js index a4d594bab159699c5a2c247589176075e5f788ad..65b3acf7c14b86c05b3ba3e9ed572920aa7820f0 100644 --- a/smash/web/static/js/appointment.js +++ b/smash/web/static/js/appointment.js @@ -208,7 +208,6 @@ function get_calendar_events_function(source, allow_url_redirection, day_headers } return function (start, end, timezone, callback) { if (day_headers !== undefined) { - console.log("XXXX"); $.ajax({ data: { start_date: start.format(), diff --git a/smash/web/tests/api_views/test_appointment.py b/smash/web/tests/api_views/test_appointment.py index 5074b3ddb061aa046631ae32b2b6b8f8135c23ab..0ca8000963246a9cd24a0977b2c0f5b34d5d402b 100644 --- a/smash/web/tests/api_views/test_appointment.py +++ b/smash/web/tests/api_views/test_appointment.py @@ -25,10 +25,6 @@ class TestAppointmentApi(TestCase): self.worker = create_worker(self.user) self.client.login(username=username, password=password) - def test_appointments_invalid(self): - response = self.client.get(reverse('web.api.appointments', kwargs={'type': "bla"})) - self.assertEqual(response.status_code, 500) - def test_appointments_valid(self): place = "Some new flying team location" name = "Piotrek"