aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/organisations/models.py3
-rw-r--r--ctrack/organisations/tests/test_models.py11
-rw-r--r--ctrack/register/forms.py5
-rw-r--r--ctrack/register/tests/test_forms.py31
-rw-r--r--ctrack/register/tests/test_models.py2
-rw-r--r--ctrack/register/tests/test_views.py21
-rw-r--r--ctrack/register/urls.py3
-rw-r--r--ctrack/register/views.py9
8 files changed, 76 insertions, 9 deletions
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index f884d39..c7394e4 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -154,6 +154,9 @@ class Organisation(models.Model):
def __str__(self):
return self.name
+ def get_people(self):
+ return self.person_set.all()
+
def primary_contacts(self):
return self.person_set.filter(primary_nis_contact=True)
diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py
index adb61d9..e4caeb5 100644
--- a/ctrack/organisations/tests/test_models.py
+++ b/ctrack/organisations/tests/test_models.py
@@ -7,10 +7,17 @@ from ctrack.caf.models import CAF, Grading
from ctrack.caf.models import EssentialService
from ctrack.caf.tests.factories import ApplicableSystemFactory
from ctrack.core.utils import fnames
+from ctrack.organisations.tests.factories import PersonFactory
pytestmark = pytest.mark.django_db
+def test_get_people(org, person):
+ person.organisation = org
+ person.save()
+ assert person in org.get_people()
+
+
def test_lead_deputy_inspector(org):
assert org.lead_inspector
assert org.deputy_lead_inspector
@@ -45,8 +52,8 @@ def test_essential_service(org):
triage_review_date=None,
triage_review_inspector=None,
)
- ass = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf,)
- ass2 = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf,)
+ ass = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf, )
+ ass2 = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf, )
es = EssentialService.objects.create(
name="Test ES", description="Test ES Description", organisation=org
)
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index adb154f..d658c9d 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -34,7 +34,12 @@ class CreateSimpleDateTimeEventForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user")
+ self.org_slug = kwargs.pop("org_slug")
super().__init__(*args, **kwargs)
+ if self.org_slug:
+ org = Organisation.objects.get(slug=self.org_slug)
+ self.fields["participants"].queryset = org.get_people()
+ self.fields["participants"].help_text = f"Click to select participants from {org}"
def clean(self):
cleaned_data = super().clean()
diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py
index 2307a20..e392aca 100644
--- a/ctrack/register/tests/test_forms.py
+++ b/ctrack/register/tests/test_forms.py
@@ -22,7 +22,26 @@ def test_init(user):
"comments": "Test Comments",
"location": "Transient Moats",
},
- user=user,
+ user=user, org_slug=None
+ )
+ assert form.is_valid()
+
+
+def test_simple_event_limited_to_org_participants(user, org, person):
+ person.organisation = org
+ person.save()
+ people_from_org = org.get_people()
+ form = CreateSimpleDateTimeEventForm(
+ {
+ "type_descriptor": "PHONE_CALL",
+ "short_description": "Test Short Description",
+ "datetime": "2010-10-10 10:00",
+ "requested_response_date": "2020-12-24",
+ "response_received_date": "2020-12-25",
+ "participants": people_from_org,
+ "url": "https://fake.url.com",
+ "comments": "Test Comments not needed"
+ }, user=user, org_slug=org.slug
)
assert form.is_valid()
@@ -35,7 +54,7 @@ def test_cannot_create_disallowed_single_date_event_type_with_form(user):
"datetime": "2020-10-10",
"comments": "Test Comments",
},
- user=user,
+ user=user, org_slug=None
)
assert form.is_valid() is False
assert form.errors == {
@@ -55,7 +74,7 @@ def test_create_simple_datetime_event(user):
"response_received_date": "2020-12-25",
"url": "https://fake.url.com",
"comments": "Test Comments not needed"
- }, user=user,
+ }, user=user, org_slug=None
)
assert form.is_valid()
@@ -71,7 +90,7 @@ def test_create_private_note(user):
"url": "https://fake.url.com",
"private": True,
"comments": "Test Comments not needed"
- }, user=user,
+ }, user=user, org_slug=None
)
assert form.is_valid()
@@ -85,7 +104,7 @@ def test_response_date_cannot_be_before_date(user):
"requested_response_date": "2009-12-24",
"response_received_date": None,
"comments": "Test Comments not needed"
- }, user=user,
+ }, user=user, org_slug=None
)
assert not form.is_valid()
assert form.errors == {"__all__": ["Requested response cannot be before date."]}
@@ -99,7 +118,7 @@ def test_meeting_blank_data(user):
"short_description": "Test short description",
"comments": "Test Comments",
},
- user=user,
+ user=user, org_slug=None
)
assert form.is_valid() is False
assert form.errors == {"datetime": ["This field is required."]}
diff --git a/ctrack/register/tests/test_models.py b/ctrack/register/tests/test_models.py
index 1f8923b..e4f6a8d 100644
--- a/ctrack/register/tests/test_models.py
+++ b/ctrack/register/tests/test_models.py
@@ -171,7 +171,7 @@ def test_single_datetime_event(person, user, allowed_type):
event = SingleDateTimeEvent.objects.create(
type_descriptor=allowed_type,
short_description="Important event",
- url = "http://fake.url.com",
+ url="http://fake.url.com",
requested_response_date="2021-01-24",
response_received_date=None,
datetime="2020-10-10T15:00",
diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py
index b806165..da26d50 100644
--- a/ctrack/register/tests/test_views.py
+++ b/ctrack/register/tests/test_views.py
@@ -108,6 +108,27 @@ class TestSingleDateTimeEvent:
view.setup(request)
assert "user" in view.get_form_kwargs()
+ def test_can_create_simple_event_with_org_slug(self, user, org, client):
+ slug = org.slug
+ url = f"/register/event/create-simple-event-from-org/{slug}"
+ client.force_login(user)
+ response = client.get(url)
+ html = response.content.decode("utf-8")
+ assert response.status_code == 200
+ test_case.assertInHTML("Create a new simple event", html)
+
+
+ @pytest.mark.skip("Until we know what we're doing")
+ def test_org_passed_as_kwarg(self, user, org, request_factory):
+ slug = org.slug
+ view = SingleDateTimeEventCreate()
+ url = f"/register/event/create-simple-event-from-org/{slug}"
+ request = request_factory.get(url)
+ request.user = user
+ view.request = request
+ view.setup(request)
+ assert "org" in view.get_form_kwargs()
+
class TestSingleDateCAFEventViews:
def test_initial_caf_received(self, client):
diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py
index 81ea445..3e85243 100644
--- a/ctrack/register/urls.py
+++ b/ctrack/register/urls.py
@@ -30,6 +30,9 @@ urlpatterns = [
view=SingleDateTimeEventCreate.as_view(),
name="event_create_simple_event",
),
+ path("event/create-simple-event-from-org/<slug:org_slug>",
+ view=SingleDateTimeEventCreate.as_view(),
+ name="event_create_simple_event_from_org")
# path(
# "event/create-caf-single-date-event",
# view=CAFSingleDateEventView.as_view(),
diff --git a/ctrack/register/views.py b/ctrack/register/views.py
index f7eab87..3363fcd 100644
--- a/ctrack/register/views.py
+++ b/ctrack/register/views.py
@@ -77,9 +77,18 @@ class SingleDateTimeEventCreate(LoginRequiredMixin, FormView):
form_class = CreateSimpleDateTimeEventForm
success_url = reverse_lazy("organisations:list")
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data()
+ if self.kwargs.get("org_slug"):
+ context["org"] = Organisation.objects.get(slug=self.kwargs["org_slug"])
+ return context
+ return context
+
+
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user
+ kwargs["org_slug"] = self.kwargs.get("org_slug")
return kwargs
def form_valid(self, form):