From 585c05e32096b1d84e285064e78150db40a0ca05 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 23 Oct 2020 17:10:54 +0100 Subject: limited note entry to the org in question --- .../templates/organisations/organisation_detail.html | 2 +- ctrack/register/forms.py | 8 +++++++- ctrack/register/urls.py | 6 ++++++ ctrack/register/views.py | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index f85506c..46d1aba 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -277,7 +277,7 @@ - New + New note  [Help] diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 5a612e9..a6db25f 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -33,8 +33,14 @@ class CreateNoteEventForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.user = kwargs.pop("user") + if kwargs.get("org_slug"): + got_org = True + self.org_slug = kwargs.pop("org_slug") super().__init__(*args, **kwargs) - self.fields["organisation"].queryset = Organisation.objects.all().order_by('name') + if got_org : + self.fields["organisation"].queryset = Organisation.objects.filter(slug=self.org_slug) + else: + self.fields["organisation"].queryset = Organisation.objects.all().order_by('name') def save(self, commit=True, **kwargs): new_note = super().save(commit=False) diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py index 7be778e..d08b570 100644 --- a/ctrack/register/urls.py +++ b/ctrack/register/urls.py @@ -5,6 +5,7 @@ from ctrack.register.views import ( EngagementEventCreateFromCaf, EngagementEventDelete, SingleDateTimeEventCreate, SingleDateTimeEventUpdate, CreateNoteEvent, CAFCreateSingleDateEventView, + CreateNoteEventFromOrg, ) app_name = "register" @@ -50,6 +51,11 @@ urlpatterns = [ view=CreateNoteEvent.as_view(), name="event_create_note" ), + path( + "event/create-note-for-org/", + view=CreateNoteEventFromOrg.as_view(), + name="event_create_note_from_org" + ), path( "event/create-caf-single-date-event/", view=CAFCreateSingleDateEventView.as_view(), diff --git a/ctrack/register/views.py b/ctrack/register/views.py index d5b39f3..63628e1 100644 --- a/ctrack/register/views.py +++ b/ctrack/register/views.py @@ -94,6 +94,24 @@ class CreateNoteEvent(CreateView): return reverse_lazy("organisations:detail", args=[self.object.organisation.slug]) +class CreateNoteEventFromOrg(CreateView): + form_class = CreateNoteEventForm + model = NoteEvent + template_name = "register/create_note_event_form.html" + + 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): + note = form.save(commit=False) + note.user = self.request.user + note.save() + return super().form_valid(form) + + class SingleDateTimeEventUpdate(UpdateView): model = SingleDateTimeEvent fields = [ -- cgit v1.2.3