2012-07-10 22:18:48 +00:00
|
|
|
import re
|
2012-07-10 19:35:30 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2012-07-10 22:18:48 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core.exceptions import ValidationError
|
2012-07-10 19:35:30 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from markitup.fields import MarkupField
|
|
|
|
|
|
|
|
from taggit.managers import TaggableManager
|
|
|
|
|
|
|
|
import reversion
|
|
|
|
|
2012-07-10 22:18:48 +00:00
|
|
|
from .managers import PublishedPageManager
|
|
|
|
|
2012-07-10 19:35:30 +00:00
|
|
|
|
2012-07-10 22:18:48 +00:00
|
|
|
class Page(models.Model):
|
2012-07-10 19:35:30 +00:00
|
|
|
|
|
|
|
STATUS_CHOICES = (
|
|
|
|
(1, _("Draft")),
|
|
|
|
(2, _("Public")),
|
|
|
|
)
|
2012-07-10 22:18:48 +00:00
|
|
|
|
2012-07-10 19:35:30 +00:00
|
|
|
title = models.CharField(max_length=100)
|
2012-07-10 22:18:48 +00:00
|
|
|
path = models.CharField(max_length=100, unique=True)
|
2012-07-10 19:35:30 +00:00
|
|
|
body = MarkupField()
|
|
|
|
status = models.IntegerField(choices=STATUS_CHOICES, default=2)
|
2012-07-10 22:18:48 +00:00
|
|
|
publish_date = models.DateTimeField(default=datetime.now)
|
2012-07-10 19:35:30 +00:00
|
|
|
created = models.DateTimeField(editable=False, default=datetime.now)
|
|
|
|
updated = models.DateTimeField(editable=False, default=datetime.now)
|
2012-07-10 22:18:48 +00:00
|
|
|
tags = TaggableManager(blank=True)
|
|
|
|
|
|
|
|
published = PublishedPageManager()
|
|
|
|
|
2012-07-10 19:35:30 +00:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
2012-07-10 22:18:48 +00:00
|
|
|
|
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return ("cms_page", [self.path])
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.updated = datetime.now()
|
2012-07-10 19:35:30 +00:00
|
|
|
super(Page, self).save(*args, **kwargs)
|
|
|
|
|
2012-07-10 22:18:48 +00:00
|
|
|
def clean_fields(self, exclude=None):
|
|
|
|
super(Page, self).clean_fields(exclude)
|
|
|
|
if not re.match(settings.SYMPOSION_PAGE_REGEX, self.path):
|
|
|
|
raise ValidationError({"path": [_("Path can only contain letters, numbers and hyphens and end with /"),]})
|
2012-07-10 19:35:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
reversion.register(Page)
|