Code Documentation

Pages

Pages app for the CDH website. Includes logic related to generic content pages & landing pages.

Models

cdhweb.pages.models.ALT_TEXT_HELP = 'Alternative text for visually impaired users to\nbriefly communicate the intended message of the image in this context.'

help text for image alternative text

class cdhweb.pages.models.AttachmentBlock(*args, **kwargs)[source]

Page attachments, including local files and external URLs.

class cdhweb.pages.models.BasePage(*args, **kwargs)[source]

Abstract Page class from which all Wagtail page types are derived.

attachments

relationship to uploaded documents and external links

body

main page text

class cdhweb.pages.models.BodyContentBlock(*args, **kwargs)[source]

Common set of blocks available in StreamFields for body text.

migrated

used to hold content migrated from mezzanine via a “kitchen-sink” approach; enable all supported wagtail features. Should NOT be used when creating new pages.

class cdhweb.pages.models.CaptionedImageBlock(*args, **kwargs)[source]

StructBlock for an image with alternative text and optional formatted caption, so that both caption and alternative text can be context-specific.

class cdhweb.pages.models.ContentPage(*args, **kwargs)[source]

Basic content page model.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.pages.models.DateRange(*args, **kwargs)[source]

Abstract model with start and end dates. Includes validation that requires end date falls after start date (if set), and custom properties to check if dates are current/active and to display years.

clean_fields(exclude=None)[source]

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

end_date

end date (optional)

property is_current

is current: start date before today and end date in the future or not set

start_date

start date

property years

year or year range for display

class cdhweb.pages.models.DisplayUrlMixin(*args, **kwargs)[source]

Mixin that provides a single required URL field and a display method.

property display_url

URL cleaned up for display, with scheme and extra params removed.

class cdhweb.pages.models.ExternalAttachment(*args, **kwargs)[source]

An externally hosted link or file that can be associated with a Page.

exception DoesNotExist
exception MultipleObjectsReturned
get_usage()

Returns a queryset of pages that link to a particular object

class cdhweb.pages.models.HomePage(*args, **kwargs)[source]

A home page that aggregates and displays featured content.

exception DoesNotExist
exception MultipleObjectsReturned
get_context(request)[source]

Add featured updates, projects, pages, and events to page context.

class cdhweb.pages.models.LandingPage(*args, **kwargs)[source]

Page type that aggregates and displays multiple ContentPages.

exception DoesNotExist
exception MultipleObjectsReturned
header_image

image that will be used for the header

tagline

short sentence overlaid on the header image

class cdhweb.pages.models.LinkPage(*args, **kwargs)[source]

Link page for controlling appearance in menus of non-Page content.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.pages.models.LocalAttachment(*args, **kwargs)[source]

A locally hosted file that can be associated with a Page.

exception DoesNotExist
exception MultipleObjectsReturned
cdhweb.pages.models.PARAGRAPH_FEATURES = ['h3', 'h4', 'bold', 'italic', 'link', 'ol', 'ul', 'hr', 'blockquote', 'document', 'superscript', 'subscript', 'strikethrough', 'code']

common features for paragraph text

class cdhweb.pages.models.PageIntro(*args, **kwargs)[source]

Snippet for optional page intro text on for pages generated from django views not managed by wagtail

exception DoesNotExist
exception MultipleObjectsReturned
get_usage()

Returns a queryset of pages that link to a particular object

paragraph

intro text

class cdhweb.pages.models.PagePreviewDescriptionMixin(*args, **kwargs)[source]

Page mixin with logic for page preview content. Adds an optional richtext description field, and methods to get description and plain-text description, for use in previews on the site and plain-text metadata previews.

allowed_tags = ['em', 'acronym', 'ol', 'code', 'b', 'ul', 'abbr', 'strong', 'li', 'i']

allowed tags for bleach html stripping in description

description

brief description for preview display

get_description()[source]

Get formatted description for preview. Uses description field if there is content, otherwise uses beginning of the body content.

get_plaintext_description()[source]

Get plain-text description for use in metadata. Uses search_description field if set; otherwise uses the result of get_description() with tags stripped.

max_length = 225

