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
5 from django.core.urlresolvers import reverse
8 ('rst', 'reStructuredText'),
12 class CSSDocument(models.Model):
13 title = models.CharField(max_length=150)
14 slug = models.SlugField()
15 content = models.TextField()
18 return self.__unicode__()
20 def __unicode__(self):
21 return u'%s' %(self.title,)
23 class Document(models.Model):
24 title = models.CharField(max_length=150)
25 islive = models.BooleanField()
26 extracss = models.ManyToManyField(CSSDocument, null=True, blank=True)
27 folder = models.ForeignKey('Folder', null=True, blank=True)
28 format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
29 slug = models.SlugField()
30 content = models.TextField()
33 return self.__unicode__()
35 def __unicode__(self):
36 return u'%s (%s)' %(self.title, self.slug)
39 super(Document, self).save()
40 # now check if we just set our selves to be live
43 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
45 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
50 def get_basic_url(self):
51 folderstring = self.get_folder_path()
52 if folderstring != u'':
53 folderstring = "%s/" %(folderstring,)
55 return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
57 def get_folder_path(self):
61 return self.folder.get_path()
63 def get_absolute_url(self):
64 if self.slug == 'index':
65 if self.folder.parent:
66 return reverse('bpcms.views.document_view', kwargs={'folders': self.folder.parent.get_path(), 'slug': self.folder.slug})
68 return reverse('bpcms.views.document_view', kwargs={'slug': self.folder.slug})
71 return reverse('bpcms.views.document_view', kwargs={'folders': self.get_folder_path(), 'slug': self.slug})
73 return reverse('bpcms.views.document_view', kwargs={'slug': self.slug})
75 class Folder(models.Model):
76 title = models.CharField(max_length=150)
77 slug = models.SlugField()
78 parent = models.ForeignKey('self', null=True, blank=True)
81 return self.__unicode__()
83 def __unicode__(self):
84 return u'%s - %s' %(self.get_path(), self.title)
89 while curfolder != None:
90 folders.append(curfolder.slug)
91 curfolder = curfolder.parent
94 folderstring = "/".join(folders)
97 def save(self, force_insert=False, force_update=False):
98 super(Folder, self).save(force_insert, force_update)
99 if self.parent == None:
100 cache.delete('bpcms_mainmenu')
102 cache.delete('bpcms_submenu_%s' %(self.get_path()))
104 def get_absolute_url(self):
106 return reverse('bpcms.views.document_view', kwargs={'folders': self.parent.get_path(), 'slug': self.slug})
108 return reverse('bpcms.views.document_view', kwargs={'slug': self.slug})