diff options
author | luxagraf <sng@luxagraf.net> | 2023-11-18 08:59:29 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-11-18 08:59:29 -0500 |
commit | 4c8c13d44fe30bc284ed03087454dd19c1f281f8 (patch) | |
tree | 4db5aa524c10ae55b2734b5810245a156094481f | |
parent | 344da65e7ef3c7b5fa97909d6d8fb2dbb453be92 (diff) |
gtd: added per project filtering to notes view
-rw-r--r-- | app/gtd/templates/gtd/note_list.html | 5 | ||||
-rw-r--r-- | app/gtd/views.py | 28 |
2 files changed, 29 insertions, 4 deletions
diff --git a/app/gtd/templates/gtd/note_list.html b/app/gtd/templates/gtd/note_list.html index 5457443..b2c0478 100644 --- a/app/gtd/templates/gtd/note_list.html +++ b/app/gtd/templates/gtd/note_list.html @@ -8,6 +8,10 @@ {% endfor %} <li class="right"><a href="{% url 'gtd:note-create' %}" class="btn">New Note</a></li> </ul> +<select class="form-control" style="margin-top: 2%;" onchange="go_from_select(this.options[this.selectedIndex].value)"> + <option value="">All Projects</option>{% for object in projects %} + <option {% if object.title == project %}selected="selected" {%endif%}value="?project={{object}}">{{object}}</option>{%endfor%} +</select> </div> <div class="note-list">{% for object in object_list %}<article> <h2>{{object.title}}<span class="note-edit"><a href="{%url 'gtd:note-edit' object.pk%}">edit</a></span></h2> @@ -22,4 +26,5 @@ {% endblock %} {% block js %} +<script type="text/javascript">var go_from_select = function(opt) { window.location = window.location.pathname + opt };</script> {% endblock%} 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): |