From 59592232da815f4e8c6f61cb9042e738990c1b6e Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 16 Oct 2020 14:29:01 +0100 Subject: better handling of simple event form and participants --- ctrack/register/forms.py | 4 +++- ctrack/register/templates/single_datetime_event_create.html | 10 +++++++--- ctrack/register/tests/test_views.py | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index d658c9d..1549f75 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -39,7 +39,9 @@ class CreateSimpleDateTimeEventForm(forms.ModelForm): 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}" + self.fields["participants"].help_text = f"Click to select participants from {org}." + else: + self.fields["participants"].widget = forms.HiddenInput() def clean(self): cleaned_data = super().clean() diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/single_datetime_event_create.html index 6e607be..34ff22c 100644 --- a/ctrack/register/templates/single_datetime_event_create.html +++ b/ctrack/register/templates/single_datetime_event_create.html @@ -4,10 +4,14 @@ {% load crispy_forms_tags %} {% block form %} -

Create a new simple event

+ {% if org %} +

Create a new simple event involving {{ org }}

+ {% else %} +

Create a new simple event

+ {% endif %}

Simple events are emails, phone calls, basic meetings, notes, deadlines, etc. - If you arrived at this page from an organisation's page, you are able to select - participants in the event from that organisation.

+ If you arrived at this page from an organisation's page, you are able to select + participants in the event from that organisation.

{% csrf_token %} {{ form|crispy }} diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py index 94edc4f..5f7ca35 100644 --- a/ctrack/register/tests/test_views.py +++ b/ctrack/register/tests/test_views.py @@ -108,9 +108,16 @@ class TestSingleDateTimeEvent: view.setup(request) assert "user" in view.get_form_kwargs() + def test_create_simple_event_without_org_means_no_participants(self, user, client): + client.force_login(user) + url = reverse("register:event_create_simple_event") + response = client.get(url) + html = response.content.decode("utf-8") + assert '' in html + 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}" + url = reverse("register:event_create_simple_event_from_org", args=[slug]) client.force_login(user) response = client.get(url) html = response.content.decode("utf-8") -- cgit v1.2.3