diff options
author | luxagraf <sng@luxagraf.net> | 2023-11-18 09:08:52 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-11-18 09:08:52 -0500 |
commit | b2f7894ed55eabf89089e318111f6dd06d480792 (patch) | |
tree | 4be781564fc14c1c3f63a059108d97a01383d437 /app | |
parent | 4c8c13d44fe30bc284ed03087454dd19c1f281f8 (diff) |
gtd: added per post filtering to wirednotes
Diffstat (limited to 'app')
-rw-r--r-- | app/gtd/templates/gtd/wirednote_list.html | 6 | ||||
-rw-r--r-- | app/gtd/views.py | 23 |
2 files changed, 19 insertions, 10 deletions
diff --git a/app/gtd/templates/gtd/wirednote_list.html b/app/gtd/templates/gtd/wirednote_list.html index 73c93bb..fb2a214 100644 --- a/app/gtd/templates/gtd/wirednote_list.html +++ b/app/gtd/templates/gtd/wirednote_list.html @@ -7,6 +7,11 @@ {% endfor %} <li class="right"><a href="{% url 'gtd:wirednote-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 Posts</option>{% for object in posts %} + <option {% if object.title == post %}selected="selected" {%endif%}value="?post={{object}}">{{object}}</option>{%endfor%} +</select> </div> <div class="note-list">{% for object in object_list %}<article> <h2>{%if object.url%}<a href="{{object.url}}">{{object.title}}</a>{%else%}{{object.title}}{%endif%}<span class="note-edit"><a href="{{object.get_absolute_url}}">edit</a></span></h2> @@ -21,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 235867d..db014b1 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -52,23 +52,18 @@ class GTDNoteListView(ListView): template_name = "gtd/note_list.html" def get_queryset(self): + project = self.request.GET.get("project", False) if self.kwargs['note_type']: 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()] - try: - project = self.request.GET["project"] - print(project) + if project: return GTDNote.objects.filter(note_type=note_type, project__title=project) - except: - return GTDNote.objects.filter(note_type=note_type) + return GTDNote.objects.filter(note_type=note_type) else: - try: - project = self.request.GET["project"] - print(project) + if project: return GTDNote.objects.filter(project__title=project) - except: - return GTDNote.objects.all() + return GTDNote.objects.all() def get_context_data(self, **kwargs): context = super(GTDNoteListView, self).get_context_data(**kwargs) @@ -179,15 +174,23 @@ class WiredNoteListView(ListView): template_name = "gtd/wirednote_list.html" def get_queryset(self): + wiredpost = self.request.GET.get("post", False) if self.kwargs['status']: status_reverse = dict((v, k) for k, v in WiredNote.STATUS) status = status_reverse[self.kwargs['status'].title()] + if wiredpost: + return WiredNote.objects.filter(status=status, post__title=wiredpost) return WiredNote.objects.filter(status=status) + else: + if wiredpost: + return WiredNote.objects.filter(post__title=wiredpost) return WiredNote.objects.all() def get_context_data(self, **kwargs): context = super(WiredNoteListView, self).get_context_data(**kwargs) context['note_statuses'] = WiredNote.STATUS + context['posts'] = WiredPost.objects.all() + context['post'] = self.request.GET.get("post", False) return context |