CMS

This is the content management system for backend users which contains all database models, views, forms and templates.

Admin

Register models for Django’s CRUD back end and specify autocomplete_fields, search_fields and nested modules

lunes_cms.cms.admin.get_app_list(self, request)

Function that returns a sorted list of all the installed apps that have been registered in this site.

Parameters:
  • self (class: admin.AdminSite) – A handle to the admin.AdminSite

  • request (django.http.request) – current user request

Returns:

list of app dictionaries (e.g. containing models)

Return type:

list

Apps

class lunes_cms.cms.apps.CmsConfig(app_name, app_module)

Bases: AppConfig

Application settings for the cms app, which is our main cms app. Inherits from AppConfig.

name = 'lunes_cms.cms'
verbose_name = 'vocabulary management'

Forms

class lunes_cms.cms.forms.DisciplineChoiceField(queryset, **kwargs)

Bases: ModelMultipleChoiceField

Custom form field in order to include parent nodes in string representation. Inherits from forms.ModelMultipleChocieField.

label_from_instance(obj)

Convert objects into strings and generate the labels for the choices presented by this object. Subclasses can override this method to customize the display of the choices.

class lunes_cms.cms.forms.TrainingSetForm(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)

Bases: ModelForm

Defining custom form for the training set admin interface. Inherits from forms.ModelForm.

Form fields:

clean()

Make sure the training set is only released when it contains at least as many vocabularies as defined in TRAININGSET_MIN_DOCS.

Returns:

The cleaned data for this form

Return type:

dict

description = <django.db.models.CharField>
property media

Return all media required to render the widgets on this form.

title = <django.db.models.CharField>

List Filter

class lunes_cms.cms.list_filter.ApprovedImageListFilter(request, params, model, model_admin)

Bases: SimpleListFilter

Filter for approved images within document list display. Inherits from admin.SimpleListFilter.

default_value = None
lookups(request, model_admin)

Defining look up values that can be seen in the admin interface. Returns tuples: the first element is a coded value, whereas the second one is human-readable

Parameters:
  • request (django.http.request) – current user request

  • model_admin (ModelAdmin) – admin of current model

Returns:

list of tuples containing id and title of each discipline

Return type:

list

parameter_name = 'images'
queryset(request, queryset)

Returns the filtered queryset based on the value provided in the query string and retrievable via self.value().

Parameters:
  • request (django.http.request) – current user request

  • queryset (QuerySet) – current queryset

Returns:

filtered queryset based on the value provided in the query string

Return type:

QuerySet

title = 'Images'
class lunes_cms.cms.list_filter.AssignedListFilter(request, params, model, model_admin)

Bases: SimpleListFilter

Filter for documents that are either assigned or unassigned to at least one training set. Inherits from admin.SimpleListFilter.

default_value = None
lookups(request, model_admin)

Defining look up values that can be seen in the admin interface. Returns tuples: the first element is a coded value, whereas the second one is human-readable

Parameters:
  • request (django.http.request) – current user request

  • model_admin (ModelAdmin) – admin of current model

Returns:

list of tuples containing id and title of each discipline

Return type:

list

parameter_name = 'assigned'
queryset(request, queryset)

Returns the filtered queryset based on the value provided in the query string and retrievable via self.value().

Parameters:
  • request (django.http.request) – current user request

  • queryset (QuerySet) – current queryset

Returns:

filtered queryset based on the value provided in the query string

Return type:

QuerySet

title = 'Assignments'
class lunes_cms.cms.list_filter.DisciplineListFilter(request, params, model, model_admin)

Bases: SimpleListFilter

Generic Filter for models that have a direct relationship to disciplines. Inherits from admin.SimpleListFilter.

lookups(request, model_admin)

Defining look up values that can be seen in the admin interface. Returns tuples: the first element is a coded value, whereas the second one is human-readable.

Parameters:
  • request (django.http.request) – current user request

  • model_admin (ModelAdmin) – admin of current model

Returns:

list of tuples containing id and title of each discipline

Return type:

list

parameter_name = 'disciplines'
queryset(request, queryset)

Returns the filtered queryset based on the value provided in the query string and retrievable via self.value().

Parameters:
  • request (django.http.request) – current user request

  • queryset (QuerySet) – current queryset

Returns:

filtered queryset based on the value provided in the query string

Return type:

QuerySet

template = 'admin/discipline_filter.html'
title = 'disciplines'
class lunes_cms.cms.list_filter.DocumentDisciplineListFilter(request, params, model, model_admin)

Bases: DisciplineListFilter

Filter for disciplines within document list display. Inherits from admin.SimpleListFilter.

queryset(request, queryset)

Returns the filtered queryset based on the value provided in the query string and retrievable via self.value().

Parameters:
  • request (django.http.request) – current user request

  • queryset (QuerySet) – current queryset

Returns:

filtered queryset based on the value provided in the query string

Return type:

QuerySet

class lunes_cms.cms.list_filter.DocumentTrainingSetListFilter(request, params, model, model_admin)

Bases: SimpleListFilter

