From 4c8c13d44fe30bc284ed03087454dd19c1f281f8 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sat, 18 Nov 2023 08:59:29 -0500 Subject: gtd: added per project filtering to notes view --- app/gtd/views.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'app/gtd/views.py') diff --git a/app/gtd/views.py b/app/gtd/views.py index b49f106..235867d 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -40,7 +40,11 @@ class GTDNoteUpdateView(UpdateView): return context def get_success_url(self): - return reverse('gtd:project-detail', kwargs={"pk": self.object.project.pk}) + if self.object.project: + return reverse('gtd:project-detail', kwargs={"pk": self.object.project.pk}) + else: + return reverse('gtd:note-list', kwargs={"pk": self.object.project.pk}) + class GTDNoteListView(ListView): @@ -52,12 +56,25 @@ class GTDNoteListView(ListView): print(self.kwargs['note_type']) note_type_reverse = dict((v, k) for k, v in GTDNote.NOTE_TYPE) note_type = note_type_reverse[self.kwargs['note_type'].title()] - return GTDNote.objects.filter(note_type=note_type) - return GTDNote.objects.all() + try: + project = self.request.GET["project"] + print(project) + return GTDNote.objects.filter(note_type=note_type, project__title=project) + except: + return GTDNote.objects.filter(note_type=note_type) + else: + try: + project = self.request.GET["project"] + print(project) + return GTDNote.objects.filter(project__title=project) + except: + return GTDNote.objects.all() def get_context_data(self, **kwargs): context = super(GTDNoteListView, self).get_context_data(**kwargs) context['note_types'] = GTDNote.NOTE_TYPE + context['projects'] = GTDProject.objects.all() + context['project'] = self.request.GET.get("project", False) return context @@ -151,7 +168,10 @@ class WiredNoteUpdateView(UpdateView): return context def get_success_url(self): - return reverse('gtd:wiredpost-detail', kwargs={"pk": self.object.post.pk}) + if self.object.post: + return reverse('gtd:wiredpost-detail', kwargs={"pk": self.object.post.pk}) + else: + return reverse('gtd:wirednote-list', kwargs={"pk": self.object.project.pk}) class WiredNoteListView(ListView): -- cgit v1.2.3-70-g09d2