1 from django.db import models
2 from content.content_val import is_unique_name
5 ('rst', 'reStructuredText'),
9 class Document(models.Model):
10 title = models.CharField(maxlength=150)
11 islive = models.BooleanField()
12 folder = models.ForeignKey('Folder', null=True, blank=True)
13 format = models.CharField(maxlength=10, choices=FORMAT_CHOICES)
14 slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_unique_name,])
15 content = models.TextField()
18 return self.__unicode__()
20 def __unicode__(self):
21 return u'%s (%s)' %(self.title, self.slug)
24 super(Document, self).save()
25 # now check if we just set our selves to be live
28 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
30 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
35 def get_basic_url(self):
37 curfolder = self.folder
38 while curfolder != None:
39 folders.append(curfolder.slug)
40 curfolder = curfolder.parent
43 folderstring = "/".join(folders)
44 if folderstring != u'':
45 folderstring = "%s/" %(folderstring,)
47 return "%s%s/" %(folderstring, self.slug)
52 class Folder(models.Model):
53 title = models.CharField(maxlength=150)
54 slug = models.SlugField(prepopulate_from=("title",))
55 parent = models.ForeignKey('self', null=True, blank=True)
58 return self.__unicode__()
60 def __unicode__(self):
61 return u'%s' %(self.title)
63 def get_basic_url(self):
66 while curfolder != None:
67 folders.append(curfolder.slug)
68 curfolder = curfolder.parent
71 folderstring = "/".join(folders)
72 if folderstring != u'':
73 folderstring = "%s/" %(folderstring,)
75 return "%s/" %(folderstring)