maximum length for description to be displayed

Abstract typed relationship between a URL and a model. Used for personal URLs like Twitter, project links like Github, etc.

class cdhweb.pages.models.RelatedLinkType(*args, **kwargs)[source]

Link types for RelatedLinks, with sort order determined by type.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.pages.models.SVGImageBlock(*args, **kwargs)[source]

StructBlock for an SVG image with alternative text and optional formatted caption. Separate from CaptionedImageBlock because Wagtail image handling does not work with SVG.

Views

class cdhweb.pages.views.LastModifiedListMixin(**kwargs)[source]

Mixin that adds last-modified timestamps to response for list views.

Uses Django’s get_conditional_response to return a 304 if none of the objects in the list have been modified since time specified in the HTTP if-modified-since header.

last_modified()[source]

Get the most recent modification date among all view objects.

class cdhweb.pages.views.LastModifiedMixin(**kwargs)[source]

Mixin that adds last-modified timestamps to response for detail views.

Uses Django’s get_conditional_response to return a 304 if object has not been modified since time specified in the HTTP if-modified-since header.

last_modified()[source]

Get the last modified date of the view object.

class cdhweb.pages.views.OpenSearchDescriptionView(**kwargs)[source]

Basic open search description for searching the site via browser or other tools.

class cdhweb.pages.views.SiteSearchView(**kwargs)[source]

Search across all pages on the site.

form_class

alias of cdhweb.pages.forms.SiteSearchForm

get_context_data(**kwargs)[source]

Get the context for this view.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

model

alias of wagtail.core.models.Page

People

People app for the CDH webapp. Provides a profile related to Django User, along with job titles and position information.

Models

class cdhweb.people.models.PeopleLandingPage(*args, **kwargs)[source]

LandingPage subtype for People that holds Profiles.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.people.models.Person(id, first_name, last_name, email, user, cdh_staff, job_title, department, institution, phone_number, office_location, pu_status, image, updated_at)[source]
exception DoesNotExist
exception MultipleObjectsReturned
property current_title

Return the first of any non-expired titles held by this Person.

property lastname_first

display person as lastname, first for sorting

property latest_grant

most recent grants where this person has director role

property most_recent_title

Return the most recent of any titles held by this Person.

property profile_url

Provide the link to published profile on this site if there is one; otherwise look for an associated website url

updated_at

update timestamp

class cdhweb.people.models.PersonQuerySet(model=None, query=None, using=None, hints=None)[source]
affiliates()[source]

Faculty and staff affiliates based on PU status and Project Director project role. Excludes CDH staff.

cdh_staff()[source]

Return only CDH staff members

current()[source]

Return people with a current position or current grant based on start and end dates.

current_grant()[source]

Return profiles for users with a current grant.

current_position()[source]

Return profiles for users with a current position.

current_position_nonexec()[source]

Return profiles for users with a current position, excluding current executive committee positions.

director_roles = ['Project Director', 'Co-PI: Research Lead']

position titles that indicate a person is a project director

exec_member()[source]

Executive committee members

exec_member_title = 'Executive Committee Member'

executive committee member titles

executive_committee()[source]

Executive committee members; based on position title.

grant_years()[source]

Annotate with first start and last end grant year for grants that a person was project director.

not_students()[source]

Filter out students based on PU status

order_by_position()[source]

order by job title sort order and then by start date

postdoc_titles = ['Postdoctoral Fellow', 'Postdoctoral Fellow and Communications Lead']

position titles that indicate a person is a postdoc

project_manager_years()[source]

Annotate with first start and last end grant year for grants that a person was project manager.

project_roles = ['Project Director', 'Project Manager', 'Co-PI: Research Lead']

membership roles that indicate someone is an affiliate

sits_with_exec()[source]

Non-faculty Executive committee members

student_affiliates()[source]

Return CDH student staff members, grantees, and PGRAs based on Project Director or Project Manager role.

student_pu_status = ['graduate', 'undergraduate']

student status codes from LDAP

student_titles = ['Graduate Fellow', 'Graduate Assistant', 'Undergraduate Assistant', 'Postgraduate Research Associate']

