Skip to content

Commit

Permalink
Merge branch 'main' into boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
hUwUtao committed Jun 1, 2024
2 parents 6868dcd + b547c62 commit fbd71f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
41 changes: 24 additions & 17 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 + [
Expand All @@ -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
]
]
13 changes: 9 additions & 4 deletions fuhoblog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -30,7 +30,6 @@
INSTALLED_APPS = [
# MVC stuff
'blog',
# 'search',
'gallery',
# Stuff
# 'wagtail.contrib.modeladmin',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
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'

0 comments on commit fbd71f4

Please sign in to comment.