b06daba446
* master: added BSD license Update master use django-forms-bootstrap fixed account links on homepage fixed staticfiles settings removed homepage use of ifsetting_tag updated urls updated templates updated imports to reflect new layout updated imports to reflect new layout updated settings updated manage.py updated requirements to 1.4 / DUA and latest versions updated project layout for 1.4 (without content changes) Conflicts: requirements/base.txt symposion/settings.py symposion_project/urls.py
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from markitup.fields import MarkupField
|
|
|
|
from taggit.managers import TaggableManager
|
|
|
|
from mptt.models import MPTTModel, TreeForeignKey
|
|
from mptt.utils import drilldown_tree_for_node
|
|
|
|
import reversion
|
|
|
|
|
|
class ContentBase(models.Model):
|
|
|
|
STATUS_CHOICES = (
|
|
(1, _("Draft")),
|
|
(2, _("Public")),
|
|
)
|
|
|
|
title = models.CharField(max_length=100)
|
|
slug = models.CharField(max_length=100, blank=True, null=True)
|
|
body = MarkupField()
|
|
|
|
tags = TaggableManager(blank=True)
|
|
|
|
status = models.IntegerField(choices=STATUS_CHOICES, default=2)
|
|
published = models.DateTimeField(default=datetime.now)
|
|
created = models.DateTimeField(editable=False, default=datetime.now)
|
|
updated = models.DateTimeField(editable=False, default=datetime.now)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
|
|
class Page(MPTTModel, ContentBase):
|
|
|
|
parent = TreeForeignKey("self", null=True, blank=True, related_name="children")
|
|
ordering = models.PositiveIntegerField(default=1)
|
|
path = models.TextField(blank=True, editable=False)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|
|
|
|
def save(self, calculate_path=True, *args, **kwargs):
|
|
super(Page, self).save(*args, **kwargs)
|
|
if calculate_path:
|
|
self.calculate_path()
|
|
|
|
def calculate_path(self):
|
|
self.path = ""
|
|
for page in drilldown_tree_for_node(self):
|
|
if page == self:
|
|
self.path += page.slug
|
|
break
|
|
else:
|
|
self.path += "%s/" % page.slug
|
|
self.save(calculate_path=False)
|
|
|
|
class MPTTMeta:
|
|
order_insertion_by = ["ordering", "title"]
|
|
|
|
reversion.register(Page)
|