position titles that indicate a staff person is a student

Through-model for associating people with resource types and corresponding URLs for the specified resource type.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.people.models.Position(*args, **kwargs)[source]

Through model for many-to-many relation between people and titles. Adds start and end dates to the join table.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.people.models.Profile(*args, **kwargs)[source]

Profile page for a Person, managed via wagtail.

exception DoesNotExist
exception MultipleObjectsReturned
clean()[source]

Validate that a Person was specified for this profile.

get_context(request)[source]

Add recent BlogPosts by this Person to their Profile.

class cdhweb.people.models.Title(*args, **kwargs)[source]

Job titles for people

exception DoesNotExist
exception MultipleObjectsReturned
num_people()[source]

Number of people with this position title

cdhweb.people.models.cleanup_profile(sender, **kwargs)[source]

Handler to delete the corresponding Profile on Person deletion.

cdhweb.people.models.init_person_from_ldap(user, ldapinfo)[source]

Extra User init logic for creating and auto-populating a corresponding Person with data from LDAP.

Views

class cdhweb.people.views.AffiliateListView(**kwargs)[source]

Display current and past faculty & staff affiliates

get_current()[source]

Get current people from the queryset. Override to customize which filter is used. By default, uses generic current logic that checks both positions and grants.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

class cdhweb.people.views.ExecListView(**kwargs)[source]

Display current and past executive committee members.

get_context_data()[source]

Get the context for this view.

get_current()[source]

Get current people from the queryset. Override to customize which filter is used. By default, uses generic current logic that checks both positions and grants.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

class cdhweb.people.views.PersonListView(**kwargs)[source]

Base class for person list views

current_title = ''

title for non-past people in this category of people

get_context_data()[source]

Get the context for this view.

get_current()[source]

Get current people from the queryset. Override to customize which filter is used. By default, uses generic current logic that checks both positions and grants.

get_past()[source]

Get past people. Override to customize filters and ordering. By default, assumes any profiles that aren’t current are past.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

grant_label(grant)[source]

Convert a grant into a label with date.

model

alias of cdhweb.people.models.Person

page_title = ''

title for this category of people

past_title = ''

label for past people in this category of people

class cdhweb.people.views.StaffListView(**kwargs)[source]

Display current and past CDH staff

get_current()[source]

Get current people from the queryset. Override to customize which filter is used. By default, uses generic current logic that checks both positions and grants.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

class cdhweb.people.views.StudentListView(**kwargs)[source]

Display current and past graduate fellows, graduate and undergraduate assistants.

get_past()[source]

Get past people. Override to customize filters and ordering. By default, assumes any profiles that aren’t current are past.

