diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-19 17:11:19 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-19 17:11:19 +0100 |
commit | c07178fb19f55ea8354b2de153a2d41c66d58f32 (patch) | |
tree | 68c6e3f87a349fe7077e037fafdcaa1a7d9c79df /ctrack | |
parent | d8a07a2157c627c51a5dce963a92be87baf7c31d (diff) |
started writing the code for the note event
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/register/forms.py | 40 | ||||
-rw-r--r-- | ctrack/register/models.py | 25 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 36 | ||||
-rw-r--r-- | ctrack/register/tests/test_models.py | 16 |
4 files changed, 78 insertions, 39 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 3253ed5..65c954b 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -14,9 +14,35 @@ from ctrack.register.models import ( EngagementEvent, EngagementType, SingleDateTimeEvent, + NoteEvent, ) +class CreateNoteEventForm(forms.ModelForm): + class Meta: + model = NoteEvent + fields = [ + "type_descriptor", + "short_description", + "comments", + "private", + "url", + "requested_response_date", + "response_received_date", + ] + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop("user") + super().__init__(*args, **kwargs) + + def save(self, commit=True, **kwargs): + new_note = super().save(commit=False) + new_note.user = self.user + new_note.save() + self.save_m2m() + return new_note + + class CreateSimpleDateTimeEventForm(forms.ModelForm): class Meta: model = SingleDateTimeEvent @@ -32,9 +58,7 @@ class CreateSimpleDateTimeEventForm(forms.ModelForm): "location", "comments", ] - widgets = { - "participants": forms.CheckboxSelectMultiple() - } + widgets = {"participants": forms.CheckboxSelectMultiple()} def __init__(self, *args, **kwargs): self.event_type = None @@ -48,8 +72,10 @@ 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 = mark_safe(f"Click to select participants from {org}. <strong>IMPORTANT:</strong>" \ - f"You must select at least one participant.") + self.fields["participants"].help_text = mark_safe( + f"Click to select participants from {org}. <strong>IMPORTANT:</strong>" + f"You must select at least one participant." + ) if self.event_type: self.fields["type_descriptor"].initial = self.event_type else: @@ -104,8 +130,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 45ee99e..0c88a54 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -17,7 +17,6 @@ class EventType(Enum): PHONE_CALL = auto() VIDEO_CALL = auto() EMAIL = auto() - NOTE = auto() # single date caf events CAF_INITIAL_CAF_RECEIVED = auto() CAF_FEEDBACK_EMAILED_OES = auto() @@ -88,7 +87,9 @@ class EventBase(AuditableEventBase): class ThirdPartyEventMixin(models.Model): - participants = models.ManyToManyField(Person, blank=False) + participants = models.ManyToManyField( + Person, blank=False + ) # cannot enforce this at DB level location = models.CharField( max_length=100, blank=True, @@ -160,15 +161,28 @@ class ResponseRequiredMixin(models.Model): class PrivateEventMixin(models.Model): private = models.BooleanField( - default=False, help_text="Private events can only be seen by you. Official records should " - "not be private, but you can use private events to track your own " - "work." + default=False, + help_text="Private events can only be seen by you. Official records should " + "not be private, but you can use private events to track your own " + "work.", ) class Meta: abstract = True +class NoteEvent( + EventBase, + ResponseRequiredMixin, + URLEventMixin, + PrivateEventMixin, +): + type_descriptor = models.CharField(blank=False, max_length=50, default="NOTE") + organisation = models.ForeignKey( + "organisations.Organisation", on_delete=models.CASCADE, blank=False + ) + + class SingleDateTimeEvent( EventBase, ResponseRequiredMixin, @@ -182,7 +196,6 @@ class SingleDateTimeEvent( (EventType.PHONE_CALL.name, "Phone Call"), (EventType.VIDEO_CALL.name, "Video Call"), (EventType.EMAIL.name, "Email"), - (EventType.NOTE.name, "Note"), ] type_descriptor = models.CharField( blank=False, max_length=50, choices=AVAILABLE_TYPES, verbose_name="Event Type" diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index fbc6479..b9c8b0b 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 CreateSimpleDateTimeEventForm, CAFSingleDateEventForm, CAFTwinDateEventForm +from ..forms import CreateSimpleDateTimeEventForm, CAFSingleDateEventForm, CAFTwinDateEventForm, CreateNoteEventForm pytestmark = pytest.mark.django_db @@ -83,23 +83,6 @@ def test_create_simple_datetime_event(user, org_with_people): assert form.is_valid() -def test_create_private_note(user, org_with_people): - form = CreateSimpleDateTimeEventForm( - { - "type_descriptor": "NOTE", - "short_description": "Test Short Description", - "datetime": "2010-10-10 10:00", - "requested_response_date": "2020-12-24", - "response_received_date": "2020-12-25", - "url": "https://fake.url.com", - "private": True, - "participants": org_with_people.get_people(), - "comments": "Test Comments not needed" - }, user=user, org_slug=None - ) - assert form.is_valid() - - def test_response_date_cannot_be_before_date(user, org_with_people): form = CreateSimpleDateTimeEventForm( { @@ -131,6 +114,23 @@ def test_meeting_blank_data(user, org_with_people): assert form.errors == {"datetime": ["This field is required."]} +# TODO - write the template and test the view for this and link from org detail page +def test_create_note(user, org_with_people): + """ + A note is related to an organisation rather than to persons in that organisation. + """ + form = CreateNoteEventForm( + { + "type_descriptor": "NOTE", + "short_description": "Test note", + "organisation": org_with_people, + "private": True, + "url": "https://www.bobbins.com/there-bos" + }, user=user + ) + assert form.is_valid() + + @pytest.mark.parametrize( "allowed_type", [ diff --git a/ctrack/register/tests/test_models.py b/ctrack/register/tests/test_models.py index e4f6a8d..aafd37f 100644 --- a/ctrack/register/tests/test_models.py +++ b/ctrack/register/tests/test_models.py @@ -7,7 +7,7 @@ from ctrack.register.models import ( EventType, SingleDateTimeEvent, CAFSingleDateEvent, - CAFTwinDateEvent, + CAFTwinDateEvent, NoteEvent, ) pytestmark = pytest.mark.django_db @@ -150,7 +150,6 @@ def test_event_type_enum(): assert EventType.PHONE_CALL.name == "PHONE_CALL" assert EventType.VIDEO_CALL.name == "VIDEO_CALL" assert EventType.EMAIL.name == "EMAIL" - assert EventType.NOTE.name == "NOTE" 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" @@ -220,15 +219,16 @@ def test_meeting_event(user, person): assert e.modified_date.day == now.day -@pytest.mark.parametrize("allowed_type", ["NOTE"]) -def test_note_event(user, allowed_type): - e = SingleDateTimeEvent.objects.create( - type_descriptor=allowed_type, +def test_note_event(user, org): + e = NoteEvent.objects.create( + type_descriptor="NOTE", short_description="Test short description", - datetime="2020-10-10 10:30", comments="The guy I deal with at X Co Ltd is made of cheese,", + organisation=org, url="https://evidenceofcheese.com", private=True, user=user ) - assert e.type_descriptor == allowed_type + assert e.type_descriptor == "NOTE" + + |