summaryrefslogtreecommitdiff
path: root/app/gtd/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/gtd/models.py')
-rw-r--r--app/gtd/models.py35
1 files changed, 15 insertions, 20 deletions
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()