diff --git a/blog/models.py b/blog/models.py index a4f5f72..786eb7c 100644 --- a/blog/models.py +++ b/blog/models.py @@ -3,19 +3,19 @@ from wagtail.fields import RichTextField from wagtail.admin.panels import FieldPanel from wagtail.api import APIField - -from rest_framework.fields import DateField - -# add this: from wagtail.search import index - from wagtail.images.models import Image -from wagtail.images.api.fields import ImageRenditionField # keep the definition of BlogIndexPage model, and add the BlogPage model: class BlogPage(Page): + THUMB_RENDITIONS = { + 'featured/large': 'fill-740x324', + 'featured/medium': 'fill-316x178|jpegquality-75', + 'media/facebook': 'fill-1280x628', + 'media/x': 'fill-800x418', + } thumb = models.ForeignKey( Image, on_delete=models.SET_NULL, @@ -29,9 +29,9 @@ class BlogPage(Page): localize_default_translation_mode = 'simple' search_fields = Page.search_fields + [ - index.SearchField('intro'), - index.SearchField('body'), - index.SearchField('seo_title'), + index.SearchField('intro', boost=0.6), + index.SearchField('body', boost=0.5), + index.SearchField('seo_title', boost=1.727), ] content_panels = Page.content_panels + [ @@ -40,16 +40,23 @@ class BlogPage(Page): FieldPanel('body'), ] + @property + def thumbnail_set(self) -> dict[str, str]: + """ + Generate rendition set (might trouble api client though) + """ + global THUMB_RENDITIONS + + return dict( + (k, self.thumb.get_rendition(v).full_url) + for k, v in THUMB_RENDITIONS.items() + ) + api_fields = [ APIField('body'), - APIField('thumb'), - APIField( - 'th_fb', serializer=ImageRenditionField('fill-1280x628', source='thumb') - ), - APIField( - 'th_x', serializer=ImageRenditionField('fill-800x418', source='thumb') - ), + APIField('intro'), + APIField('thumbnail_set'), # APIField( # 'authors' # ), # This will nest the relevant BlogPageAuthor objects in the API response - ] + ] diff --git a/fuhoblog/settings/base.py b/fuhoblog/settings/base.py index 76887bb..8227e35 100644 --- a/fuhoblog/settings/base.py +++ b/fuhoblog/settings/base.py @@ -19,7 +19,7 @@ PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) -SECRET_KEY = os.environ['SECRET_KEY'] or '' +SECRET_KEY = os.environ.setdefault('SECRET_KEY', '') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ @@ -30,7 +30,6 @@ INSTALLED_APPS = [ # MVC stuff 'blog', - # 'search', 'gallery', # Stuff # 'wagtail.contrib.modeladmin', @@ -179,7 +178,7 @@ # Wagtail settings -WAGTAIL_SITE_NAME = 'fuhoblog' +WAGTAIL_SITE_NAME = 'Team Fuho' # Search # https://docs.wagtail.org/en/stable/topics/search/backends.html @@ -222,4 +221,10 @@ # Base URL to use when referring to full URLs within the Wagtail admin backend - # e.g. in notification emails. Don't include '/admin' or a trailing slash -WAGTAILADMIN_BASE_URL = 'http://example.com' \ No newline at end of file +WAGTAILADMIN_BASE_URL = os.environ.setdefault("API_BASE", "http://example.com") +WAGTAIL_ALLOW_UNICODE_SLUGS = False +WAGTAIL_USAGE_COUNT_ENABLED = True + +WAGTAIL_DATE_FORMAT = '%d.%m.%Y.' +WAGTAIL_DATETIME_FORMAT = '%d.%m.%Y. %H:%M' +WAGTAIL_TIME_FORMAT = '%H:%M'