summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-11-17 19:02:57 -0500
committerluxagraf <sng@luxagraf.net>2023-11-17 19:02:57 -0500
commit6a29eafe6fc9762e899aaf538f97cdb2fe6b02d3 (patch)
tree55f96eaad213b2356479e1c724b8eb9cd436a830
parent96866e3f83920e43e736d2ad9a89e03321dab03c (diff)
gtd: ran flake8 to clean up code
-rw-r--r--app/gtd/forms.py19
-rw-r--r--app/gtd/models.py35
-rw-r--r--app/gtd/urls.py8
-rw-r--r--app/gtd/views.py75
4 files changed, 59 insertions, 78 deletions
diff --git a/app/gtd/forms.py b/app/gtd/forms.py
index 2e1c576..595611b 100644
--- a/app/gtd/forms.py
+++ b/app/gtd/forms.py
@@ -1,18 +1,17 @@
from django.forms import ModelForm
-from django.forms import ChoiceField
from .models import GTDNote, GTDProject, WiredNote, WiredPost
class GTDNoteCreateForm(ModelForm):
class Meta:
- model = GTDNote
+ model = GTDNote
fields = ['title', 'url', 'body_markdown', 'project', 'note_type', 'reminder', 'status']
class GTDNoteEditForm(ModelForm):
class Meta:
- model = GTDNote
+ model = GTDNote
fields = ['title', 'url', 'body_markdown', 'project', 'note_type', 'reminder', 'status']
@@ -30,10 +29,10 @@ class GTDProjectUpdateForm(ModelForm):
class WiredNoteCreateForm(ModelForm):
- def __init__(self,*args,**kwargs):
+ def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
self.user = user
- super(WiredNoteCreateForm,self).__init__(*args,**kwargs)
+ super(WiredNoteCreateForm, self).__init__(*args, **kwargs)
self.fields['post'].required = False
def save(self, commit=True):
@@ -41,26 +40,26 @@ class WiredNoteCreateForm(ModelForm):
return super().save(commit=commit)
class Meta:
- model = WiredNote
+ model = WiredNote
fields = ['title', 'url', 'body_markdown', 'post']
class WiredNoteEditForm(ModelForm):
- def __init__(self,*args,**kwargs):
- super(WiredNoteEditForm,self).__init__(*args,**kwargs)
+ def __init__(self, *args, **kwargs):
+ super(WiredNoteEditForm, self).__init__(*args, **kwargs)
self.fields['post'].queryset = WiredPost.objects.all().order_by("title")
def save(self, commit=True):
return super().save(commit=commit)
class Meta:
- model = WiredNote
+ model = WiredNote
fields = ['title', 'url', 'body_markdown', 'post', 'status', 'plan']
class WiredPostUpdateForm(ModelForm):
class Meta:
- model = WiredPost
+ model = WiredPost
fields = ['title', 'post_status', 'url', 'template_type', 'update_frequency', 'edit_url', 'date_last_pub']
diff --git a/app/gtd/models.py b/app/gtd/models.py
index 1ca0d6e..3352394 100644
--- a/app/gtd/models.py
+++ b/app/gtd/models.py
@@ -1,17 +1,12 @@
import datetime
-import os
-from django.utils import timezone
from django.contrib.gis.db import models
-from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
-from django.contrib.contenttypes.models import ContentType
-from django.contrib.sites.models import Site
from django.urls import reverse
from django.apps import apps
-from django.conf import settings
-from django.contrib.sitemaps import Sitemap
+from django.utils import timezone
+from django.utils.html import format_html
-from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image
+from utils.util import render_images, markdown_to_html
def get_upload_path(self, filename):
@@ -75,13 +70,13 @@ class GTDProject(models.Model):
@property
def get_previous_admin_url(self):
n = self.get_previous_by_date_goal()
- return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] )
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[n.id])
@property
def get_next_admin_url(self):
model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
try:
- return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_date_goal().pk] )
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next_by_date_goal().pk])
except model.DoesNotExist:
return ''
@@ -116,7 +111,7 @@ class GTDNote(models.Model):
NONE = 0
OPEN = 1
COMPLETED = 2
- STATUS= [
+ STATUS = [
(NONE, 'None'),
(OPEN, 'Open'),
(COMPLETED, 'Completed'),
@@ -129,7 +124,7 @@ class GTDNote(models.Model):
def __str__(self):
return self.title
-
+
def save(self, *args, **kwargs):
self.body_html = markdown_to_html(self.body_markdown)
super(GTDNote, self).save(*args, **kwargs)
@@ -137,6 +132,7 @@ class GTDNote(models.Model):
def get_absolute_url(self, *args, **kwargs):
return reverse('gtd:note-edit', kwargs={"pk": self.pk})
+
class PostType(models.IntegerChoices):
REVIEW = 0, ('review')
GUIDE = 1, ('guide')
@@ -166,12 +162,11 @@ class WiredPost(models.Model):
post_type = models.IntegerField(choices=PostType.choices, default=PostType.GUIDE)
template_type = models.IntegerField(choices=TemplateType.choices, default=TemplateType.STORY)
update_frequency = models.BigIntegerField(help_text="In days")
- #products = models.ManyToManyField(ProductLink, blank=True, null=True)
+ # products = models.ManyToManyField(ProductLink, blank=True, null=True)
needs_update = models.BooleanField(default=False)
is_live = models.BooleanField(default=True)
post_status = models.IntegerField(choices=PostStatus.choices, default=PostStatus.PUBLISHED)
-
class Meta:
ordering = ('date_last_pub',)
@@ -179,17 +174,17 @@ class WiredPost(models.Model):
return self.title
def time_since_update(self):
- td = datetime.date.today() - self.date_last_pub
+ td = datetime.date.today() - self.date_last_pub
return int(td.days)
- #def get_needs_update(self):
+ # def get_needs_update(self):
# if self.time_since_update() > self.update_frequency:
# return True
# else:
# return False
def days_overdue(self):
- if self.needs_update == True:
+ if self.needs_update:
return self.time_since_update() - self.update_frequency
else:
return 0
@@ -203,11 +198,11 @@ class WiredPost(models.Model):
def save(self, *args, **kwargs):
if self.date_last_pub:
- td = datetime.date.today() - self.date_last_pub
+ td = datetime.date.today() - self.date_last_pub
if td.days > self.update_frequency and self.post_status != 1:
self.needs_update = True
- else:
- self.needs_update = False
+ else:
+ self.needs_update = False
super(WiredPost, self).save()
diff --git a/app/gtd/urls.py b/app/gtd/urls.py
index 27a2dd8..a56bbf4 100644
--- a/app/gtd/urls.py
+++ b/app/gtd/urls.py
@@ -1,4 +1,4 @@
-from django.urls import path, re_path
+from django.urls import path
from . import views
@@ -13,7 +13,7 @@ urlpatterns = [
path(
r'notes',
views.GTDNoteListView.as_view(),
- {'note_type':None},
+ {'note_type': None},
name="note-list"
),
path(
@@ -39,7 +39,7 @@ urlpatterns = [
path(
r'projects',
views.GTDProjectListView.as_view(),
- {'project_type':None},
+ {'project_type': None},
name="project-list"
),
path(
@@ -70,7 +70,7 @@ urlpatterns = [
path(
r'wirednotes',
views.WiredNoteListView.as_view(),
- {'status':None},
+ {'status': None},
name="wirednote-list"
),
path(
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"