This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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, |