1 from django.db import models
2 from django.conf import settings
3 from django.contrib import admin
4 from django.core.cache import cache
7 ('rst', 'reStructuredText'),
11 class Document(models.Model):
12 title = models.CharField(max_length=150)
13 islive = models.BooleanField()
14 folder = models.ForeignKey('Folder', null=True, blank=True)
15 format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
16 slug = models.SlugField()
17 content = models.TextField()
20 return self.__unicode__()
22 def __unicode__(self):
23 return u'%s (%s)' %(self.title, self.slug)
26 super(Document, self).save()
27 # now check if we just set our selves to be live
30 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
32 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
37 def get_basic_url(self):
39 curfolder = self.folder
40 while curfolder != None:
41 folders.append(curfolder.slug)
42 curfolder = curfolder.parent
45 folderstring = "/".join(folders)
46 if folderstring != u'':
47 folderstring = "%s/" %(folderstring,)
49 return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
51 class Folder(models.Model):
52 title = models.CharField(max_length=150)
53 slug = models.SlugField()
54 parent = models.ForeignKey('self', null=True, blank=True)
57 return self.__unicode__()
59 def __unicode__(self):
60 return u'%s - %s' %(self.get_path(), self.title)
65 while curfolder != None:
66 folders.append(curfolder.slug)
67 curfolder = curfolder.parent
70 folderstring = "/".join(folders)
71 if folderstring != u'':
72 folderstring = "%s/" %(folderstring,)
76 def save(self, force_insert=False, force_update=False):
77 super(Folder, self).save(force_insert, force_update)
78 if self.parent == None:
79 cache.delete('bpcms_mainmenu')
81 cache.delete('bpcms_submenu_%s' %(self.get_path()))
84 def get_basic_url(self):
85 return "%s%s" %(settings.BPCMS_ROOT, self.get_path())