X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/a2883504e45a556b06e76f023395e879e01ae03c..56b2cdf3569443cf4504fe085de9db0466dcd09f:/sommitrealweird/content/models.py?ds=inline diff --git a/sommitrealweird/content/models.py b/sommitrealweird/content/models.py deleted file mode 100644 index a310a79..0000000 --- a/sommitrealweird/content/models.py +++ /dev/null @@ -1,78 +0,0 @@ -from django.db import models -from content.content_val import is_unique_name - -FORMAT_CHOICES = ( - ('rst', 'reStructuredText'), - ('html', 'HTML'), - ) - -class Document(models.Model): - title = models.CharField(maxlength=150) - islive = models.BooleanField() - folder = models.ForeignKey('Folder', null=True, blank=True) - format = models.CharField(maxlength=10, choices=FORMAT_CHOICES) - slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_unique_name,]) - content = models.TextField() - - def __str__(self): - return self.__unicode__() - - def __unicode__(self): - return u'%s (%s)' %(self.title, self.slug) - - def save(self): - super(Document, self).save() - # now check if we just set our selves to be live - if self.islive: - if self.folder: - otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id) - else: - otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id) - for doc in otherdocs: - doc.islive = False - doc.save() - - def get_basic_url(self): - folders = [] - curfolder = self.folder - while curfolder != None: - folders.append(curfolder.slug) - curfolder = curfolder.parent - - folders.reverse() - folderstring = "/".join(folders) - if folderstring != u'': - folderstring = "%s/" %(folderstring,) - - return "%s%s/" %(folderstring, self.slug) - - class Admin: - pass - -class Folder(models.Model): - title = models.CharField(maxlength=150) - slug = models.SlugField(prepopulate_from=("title",)) - parent = models.ForeignKey('self', null=True, blank=True) - - def __str__(self): - return self.__unicode__() - - def __unicode__(self): - return u'%s' %(self.title) - - def get_basic_url(self): - folders = [] - curfolder = self - while curfolder != None: - folders.append(curfolder.slug) - curfolder = curfolder.parent - - folders.reverse() - folderstring = "/".join(folders) - if folderstring != u'': - folderstring = "%s/" %(folderstring,) - - return "%s/" %(folderstring) - - class Admin: - pass