From 521cacd081fa93507f7ad0f6df383f8a3b502502 Mon Sep 17 00:00:00 2001
From: luxagraf <sng@luxagraf.net>
Date: Sun, 21 Jan 2024 08:39:22 -0500
Subject: gtd: fixed a sorting bug on notes

---
 app/gtd/models.py                    | 11 ++++++++++-
 app/gtd/templates/gtd/note_list.html |  2 +-
 app/gtd/views.py                     |  6 ++----
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/app/gtd/models.py b/app/gtd/models.py
index 3feda46..3ad2931 100644
--- a/app/gtd/models.py
+++ b/app/gtd/models.py
@@ -90,12 +90,21 @@ class GTDProject(models.Model):
             self.body_html = markdown_to_html(md)
         super(GTDProject, self).save(*args, **kwargs)
 
+
 class NoteType(models.IntegerChoices):
     ACTION = 0, ('Action')
     REMINDER = 1, ('Reminder')
     REFERENCE = 2, ('Reference')
     SOMEDAY = 3, ('Someday')
-
+    
+    @classmethod
+    def string_to_int(cls, the_string):
+        """Convert the string value to an int value, or return None."""
+        for num, string in cls.choices:
+            print(num, string)
+            if string == the_string:
+                return num
+        return None
 
 class GTDNote(models.Model):
     title = models.CharField(max_length=200)
diff --git a/app/gtd/templates/gtd/note_list.html b/app/gtd/templates/gtd/note_list.html
index f5a9c77..d847ff2 100644
--- a/app/gtd/templates/gtd/note_list.html
+++ b/app/gtd/templates/gtd/note_list.html
@@ -4,7 +4,7 @@
     <div class="post-header"><ul class="flex header-list">
         <li><a class="btn" href="{% url 'gtd:note-list' %}">All</a></li>
         {% for object in note_types %}
-        <li><a class="btn" href="{% url 'gtd:note-list-status' object.1|lower%}">{{object.1}}</a></li>
+        <li><a class="btn" href="{% url 'gtd:note-list-status' object.label|lower%}">{{object.label}}</a></li>
         {% endfor %}
         <li class="right"><a href="{% url 'gtd:note-create' %}" class="btn">New Note</a></li>
         </ul>
diff --git a/app/gtd/views.py b/app/gtd/views.py
index dbf7587..9643511 100644
--- a/app/gtd/views.py
+++ b/app/gtd/views.py
@@ -60,9 +60,7 @@ class GTDNoteListView(ListView):
     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()]
+            note_type = NoteType.string_to_int(self.kwargs['note_type'].title())
             if project:
                 return GTDNote.objects.filter(note_type=note_type, project__title=project, status__in=[0,1])
             return GTDNote.objects.filter(note_type=note_type, status__in=[0,1])
@@ -73,7 +71,7 @@ class GTDNoteListView(ListView):
 
     def get_context_data(self, **kwargs):
         context = super(GTDNoteListView, self).get_context_data(**kwargs)
-        context['note_types'] = GTDNote.NOTE_TYPE
+        context['note_types'] = NoteType
         context['projects'] = GTDProject.objects.all()
         context['project'] = self.request.GET.get("project", False)
         return context
-- 
cgit v1.2.3-70-g09d2