1 from django.db import models
2 from django.contrib.auth.models import User
4 # Create your models here.
5 class PartCache(models.Model):
6 document_id = models.CharField(max_length=255)
7 user_id = models.CharField(max_length=64, blank=True)
8 part_id = models.CharField(max_length=255)
11 def update_cache(me, docid, userid, old, new):
15 related = me.objects.filter(user_id=userid, document_id=docid)
17 missing = old.difference(new)
18 related.filter(part_id__in=missing).delete()
20 created = new.difference(old)
23 me.objects.create(user_id=userid, document_id=docid, part_id=part)
26 class PullRequest(models.Model):
29 "E": "Edited/Conflicting",
31 "A": "Accepted & merged",
34 comitter = models.ForeignKey(User) # the user who request the pull
35 comment = models.TextField() # addtional comments to the request
37 timestamp = models.DateTimeField(auto_now_add=True)
40 document = models.CharField(max_length=255)
42 # revision to be merged into the main branch
43 source_revision = models.CharField(max_length=40, unique=True)
44 target_revision = models.CharField(max_length=40)
47 status = models.CharField(max_length=1, choices=REQUEST_STATUSES.items())
49 # comment to the status change of request (if applicable)
50 response_comment = models.TextField(blank=True)
52 # revision number in which the changes were merged (if any)
53 merged_revision = models.CharField(max_length=40, blank=True, null=True)
54 merge_timestamp = models.DateTimeField(blank=True, null=True)
56 def __unicode__(self):
57 return unicode(self.comitter) + u':' + self.document
62 ("view_prq", "Can view pull request's contents."),
66 # This is actually an abstract Model, but if we declare
67 # it as so Django ignores the permissions :(
68 class Document(models.Model):
71 ("share_document", "Can share documents without pull requests."),
72 ("view_other_document", "Can view other's documents."),