1 from django.db import models
2 from bpcms.content_val import is_unique_name
3 from django.conf import settings
6 ('rst', 'reStructuredText'),
10 class Document(models.Model):
11 title = models.CharField(maxlength=150)
12 islive = models.BooleanField()
13 folder = models.ForeignKey('Folder', null=True, blank=True)
14 format = models.CharField(maxlength=10, choices=FORMAT_CHOICES)
15 slug = models.SlugField(prepopulate_from=("title",))
16 content = models.TextField()
19 return self.__unicode__()
21 def __unicode__(self):
22 return u'%s (%s)' %(self.title, self.slug)
25 super(Document, self).save()
26 # now check if we just set our selves to be live
29 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
31 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
36 def get_basic_url(self):
38 curfolder = self.folder
39 while curfolder != None:
40 folders.append(curfolder.slug)
41 curfolder = curfolder.parent
44 folderstring = "/".join(folders)
45 if folderstring != u'':
46 folderstring = "%s/" %(folderstring,)
48 return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
53 class Folder(models.Model):
54 title = models.CharField(maxlength=150)
55 slug = models.SlugField(prepopulate_from=("title",))
56 parent = models.ForeignKey('self', null=True, blank=True)
59 return self.__unicode__()
61 def __unicode__(self):
62 return u'%s' %(self.title)
64 def get_basic_url(self):
67 while curfolder != None:
68 folders.append(curfolder.slug)
69 curfolder = curfolder.parent
72 folderstring = "/".join(folders)
73 if folderstring != u'':
74 folderstring = "%s/" %(folderstring,)
76 return "%s%s" %(settings.BPCMS_ROOT, folderstring)