From 5e850f27e2dbb836adb652a99821824b5476f823 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 30 Mar 2017 16:38:22 +0200 Subject: [PATCH] api for list of locations --- smash/web/api_urls.py | 1 + smash/web/api_views.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/smash/web/api_urls.py b/smash/web/api_urls.py index 65db6f11..5f8a865f 100644 --- a/smash/web/api_urls.py +++ b/smash/web/api_urls.py @@ -22,6 +22,7 @@ urlpatterns = [ 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'), diff --git a/smash/web/api_views.py b/smash/web/api_views.py index 3fa93ecc..f84dc656 100644 --- a/smash/web/api_views.py +++ b/smash/web/api_views.py @@ -3,7 +3,7 @@ import json from django.contrib.auth.decorators import login_required from django.http import JsonResponse -from models import Subject, Worker, AppointmentType +from models import Subject, Worker, AppointmentType, Location from views.subject import SUBJECT_LIST_GENERIC @@ -15,6 +15,14 @@ def cities(request): }) +@login_required +def locations(request): + X = Location.objects.values_list('name').distinct() + return JsonResponse({ + "locations": [x[0] for x in X] + }) + + @login_required def countries(request): X = Subject.objects.filter(country__isnull=False).values_list('country').distinct() @@ -94,11 +102,11 @@ def get_subjects_filtered(subjects, filters): elif column == "screening_number": result = result.filter(screening_number__contains=value) elif column == "dead": - result = result.filter(dead=(value=="true")) + result = result.filter(dead=(value == "true")) elif column == "resigned": - result = result.filter(resigned=(value=="true")) + result = result.filter(resigned=(value == "true")) elif column == "postponed": - result = result.filter(postponed=(value=="true")) + result = result.filter(postponed=(value == "true")) else: print row # elif order_column == "default_location": -- GitLab