heliport.archive package
Subpackages
Submodules
heliport.archive.admin module
Registers Django admin pages.
See django.contrib.admin.ModelAdmin from Django documentation.
- class heliport.archive.admin.ArchiveAdmin(model, admin_site)
Bases:
DigitalObjectAdminAdmin interface for the
Archiveclass.In addition to the parent class features, the
archive_numberis shown.- digital_object_attributes: List[str] = ['archive_number']
- property media
heliport.archive.apps module
Django app configuration.
Some HELIPORT hooks can be registered in app config django.apps.AppConfig.ready().
See also Django documentation
heliport.archive.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.archive.interface.ArchiveModule
Bases:
DigitalObjectModule- get_url(project)
Return the URL for the entry point of this module.
- module_id = 'archive'
- name = 'Archive'
- property object_class
Archive.
- heliport.archive.interface.get_search_url()
Return the search URL for this app.
This URL is used to implement the global HELIPORT string search.
heliport.archive.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.archive.models.Archive(digital_object_id, persistent_id, generated_persistent_id, category, label, label_is_public, description, description_is_public, created, last_modified, last_modified_is_public, deleted, permission, special_heliport_role, is_helper, projects_is_public, owner, members_is_public, digitalobject_ptr, archive_id)
Bases:
DigitalObject- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- archive_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- archive_number
Defines a python descriptor for metadata properties.
This descriptor should be used on
DigitalObjectsubclasses.In principle most properties of subclasses of
DigitalObjectcan be considered “Metadata Properties” however usingMetadataFiledhas 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
Vocabularyand 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
DigitalObjectAttributesand 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_dbparameter uniquely for each. Also if you change the metadata attribute or therole_name_in_dbyou need to write a database migration.
- 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.placeis aForwardOneToOneDescriptorinstance.
- digitalobject_ptr_id
- link
Defines a python descriptor for metadata properties.
This descriptor should be used on
DigitalObjectsubclasses.In principle most properties of subclasses of
DigitalObjectcan be considered “Metadata Properties” however usingMetadataFiledhas 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
Vocabularyand 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
DigitalObjectAttributesand 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_dbparameter uniquely for each. Also if you change the metadata attribute or therole_name_in_dbyou need to write a database migration.
heliport.archive.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.archive.serializers.ArchiveDATACITESerializer
Bases:
DigitalObjectDATACITESerializer- resource_type(archive)
heliport.archive.tests module
Test the behaviour of this app.
This follows the Writing tests guide in Django.
- class heliport.archive.tests.ArchiveTests(methodName='runTest')
Bases:
TestCaseTest archive app.
- setUp()
Set up projects and logged in users.
- test_create()
Test creating archive.
- test_list()
Test listing archives.
- test_url()
Test url normalization of archive.
- class heliport.archive.tests.ProjectSerializeTest(methodName='runTest')
Bases:
TestCaseTest metadata serialization.
- static landing_page_url(obj)
Construct landing page url for an object.
- setUp()
Set up projects, instances and logged-in users.
- test_datacite()
Test datacite generation.
- test_json_ld()
Test JSON LD generation.
- test_not_public()
Test to not see private information on landing page.
- test_rest_api()
Test REST API including serialization.
heliport.archive.urls module
Map django views to urls.
See this Example including explanation from the Django documentation.
heliport.archive.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.archive.views.ArchiveView
Bases:
HeliportObjectListView- action_open(obj)
- 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', {'link': 'https://www.hzdr.de/archiv', 'text': 'create'}, 'one first']
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 = {'archive_number', '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 = 'HELIPORT/archive'
Namespace used for handle generation
- columns = [('Archive Number', 'archive_number', 'small'), ('Name', 'label', 'normal'), ('Description', 'description', '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 an Archive'
Text displayed as heading over form when creating obj. See also
get_create_heading(). # noqa: E501
- edit_fields = [('Name', 'label', 'normal'), ('Archive Number', 'archive_number', 'normal'), ('Link', 'link', 'normal'), ('Description', 'description', 'large')]
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 = 'Archives'
Text displayed as heading
- list_url = 'archive: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_urlis required by the defaultaction_edit()implementation to link back to original page after editing.
- update_url = 'archive: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_urlis required by the defaultaction_edit()implementation.
- class heliport.archive.views.ArchiveViewSet(**kwargs)
Bases:
HeliportModelViewSetArchive.
- filter_backends = [<class 'rest_framework.filters.SearchFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>]
- filterset_fields = ['archive_id', 'persistent_id']
- get_queryset()
- search_fields = ['label', 'description', 'owner__display_name', 'attributes__value']
- serializer_class
alias of
ArchiveSerializer
- class heliport.archive.views.SearchView(**kwargs)
Bases:
HeliportLoginRequiredMixin,TemplateView- get_context_data(**kwargs)
Add extra context for rendering template (Called by django base view).
The extra context includes the search results.
- template_name = 'archive/search.html'
Module contents
App to store metadata about archived data.
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()).