diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-10-23 17:10:54 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-10-23 17:10:54 +0100 |
commit | 585c05e32096b1d84e285064e78150db40a0ca05 (patch) | |
tree | 0736bcee955cd702b3580c5bb8f98d4a9b43401d | |
parent | 5688e9b1c79ff45a8867891205791a3ffcc6b91d (diff) |
limited note entry to the org in question
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_detail.html | 2 | ||||
-rw-r--r-- | ctrack/register/forms.py | 8 | ||||
-rw-r--r-- | ctrack/register/urls.py | 6 | ||||
-rw-r--r-- | 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 @@ <path fill-rule="evenodd" d="M5 10.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"/> </svg> - <a href="{% url "register:event_create_note" %}">New + <a href="{% url "register:event_create_note_from_org" object.slug %}">New note</a> <a href="#">[Help]</a> </div> 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" @@ -51,6 +52,11 @@ urlpatterns = [ name="event_create_note" ), path( + "event/create-note-for-org/<slug:org_slug>", + view=CreateNoteEventFromOrg.as_view(), + name="event_create_note_from_org" + ), + path( "event/create-caf-single-date-event/<int:caf_id>", view=CAFCreateSingleDateEventView.as_view(), name="event_caf_create_single_date_event_from_caf" 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 = [ |