diff --git a/smash/web/api_urls.py b/smash/web/api_urls.py index 5f8a865ff9c2e8dfe6a47ceedad30ac40421f246..1efb028f94a31f4d4c27d32a536c4a4d88d7d65e 100644 --- a/smash/web/api_urls.py +++ b/smash/web/api_urls.py @@ -15,15 +15,15 @@ Including another URLconf """ from django.conf.urls import url -from web import api_views +from web.api_views import worker, location, subject, appointment_type urlpatterns = [ - url(r'^cities$', api_views.cities, name='web.api.cities'), - url(r'^countries$', api_views.countries, name='web.api.countries'), - url(r'^specializations$', api_views.specializations, name='web.api.specializations'), - url(r'^units$', api_views.units, name='web.api.units'), - url(r'^locations$', api_views.locations, name='web.api.locations'), - url(r'^referrals$', api_views.referrals, name='web.api.referrals'), - url(r'^appointment_types$', api_views.appointment_types, name='web.api.appointment_types'), - url(r'^subjects/(?P<type>[A-z]+)$', api_views.subjects, name='web.api.subjects'), + url(r'^cities$', subject.cities, name='web.api.cities'), + url(r'^countries$', subject.countries, name='web.api.countries'), + url(r'^specializations$', worker.specializations, name='web.api.specializations'), + url(r'^units$', worker.units, name='web.api.units'), + url(r'^locations$', location.locations, name='web.api.locations'), + url(r'^referrals$', subject.referrals, name='web.api.referrals'), + url(r'^appointment_types$', appointment_type.appointment_types, name='web.api.appointment_types'), + url(r'^subjects/(?P<type>[A-z]+)$', subject.subjects, name='web.api.subjects'), ] diff --git a/smash/web/api_views/__init__.py b/smash/web/api_views/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e23cf4209db9249f6a3c07942770e0f89fee5a1c --- /dev/null +++ b/smash/web/api_views/__init__.py @@ -0,0 +1,6 @@ +# coding=utf-8 + +import appointment_type +import location +import subject +import worker diff --git a/smash/web/api_views/appointment_type.py b/smash/web/api_views/appointment_type.py new file mode 100644 index 0000000000000000000000000000000000000000..66f9af836adc5cd2f17cbd1a35cbd974fc6fa840 --- /dev/null +++ b/smash/web/api_views/appointment_type.py @@ -0,0 +1,20 @@ +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse + +from web.models import AppointmentType + + +@login_required +def appointment_types(request): + appointments = AppointmentType.objects.filter().all() + result = [] + for appointment in appointments: + result.append({ + "id": appointment.id, + "type": appointment.code, + "default_duration": appointment.default_duration, + "can_be_parallelized": appointment.can_be_parallelized, + }) + return JsonResponse({ + "appointment_types": result + }) diff --git a/smash/web/api_views/location.py b/smash/web/api_views/location.py new file mode 100644 index 0000000000000000000000000000000000000000..d5da64abfea495e4340409fb87012254bcf46e99 --- /dev/null +++ b/smash/web/api_views/location.py @@ -0,0 +1,15 @@ +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse + +from web.models import Location + + +@login_required +def locations(request): + locations = Location.objects.all() + data = [] + for location in locations: + data.append({"id": location.id, "name": location.name}) + return JsonResponse({ + "locations": data + }) diff --git a/smash/web/api_views.py b/smash/web/api_views/subject.py similarity index 79% rename from smash/web/api_views.py rename to smash/web/api_views/subject.py index 1d56a1fd720ecab3f7bc55077119bc6ce9490291..9368d26c2cfbdd89c16876695b29501fc8e26469 100644 --- a/smash/web/api_views.py +++ b/smash/web/api_views/subject.py @@ -1,10 +1,10 @@ from django.contrib.auth.decorators import login_required from django.http import JsonResponse -from models import Subject, Worker, AppointmentType, Location -from views import e500_error -from views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT -from views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder +from web.models import Subject +from web.views import e500_error +from web.views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder +from web.views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT @login_required @@ -15,17 +15,6 @@ def cities(request): }) -@login_required -def locations(request): - locations = Location.objects.all() - data = [] - for location in locations: - data.append({"id": location.id, "name": location.name}) - return JsonResponse({ - "locations": data - }) - - @login_required def countries(request): X = Subject.objects.filter(country__isnull=False).values_list('country').distinct() @@ -42,22 +31,6 @@ def referrals(request): }) -@login_required -def specializations(request): - X = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct() - return JsonResponse({ - "specializations": [x[0] for x in X] - }) - - -@login_required -def units(request): - X = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct() - return JsonResponse({ - "units": [x[0] for x in X] - }) - - @login_required def get_subjects(request, type): if type == SUBJECT_LIST_GENERIC: @@ -170,6 +143,7 @@ def subjects(request, type): except: return e500_error(request) + def get_yes_no(val): if val: return "YES" @@ -194,19 +168,3 @@ def serialize_subject(subject): "id": subject.id, } return result - - -@login_required -def appointment_types(request): - appointments = AppointmentType.objects.filter().all() - result = [] - for appointment in appointments: - result.append({ - "id": appointment.id, - "type": appointment.code, - "default_duration": appointment.default_duration, - "can_be_parallelized": appointment.can_be_parallelized, - }) - return JsonResponse({ - "appointment_types": result - }) diff --git a/smash/web/api_views/worker.py b/smash/web/api_views/worker.py new file mode 100644 index 0000000000000000000000000000000000000000..3c141e25dd9e32e08d8a2523b4804a2e03f726a7 --- /dev/null +++ b/smash/web/api_views/worker.py @@ -0,0 +1,20 @@ +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse + +from web.models import Worker + + +@login_required +def specializations(request): + X = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct() + return JsonResponse({ + "specializations": [x[0] for x in X] + }) + + +@login_required +def units(request): + X = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct() + return JsonResponse({ + "units": [x[0] for x in X] + }) diff --git a/smash/web/tests/test_api.py b/smash/web/tests/test_api.py index 762001b13da911d651779e672295d8af52313e7a..b90f1c354301eaa6b283b26bebbd09e11acc001c 100644 --- a/smash/web/tests/test_api.py +++ b/smash/web/tests/test_api.py @@ -9,7 +9,7 @@ from django.urls import reverse from web.tests.functions import create_subject, create_worker, create_appointment_type, create_location, \ create_get_suffix from web.views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT -from web.api_views import get_subjects_order, get_subjects_filtered, serialize_subject +from web.api_views.subject import get_subjects_order, get_subjects_filtered, serialize_subject from web.models import Subject