diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-14 17:01:22 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-14 17:01:22 +0100 |
commit | 14fa59eee9ba35ad462b5b17229a09164f5d716d (patch) | |
tree | 1223522b7cc30cf57ad8ec66e50c5081727fe3d4 /ctrack | |
parent | bc4edc69407f20da32a48d534b3d725cc3818c1a (diff) |
about to nuke migrations
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/register/forms.py | 19 | ||||
-rw-r--r-- | ctrack/register/models.py | 16 | ||||
-rw-r--r-- | ctrack/register/templates/single_datetime_event_create.html | 29 | ||||
-rw-r--r-- | ctrack/register/tests/test_event_models.py | 5 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 37 | ||||
-rw-r--r-- | ctrack/register/views.py | 6 | ||||
-rw-r--r-- | ctrack/templates/snippets/event_form_base.html | 16 |
7 files changed, 96 insertions, 32 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index d3e93ab..2afc1a1 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -16,13 +16,15 @@ from ctrack.register.models import ( ) -class AddMeetingForm(forms.ModelForm): +class CreateSimpleDateTimeEventForm(forms.ModelForm): class Meta: model = SingleDateTimeEvent fields = [ "type_descriptor", "short_description", "datetime", + "requested_response_date", + "response_received_date", "comments", "location", ] @@ -31,6 +33,17 @@ class AddMeetingForm(forms.ModelForm): self.user = kwargs.pop("user") super().__init__(*args, **kwargs) + def clean(self): + cleaned_data = super().clean() + date = cleaned_data.get("datetime") + if not date: + return cleaned_data + # WOOO - walrus operator + if requested := cleaned_data.get("requested_response_date"): + if requested < date.date(): + raise ValidationError("Requested response cannot be before date.") + return cleaned_data + def save(self, **kwargs): form = super().save(commit=False) form.user = self.user @@ -68,8 +81,8 @@ class CAFTwinDateEventForm(forms.ModelForm): caf = self.cleaned_data["related_caf"] existing_obj = ( CAFTwinDateEvent.objects.filter(start_date=data) - .filter(related_caf=caf) - .first() + .filter(related_caf=caf) + .first() ) if existing_obj: raise ValidationError( diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 2729fa5..4687a91 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -16,6 +16,7 @@ class EventType(Enum): MEETING = auto() PHONE_CALL = auto() VIDEO_CALL = auto() + EMAIL = auto() # single date caf events CAF_INITIAL_CAF_RECEIVED = auto() CAF_FEEDBACK_EMAILED_OES = auto() @@ -118,12 +119,24 @@ class TwinDateMixin(models.Model): class CAFMixin(models.Model): related_caf = models.ForeignKey(CAF, on_delete=models.CASCADE, blank=False) + class Meta: + abstract = True + -class SingleDateTimeEvent(EventBase, ThirdPartyEventMixin, SingleDateTimeEventMixin): +class ResponseRequiredMixin(models.Model): + requested_response_date = models.DateField(blank=True, null=True, help_text="DD/MM/YY format") + response_received_date = models.DateField(blank=True, null=True, help_text="DD/MM/YY format") + + class Meta: + abstract = True + + +class SingleDateTimeEvent(EventBase, ResponseRequiredMixin, ThirdPartyEventMixin, SingleDateTimeEventMixin): AVAILABLE_TYPES = [ (EventType.MEETING.name, "Meeting"), (EventType.PHONE_CALL.name, "Phone Call"), (EventType.VIDEO_CALL.name, "Video Call"), + (EventType.EMAIL.name, "Email") ] type_descriptor = models.CharField( blank=False, max_length=50, choices=AVAILABLE_TYPES @@ -184,6 +197,7 @@ class CAFTwinDateEvent(EventBase, CAFMixin, TwinDateMixin): ) ] + # OLD CODE BELOW class EngagementType(models.Model): """ diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/single_datetime_event_create.html index 3494792..f663dac 100644 --- a/ctrack/register/templates/single_datetime_event_create.html +++ b/ctrack/register/templates/single_datetime_event_create.html @@ -1,24 +1,13 @@ -{% extends "base.html" %} +{% extends "snippets/event_form_base.html" %} {% load static %} {% load crispy_forms_tags %} -{% block title %} - Create a new event (Meeting, Phone call, Email) -{% endblock %} - - -{% block content %} - <div class="container"> - <div class="row justify-content-center"> - <div class="col-8"> - <h3 class="mt-2">Create a new Simple Event</h3> - <form method="post"> - {% csrf_token %} - {{ form|crispy}} - <button type="submit" class="btn btn-success">Submit</button> - </form> - </div> - </div> - </div> -{% endblock content%} +{% block form %} + <h3 class="mt-2">Create a new Simple Event (Meeting, Phone call, Email)</h3> + <form method="post"> + {% csrf_token %} + {{ form|crispy }} + <button type="submit" class="btn btn-success">Submit</button> + </form> +{% endblock form %} diff --git a/ctrack/register/tests/test_event_models.py b/ctrack/register/tests/test_event_models.py index cb6e0db..6469ea7 100644 --- a/ctrack/register/tests/test_event_models.py +++ b/ctrack/register/tests/test_event_models.py @@ -149,6 +149,7 @@ def test_event_type_enum(): assert EventType.MEETING.name == "MEETING" assert EventType.PHONE_CALL.name == "PHONE_CALL" assert EventType.VIDEO_CALL.name == "VIDEO_CALL" + assert EventType.EMAIL.name == "EMAIL" assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED" assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES" assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED" @@ -162,13 +163,15 @@ def test_event_type_enum(): ) -@pytest.mark.parametrize("allowed_type", ["PHONE_CALL", "MEETING", "VIDEO_CALL"]) +@pytest.mark.parametrize("allowed_type", ["PHONE_CALL", "MEETING", "VIDEO_CALL", "EMAIL"]) def test_single_datetime_event(person, user, allowed_type): """This tests for phone call, video call and email events""" now = datetime.datetime.now() event = SingleDateTimeEvent.objects.create( type_descriptor=allowed_type, short_description="Important event", + requested_response_date="2021-01-24", + response_received_date=None, datetime="2020-10-10T15:00", comments="Comments on important event", # location is optional diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 49cd5b4..16d81ae 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -1,7 +1,7 @@ import pytest from django.db import IntegrityError -from ..forms import AddMeetingForm, CAFSingleDateEventForm, CAFTwinDateEventForm +from ..forms import CreateSimpleDateTimeEventForm, CAFSingleDateEventForm, CAFTwinDateEventForm pytestmark = pytest.mark.django_db @@ -14,7 +14,7 @@ def test_init(user): """Here we test that we can pass in the user value from the view. We don't want that to be field in the form. """ - form = AddMeetingForm( + form = CreateSimpleDateTimeEventForm( { "type_descriptor": "MEETING", # Must be Meeting as that is in the choices param "short_description": "Test short description", @@ -28,7 +28,7 @@ def test_init(user): def test_cannot_create_disallowed_single_date_event_type_with_form(user): - form = AddMeetingForm( + form = CreateSimpleDateTimeEventForm( { "type_descriptor": "NOT ALLOWED EVENT", "short_description": "Test short description", @@ -45,9 +45,38 @@ def test_cannot_create_disallowed_single_date_event_type_with_form(user): } +def test_create_simple_datetime_event(user): + 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", + "comments": "Test Comments not needed" + }, user=user, + ) + assert form.is_valid() + + +def test_response_date_cannot_be_before_date(user): + form = CreateSimpleDateTimeEventForm( + { + "type_descriptor": "PHONE_CALL", + "short_description": "Test Short Description", + "datetime": "2010-10-10 10:00", + "requested_response_date": "2009-12-24", + "response_received_date": None, + "comments": "Test Comments not needed" + }, user=user, + ) + assert not form.is_valid() + assert form.errors == {"__all__": ["Requested response cannot be before date."]} + + def test_meeting_blank_data(user): """Missing datetime fields is required. Location is optional""" - form = AddMeetingForm( + form = CreateSimpleDateTimeEventForm( { "type_descriptor": "MEETING", "short_description": "Test short description", diff --git a/ctrack/register/views.py b/ctrack/register/views.py index 9ec96e8..3fd8f1f 100644 --- a/ctrack/register/views.py +++ b/ctrack/register/views.py @@ -6,7 +6,7 @@ from django.views.generic import FormView, DeleteView, CreateView from ctrack.caf.models import CAF from ctrack.organisations.models import Organisation -from ctrack.register.forms import EngagementEventCreateForm, AddMeetingForm +from ctrack.register.forms import EngagementEventCreateForm, CreateSimpleDateTimeEventForm from ctrack.register.models import EngagementEvent, SingleDateTimeEvent @@ -48,7 +48,7 @@ class EngagementEventCreate(LoginRequiredMixin, FormView): class EngagementEventCreateFromCaf(LoginRequiredMixin, FormView): fields = "__all__" form_class = EngagementEventCreateForm - template_name = "register/engagementevent_form.html" + template_name = "snippets/event_form_base.html" def form_valid(self, form): ee = form.save(commit=False) @@ -74,7 +74,7 @@ class EngagementEventCreateFromCaf(LoginRequiredMixin, FormView): class SingleDateTimeEventCreate(LoginRequiredMixin, FormView): template_name = "single_datetime_event_create.html" - form_class = AddMeetingForm + form_class = CreateSimpleDateTimeEventForm success_url = reverse_lazy("organisations:list") def get_form_kwargs(self): diff --git a/ctrack/templates/snippets/event_form_base.html b/ctrack/templates/snippets/event_form_base.html new file mode 100644 index 0000000..aeedb16 --- /dev/null +++ b/ctrack/templates/snippets/event_form_base.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %} + Create a new event (Meeting, Phone call, Email) +{% endblock %} + + +{% block content %} + <div class="container"> + <div class="row justify-content-center"> + <div class="col-8"> + {% block form %}{% endblock form %} + </div> + </div> + </div> +{% endblock content %} |