get_queryset()[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

Projects

Projects app for the CDH website. Handles project data and members associated with projects.

Models

class cdhweb.projects.models.Grant(*args, **kwargs)[source]

A specific grant associated with a project

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.GrantType(*args, **kwargs)[source]

Model to track kinds of grants

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.Membership(*args, **kwargs)[source]

Project membership - joins project, user, and role.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.Project(*args, **kwargs)[source]

Page type for a CDH sponsored project or working group.

exception DoesNotExist
exception MultipleObjectsReturned
alums()[source]

PersonQueryset of past members sorted by last name

current_memberships()[source]

MembershipQueryset of current members sorted by role

get_sitemap_urls(request)[source]

Override sitemap to prioritize projects built by CDH with a website.

latest_grant()[source]

Most recent Grant for this Project

property website_url

URL for this Project’s website, if set

class cdhweb.projects.models.ProjectQuerySet(*args, **kwargs)[source]
current()[source]

Projects with a current grant, based on dates

highlighted()[source]

return projects that are marked as highlighted

not_current()[source]

Projects with no current grant, based on dates

not_staff_or_postdoc()[source]

Exclude staff and postdoc projects, based on grant type

order_by_newest_grant()[source]

order by grant start date, most recent grants first; secondary sort by project title

staff_or_postdoc()[source]

Staff and postdoc projects, based on grant type

staff_postdoc_grants = ['Staff R&D', 'Staff Project', 'Postdoctoral Research Project']

grant types that indicate staff or postdoc project

working_groups()[source]

Include only projects with the working group flag set

Through-model for associating projects with relatedlinks

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.ProjectTag(*args, **kwargs)[source]

Tags for Project pages.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.ProjectsLandingPage(*args, **kwargs)[source]

Container page that defines where Project pages can be created.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.projects.models.Role(*args, **kwargs)[source]

A role on a project

exception DoesNotExist
exception MultipleObjectsReturned

Views

class cdhweb.projects.views.ProjectListView(**kwargs)[source]

Base class for project list views.

get_context_data(*args, **kwargs)[source]

Add projects, titles, and navigation to context.

get_current()[source]

Get current projects from the queryset. Override to customize which filter is used.

get_past()[source]

Get past projects from the queryset. Override to customize which filter is used.

get_queryset()[source]

Get all published projects ordered by newest grant.

model

alias of cdhweb.projects.models.Project

page_title = 'Projects'

title for this category of projects

past_title = 'Past Projects'

title for past projects in this category of projects

class cdhweb.projects.views.SponsoredProjectListView(**kwargs)[source]

Main project list, i.e. not staff/postdoc/working group.

get_queryset()[source]

Get all published sponsored projects.

class cdhweb.projects.views.StaffProjectListView(**kwargs)[source]

Staff and postdoc projects, based on grant type.

get_queryset()[source]

Get all published staff/postdoc projects.

class cdhweb.projects.views.WorkingGroupListView(**kwargs)[source]

DH Working group list, based on working group project flag.

get_context_data(*args, **kwargs)[source]

Override so that working groups are never shown as past.

get_queryset()[source]

Get all published DH working groups.

Events

Events app for the CDH webapp. Provides event types, locations, and events

Models

class cdhweb.events.models.Event(*args, **kwargs)[source]

Page type for an event, such as a workshop, lecture, or conference.

exception DoesNotExist
exception MultipleObjectsReturned
clean()[source]

Validate that a type was specified for this event.

duration()[source]

duration between start and end time as datetime.timedelta

get_ical_url()[source]

URL to download this event as a .ics (iCal) file.

get_url_parts(*args, **kwargs)[source]

Custom event page URLs of the form /events/2014/03/my-event.

ical_event()[source]

Return the current event as a icalendar.Event for inclusion in a icalendar.Calendar

is_virtual()[source]

If an event takes place in a virtual location, it is virtual

property speaker_list

Comma-separated list of speaker names.

when()[source]

Event start/end date and time, formatted for display.

Removes leading zeros from hours and converts am/pm to lower case.

class cdhweb.events.models.EventQuerySet(*args, **kwargs)[source]
recent()[source]

Find past events, most recent first. Only includes events with end date in the past.

upcoming()[source]

Find upcoming events. Includes events that end on the current day even if the start time is past.

class cdhweb.events.models.EventTag(*args, **kwargs)[source]

Tags for Event pages.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.events.models.EventType(id, name)[source]
exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.events.models.EventsLinkPage(*args, **kwargs)[source]

Container page that defines where Project pages can be created.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.events.models.Location(id, name, short_name, address, is_virtual)[source]
exception DoesNotExist
exception MultipleObjectsReturned
clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

property display_name

A name for template display

class cdhweb.events.models.Speaker(*args, **kwargs)[source]

Relationship between Person and Event.

exception DoesNotExist
exception MultipleObjectsReturned

Views

class cdhweb.events.views.EventDetailView(**kwargs)[source]

Event detail page

get(request, *args, **kwargs)[source]

Serve the requested Event using Wagtail’s Page.serve().

get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

class cdhweb.events.views.EventIcalView(**kwargs)[source]

Download event information as ical

get(request, *args, **kwargs)[source]

Serve the requested Event using Wagtail’s Page.serve().

class cdhweb.events.views.EventMixinView[source]

View mixin that sets model to Event and returns a published Event queryset.

get_queryset()[source]

use manager to find published events only

model

alias of cdhweb.events.models.Event

class cdhweb.events.views.EventSemesterArchiveView(**kwargs)[source]

Display events by semester

get_context_data(*args, **kwargs)[source]

Get the context for this view.

get_date_list(*args, **kwargs)[source]

Get a date list by calling queryset.dates/datetimes(), checking along the way for empty lists that aren’t allowed.

get_dated_items()[source]

Return (date_list, items, extra_context) for this request.

get_queryset()[source]

use manager to find published events only

class cdhweb.events.views.EventSemesterDates[source]

Mixin to return list of event semester dates based on event dates in the system.

static get_semester(date)[source]

Return the semester a date occurs in as a string.

get_semester_date_list()[source]

Get a list of semester labels (semester and year) for published events. Semesters are Spring (through May), Summer (through August), and Fall.

class cdhweb.events.views.UpcomingEventsView(**kwargs)[source]

Upcoming events view. Displays future published events and 6 most recent past events.

get_context_data(*args, **kwargs)[source]

Get the context for this view.

last_modified()[source]

Get the recent last modified date from included events.

Blog

Blog app for the CDH website. Similar to the built-in grappelli blog, but allows multiple authors (other than the current user) to be associated with a post.

Models

class cdhweb.blog.models.Author(*args, **kwargs)[source]

Ordered relationship between Person and BlogPost.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.blog.models.BlogLinkPage(*args, **kwargs)[source]

Container page that defines where blog posts can be created.

exception DoesNotExist
exception MultipleObjectsReturned
class cdhweb.blog.models.BlogPost(*args, **kwargs)[source]

A Blog post, implemented as a Wagtail page.

exception DoesNotExist
exception MultipleObjectsReturned
property author_list

Comma-separated list of author names.

get_sitemap_urls(request)[source]

Override sitemap listings to add priority for featured posts.

get_url_parts(*args, **kwargs)[source]

Custom blog post URLs of the form /updates/2014/03/01/my-post.

property short_description

Shorter description with ellipsis.

property short_title

Shorter title with ellipsis.

class cdhweb.blog.models.BlogPostQuerySet(*args, **kwargs)[source]
featured()[source]

return blog posts that are marked as featured

recent()[source]

Order blog posts by date published.

class cdhweb.blog.models.BlogPostTag(*args, **kwargs)[source]

Tags for Blog posts.

exception DoesNotExist
exception MultipleObjectsReturned

Views

class cdhweb.blog.views.AtomBlogPostFeed[source]

Blog post Atom feed

feed_type

alias of django.utils.feedgenerator.Atom1Feed

class cdhweb.blog.views.BlogDetailView(**kwargs)[source]

Blog post detail view

get_context_data(*args, **kwargs)[source]

Add next/previous post to context.

class cdhweb.blog.views.BlogIndexView(**kwargs)[source]

Main blog post list view

get_context_data(*args, **kwargs)[source]

Get the context for this view.

get_queryset()[source]

Return published posts with most recent first.

class cdhweb.blog.views.BlogMonthArchiveView(**kwargs)[source]

Blog post archive by month

get_context_data(*args, **kwargs)[source]

Get the context for this view.

class cdhweb.blog.views.BlogPostArchiveMixin(**kwargs)[source]

Mixin with common settings for blogpost archive views

class cdhweb.blog.views.BlogPostMixinView[source]

Mixin that sets model to BlogPost and orders/filters queryset.

get_queryset()[source]

Return published posts with most recent first.

model

alias of cdhweb.blog.models.BlogPost

class cdhweb.blog.views.BlogYearArchiveView(**kwargs)[source]

Blog post archive by year

get_context_data(*args, **kwargs)[source]

Get the context for this view.

class cdhweb.blog.views.RssBlogPostFeed[source]

Blog post RSS feed

item_author_email(item)[source]

author email, if there is only one author

link to author profile page, if there is only one author and the author has a published profile

item_author_name(item)[source]

author of the blog post; comma-separated list for multiple

item_categories(item)[source]

keyword category terms

item_description(item)[source]

blog post description, for feed content

absolute link to blog post

item_pubdate(item)[source]

publication date

item_title(item)[source]

blog post title

item_updateddate(item)[source]

last modified date

items()[source]

ten most recent blog posts, ordered by publish date