Code Documentation¶
Common¶
Django app for shared code and functionality used across other applications within the project. Currently includes abstract database models with common functionality or fields that are used by models in multiple apps within the project.
Models¶
-
class
mep.common.models.
AliasIntegerField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]¶ Alias field adapted from https://djangosnippets.org/snippets/10440/ to allow accessing an existing db field by a different name, both for user display and in model and queryset use.
-
class
mep.common.models.
DateRange
(*args, **kwargs)[source]¶ Abstract model with optional start and end years, and a custom dates property to display the date range nicely. Includes validation that requires end year falls after start year.
-
property
dates
¶ Date or date range as a string for display
-
end_year
¶ end year (optional)
-
start_year
¶ start year (optional)
-
property
-
class
mep.common.models.
Named
(*args, **kwargs)[source]¶ Abstract model with a ‘name’ field; by default, name is used as the string display.
-
name
¶ unique name (required)
-
-
class
mep.common.models.
Notable
(*args, **kwargs)[source]¶ Abstract model with an optional notes text field
-
notes
¶ optional notes
-
Utils¶
-
mep.common.utils.
abbreviate_labels
(labels)[source]¶ Abbreviate labels so they are as short as possible but distinct from preceding and following labels. Optionally used with
alpha_pagelabels()
-
mep.common.utils.
absolutize_url
(local_url, request=None)[source]¶ Convert a local url to an absolute url, with scheme and server name, based on the current configured
Site
.- Parameters
local_url – local url to be absolutized, e.g. something generated by
reverse()
-
mep.common.utils.
alpha_pagelabels
(paginator, objects, attr_meth, max_chars=None)[source]¶ Generate abbreviated, alphabetical page labels for pagination items. Label format should be something like ‘Ab - Ad’, ‘Ard - Art’.
- Parameters
paginator – a django paginator
objects – the complete list of objects paginated by the paginator
attr_meth – method or lambda to retrieve the attribute on the object that should be used for page labels
- Returns
OrderedDict
where keys are page numbers and values are page labels
-
mep.common.utils.
login_temporarily_required
(func)[source]¶ Test decorator for views that have LoginRequiredOr404 enabled. Creates a user with no permissions on first run for a given class, and logs in as that user before running the decorated test method. Intended for use on Django TestCase class methods.
Views¶
-
class
mep.common.views.
AjaxTemplateMixin
(**kwargs)[source]¶ View mixin to use a different template when responding to an ajax request.
-
ajax_template_name
= None¶ name of the template to use for ajax request
-
get_template_names
()[source]¶ Return
ajax_template_name
if this is an ajax request; otherwise return default template name.
-
vary_headers
= ['X-Requested-With']¶ vary on X-Request-With to avoid browsers caching and displaying ajax response for the non-ajax response
-
-
class
mep.common.views.
FacetJSONMixin
(**kwargs)[source]¶ View mixin to respond with JSON representation of Solr facets when the HTTP Accept: header specifies application/json.
-
render_facets
(request, *args, **kwargs)[source]¶ Construct a JsonResponse based on the already-populated queryset data for the view.
-
render_to_response
(request, *args, **kwargs)[source]¶ Return a JsonResponse if the client asked for JSON, otherwise just call dispatch(). NOTE that this isn’t currently smart enough to detect if the view’s queryset is a SolrQuerySet; it will just break.
-
vary_headers
= ['Accept']¶ vary on Accept: so that facets and results are cached separately
-
-
class
mep.common.views.
LabeledPagesMixin
[source]¶ View mixin to add labels for pages to a paginated view’s context, for use in rendering pagination controls.
-
class
mep.common.views.
LoginRequiredOr404Mixin
[source]¶ Extend
LoginRequiredMixin
to return a 404 if access is denied, rather than redirecting to the login form.
-
class
mep.common.views.
RdfViewMixin
[source]¶ View mixin to add an RDF linked data graph to context for use in serializing and embedding structured data in templates.
breadcrumbs, used to render breadcrumb navigation. they should be a list of tuples like (‘Title’, ‘/url’)
-
get_absolute_url
()[source]¶ Get a URI for this page to use for making RDF assertions. Note that this should return a full absolute path, e.g. with absolutize_url().
Generate the breadcrumbs that lead to this page. Returns the value of breadcrumbs set on the View by default.
-
get_context
(request, *args, **kwargs)[source]¶ Add generated breadcrumbs and RDF graph to Wagtail page context.
-
get_context_data
(*args, **kwargs)[source]¶ Add generated breadcrumbs and an RDF graph to the view context.
-
rdf_type
= rdflib.term.URIRef('http://schema.org/WebPage')¶ default schema.org type for a View
-
class
mep.common.views.
SolrLastModifiedMixin
(**kwargs)[source]¶ View mixin to add last modified headers based on Solr
-
dispatch
(request, *args, **kwargs)[source]¶ Wrap the dispatch method to add a last modified header if one is available, then return a conditional response.
-
get_solr_lastmodified_filters
()[source]¶ Get filters for last modified Solr query. By default returns
solr_lastmodified_filters
.
-
last_modified
()[source]¶ Return last modified
datetime.datetime
from the specified Solr query
-
solr_lastmodified_filters
= {}¶ solr query filter for getting last modified date
-
Accounts¶
Django app to manage information about accounts for people who were members of the Sylvia Beach lending library.
Models¶
-
class
mep.accounts.models.
Account
(*args, **kwargs)[source]¶ Central model for all account and related information, M2M explicity to
people.Person
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
add_event
(etype='event', **kwargs)[source]¶ - Helper function to add a
Event
or subclass to an instance of
Account
. Requires that theAccount
object be saved first (so it has a set primary key). This provides functionality normally in theself.*_set
functionality of Django, but not provided with subclassed table inheritence.
- Parameters
etype –
str
One ofborrow
,event
,subscription
,purchase
,reimbursement
- Helper function to add a
-
get_events
(etype='event', **kwargs)[source]¶ Helper function to retrieve related events of any valid type for
Account.add_event()
. This provides functionality normally in theself.*_set
functionality, but not provided with subclassed table inheritence.- Parameters
etype –
str
One ofborrow
,event
,subscription
,purchase
,reimbursement
- Keyword Arguments
Any valid query kwargs for
Account
, defaults to equivalent ofFoo.objects.all()
.
-
list_locations
()[source]¶ List of associated
mep.people.models.Location
-
list_persons
()[source]¶ List
mep.people.models.Person
instances associated with this account.
-
member_card_images
()[source]¶ Return a queryset for card images that are part of this account’s associated card manifest OR that have events for this account. Note that this returns a union queryset, which puts some retrictions on supported operations.
-
property
reimbursement_set
¶ associated reimbursement events, as queryset of
Reimbursement
-
property
subscription_set
¶ associated subscription events, as queryset of
Subscription
-
exception
-
class
mep.accounts.models.
Address
(*args, **kwargs)[source]¶ Address associated with an
Account
or aPerson
. Used to associate locations with people and accounts, with optional start and end dates and a care/of person.-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.accounts.models.
Borrow
(*args, **kwargs)[source]¶ Inherited table indicating borrow events
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
save
(*args, **kwargs)[source]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
-
exception
-
class
mep.accounts.models.
CurrencyMixin
(*args, **kwargs)[source]¶ Mixin for currency field with currency symbol display
-
class
mep.accounts.models.
Event
(*args, **kwargs)[source]¶ Base table for events in the Shakespeare and Co. Lending Library
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
event_label
¶ Event type label that includes nonstandard events indicated by notation in private notes as well as all the standard types.
-
nonstandard_notation
= {'NOTATION: BOUGHTFOR': 'Purchase', 'NOTATION: LOAN': 'Loan', 'NOTATION: PERIODICALSUBSCRIPTION': 'Periodical Subscription', 'NOTATION: REQUEST': 'Request', 'NOTATION: SBGIFT': 'Gift', 'NOTATION: SOLDFOR': 'Purchase', 'STRIKETHRU': 'Crossed out'}¶ notation in private notes indicating kind of nonstandard events
-
exception
-
class
mep.accounts.models.
EventQuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Custom
Queryset
forEvent
with filter methods for generic events and each event subtype.
-
class
mep.accounts.models.
Purchase
(*args, **kwargs)[source]¶ Inherited table indicating purchase events; extends
Event
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
date
()[source]¶ alias of
date_range
for display; since reimbersument is a single-day event will always be a single partial date.
-
save
(*args, **kwargs)[source]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
-
exception
-
class
mep.accounts.models.
Reimbursement
(*args, **kwargs)[source]¶ Reimbursement event; extends
Event
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.accounts.models.
Subscription
(*args, **kwargs)[source]¶ Records subscription events in the MEP database
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
calculate_duration
()[source]¶ calculate and set subscription duration based on start and end date, when both are known
-
purchase_date
¶ date the purchase was bought; not necessarily the day it started!
-
readable_duration
()[source]¶ Generate a human-readable version of the subscription duration. Intended to follow Beach’s conventions, e.g. 1 year rather than 12 months; 1 week rather than 7 days.
-
save
(*args, **kwargs)[source]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
-
exception
Partial Dates¶
-
class
mep.accounts.partial_date.
DatePrecision
[source]¶ Flag class to indicate which parts of a date are known.
-
class
mep.accounts.partial_date.
DatePrecisionField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]¶ Integer representation of a
DatePrecision
.-
from_db_value
(value, expression, connection)[source]¶ Convert values returned from database to
DatePrecision
usingto_python()
-
-
class
mep.accounts.partial_date.
KnownYear
(lhs, rhs)[source]¶ Custom lookup to filter on known year in :class:`DatePrecisionField
-
class
mep.accounts.partial_date.
PartialDate
(date_field, date_precision_field, unknown_year=1, label=None)[source]¶ Descriptor that gets and sets a related
datetime.date
andDatePrecision
from partial date strings, e.g. –05-02.-
static
date_format
(value)[source]¶ Return a format string for use with
datetime.date.strftime()
to output a date with the appropriate precision
-
parse_date
(value)[source]¶ Parse a partial date string and return a
datetime.date
and precision value.
-
static
-
class
mep.accounts.partial_date.
PartialDateFormMixin
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶ Provides form validation and setting for models that inherit from
mep.accounts.models.PartialDateMixin
.
-
class
mep.accounts.partial_date.
PartialDateMixin
(*args, **kwargs)[source]¶ Mixin to add fields for partial start and end dates to a model using
DatePrecisionField
andPartialDate
.-
calculate_date
(kind, dateval=None, earliest=None, latest=None)[source]¶ Calculate end or start date based on a single value in a supported partial date form or based on earliest/latest datetime.
-
property
date_range
¶ Borrowing event date range as string, using partial dates. Returns a single date in partial date format if both dates are set to the same date. Uses “??” for unset dates, and returns in format start/end.
-
views¶
-
class
mep.accounts.views.
AccountAutocomplete
(**kwargs)[source]¶ Basic autocomplete lookup, for use with django-autocomplete-light and
mep.accounts.models.Account
in address many-to-many
-
class
mep.accounts.views.
Twitter100yearsReview
(**kwargs)[source]¶ Admin view to review upcoming 100 years tweets before they are posted on twitter. Finds and displays tweets for events in the next three months, using the same logic for generating tweet content that the twitter bot manage command uses.
-
get_date_range
()[source]¶ Determine start and end date for events to review. Start 100 years before today, end 4 weeks after that.
-
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
mep.accounts.models.Event
-
Manage Commands¶
report timegaps¶
Manage command to identify and report on large gaps in time between events in a single library account, to identify possible candidates for demerging. Options allow specifying the minimum gap to look for in months (default is 6 months) and a required filename to use for CSV output. By default, borrowing events are not included. If specified, borrowing events will be included but borrow events with partially know dates will be skipped.
Example usage:
python manage.py report_timegaps -o 6month-gaps.csv
python manage.py report_timegaps -g 12 months -o 12month-gaps.csv
python manage.py report_timegaps -g 12 months --borrows -o 12month-gaps-with-borrows.csv
-
class
mep.accounts.management.commands.report_timegaps.
Command
(stdout=None, stderr=None, no_color=False, force_color=False)[source]¶ Look for accounts with large time gaps between events to identify possible candidates for demerge
-
csv_header
= ['Admin URL(s)', 'Account', 'Account Date Range', '# Gaps', 'Longest Gap in days', 'Details']¶ columns for CSV output
-
find_gaps
(account, gapsize)[source]¶ Identify and return gaps between account events that are larger than the specified gap size. Returns a list of tuples of start and event dates for any gaps found. Currently ignores borrow events with partially known dates.
- Parameters
account –
mep.accounts.models.Account
gapsize –
datetime.timedelta
-
format_relativedelta
(rel_delta)[source]¶ Generate a human-readable display for a relativedelta in years, months, and days
-
handle
(*args, **kwargs)[source]¶ The actual logic of the command. Subclasses must implement this method.
-
include_borrows
= False¶ include borrowing events when checking for gaps between events?
-
report_gap_details
(gaps)[source]¶ Given a list of gaps as generated by
find_gaps()
, return the maximum gap size in days and a message reporting the specifics of the event types and dates with gaps.
-
v_normal
= 1¶ default verbosity
-
export events¶
Manage command to export event data for use by others.
Generates a CSV and JSON file including details on every event in the database with summary details and URIs for associated library member(s) and book (for events linked to books).
-
class
mep.accounts.management.commands.export_events.
Command
(stdout=None, stderr=None, no_color=False, force_color=False)[source]¶ Export event data.
-
model
¶ alias of
mep.accounts.models.Event
-
twitterbot 100years¶
-
class
mep.accounts.management.commands.twitterbot_100years.
Command
(stdout=None, stderr=None, no_color=False, force_color=False)[source]¶ -
-
find_events
(date)[source]¶ Find events 100 years before the current day or a specified day in YYYY-MM-DD format.
-
get_date
(date=None, mode=None, **kwargs)[source]¶ Find events relative to the specified day, if set, or the date 100 years ago. Overriding the date is only allowed in report mode.
-
-
mep.accounts.management.commands.twitterbot_100years.
can_tweet
(ev, day)[source]¶ Check if the event can be tweeted on the specified day
-
mep.accounts.management.commands.twitterbot_100years.
card_url
(member, ev)[source]¶ Return the member card detail url for the event based on footnote image, if present.
-
mep.accounts.management.commands.twitterbot_100years.
tweet_content
(ev, day)[source]¶ Generate tweet content for the specified event on the specified day.
-
mep.accounts.management.commands.twitterbot_100years.
work_label
(work)[source]¶ Convert a
Work
for display in tweet content. Standard formats: - author’s “title” (year) - periodical: an issue of “title”Handles multiple authors (and for two, et al. for more), includes editors if there are no authors. Only include years after 1500.
Books¶
Django app to manage information about titles associated with the Sylvia Beach lending library.
Models¶
-
class
mep.books.models.
Creator
(id, notes, creator_type, person, work, order)[source]¶ -
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
CreatorType
(*args, **kwargs)[source]¶ Type of creator role a person can have in relation to a work; author, editor, translator, etc.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
Edition
(*args, **kwargs)[source]¶ A specific known edition of a
Work
that circulated.-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
display_html
()[source]¶ Render volume/issue citation with formatting, suitable for inclusion on a webpage.
-
updated_at
¶ update timestamp
-
exception
-
class
mep.books.models.
EditionCreator
(*args, **kwargs)[source]¶ Creator specific to an
Edition
of aWork
.-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
Format
(*args, **kwargs)[source]¶ Format of items in the library (book, periodical, etc)
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
uri
¶ linked data URI for the format
-
exception
-
class
mep.books.models.
Genre
(*args, **kwargs)[source]¶ Genres of items from OCLC
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
PastWorkSlug
(*args, **kwargs)[source]¶ A slug that was previously associated with a
Work
; preserved so that former slugs will resolve to the correct work.-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
slug
¶ slug
-
work
¶ work record this slug belonged to
-
exception
-
class
mep.books.models.
Publisher
(*args, **kwargs)[source]¶ Model for publishers
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
PublisherPlace
(*args, **kwargs)[source]¶ Model for place where publishers are located
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.books.models.
Subject
(*args, **kwargs)[source]¶ Linked data subjects for describing
Item
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
classmethod
create_from_uri
(uri)[source]¶ Initialize a new
Subject
from a URI. Loads the URI as anrdflib.Graph
in order to pull the preferred label and RDF type for the URI.
-
name
¶ name/label for the subject (required but not required unique)
-
rdf_type
¶ rdf type for the subject
-
uri
¶ linked data URI for the subject
-
exception
-
class
mep.books.models.
Work
(*args, **kwargs)[source]¶ Work record for an item that circulated in the library or was other referenced in library activities.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
UNCERTAINTY_MESSAGE
= 'Work data is uncertain or incomplete.'¶ Message that will be read to users of assistive technology in place of the uncertainty icon.
semicolon separated list of author names
work creators with type author
-
property
borrow_count
¶ Number of times this work was borrowed.
-
property
creator_names
¶ list of all creator names, including authors
-
property
editors
¶ work creators with type editor
-
property
event_count
¶ Number of events of any kind associated with this work.
-
property
first_known_interaction
¶ date of the earliest known interaction for this item
-
generate_slug
()[source]¶ Generate a slug for this work based on author and title and ensure it is unique.
-
genres
¶ optional genres, from OCLC record
-
property
is_uncertain
¶ Returns True if the Work’s notes indicate that it should show an uncertainty icon via the UNCERTAINTYICON tag.
-
classmethod
items_to_index
()[source]¶ Modify the queryset used for indexing in bulk; prefetch creators, annotate event counts.
-
mep_id
¶ mep id from stub records imported from xml
-
populate_from_worldcat
(worldcat_entity)[source]¶ Set work URI, edition URI, genre, item type, and subjects based on a WorldCat record.
-
public_notes
¶ a field for notes publicly displayed on the website
-
property
purchase_count
¶ Number of times this work was purchased.
-
slug
¶ slug for use in urls
semicolon separated list of author sort names
-
subjects
¶ optional subjects, from OCLC record
-
property
translators
¶ work creators with type translator
-
updated_at
¶ update timestamp
-
exception
-
class
mep.books.models.
WorkQuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Custom
models.QuerySet
forWork
-
class
mep.books.models.
WorkSignalHandlers
[source]¶ Signal handlers for indexing
Work
records when related records are saved or deleted.-
static
creator_change
(sender, instance=None, raw=False, **_kwargs)[source]¶ reindex associated work when a creator record is changed
-
static
creatortype_delete
(sender, instance, **_kwargs)[source]¶ reindex all associated works when a creator type is deleted
-
static
creatortype_save
(sender, instance=None, raw=False, **_kwargs)[source]¶ reindex all associated works when a creator type is changed
-
static
event_delete
(sender, instance, **kwargs)[source]¶ when an event is delete, reindex people associated with the corresponding account.
-
static
event_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when an event is saved, reindex associated work if there is one
-
static
format_delete
(sender, instance, **_kwargs)[source]¶ reindex all associated works when a format is deleted
-
static
format_save
(sender, instance=None, raw=False, **_kwargs)[source]¶ reindex associated work when a format is changed
-
static
Views¶
-
class
mep.books.views.
WorkAutocomplete
(**kwargs)[source]¶ Basic autocomplete lookup, for use with django-autocomplete-light and
mep.books.models.Work
for borrowing and purchasing events
-
class
mep.books.views.
WorkCardList
(**kwargs)[source]¶ Card thumbnails for lending card associated with a single library member.
Get the list of breadcrumbs and links to display for this page.
-
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
mep.footnotes.models.Footnote
-
class
mep.books.views.
WorkCirculation
(**kwargs)[source]¶ Display a list of circulation events (borrows, purchases, etc) for an individual work.
Get the list of breadcrumbs and links to display for this page.
-
model
¶ alias of
mep.accounts.models.Event
-
class
mep.books.views.
WorkDetail
(**kwargs)[source]¶ Detail page for a single library book.
Get the list of breadcrumbs and links to display for this page.
-
model
¶ alias of
mep.books.models.Work
-
class
mep.books.views.
WorkLastModifiedListMixin
(**kwargs)[source]¶ last modified mixin with common logic for all work detail views
-
class
mep.books.views.
WorkList
(**kwargs)[source]¶ List page for searching and browsing library items.
-
form_class
¶ alias of
mep.books.forms.WorkSearchForm
Get the list of breadcrumbs and links to display for this page.
-
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.
-
get_range_stats
()[source]¶ Return the min and max for fields specified in
WorkList
’s stats_fields- Returns
Dictionary keyed on form field name with a tuple of (min, max) as integers. If stats are not returned from the field, the key is not added to a dictionary.
- Return type
-
model
¶ alias of
mep.books.models.Work
-
range_field_map
= {'event_years': 'circulation_dates'}¶ mappings for Solr field names to form aliases
-
search_bib_query
= '{!qf=$bib_qf pf=$bib_pf v=$bib_query}'¶ bib data query alias field syntax (configured defaults is edismax)
-
stats_fields
= ('event_years',)¶ fields to generate stats on in self.get_ranges
-
Utils¶
Utility methods for generating slugs for works. Used in Work model save method and model migration.
-
mep.books.utils.
creator_lastname
(work)[source]¶ Get the lastname of the first creator (first author or first editor if no authors) on this work.
-
mep.books.utils.
generate_sort_title
(title)[source]¶ Generate sort title based on title. Removes leading punctuation and stop word.
People¶
Django app to manage information about people associated with the Sylvia Beach lending library.
Models¶
-
class
mep.people.models.
Country
(*args, **kwargs)[source]¶ Countries, for documenting nationalities of a
Person
or location of anAddress
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.people.models.
InfoURL
(*args, **kwargs)[source]¶ Informational urls (other than VIAF) associated with a
Person
, e.g. Wikipedia page.-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.people.models.
Location
(*args, **kwargs)[source]¶ Locations for addresses associated with people and accounts
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
arrondissement
()[source]¶ Get the arrondissement corresponding to a particular postal code in Paris. If the Location is not in Paris or doesn’t have a postal code, return None.
-
city
¶ city or town
-
latitude
¶ latitude
-
longitude
¶ longitude
-
name
¶ optional name of the location (e.g., hotel)
-
street_address
¶ street address
-
exception
-
class
mep.people.models.
PastPersonSlug
(*args, **kwargs)[source]¶ A slug that was previously associated with a person; preserved so that former slugs will resolve to the correct person.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
person
¶ person record this slug belonged to
-
slug
¶ slug
-
exception
-
class
mep.people.models.
Person
(*args, **kwargs)[source]¶ Model for people in the MEP dataset
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
account_id
()[source]¶ Return the id number of the person’s associated
Account
or empty string if not.
-
address_count
()[source]¶ Number of documented addresses for this person, associated through their account.
-
birth_year
¶ birth year
-
property
card
¶ Lending library card record associated with member account
-
death_year
¶ death year
-
property
firstname_last
¶ Primary name in ‘firstname lastname’ format for display
-
gender
¶ gender
-
has_account
()[source]¶ Return whether an instance of
mep.accounts.models.Account
exists for this person.
-
is_creator
()[source]¶ Return whether this person is a
mep.books.models.Creator
of anmep.books.models.Item
.
-
is_organization
¶ flag to indicate organization instead of person
-
classmethod
items_to_index
()[source]¶ Custom logic for finding items to be indexed when indexing in bulk; only include library members.
-
list_nationalities
()[source]¶ Return comma separated list of nationalities (if any) for
Person
list_view.
-
mep_id
¶ MEP xml id
-
name
¶ names (first middle last)
-
profession
¶
-
public_notes
¶ a field for notes publicly displayed on the website
-
relations
¶ relationships to other people, via
Relationship
-
save
(*args, **kwargs)[source]¶ Adds birth and death dates if they aren’t already set and there’s a viaf id for the record
-
property
short_name
¶ Shortened form of name used for locations where space is tight, e.g. breadcrumb navigation
-
slug
¶ slug for use in urls
-
sort_name
¶ sort name; authorized name for people with VIAF
-
subscription_dates
()[source]¶ Return a semi-colon separated list of
mep.accounts.models.Subscription
instances associated with this person’s account(s).
-
title
¶ title
-
updated_at
¶ update timestamp
-
validate_unique
(exclude=None)[source]¶ Check unique constraints on the model and raise ValidationError if any failed.
-
verified
¶ verified flag
-
property
viaf
¶ viapy.api.ViafEntity
for this record ifviaf_id
is set.
-
viaf_id
¶ viaf identifiers
-
exception
-
class
mep.people.models.
PersonQuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Custom
models.QuerySet
forPerson
-
library_members
()[source]¶ Restrict queryset to people who are library members, based on associated account.
-
merge_with
(person)[source]¶ Merge all person records in the current queryset with the specified person. This entails the following:
all events from accounts associated with people in the queryset are reassociated with the specified person
all addresses associated with people in the queryset or their accounts are reassociated with the specified person or their account
TODO: copy other details and update other relationships
after data has been copied over, people in the queryset and their accounts will be deleted
Raises an error if the specified person has more than one account or if any people in the queryset have an account associated with another person.
- Parameters
person –
Person
person- Raises
django.core.exceptions.MultipleObjectsReturned – if selected
Person
has multiple accounts _or_ any person in the queryset has an account shared with another person
-
-
class
mep.people.models.
PersonSignalHandlers
[source]¶ Signal handlers for indexing
Person
records when related records are saved or deleted.-
static
account_delete
(sender, instance, **kwargs)[source]¶ when an account is deleted, reindex associated people before deletion is processed
-
static
account_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when an account is saved, reindex associated people
-
static
address_delete
(sender, instance, **kwargs)[source]¶ when an address is deleted, reindex people associated with the corresponding account.
-
static
address_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when an address is saved, reindex people associated with the corresponding account.
-
static
country_delete
(sender, instance, **kwargs)[source]¶ when a country is deleted, reindex any people associated via nationality before deletion is processed
-
static
country_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when a country is saved, reindex any people associated via nationality
-
static
-
class
mep.people.models.
Profession
(*args, **kwargs)[source]¶ Profession for a
Person
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
Forms¶
Views¶
-
class
mep.people.views.
BorrowingActivities
(**kwargs)[source]¶ Display a list of book-related activities (borrows, purchases, gifts) for an individual member.
Get the list of breadcrumbs and links to display for this page.
-
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
mep.accounts.models.Event
-
class
mep.people.views.
CountryAutocomplete
(**kwargs)[source]¶ Basic autocomplete lookup, for use with django-autocomplete-light and
mep.people.models.Person
in nationalities many-to-many.
-
class
mep.people.views.
GeoNamesLookup
(**kwargs)[source]¶ GeoNames ajax lookup for use as autocomplete. Optional mode parameter to restrict to countries only.
-
class
mep.people.views.
LocationAutocomplete
(**kwargs)[source]¶ Basic autocomplete lookup, for use with django-autocomplete-light and
mep.people.models.Person
in address many-to-many-
get_queryset
()[source]¶ Get queryset of
mep.people.models.Location
objects. Use Q objects to search all relevant fields in autocomplete.
-
-
class
mep.people.views.
MemberCardDetail
(**kwargs)[source]¶ Card image viewer for image of a single lending card page associated with a single library member.
Get the list of breadcrumbs and links to display for this page.
-
get_object
()[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.
-
model
¶ alias of
djiffy.models.Canvas
-
class
mep.people.views.
MemberCardList
(**kwargs)[source]¶ Card thumbnails for lending card associated with a single library member.
Get the list of breadcrumbs and links to display for this page.
-
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
djiffy.models.Canvas
-
class
mep.people.views.
MemberDetail
(**kwargs)[source]¶ Detail page for a single library member.
Get the list of breadcrumbs and links to display for this page.
-
get_queryset
()[source]¶ Return the QuerySet that will be used to look up the object.
This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.
-
model
¶ alias of
mep.people.models.Person
-
class
mep.people.views.
MemberLastModifiedListMixin
(**kwargs)[source]¶ last modified mixin with common logic for all single-member views
-
class
mep.people.views.
MemberPastSlugMixin
[source]¶ View mixin to handle redirects for previously used slugs. If the main view logic raises a 404, looks for a library member by past slug; if one is found, redirects to the corresponding member detail page with the new slug.
-
class
mep.people.views.
MembersList
(**kwargs)[source]¶ List page for searching and browsing library members.
-
form_class
¶ alias of
mep.people.forms.MemberSearchForm
Get the list of breadcrumbs and links to display for this page.
-
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.
-
get_range_stats
()[source]¶ Return the min and max for fields specified in
MembershipList
’s stats_fields- Returns
Dictionary keyed on form field name with a tuple of (min, max) as integers. If stats are not returned from the field, the key is not added to a dictionary.
- Return type
-
initial
= {'sort': 'name'}¶ initial form values
-
model
¶ alias of
mep.people.models.Person
-
range_field_map
= {'account_years': 'membership_dates'}¶ mappings for Solr field names to form aliases
-
search_name_query
= '{!qf=$name_qf pf=$name_pf v=$name_query}'¶ name query alias field syntax (type defaults to edismax in solr config)
-
stats_fields
= ('account_years', 'birth_year')¶ fields to generate stats on in self.get_ranges
-
-
class
mep.people.views.
MembershipActivities
(**kwargs)[source]¶ Display a list of membership activities (subscriptions, renewals, and reimbursements) for an individual member.
Get the list of breadcrumbs and links to display for this page.
-
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
mep.accounts.models.Event
-
class
mep.people.views.
MembershipGraphs
(**kwargs)[source]¶ -
model
¶ alias of
mep.people.models.Person
-
-
class
mep.people.views.
PersonAutocomplete
(**kwargs)[source]¶ Basic person autocomplete lookup, for use with django-autocomplete-light. Use Q objects to help distinguish people using mepid.
-
class
mep.people.views.
PersonMerge
(**kwargs)[source]¶ View method to merge one or more
Person
records. DisplaysPersonMergeForm
on GET, processes merge withmep.people.models.PersonQuerySet.merge_with()
on successful POST. Should be called with a list of person ids in the querystring as a comma-separated list. Created for use with custom admin actionmep.people.admin.PersonAdmin.merge_people()
.-
form_class
¶ alias of
mep.people.forms.PersonMergeForm
-
get_success_url
()[source]¶ Redirect to the
mep.people.models.Person
change_list in the Django admin with pagination and filters preserved. Expectsmep.people.admin.PersonAdmin.merge_people()
to have set ‘people_merge_filter’ in the request’s session.
-
GeoNames¶
-
class
mep.people.geonames.
GeoNamesAPI
[source]¶ Minimal wrapper around GeoNames API. Currently supports simple searching by name and generating a uri from an id. Expects GEONAMES_USERNAME to be configured in django settings.
-
call_api
(method, params=None)[source]¶ Generic method to handle calling geonames api and raising an exception if an error occurred.
-
property
countries
¶ Country information as returned by countryInfoJSON.
-
countries_by_code
¶ Dictionary of country information keyed on two-letter code.
-
GeoNames unauthorized response (raised when username is not set)
Admin¶
-
class
mep.people.admin.
CountryAdmin
(model, admin_site)[source]¶ -
form
¶ alias of
CountryAdminForm
-
-
class
mep.people.admin.
CountryAdminForm
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶ Custom model form for Place editing, used to add geonames lookup.
-
class
mep.people.admin.
GeoNamesLookupWidget
(url=None, forward=None, *args, **kwargs)[source]¶ Customize autocomplete select widget to display Geonames URI as a link.
-
class
mep.people.admin.
InfoURLInline
(parent_model, admin_site)[source]¶ -
model
¶ alias of
mep.people.models.InfoURL
-
-
class
mep.people.admin.
LocationAdmin
(model, admin_site)[source]¶ -
form
¶ alias of
LocationAdminForm
-
-
class
mep.people.admin.
LocationAdminForm
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶ Custom model form for Address editing.
-
mapbox_token
= None¶ add a hidden field to pass in a mapbox access token from local settings
-
-
class
mep.people.admin.
MapWidget
(attrs=None)[source]¶ Customize numeric input and add a map div to display a leaflet map for latitude and longitude values on the form.
-
class
mep.people.admin.
PersonAdmin
(model, admin_site)[source]¶ ModelAdmin for
Person
. Uses custom template to display account subscription events and any relationships _to_ this person (only relationships to _other_ people are edited here).-
export_fields
= ['id', 'name', 'sort_name', 'mep_id', 'account_id', 'birth_year', 'death_year', 'gender', 'title', 'profession', 'is_organization', 'is_creator', 'has_account', 'in_logbooks', 'has_card', 'subscription_dates', 'verified', 'updated_at', 'admin_url']¶ fields to be included in CSV export
-
form
¶ alias of
PersonAdminForm
-
-
class
mep.people.admin.
PersonAdminForm
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶ Custom model form for Person editing; used to add VIAF lookup
-
class
mep.people.admin.
PersonTypeListFilter
(request, params, model, model_admin)[source]¶ Filter that for
Person
that can distinguish between people who are creators of books vs. those who are library members.
-
class
mep.people.admin.
RelationshipInline
(parent_model, admin_site)[source]¶ Inline class for Relationships
-
form
¶ alias of
RelationshipInlineForm
-
model
¶ alias of
mep.people.models.Relationship
-
-
class
mep.people.admin.
RelationshipInlineForm
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶ Custom model form for Book editing, used to add autocomplete for place lookup.
Footnotes¶
Django app for footnotes that can be associated with other content anywhere in the project.
Models¶
-
class
mep.footnotes.models.
Bibliography
(id, notes, bibliographic_note, source_type, manifest)[source]¶ -
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
classmethod
items_to_index
()[source]¶ Custom logic for finding items for bulk indexing; only include records associated with an account and with a IIIF manifest.
-
manifest
¶ digital version as instance of
djiffy.models.Manifest
-
exception
-
class
mep.footnotes.models.
BibliographySignalHandlers
[source]¶ Signal handlers for indexing
Bibliography
records when related records are saved or deleted.-
static
account_delete
(sender, instance, **kwargs)[source]¶ when an account is deleted, reindex any associated library lending card
-
static
account_save
(sender=None, instance=None, raw=False, **_kwargs)[source]¶ when an account is saved, reindex any associated library lending card.
-
static
canvas_delete
(sender, instance, **kwargs)[source]¶ when a canvas is deleted, reindex library lending card associated via manifest
-
static
canvas_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when a canvas is saved, reindex library lending card associated via manifest
-
static
debug_log
(name, count, mode='save')[source]¶ shared debug logging for card signal save handlers
-
static
event_delete
(sender, instance, **kwargs)[source]¶ when an event is deleted, reindex library lending card associated via account
-
static
event_save
(sender=None, instance=None, raw=False, **_kwargs)[source]¶ when an event is saved, reindex library lending card associated via account
-
static
manifest_delete
(sender, instance, **kwargs)[source]¶ when a manifest is deleted, reindex associated library lending card
-
static
manifest_save
(sender=None, instance=None, raw=False, **kwargs)[source]¶ when a manifest is saved, reindex associated library lending card
-
static
-
class
mep.footnotes.models.
Footnote
(*args, **kwargs)[source]¶ Footnote that can be associated with any other model via generic relationship. Used to provide supporting documentation for or against information in the system.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
-
class
mep.footnotes.models.
FootnoteQuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Custom
models.QuerySet
forFootnote
-
event_date_range
()[source]¶ Find earliest and latest dates for any events associated with footnotes in this queryset. Returns a tuple of earliest and latest dates, or None if no dates are found.
-