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.urls 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(default=False)
26 extracss = models.ManyToManyField(CSSDocument, blank=True)
27 folder = models.ForeignKey('Folder', on_delete=models.SET_NULL, null=True, blank=True)
28 format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
29 slug = models.SlugField()
30 content = models.TextField()
36 return self.__unicode__()
38 def __unicode__(self):
39 return u'%s - %s' %(self.get_basic_url(), self.title)
42 super(Document, self).save()
43 # now check if we just set our selves to be live
46 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
48 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
53 def get_basic_url(self):
54 folderstring = self.get_folder_path()
55 if folderstring != u'':
56 folderstring = "%s/" %(folderstring,)
58 return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
60 def get_folder_path(self):
64 return self.folder.get_path()
66 def get_absolute_url(self):
67 if self.slug == 'index':
68 if self.folder.parent:
69 return reverse('bpcms-document-view', kwargs={'folders': self.folder.parent.get_path(), 'slug': self.folder.slug})
71 return reverse('bpcms-document-view', kwargs={'slug': self.folder.slug})
74 return reverse('bpcms-document-view', kwargs={'folders': self.get_folder_path(), 'slug': self.slug})
76 return reverse('bpcms-document-view', kwargs={'slug': self.slug})
78 class Folder(models.Model):
79 title = models.CharField(max_length=150)
80 slug = models.SlugField()
81 parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True)
84 return self.__unicode__()
86 def __unicode__(self):
87 return u'%s - %s' %(self.get_path(), self.title)
92 while curfolder != None:
93 folders.append(curfolder.slug)
94 curfolder = curfolder.parent
97 folderstring = "/".join(folders)
100 def save(self, force_insert=False, force_update=False):
101 super(Folder, self).save(force_insert, force_update)
102 if self.parent == None:
103 cache.delete('bpcms_mainmenu')
105 cache.delete('bpcms_submenu_%s' %(self.get_path()))
107 def get_absolute_url(self):
109 return reverse('bpcms-document-view', kwargs={'folders': self.parent.get_path(), 'slug': self.slug})
111 return reverse('bpcms-document-view', kwargs={'slug': self.slug})