From e761db4cc51ead40730702a4b05e27347340886c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 21 Dec 2012 19:19:09 -0600 Subject: Add initial todolists models migration Signed-off-by: Dan McGee --- todolists/models.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 todolists/models.py (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3-2-g168b From 8be27a5cafde87c439b19f64a7c215410c88484b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 21 Dec 2012 19:26:35 -0600 Subject: Add new todolists and todolist package model Move the todolist model from main to the todolists application, and make a few minor tweaks to field names along the way. Also add a 'raw' field that will hold the originally input text data from the creator or last modifier of the todolist. Add pkgname, pkgbase, arch, and repo fields to a new todolist package model, which will supplement the former foreign key to an actual package object. This will prevent todolist package objects from ever being deleted as they can be now, which is not intuitive. Also change the current boolean 'complete' flag to a 'status' enum that can hold other values. For now, we add 'In-progress' to the mix. Finally, add a 'user' field, and a 'comments' field that will be utilized later by the UI. Signed-off-by: Dan McGee --- todolists/models.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index e69de29b..7af7faf9 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -0,0 +1,81 @@ +from django.contrib.auth.models import User +from django.contrib.sites.models import Site +from django.db import models +from django.db.models import Q +from django.db.models.signals import pre_save + +from main.models import Arch, Repo, Package +from main.utils import set_created_field + + +class TodolistManager(models.Manager): + def incomplete(self): + not_done = (Q(todolistpackage__status=TodolistPackage.INCOMPLETE) | + Q(todolistpackage__status=TodolistPackage.IN_PROGRESS)) + return self.order_by().filter(not_done).distinct() + + +class Todolist(models.Model): + old_id = models.IntegerField(null=True, unique=True) + name = models.CharField(max_length=255) + description = models.TextField() + creator = models.ForeignKey(User, on_delete=models.PROTECT, + related_name="created_todolists") + created = models.DateTimeField(db_index=True) + last_modified = models.DateTimeField(editable=False) + raw = models.TextField(blank=True) + + objects = TodolistManager() + + class Meta: + get_latest_by = 'created' + + def __unicode__(self): + return self.name + + def get_absolute_url(self): + return '/todo/%i/' % self.id + + def get_full_url(self, proto='https'): + '''get a URL suitable for things like email including the domain''' + domain = Site.objects.get_current().domain + return '%s://%s%s' % (proto, domain, self.get_absolute_url()) + + +class TodolistPackage(models.Model): + INCOMPLETE = 0 + COMPLETE = 1 + IN_PROGRESS = 2 + STATUS_CHOICES = ( + (INCOMPLETE, 'Incomplete'), + (COMPLETE, 'Complete'), + (IN_PROGRESS, 'In-progress'), + ) + + todolist = models.ForeignKey(Todolist) + pkg = models.ForeignKey(Package, null=True, on_delete=models.SET_NULL) + pkgname = models.CharField(max_length=255) + pkgbase = models.CharField(max_length=255) + arch = models.ForeignKey(Arch) + repo = models.ForeignKey(Repo) + created = models.DateTimeField() + status = models.SmallIntegerField(default=0, choices=STATUS_CHOICES) + user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) + comments = models.TextField(null=True, blank=True) + + class Meta: + unique_together = (('todolist','pkgname', 'arch'),) + + def __unicode__(self): + return self.pkgname + + def status_css_class(self): + return self.get_status_display().lower().replace('-', '') + + +pre_save.connect(set_created_field, sender=Todolist, + dispatch_uid="todolists.models") +pre_save.connect(set_created_field, sender=TodolistPackage, + dispatch_uid="todolists.models") + +# vim: set ts=4 sw=4 et: -- cgit v1.2.3-2-g168b From f07a5862c9ed40646677344eaf920dbd05a1a137 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 27 Dec 2012 23:32:05 -0600 Subject: Add packages method to new Todolist model Signed-off-by: Dan McGee --- todolists/models.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index 7af7faf9..c38c564e 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -41,6 +41,12 @@ class Todolist(models.Model): domain = Site.objects.get_current().domain return '%s://%s%s' % (proto, domain, self.get_absolute_url()) + def packages(self): + if not hasattr(self, '_packages'): + self._packages = self.todolistpackage_set.select_related( + 'pkg', 'repo', 'arch').order_by('pkgname', 'arch') + return self._packages + class TodolistPackage(models.Model): INCOMPLETE = 0 -- cgit v1.2.3-2-g168b From 2ff967c3d9433361b1f086c326f3a473f10373e3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 09:22:23 -0600 Subject: Todolist URLs map to old_id now, not id This is a short-term fix before adding a slug field to todo lists as we did to news a while back. Signed-off-by: Dan McGee --- todolists/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index c38c564e..d19ad92d 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -34,7 +34,7 @@ class Todolist(models.Model): return self.name def get_absolute_url(self): - return '/todo/%i/' % self.id + return '/todo/%i/' % self.old_id def get_full_url(self, proto='https'): '''get a URL suitable for things like email including the domain''' -- cgit v1.2.3-2-g168b From 46a51a99cc9d1839b622252a4cb0b4cd1d0c50e4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 09:35:47 -0600 Subject: Add todolists slug field This will be used to make more descriptive URLs for our todolists. The `null=True` bit will be removed once a data migration is added to add slugs to all previously created todolists. Signed-off-by: Dan McGee --- todolists/models.py | 1 + 1 file changed, 1 insertion(+) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index d19ad92d..8ee4b5ce 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -16,6 +16,7 @@ class TodolistManager(models.Manager): class Todolist(models.Model): + slug = models.SlugField(max_length=255, null=True, unique=True) old_id = models.IntegerField(null=True, unique=True) name = models.CharField(max_length=255) description = models.TextField() -- cgit v1.2.3-2-g168b From 1dc6b867f48786ab6973d6832f386c9d771b58e0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 09:42:17 -0600 Subject: Populate the todolist slug field and mark non-null This is ripped off from commit 7c92ddbd3c86d when we added slugs to News objects. Signed-off-by: Dan McGee --- todolists/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index 8ee4b5ce..a6dda2ab 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -16,7 +16,7 @@ class TodolistManager(models.Manager): class Todolist(models.Model): - slug = models.SlugField(max_length=255, null=True, unique=True) + slug = models.SlugField(max_length=255, unique=True) old_id = models.IntegerField(null=True, unique=True) name = models.CharField(max_length=255) description = models.TextField() -- cgit v1.2.3-2-g168b From 0c94cc4465530866da7b6437975a287aa7f063a8 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 10:06:32 -0600 Subject: Use todolist slugs for all URLs Signed-off-by: Dan McGee --- todolists/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index a6dda2ab..76af0d35 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -35,7 +35,7 @@ class Todolist(models.Model): return self.name def get_absolute_url(self): - return '/todo/%i/' % self.old_id + return '/todo/%s/' % self.slug def get_full_url(self, proto='https'): '''get a URL suitable for things like email including the domain''' -- cgit v1.2.3-2-g168b From 5a09e335ae3b9d1f2bc814d011bcf90a16220777 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 31 Dec 2012 09:52:28 -0600 Subject: Add 'removed' field to todolist packages This will be utilized to soft-delete items from the list if the packages are modified, rather than deleting them outright. Signed-off-by: Dan McGee --- todolists/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index 76af0d35..e02cdd1a 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -66,12 +66,15 @@ class TodolistPackage(models.Model): arch = models.ForeignKey(Arch) repo = models.ForeignKey(Repo) created = models.DateTimeField() - status = models.SmallIntegerField(default=0, choices=STATUS_CHOICES) + removed = models.DateTimeField(null=True, blank=True) + status = models.SmallIntegerField(default=INCOMPLETE, + choices=STATUS_CHOICES) user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) comments = models.TextField(null=True, blank=True) class Meta: unique_together = (('todolist','pkgname', 'arch'),) + get_latest_by = 'created' def __unicode__(self): return self.pkgname -- cgit v1.2.3-2-g168b From c37fe107282f1aa4925d6c3eef9b7c1598ab4aa1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 31 Dec 2012 10:24:09 -0600 Subject: Minor coding style tweaks Signed-off-by: Dan McGee --- todolists/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index e02cdd1a..156b041d 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -73,7 +73,7 @@ class TodolistPackage(models.Model): comments = models.TextField(null=True, blank=True) class Meta: - unique_together = (('todolist','pkgname', 'arch'),) + unique_together = (('todolist', 'pkgname', 'arch'),) get_latest_by = 'created' def __unicode__(self): -- cgit v1.2.3-2-g168b From 7952fe0ede3a5a68a64f05eccb180194394652f3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 31 Dec 2012 11:31:35 -0600 Subject: Mark todolist packages as removed rather than deleting them This makes it easier to see the progression of a todolist and its contents easier since we are no longer losing the data. Signed-off-by: Dan McGee --- todolists/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index 156b041d..040f8a29 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -10,8 +10,9 @@ from main.utils import set_created_field class TodolistManager(models.Manager): def incomplete(self): - not_done = (Q(todolistpackage__status=TodolistPackage.INCOMPLETE) | - Q(todolistpackage__status=TodolistPackage.IN_PROGRESS)) + not_done = ((Q(todolistpackage__status=TodolistPackage.INCOMPLETE) | + Q(todolistpackage__status=TodolistPackage.IN_PROGRESS)) & + Q(todolistpackage__removed__isnull=True)) return self.order_by().filter(not_done).distinct() @@ -44,7 +45,8 @@ class Todolist(models.Model): def packages(self): if not hasattr(self, '_packages'): - self._packages = self.todolistpackage_set.select_related( + self._packages = self.todolistpackage_set.filter( + removed__isnull=True).select_related( 'pkg', 'repo', 'arch').order_by('pkgname', 'arch') return self._packages -- cgit v1.2.3-2-g168b From 6fe28b4206979a0db9c7d1f2f5f3a81c49d77951 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 12 Jan 2013 16:33:31 -0600 Subject: Add last_modified field to todolist packages Signed-off-by: Dan McGee --- todolists/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'todolists/models.py') diff --git a/todolists/models.py b/todolists/models.py index 040f8a29..3ea80f37 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -67,7 +67,8 @@ class TodolistPackage(models.Model): pkgbase = models.CharField(max_length=255) arch = models.ForeignKey(Arch) repo = models.ForeignKey(Repo) - created = models.DateTimeField() + created = models.DateTimeField(editable=False) + last_modified = models.DateTimeField(editable=False) removed = models.DateTimeField(null=True, blank=True) status = models.SmallIntegerField(default=INCOMPLETE, choices=STATUS_CHOICES) -- cgit v1.2.3-2-g168b