diff options
author | luxagraf <sng@luxagraf.net> | 2024-01-17 15:25:44 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2024-01-17 15:25:44 -0500 |
commit | 1e362aad0f890221b7d5529dce01bb34d8f3282d (patch) | |
tree | 260c814348e92abec8a59cf0a372fd7a9888bd37 /app/gtd/models.py | |
parent | 163a4247110861510b58765a19efbd98c084b350 (diff) |
gtd: added an update schedule option and way to update the needs_update
boolean.
Diffstat (limited to 'app/gtd/models.py')
-rw-r--r-- | app/gtd/models.py | 54 |
1 files changed, 46 insertions, 8 deletions
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) |