heliport.mediawiki package
Subpackages
Submodules
heliport.mediawiki.admin module
Registers Django admin pages.
See django.contrib.admin.ModelAdmin
from Django documentation.
heliport.mediawiki.apps module
Django app configuration.
Some HELIPORT hooks can be registered in app config django.apps.AppConfig.ready()
.
See also Django documentation
heliport.mediawiki.interface module
Module with special name “interface” hooks into HELIPORT.
Some functions and heliport.core.app_interaction.Module
subclasses are detected
by HELIPORT and control how HELIPORT uses this app.
Note that this module must be imported in __init__.py of the django app.
- class heliport.mediawiki.interface.MediaWikiModule
Bases:
DigitalObjectModule
The interface to enable MediaWiki Pages inside a HELIPORT Project.
- get_url(project)
Return the URL for the entry point of this module.
- module_id = 'mediawiki'
- name = 'MediaWiki'
- property object_class
The model to test automatically if tis module is used in a project.
- heliport.mediawiki.interface.get_project_create_urls()
Return URLs to views in this app that can be used to create a new project.
- heliport.mediawiki.interface.get_search_url()
Return the search URL for this app.
This URL is used to implement the global HELIPORT string search.
heliport.mediawiki.models module
Contains django.db.models.Model
classes for Django ORM.
See Quick example from Django documentation.
In HELIPORT the heliport.core.models.DigitalObject
can be subclassed for models
containing metadata in a project.
- class heliport.mediawiki.models.MediaWikiPage(*args, **kwargs)
Bases:
DigitalObject
A WikiPage.
- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- digitalobject_ptr
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- digitalobject_ptr_id
- link
Defines a python descriptor for metadata properties.
This descriptor should be used on
DigitalObject
subclasses.In principle most properties of subclasses of
DigitalObject
can be considered “Metadata Properties” however usingMetadataFiled
has the added convenience that metadata serialization is automatically taken care of just by specifying the metadata property in the class definition. On top of that Storage if the property is public and can be shown on the landing page to everybody is handled without extra code.Use it for example like this:
class MyClass(DigitalObject): link = MetadataField(Vocabulary.primary_topic, url_normalizer)
The first argument comes from
Vocabulary
and defines the metadata property to use for serialization. The second argument is optional and is just a function that is called before setting the value.heliport.core.utils.normalization.url_normalizer()
is used in the example.The values are stored as
DigitalObjectAttributes
and identified by thir property as well as an additional identification string that is by default “attribute”. This means if you have multiple properties with the same metadata property you need to set therole_name_in_db
parameter uniquely for each. Also if you change the metadata attribute or therole_name_in_db
you need to write a database migration.
- wiki_page_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
heliport.mediawiki.serializers module
This module is for serialization into Datacite, RDF and JSON.
The JSON format is used for API endpoints via Django rest framework. Using this, it is typical to put the serializer classes into a “serializers.py” file.
For the serialization into RDF, attributes are described.
See heliport.core.attribute_description.BaseAttribute
for more detail.
- class heliport.mediawiki.serializers.MediaWikiPageSerializer(*args, **kwargs)
Bases:
ModelSerializer
Serializer for returning a MediaWik page in the REST API.
- class Meta
Bases:
object
Specify main serializer information.
- fields = ['wiki_page_id', 'label', 'projects', 'persistent_id', 'url']
- model
alias of
MediaWikiPage
- create(validated_data)
Create an object with link attribute.
See
heliport.core.models.MetadataField
for why this is necessary.
- class heliport.mediawiki.serializers.WikiPageDATACITESerializer
Bases:
DigitalObjectDATACITESerializer
Serializing
heliport.mediawiki.models.MediaWikiPage
in DataCite.- resource_type(pub)
Get DataCite resource types.
Specific type is “wikipage”. General type is “Text”.
heliport.mediawiki.tests module
Test the behaviour of this app.
This follows the Writing tests guide in Django.
heliport.mediawiki.urls module
Map django views to urls.
See this Example including explanation from the Django documentation.
heliport.mediawiki.views module
Contains Django View classes to handle HTTP requests.
See Using class-based views from Django
documentation.
In HELIPORT heliport.core.mixins
are used to create uniform views. Also
heliport.core.views.generic.HeliportObjectListView
is used to quickly create a
typical HELIPORT list view.
- class heliport.mediawiki.views.CreateProjectFromPageView(**kwargs)
Bases:
CreateProjectView
Create new HELIPORT project.
Including options for specifying initial project settings and importing contents of other projects.
- create_wiki_page(request, project)
Create new wiki page for project.
- get_context_data(**kwargs)
Get context when rendering template.
Called by django. Context includes group information and list of projects of current user.
- post(request, *args, **kwargs)
Create project and configure settings.
If template project is selected to import digital objects from, redirect to
ImportFromProjectView
.Called by django on http post.
- template_name = 'mediawiki/project_from_page.html'
HTML template rendered by this View (page for entering initial project settings)
- class heliport.mediawiki.views.MediaWikiPageListView
Bases:
HeliportObjectListView
Wiki page view.
- action_open(obj)
Handle user clicking open button.
- actions = [('Open', 'action_open', 'link'), ('Edit', 'action_edit', 'link_secondary'), ('Delete', 'action_delete', 'danger')]
Actions that are available for each column. Triples of action name, method name called on the HeliportObjectListView # noqa: E501 and style information. For more control over action overwrite
register_actions()
. # noqa: E501 See implementation ofregister_actions()
for definitions of style information. # noqa: E501
- add_text = ['or create one first at', {'link': 'https://wiki.hzdr.de', 'text': 'HZDR MediaWiki,'}, {'link': 'https://athene.fz-rossendorf.de/fwk/Main_Page', 'text': 'Athene Wiki'}, 'or', {'link': 'https://wiki-dev.fz-rossendorf.de', 'text': 'Test Wiki'}]
List of strings that are concatenated and put next to the add button for creating a new object. # noqa: E501 See
utils.form_description.FormDescription.get_add_text()
for more information. # noqa: E501
- after_save_attributes = {'link'}
List of attribute names (second value in triples of
edit_fields
) that should # noqa: E501 be set afterobj.save()
is called when creating anobj
.
- category = 'MediaWiki/page'
Namespace used for handle generation
- columns = [('ID', 'wiki_page_id', 'small'), ('Name', 'label', 'large')]
Columns shown in the table. Triples of column name, attribute shown in column, column size. # noqa: E501 For more control over columns overwrite
register_columns()
. See implementation ofregister_columns()
for definition of column sizes
- create_heading = 'Add a MediaWiki Page'
Text displayed as heading over form when creating obj. See also
get_create_heading()
. # noqa: E501
- edit_fields = [('Link', 'link', 'normal'), ('Name', 'label', 'normal')]
Fields editable in this view. Triple of key name, attribute name ware value is stored and field style For more control over form fields overwrite
register_form_columns()
. See implementation ofregister_form_columns()
for definitions of field styles. # noqa: E501
- list_heading = 'MediaWiki Pages'
Text displayed as heading
- list_url = 'mediawiki:list'
Url that leads to this view for listing objects. The list_url attribute should be a string that is valid when passed to Django’s reverse() function with kwarg “project”.
list_url
is required by the defaultaction_edit()
implementation to link back to original page after editing.
- model
alias of
MediaWikiPage
- update_url = 'mediawiki:update'
Url that leads to this view for updating. The “update_url” string is passed to
django.urls.reverse()
with “project” and “pk” url arguments to get the actual url.update_url
is required by the defaultaction_edit()
implementation.
- class heliport.mediawiki.views.MediaWikiPageViewSet(**kwargs)
Bases:
HeliportModelViewSet
MediaWiki Page API.
- filter_backends = [<class 'rest_framework.filters.SearchFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>]
- filterset_fields = ['wiki_page_id', 'persistent_id']
- get_queryset()
- search_fields = ['attributes__value', 'label']
- serializer_class
alias of
MediaWikiPageSerializer
- class heliport.mediawiki.views.SearchView(**kwargs)
Bases:
HeliportLoginRequiredMixin
,TemplateView
View for returning MediaWiki specific search results.
- get_context_data(**kwargs)
Add extra context for rendering template (Called by django base view).
The extra context includes the search results.
- template_name = 'mediawiki/search.html'
Module contents
App to interface with a MediaWiki server.
The interface
module is imported to the top level of the package for HELIPORT app
interface discovery (see heliport.core.app_interaction.get_heliport_apps()
).