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.admin.panels import FieldPanel, InlinePanel, ObjectList, TabbedInterface | |
from wagtail.models import Page, Orderable, RevisionMixin | |
from wagtail.snippets.models import register_snippet | |
from modelcluster.fields import ParentalKey | |
## imports truncated so may not be 100% complete | |
class CourseDepartment(Orderable): | |
course = ParentalKey('core.CoursePage', related_name='coursedepartments', on_delete=models.CASCADE) | |
department = models.ForeignKey('core.Department', related_name='coursedepartments', on_delete=models.CASCADE) |
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
Background info for this snippet. | |
Each site in our system is completely independent of the others. Even if you have admin permissions on more than one site, when logged in to site A, you do not see any content for site B. Each sie has 2 groups - an admin group and an editor group. | |
One of the main things we had to patch is the filters on the reports page. We do not want users on one site to even know there are other users in the system. This is implemented in the site_specific_get_users_for_filter method. | |
Although our non-page models all have site_ids, it was not possible to filter ModelLogEntries in site, so we settled for hiding that report from everyone except superusers. | |
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 django.template.response import TemplateResponse | |
from wagtail.core.models import Page, PageViewRestriction | |
DEFAULT_PAGE_CACHE_TIME = 60 * 5 # 5 minutes | |
class BasePage(Page): | |
""" | |
This model contains methods we want added to all (or nearly all) of our custom Page types. Right | |
now that is our Cache-Control headers. The values for these are a work in progress and for now |
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
# core./jobs/document_importer.py | |
import hashlib | |
import os | |
from django.core.files import File | |
from wagtail.documents import get_document_model | |
from wagtail.models import Collection | |
from catalog.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
import json | |
import re | |
import uuid | |
from django.db import connection | |
from core.logging import logger | |
from .utils import ( | |
get_document_by_import_id, | |
get_image_by_import_id, | |
load_page_by_import_id, |
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 django.db import models | |
class RobotsTxtMixin(models.Model): | |
""" | |
Always mix this class in BEFORE wagtailcore.Page. Otherwise, its override of get_sitemap_urls() won't get called. | |
""" | |
hide_from_search_engines = models.BooleanField( | |
default=False, |
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
## within our "create_site" method, we make an admin and editor group for each site. | |
## This method has already created a collecton named for the site | |
admins = Group.objects.create(name=f'{site.hostname} Admins') | |
apply_default_permissions(admins, site, 'admin') | |
admins.save() | |
editors = Group.objects.create(name=f'{site.hostname} Editors') | |
apply_default_permissions(editors, site, 'editor') | |
editors.save() |
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
################################################################################################################# | |
# Patch the wagtail.admin.views.pages.search.search method to filter by the current site. | |
# I asked Torchbox to add a hook that would let us delete this patch: https://github.com/wagtail/wagtail/issues/6235 | |
# 2020-09-03 cnk: updated to work with 2.11a | |
################################################################################################################# | |
@vary_on_headers('X-Requested-With') | |
@user_passes_test(user_has_any_page_permission) | |
def single_site_search(request): | |
# BEGIN PATCH | |
pages = all_pages = Page.objects.in_site(Site.find_for_request(request)).prefetch_related('content_type').specific() |
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 django import forms | |
from django.conf import settings | |
from django.urls import re_path | |
from django.contrib.admin.utils import quote, unquote | |
from django.core.exceptions import PermissionDenied | |
from django.core.validators import MinLengthValidator | |
from django.db import models | |
from django.http import JsonResponse, HttpResponseNotAllowed | |
from django.shortcuts import get_object_or_404 | |
from django.template.loader import render_to_string |
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
source 'https://rubygems.org' | |
gem 'github-pages', group: :jekyll_plugins |