This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MixedMediaBlock(blocks.StructBlock): | |
""" | |
A Block which can display an Image and/or a Video. | |
""" | |
def __init__(self, local_blocks=None, **kwargs): # noqa | |
super().__init__(**kwargs) | |
self.min_width = kwargs.get('min_width', None) | |
self.min_height = kwargs.get('min_height', None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MasterCalendarPage(RoutablePageMixin, Page): | |
## Fields - including one that sets the default time period: day, week, month | |
## Helpers | |
def _build_date_filtered_queryset(self, site, start_date, end_date): | |
queryset = self.base_queryset(site) | |
if start_date: | |
# If the user selected a start date, exclude all events that ended before then. | |
queryset = queryset.exclude(end_date__lte=start_date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RedirectPage(Page): | |
destination = models.CharField( | |
'Destination URL', | |
max_length=512, | |
help_text="If you want to redirect to an arbitrary URL, input it here. If redirecting off-site, the URL must " | |
"start with https://. If you want to redirect to a page on your site, use the Page field, instead.", | |
blank=True, | |
) | |
page = models.ForeignKey( | |
'wagtailcore.Page', # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarViewSetGroup(SnippetViewSetGroup): | |
""" | |
This class defines the Calendar menu, which is only displayed on www and on default sites from other servers. | |
""" | |
items = [EventSeries2ViewSet, EventSponsor2ViewSet, EventTagViewSet, EventSeason2ViewSet, AcademicTermViewSet] | |
menu_icon = 'calendar-alt' | |
menu_label = 'Calendar' | |
menu_name = 'calendar' | |
# This puts the Calendar menu just below News. | |
menu_order = 110 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsPage(Page): | |
# Other fields | |
writer = models.CharField(max_length=255, blank=True, default=get_current_user_full_name) | |
content_panels = Page.content_panels + [ | |
FieldPanel('writer'), | |
] | |
# =================== | |
# Utility Functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################################ | |
# Replace the wagtaildocs serve() view to change the cache-control header that it returns. | |
# This prevents any cache besides the user's own browser from storing any potentially confidential document. | |
################################################################################################################ | |
multitenant_document_serve = etag(document_etag)(cache_control(max_age=3600, private=True)(serve.__wrapped__)) | |
patched_wagtail_urlpatterns = [ | |
# This overrides the wagtaildocs_serve view. | |
re_path(r'^documents/(\d+)/(.*)$', multitenant_document_serve), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wagtail.contrib.routable_page.models import RoutablePageMixin | |
from wagtail.models import Page, PageViewRestriction | |
from robots_txt.models import RobotsTxtMixin | |
from ..utils import URLMixin | |
# Typical cache durations, defined in seconds. | |
DEFAULT_PAGE_CACHE_TIME = 60 * 5 # 5 minutes | |
TWENTY_FOUR_HOURS = 60 * 60 * 24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CourseIndexPage(Page): | |
# ..... fields ...... | |
base_form_class=CourseIndexPageForm | |
class CourseIndexPageForm(WagtailAdminPageForm): | |
def __init__(self, *args, **kwargs): | |
""" | |
Sets up the Course selector to treat selecting null for the Edition as setting it to "current". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsPage(Page): | |
... | |
publication_date = models.DateTimeField( | |
blank=True, | |
null=True, | |
help_text="This field will be automatically filled in once this news article is published. " | |
"After that, you may edit it. This date is used to sort articles and is displayed on the teaser." | |
) | |
exclude_fields_in_copy = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
from io import BytesIO | |
from collections import OrderedDict | |
from django.core.files import File | |
from wagtail.models import Collection | |
from wagtail.documents import get_document_model | |
from djunk.utils import get_or_generate | |
from core.logging import logger |
NewerOlder