2018-07-24 20:56:38 +01:00
|
|
|
from wagtail.core.models import Page
|
|
|
|
from django.db import models
|
2018-08-02 13:15:32 +01:00
|
|
|
from django.conf import settings
|
2018-07-24 20:56:38 +01:00
|
|
|
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
|
|
|
|
from wagtail.images.edit_handlers import ImageChooserPanel
|
|
|
|
from wagtailmetadata.models import MetadataPageMixin
|
2018-07-27 19:20:13 +01:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
SHORT_BODY_LENGTH = 30
|
2018-07-24 20:56:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Entity(MetadataPageMixin, Page):
|
|
|
|
is_home = False
|
|
|
|
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
modified = models.DateTimeField(auto_now=True)
|
|
|
|
post_date = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
|
|
promote_panels = [
|
|
|
|
MultiFieldPanel([
|
|
|
|
FieldPanel('slug'),
|
|
|
|
FieldPanel('seo_title'),
|
|
|
|
FieldPanel('post_date'),
|
|
|
|
FieldPanel('search_description'),
|
|
|
|
ImageChooserPanel('search_image'),
|
|
|
|
], 'Common page configuration'),
|
|
|
|
]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def image(self):
|
|
|
|
return self.search_image
|
|
|
|
|
|
|
|
def get_meta_description(self):
|
2018-07-24 21:16:55 +01:00
|
|
|
return self.search_description
|
2018-07-24 20:56:38 +01:00
|
|
|
|
2018-08-02 13:15:32 +01:00
|
|
|
def get_page_title(self):
|
|
|
|
from . import utils
|
|
|
|
return utils.get_page_title(self) + settings.WAGTAIL_SITE_NAME
|
|
|
|
|
2018-07-26 09:22:07 +01:00
|
|
|
def get_short_body(self):
|
2018-07-27 19:20:13 +01:00
|
|
|
body_words = BeautifulSoup(str(self.body), 'html5lib').get_text().split(' ')
|
|
|
|
ending = '...' if len(body_words) > SHORT_BODY_LENGTH else ''
|
2018-07-27 21:37:11 +01:00
|
|
|
return ' '.join(body_words[:SHORT_BODY_LENGTH]) + ending # limit to 30 words (ish)
|
2018-07-26 09:22:07 +01:00
|
|
|
|
2018-07-24 20:56:38 +01:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2018-08-01 09:01:16 +01:00
|
|
|
ordering = ('title',)
|