X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/4437d85206a7deb768c75a4fd1cb1b474e87efe3..a7a2b1c6daaa2266645abc5ee4fac91ce10a4c39:/apps/dvcs/models.py?ds=inline diff --git a/apps/dvcs/models.py b/apps/dvcs/models.py index 5ce00c0f..f81f2cab 100644 --- a/apps/dvcs/models.py +++ b/apps/dvcs/models.py @@ -38,6 +38,16 @@ class Tag(models.Model): def listener_changed(sender, instance, **kwargs): sender._object_cache = {} + def next(self): + """ + Returns the next tag - stage to work on. + Returns None for the last stage. + """ + try: + return Tag.objects.filter(ordering__gt=self.ordering)[0] + except IndexError: + return None + models.signals.pre_save.connect(Tag.listener_changed, sender=Tag) @@ -66,6 +76,7 @@ class Change(models.Model): description = models.TextField(blank=True, default='') created_at = models.DateTimeField(editable=False, db_index=True, default=datetime.now) + publishable = models.BooleanField(default=False) tags = models.ManyToManyField(Tag) @@ -167,12 +178,16 @@ class Document(models.Model): """ File in repository. """ - creator = models.ForeignKey(User, null=True, blank=True, editable=False) + creator = models.ForeignKey(User, null=True, blank=True, editable=False, + related_name="created_documents") head = models.ForeignKey(Change, null=True, blank=True, default=None, help_text=_("This document's current head."), editable=False) + user = models.ForeignKey(User, null=True, blank=True) + stage = models.ForeignKey(Tag, null=True, blank=True) + def __unicode__(self): return u"{0}, HEAD: {1}".format(self.id, self.head_id) @@ -212,6 +227,9 @@ class Document(models.Model): author = kwargs.get('author', None) author_desc = kwargs.get('author_desc', None) tags = kwargs.get('tags', []) + if tags: + # set stage to next tag after the commited one + self.stage = max(tags, key=lambda t: t.ordering).next() old_head = self.head if parent != old_head: @@ -240,13 +258,13 @@ class Document(models.Model): return rev if rev is not None else -1 def at_revision(self, rev): - if rev: + if rev is not None: return self.change_set.get(revision=rev) else: return self.head - def last_tagged(self, tag): - changes = tag.change_set.filter(tree=self).order_by('-created_at')[:1] + def publishable(self): + changes = self.change_set.filter(publishable=True).order_by('-created_at')[:1] if changes.count(): return changes[0] else: