diff options
Diffstat (limited to 'app/gtd/views.py')
-rw-r--r-- | app/gtd/views.py | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/app/gtd/views.py b/app/gtd/views.py index c4c8d92..b49f106 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -1,21 +1,24 @@ -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.views.generic import UpdateView, DetailView, ListView, CreateView, DeleteView from django.urls import reverse, reverse_lazy from django.db.models import Q from .models import GTDNote, GTDProject, GTDOutcome, WiredNote, WiredPost -from .forms import GTDNoteCreateForm, GTDNoteEditForm, GTDProjectCreateForm, GTDProjectUpdateForm, WiredNoteCreateForm, WiredNoteEditForm, WiredPostUpdateForm +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') @@ -30,7 +33,7 @@ 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 @@ -51,7 +54,7 @@ class GTDNoteListView(ListView): note_type = note_type_reverse[self.kwargs['note_type'].title()] return GTDNote.objects.filter(note_type=note_type) return GTDNote.objects.all() - + def get_context_data(self, **kwargs): context = super(GTDNoteListView, self).get_context_data(**kwargs) context['note_types'] = GTDNote.NOTE_TYPE @@ -64,17 +67,13 @@ class GTDNoteTODOView(ListView): def get_queryset(self): return GTDNote.objects.filter(status=1) - + 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') @@ -94,7 +93,7 @@ class GTDProjectUpdateView(UpdateView): class GTDProjectDetailView(DetailView): - model = GTDProject + model = GTDProject template_name = "gtd/project_detail.html" def get_context_data(self, **kwargs): @@ -103,7 +102,7 @@ class GTDProjectDetailView(DetailView): class GTDProjectListView(ListView): - model = GTDProject + model = GTDProject template_name = "gtd/project_list.html" def get_queryset(self, *args, **kwargs): @@ -118,10 +117,11 @@ class GTDProjectListView(ListView): context['project_types'] = GTDProject.PROJECT_TYPE return context + class GTDProjectDeleteView(DeleteView): # specify the model you want to use model = GTDProject - success_url ="/gtd/projects" + success_url = "/gtd/projects" template_name = "gtd/confirm_delete.html" @@ -130,11 +130,6 @@ class WiredNoteCreateView(CreateView): form_class = WiredNoteCreateForm template_name = "gtd/wirednote_form.html" - 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') @@ -149,10 +144,6 @@ class WiredNoteUpdateView(UpdateView): model = WiredNote form_class = WiredNoteEditForm template_name = "gtd/wirednote_form.html" - - 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) @@ -173,7 +164,7 @@ class WiredNoteListView(ListView): 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 @@ -181,14 +172,13 @@ class WiredNoteListView(ListView): class WiredNoteDeleteView(DeleteView): - # specify the model you want to use model = WiredNote - success_url ="/gtd/wirednote" + success_url = "/gtd/wirednote" template_name = "gtd/confirm_delete.html" class WiredPostListView(ListView): - model = WiredPost + model = WiredPost template_name = 'gtd/wiredpost_table.html' def get_queryset(self): @@ -197,25 +187,25 @@ class WiredPostListView(ListView): class WiredPostNewView(ListView): template_name = 'gtd/wiredpost_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]) + context['reviews'] = WiredNote.objects.filter(plan__in=[1, 2], status__in=[0, 1, 2, 3]) return context class WiredPostCreateView(CreateView): - model = WiredPost + model = WiredPost fields = ['title', 'post_status', 'url', 'template_type', 'update_frequency', 'edit_url', 'date_last_pub'] template_name = "gtd/wiredpost_form.html" class WiredPostTodoView(ListView): template_name = 'gtd/wiredpost_table.html' - + def get_queryset(self): qs = WiredPost.objects.filter(Q(needs_update=True) | Q(is_live=0)).exclude(post_status=1) unsorted_results = qs.all() @@ -223,12 +213,12 @@ class WiredPostTodoView(ListView): 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__in=[4,5]) + context['reviews'] = WiredNote.objects.filter(plan__in=[1, 2, 3]).exclude(status__in=[4, 5]) return context class WiredPostNotesView(DetailView): - model = WiredPost + model = WiredPost template_name = "gtd/wiredpost_detail.html" def get_context_data(self, **kwargs): @@ -242,10 +232,6 @@ class WiredPostUpdateView(UpdateView): form_class = WiredPostUpdateForm template_name = "gtd/wiredpost_form.html" - 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') @@ -255,8 +241,8 @@ class WiredPostUpdateView(UpdateView): class GTDNoteDeleteView(DeleteView): # specify the model you want to use - model = GTDNote - success_url ="/gtd/notes" + model = GTDNote + success_url = "/gtd/notes" template_name = "gtd/confirm_delete.html" @@ -278,6 +264,7 @@ class GTDOutcomeUpdateView(UpdateView): context['is_update'] = True return context + class GTDOutcomeListView(ListView): model = GTDOutcome template_name = "gtd/outcome_list.html" @@ -286,5 +273,5 @@ class GTDOutcomeListView(ListView): class GTDOutcomeDeleteView(DeleteView): # specify the model you want to use model = GTDOutcome - success_url ="/gtd/outcomes" + success_url = "/gtd/outcomes" template_name = "gtd/confirm_delete.html" |