Filter for training sets within document list display. Inherits from admin.SimpleListFilter.

lookups(request, model_admin)

Defining look up values that can be seen in the admin interface. Returns tuples: the first element is a coded value, whereas the second one is human-readable.

Parameters:
  • request (django.http.request) – current user request

  • model_admin (ModelAdmin) – admin of current model

Returns:

list of tuples containing id and title of each training set

Return type:

list

parameter_name = 'training set'
queryset(request, queryset)

Returns the filtered queryset based on the value provided in the query string and retrievable via self.value().

Parameters:
  • request (django.http.request) – current user request

  • queryset (QuerySet) – current queryset

Returns:

filtered queryset based on the value provided in the query string

Return type:

QuerySet

title = 'training sets'

Urls

Map paths to view functions. Defines custom schema views and a router that handles the url patterns described in the README.md file

lunes_cms.cms.urls.urlpatterns = [<URLPattern 'admin/password_reset/' [name='admin_password_reset']>, <URLPattern 'admin/password_reset/done/' [name='password_reset_done']>, <URLPattern 'reset/<uidb64>/<token>/' [name='password_reset_confirm']>, <URLPattern 'reset/done/' [name='password_reset_complete']>, <URLResolver <URLPattern list> (admin:admin) 'admin/'>, <URLPattern 'i18n.js' [name='javascript-translations']>]

The url patterns of this module (see URL dispatcher)

[
    <URLPattern 'admin/password_reset/' [name='admin_password_reset']>,
    <URLPattern 'admin/password_reset/done/' [name='password_reset_done']>,
    <URLPattern 'reset/<uidb64>/<token>/' [name='password_reset_confirm']>,
    <URLPattern 'reset/done/' [name='password_reset_complete']>,
    <URLResolver <URLPattern list> (admin:admin) 'admin/'>,
    <URLPattern 'i18n.js' [name='javascript-translations']>,
]

Utils

A collection of helper methods and classes

lunes_cms.cms.utils.create_resource_path(parent_dir, filename)

Create a file path with a uuid and given parent directory.

Parameters:
  • parent_dir (str) – parent directory

  • filename (str) – file name

Returns:

full file path

Return type:

str

lunes_cms.cms.utils.document_to_string(doc)

Create string representation of a document object

Parameters:

doc (models.Document) – Document object

Returns:

String representation of document image

Return type:

str

lunes_cms.cms.utils.get_child_count(disc)

Returns the number of children of a discipline. Every child contains at least one training set or is a direct/indirect parent of a discipline that contains one.

Parameters:

disc (Discipline) – Discipline instance

Returns:

sum of children

Return type:

int

lunes_cms.cms.utils.get_image_tag(image, width=330)

Image thumbnail to display a preview of a image

Parameters:
  • image (int) – The image file

  • width – The pixel width of the created image tag. Defaults to 330

Returns:

HTML tag to display an image thumbnail

Return type:

str

lunes_cms.cms.utils.get_random_key(length: int = 10, excluded_chars: list | None = None) str

Auxiliary function that creates a random key based on latin letters and digits using the passed length. Optionally, it is possible to exclude characters like l and 1.

Parameters:
  • length (int, optional) – key length, defaults to 10

  • excluded_chars (list, optional) – list of characters to be excluded (mixed dtypes possible), defaults to None

Returns:

key

Return type:

str

lunes_cms.cms.utils.get_training_set_count(disc)

Returns the total number of training sets of a discipline and all its child elements.

Parameters:

disc (Discipline) – Discipline instance

Returns:

sum of training sets

Return type:

int

lunes_cms.cms.utils.iter_to_string(iter)

Convert an iterable of objects to a readable string. It joins the first elements with commas and separates the last element by “and”.

Parameters:

iter (Iterable) – The input iterable

Returns:

The joined list

Return type:

str

Validators

lunes_cms.cms.validators.validate_file_extension(value)

Function to validate the audio file format

Parameters:

value (audio file) – audio file returned by a models.FileField

Returns:

None

Return type:

None

lunes_cms.cms.validators.validate_file_size(value)

Function to validate the size of an audio file

Parameters:

value (audio file) – audio file returned by a models.FileField

Returns:

None

Return type:

None

lunes_cms.cms.validators.validate_multiple_extensions(value)

Function that checks if an audio file has multiple extensions

Parameters:

value (audio file) – audio file returned by a models.FileField

Returns:

None

Return type:

None

Widgets

class lunes_cms.cms.widgets.ManyToManyOverlay(*args, **kwargs)

Bases: FilteredSelectMultiple

Adds an overlay to the FilteredSelectMultiple widget to preview images and audios of Document objects. Inherits from django.contrib.admin.widgets.FilteredSelectMultiple.

class Media

Bases: object

Media class of ManyToManyOverlay

css = {'all': ('css/overlay.css',)}
js = ('js/manytomany_overlay.js', 'js/overlay.js', '/en/i18n.js')
__init__(*args, **kwargs)

Instantiates model by calling super() and passing a new onclick event to the widget.

property media