summaryrefslogtreecommitdiff
path: root/app/gtd/views.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-11-15 17:08:29 -0500
committerluxagraf <sng@luxagraf.net>2023-11-15 17:08:29 -0500
commit5d26ed7dbba5475a93b70c450741b358153b0855 (patch)
tree8c9dcdb2bb1735e787cb0753215898b17e92f062 /app/gtd/views.py
parent9f1c7ef8a47ee1a2df40ce1f57df105af8b99cc1 (diff)
gtd: rolled in wired stuff plus created my own gtd app
Diffstat (limited to 'app/gtd/views.py')
-rw-r--r--app/gtd/views.py221
1 files changed, 221 insertions, 0 deletions
diff --git a/app/gtd/views.py b/app/gtd/views.py
new file mode 100644
index 0000000..8082db3
--- /dev/null
+++ b/app/gtd/views.py
@@ -0,0 +1,221 @@
+from django.views.generic import UpdateView, DetailView, ListView
+from django.views.generic.edit import CreateView, DeleteView, UpdateView
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.urls import reverse
+
+from .models import GTDNote, GTDProject, WiredNote, WiredPost
+from .forms import GTDNoteCreateForm, GTDNoteEditForm, GTDProjectCreateForm, GTDProjectUpdateForm, WiredNoteCreateForm, WiredNoteEditForm, WiredPostUpdateForm
+
+class GTDNoteCreateView(CreateView):
+ model = GTDNote
+ form_class = GTDNoteCreateForm
+ template_name = "gtd/note_form.html"
+
+ def get_form_kwargs(self):
+ kwargs = super(GTDNoteCreateView, self).get_form_kwargs()
+ return kwargs
+
+ def get_success_url(self):
+ if 'add_new' in self.request.POST:
+ return reverse('gtd:note-create')
+ else:
+ if self.object.project:
+ return reverse('gtd:project-detail', kwargs={"pk": self.object.project.pk})
+ else:
+ return reverse('gtd:note-create')
+
+
+class GTDNoteUpdateView(UpdateView):
+ model = GTDNote
+ form_class = GTDNoteEditForm
+ template_name = "gtd/note_form.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(GTDNoteUpdateView, self).get_context_data(**kwargs)
+ context['is_update'] = True
+ return context
+
+ def get_success_url(self):
+ return reverse('gtd:project-detail', kwargs={"pk": self.object.project.pk})
+
+
+class GTDNoteListView(ListView):
+ model = GTDNote
+ template_name = "gtd/note_list.html"
+
+ def get_queryset(self):
+ if self.kwargs['status']:
+ status_reverse = dict((v, k) for k, v in GTDNote.STATUS)
+ status = status_reverse[self.kwargs['status'].title()]
+ return GTDNote.objects.filter(status=status)
+ return GTDNote.objects.filter(status=1)
+
+ def get_context_data(self, **kwargs):
+ context = super(GTDNoteListView, self).get_context_data(**kwargs)
+ context['note_statuses'] = GTDNote.STATUS
+ return context
+
+
+class GTDProjectCreateView(CreateView):
+ model = GTDProject
+ form_class = GTDProjectCreateForm
+ template_name = "gtd/project_form.html"
+
+ def get_form_kwargs(self):
+ kwargs = super(GTDProjectCreateView, self).get_form_kwargs()
+ return kwargs
+
+ def get_success_url(self):
+ if 'add_new' in self.request.POST:
+ return reverse('gtd:project-create')
+ else:
+ return reverse('gtd:project-detail', kwargs={"pk": self.object.pk})
+
+
+class GTDProjectUpdateView(UpdateView):
+ model = GTDProject
+ form_class = GTDProjectUpdateForm
+ template_name = "gtd/project_form.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(GTDProjectUpdateView, self).get_context_data(**kwargs)
+ context['is_update'] = True
+ return context
+
+
+class GTDProjectDetailView(DetailView):
+ model = GTDProject
+ template_name = "gtd/project_detail.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(GTDProjectDetailView, self).get_context_data(**kwargs)
+ return context
+
+
+class GTDProjectListView(ListView):
+ model = GTDProject
+ template_name = "gtd/project_list.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(GTDProjectListView, self).get_context_data(**kwargs)
+ return context
+
+
+class GTDNoteTODOView(ListView):
+ model = GTDNote
+ template_name = "gtd/note_list.html"
+
+ def get_queryset(self):
+ return GTDNote.objects.filter(status=1)
+
+
+class WiredNoteCreateView(CreateView):
+ model = WiredNote
+ form_class = WiredNoteCreateForm
+
+ def get_form_kwargs(self):
+ kwargs = super(WiredNoteCreateView, self).get_form_kwargs()
+ kwargs.update({'user': self.request.user})
+ return kwargs
+
+ def get_success_url(self):
+ if 'add_new' in self.request.POST:
+ return reverse('gtd:wirednotes-create')
+ else:
+ if self.object.post:
+ return reverse('gtd:wiredposts-detail', kwargs={"pk": self.object.post.pk})
+ else:
+ return reverse('gtd:wirednotes-create')
+
+
+class WiredNoteUpdateView(UpdateView):
+ model = WiredNote
+ form_class = WiredNoteEditForm
+
+ def get_form_kwargs(self):
+ kwargs = super(WiredNoteUpdateView, self).get_form_kwargs()
+ return kwargs
+
+ def get_context_data(self, **kwargs):
+ context = super(WiredNoteUpdateView, self).get_context_data(**kwargs)
+ context['is_update'] = True
+ return context
+
+ def get_success_url(self):
+ return reverse('gtd:post-detail', kwargs={"pk": self.object.post.pk})
+
+
+class WiredNoteListView(ListView):
+ model = WiredNote
+
+ def get_queryset(self):
+ if self.kwargs['status']:
+ status_reverse = dict((v, k) for k, v in WiredNote.STATUS)
+ status = status_reverse[self.kwargs['status'].title()]
+ return WiredNote.objects.filter(status=status)
+ return WiredNote.objects.all()
+
+ def get_context_data(self, **kwargs):
+ context = super(WiredNoteListView, self).get_context_data(**kwargs)
+ context['note_statuses'] = WiredNote.STATUS
+ return context
+
+
+class WiredPostListView(ListView):
+ model = WiredPost
+ template_name = 'gtd/post_table.html'
+
+ def get_queryset(self):
+ return WiredPost.objects.all().order_by("-needs_update")
+
+
+class WiredPostNewView(ListView):
+ template_name = 'gtd/post_list.html'
+
+ def get_queryset(self):
+ return WiredPost.objects.filter(is_live=0)
+
+ def get_context_data(self, **kwargs):
+ context = super(WiredPostNewView, self).get_context_data(**kwargs)
+ context['reviews'] = WiredNote.objects.filter(plan__in=[1,2], status__in=[0,1,2,3])
+ return context
+
+
+class WiredPostTodoView(LoginRequiredMixin, ListView):
+ template_name = 'posts/post_table.html'
+
+ def get_queryset(self):
+ qs = WiredPost.objects.filter(user=self.request.user)
+ qs = qs.filter(Q(needs_update=True) | Q(is_live=0)).exclude(post_status=1)
+ unsorted_results = qs.all()
+ return sorted(unsorted_results, key=lambda a: a.days_overdue(), reverse=True)
+
+ def get_context_data(self, **kwargs):
+ context = super(WiredPostTodoView, self).get_context_data(**kwargs)
+ context['reviews'] = WiredNote.objects.filter(plan__in=[1,2,3]).exclude(status=4)
+ return context
+
+
+class WiredPostNotesView(DetailView):
+ model = WiredPost
+
+ def get_context_data(self, **kwargs):
+ context = super(WiredPostNotesView, self).get_context_data(**kwargs)
+ context['notes'] = self.get_object().wirednote_set.all().order_by("status")
+ return context
+
+class WiredPostUpdateView(UpdateView):
+ model = WiredPost
+ form_class = WiredPostUpdateForm
+
+ def get_form_kwargs(self):
+ kwargs = super(WiredPostUpdateView, self).get_form_kwargs()
+ return kwargs
+
+ def get_success_url(self):
+ if 'add_new' in self.request.POST:
+ return reverse('gtd:posts-create')
+ else:
+ return reverse('gtd:posts-detail', kwargs={"pk": self.object.pk})
+
+