summaryrefslogtreecommitdiff
path: root/app/gtd
diff options
context:
space:
mode:
Diffstat (limited to 'app/gtd')
-rw-r--r--app/gtd/admin.py12
-rw-r--r--app/gtd/migrations/0028_wiredupdate.py24
-rw-r--r--app/gtd/migrations/0029_wiredpost_update_schedule.py18
-rw-r--r--app/gtd/migrations/0030_wiredpost_is_priority_alter_wiredpost_post_status.py23
-rw-r--r--app/gtd/models.py54
5 files changed, 120 insertions, 11 deletions
diff --git a/app/gtd/admin.py b/app/gtd/admin.py
index 0e56f59..643ca73 100644
--- a/app/gtd/admin.py
+++ b/app/gtd/admin.py
@@ -4,15 +4,21 @@ from utils.widgets import AdminImageWidget, LGEntryForm
from .models import (
WiredNote,
- WiredPost
+ WiredPost,
+ WiredUpdate
)
-print(WiredPost)
-
@admin.register(WiredPost)
class WiredPostAdmin(admin.ModelAdmin):
list_display = ('title', 'date_last_pub', 'category', 'update_frequency', 'needs_update', 'post_status')
search_fields = ['title']
list_filter = ['post_status', 'post_type', 'update_frequency']
+ filter_horizontal = ('update_schedule',)
class Media:
js = ('next-prev-links.js',)
+
+
+@admin.register(WiredUpdate)
+class WiredUpdateAdmin(admin.ModelAdmin):
+ list_display = ('name', 'date')
+
diff --git a/app/gtd/migrations/0028_wiredupdate.py b/app/gtd/migrations/0028_wiredupdate.py
new file mode 100644
index 0000000..3ad0525
--- /dev/null
+++ b/app/gtd/migrations/0028_wiredupdate.py
@@ -0,0 +1,24 @@
+# Generated by Django 4.2.7 on 2024-01-17 14:23
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0027_wiredpost_category'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='WiredUpdate',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(blank=True, max_length=20, null=True)),
+ ('date', models.DateField(blank=True, null=True)),
+ ],
+ options={
+ 'ordering': ('-date',),
+ },
+ ),
+ ]
diff --git a/app/gtd/migrations/0029_wiredpost_update_schedule.py b/app/gtd/migrations/0029_wiredpost_update_schedule.py
new file mode 100644
index 0000000..3b1d413
--- /dev/null
+++ b/app/gtd/migrations/0029_wiredpost_update_schedule.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.7 on 2024-01-17 14:26
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0028_wiredupdate'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='wiredpost',
+ name='update_schedule',
+ field=models.ManyToManyField(blank=True, to='gtd.wiredupdate'),
+ ),
+ ]
diff --git a/app/gtd/migrations/0030_wiredpost_is_priority_alter_wiredpost_post_status.py b/app/gtd/migrations/0030_wiredpost_is_priority_alter_wiredpost_post_status.py
new file mode 100644
index 0000000..b0cb54f
--- /dev/null
+++ b/app/gtd/migrations/0030_wiredpost_is_priority_alter_wiredpost_post_status.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.7 on 2024-01-17 14:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('gtd', '0029_wiredpost_update_schedule'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='wiredpost',
+ name='is_priority',
+ field=models.BooleanField(default=True),
+ ),
+ migrations.AlterField(
+ model_name='wiredpost',
+ name='post_status',
+ field=models.IntegerField(choices=[(0, 'Assigned'), (1, 'turned in'), (2, 'published'), (3, 'in progress')], default=2),
+ ),
+ ]
diff --git a/app/gtd/models.py b/app/gtd/models.py
index d923d93..9faa6b2 100644
--- a/app/gtd/models.py
+++ b/app/gtd/models.py
@@ -1,6 +1,8 @@
import datetime
from django.contrib.gis.db import models
+from django.dispatch import receiver
+from django.db.models.signals import post_save
from django.urls import reverse
from django.apps import apps
from django.utils import timezone
@@ -145,6 +147,18 @@ class PostStatus(models.IntegerChoices):
ASSIGNED = 0, ('Assigned')
TURNEDIN = 1, ('turned in')
PUBLISHED = 2, ('published')
+ INPROGRESS = 3, ('in progress')
+
+
+class WiredUpdate(models.Model):
+ name = models.CharField(max_length=20, blank=True, null=True)
+ date = models.DateField(blank=True, null=True)
+
+ class Meta:
+ ordering = ('-date',)
+
+ def __str__(self):
+ return self.name
class WiredPost(models.Model):
@@ -161,8 +175,10 @@ class WiredPost(models.Model):
update_frequency = models.BigIntegerField(help_text="In days")
needs_update = models.BooleanField(default=False)
is_live = models.BooleanField(default=True)
+ is_priority = models.BooleanField(default=True)
post_status = models.IntegerField(choices=PostStatus.choices, default=PostStatus.PUBLISHED)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)
+ update_schedule = models.ManyToManyField(WiredUpdate, blank=True)
class Meta:
ordering = ('date_last_pub',)
@@ -175,17 +191,37 @@ class WiredPost(models.Model):
return int(td.days)
def set_needs_update(self):
- if self.date_last_pub:
+ """
+ figures out if a post needs to be update based on either
+ update frrquency or month-based schedule if there is one
+ """
+ if self.date_last_pub and not self.update_schedule.exists():
td = datetime.date.today() - self.date_last_pub
if self.post_status == 0 or self.post_status == 2:
if td.days > self.update_frequency:
self.needs_update = True
self.save()
+ if self.update_schedule.exists():
+ for m in self.update_schedule.all():
+ td = m.date - datetime.date.today()
+ if td.days <= 30:
+ self.needs_update = True
+ self.save()
return ''
def days_overdue(self):
- if self.needs_update:
+ """
+ calculates how overdue something is in day based on either how
+ often it should be updated or the update schedule if there is one
+ """
+ if self.needs_update and not self.update_schedule.exists():
return self.time_since_update() - self.update_frequency
+ elif self.needs_update and self.update_schedule.exists():
+ for m in self.update_schedule.all():
+ if m.date > datetime.date.today():
+ td = m.date - datetime.date.today()
+ if td.days <= 30:
+ return td.days
else:
return 0
@@ -197,15 +233,17 @@ class WiredPost(models.Model):
return reverse('gtd:wiredpost-detail', kwargs={"pk": self.id})
def save(self, *args, **kwargs):
- if self.date_last_pub:
- td = datetime.date.today() - self.date_last_pub
- if td.days > self.update_frequency and self.post_status == 2:
- self.needs_update = True
- else:
- self.needs_update = False
super(WiredPost, self).save()
+@receiver(post_save, sender=WiredPost)
+def post_save_events(sender, update_fields, created, instance, **kwargs):
+ post_save.disconnect(post_save_events, sender=WiredPost)
+ instance.set_needs_update()
+ instance.save()
+ post_save.connect(post_save_events, sender=WiredPost)
+
+
class WiredNote(models.Model):
title = models.CharField(max_length=400)
url = models.CharField(max_length=400, blank=True, null=True)