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 |
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 CourseChangesImporter(object): | |
def sync_with_cataloger(self, catalog_label, json_data, course_listing_page, dry_run=False): | |
courses = json_data.get('courses', []) | |
for course in courses: | |
proposal_type = course['proposal_type'] | |
course_number, course_letters = self._split_course_number(course['course_number']) | |
if proposal_type == "CHANGE": | |
course_page = self._find_current_course_page(course_listing_page, course['copied_from'], dry_run) | |
course_page = course_page.get_latest_revision_as_object() |
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 CoursePage(Page, ClusterableModel): | |
course_number = models.CharField( | |
verbose_name='Course Number', | |
max_length=256, | |
help_text="Only the numeric part", | |
) | |
course_letters = models.CharField( | |
verbose_name='Course Letters', | |
max_length=256, | |
blank=True, |
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
The tricky bit is then getting that view used for the "copy". | |
We do a lot of patching so it's hard for me to extract a good example of that |
NewerOlder