From 56b55712fe7849b97b6d64c84a998f85496fef5f Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 6 Sep 2017 11:54:47 +0200
Subject: [PATCH] when editing/adding appointment only locations and workers
 assigned to worker location are visible, workers are sorted alphabitecally,

---
 smash/web/forms.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/smash/web/forms.py b/smash/web/forms.py
index 66f6a689..982f312e 100644
--- a/smash/web/forms.py
+++ b/smash/web/forms.py
@@ -8,6 +8,7 @@ from django.utils.dates import MONTHS
 from models import Subject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, AppointmentTypeLink, \
     Availability, Holiday
 from models.constants import SUBJECT_TYPE_CHOICES, SCREENING_NUMBER_PREFIXES_FOR_TYPE
+from views.notifications import get_filter_locations
 
 """
 Possible redundancy, but if need arises, contents of forms can be easily customized
@@ -227,6 +228,9 @@ class AppointmentEditForm(ModelForm):
                                                                              queryset=AppointmentType.objects.all(),
                                                                              initial=initial_appointment_types)
         self.fields = fields
+        self.fields['worker_assigned'].queryset = Worker.objects.filter(
+            locations__in=get_filter_locations(self.user)).distinct().order_by('first_name', 'last_name')
+        self.fields['location'].queryset = get_filter_locations(self.user)
 
     def clean_location(self):
         location = self.cleaned_data['location']
@@ -273,6 +277,9 @@ class AppointmentAddForm(ModelForm):
                                                                              queryset=AppointmentType.objects.all(),
                                                                              )
         self.fields = fields
+        self.fields['worker_assigned'].queryset = Worker.objects.filter(
+            locations__in=get_filter_locations(self.user)).distinct().order_by('first_name', 'last_name')
+        self.fields['location'].queryset = get_filter_locations(self.user)
 
     def clean_location(self):
         location = self.cleaned_data['location']
-- 
GitLab