2006-05-02 09:31:56 +08:00
|
|
|
from django.contrib.sites.models import Site
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import models
|
2015-12-30 23:51:16 +08:00
|
|
|
from django.urls import get_script_prefix
|
2016-11-20 04:54:19 +08:00
|
|
|
from django.utils.encoding import iri_to_uri
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2008-03-30 00:42:39 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class FlatPage(models.Model):
|
2008-08-11 12:28:33 +08:00
|
|
|
url = models.CharField(_('URL'), max_length=100, db_index=True)
|
2007-08-05 13:14:46 +08:00
|
|
|
title = models.CharField(_('title'), max_length=200)
|
2008-06-30 21:05:47 +08:00
|
|
|
content = models.TextField(_('content'), blank=True)
|
2013-03-24 20:47:01 +08:00
|
|
|
enable_comments = models.BooleanField(_('enable comments'), default=False)
|
2016-02-06 02:53:03 +08:00
|
|
|
template_name = models.CharField(
|
|
|
|
_('template name'),
|
|
|
|
max_length=70,
|
|
|
|
blank=True,
|
2014-09-04 20:15:09 +08:00
|
|
|
help_text=_(
|
|
|
|
"Example: 'flatpages/contact_page.html'. If this isn't provided, "
|
|
|
|
"the system will use 'flatpages/default.html'."
|
|
|
|
),
|
|
|
|
)
|
2016-03-29 06:33:29 +08:00
|
|
|
registration_required = models.BooleanField(
|
|
|
|
_('registration required'),
|
2013-03-24 20:47:01 +08:00
|
|
|
help_text=_("If this is checked, only logged-in users will be able to view the page."),
|
2016-03-29 06:33:29 +08:00
|
|
|
default=False,
|
|
|
|
)
|
2015-07-12 23:39:44 +08:00
|
|
|
sites = models.ManyToManyField(Site, verbose_name=_('sites'))
|
2008-03-30 00:42:39 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Meta:
|
|
|
|
db_table = 'django_flatpage'
|
|
|
|
verbose_name = _('flat page')
|
|
|
|
verbose_name_plural = _('flat pages')
|
|
|
|
ordering = ('url',)
|
2008-08-11 12:28:33 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s -- %s" % (self.url, self.title)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2013-02-24 20:25:17 +08:00
|
|
|
# Handle script prefix manually because we bypass reverse()
|
|
|
|
return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
|