Reference
apis_entities
abc
E53_Place
Bases: Model
The feature_code field refers to the geonames feature codes, as listed on https://www.geonames.org/export/codes.html
Source code in apis_core/apis_entities/abc.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
filtersets
ModelSearchFilter
Bases: CharFilter
This filter is a customized CharFilter that
uses the generate_search_filter
method to
adapt the search filter to the model that is
searched.
It also extracts sets the help text based on
the fields searched.
Source code in apis_core/apis_entities/filtersets.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
models
AbstractEntity
Bases: RootObject
Abstract super class which encapsulates common logic between the different entity kinds and provides various methods relating to either all or one specific entity kind.
Most of the class methods are designed to be used in the subclass as they are considering contexts which depend on the subclass entity type. So they are to be understood in that dynamic context.
Source code in apis_core/apis_entities/models.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
tables
DuplicateColumn
Bases: ActionColumn
A column showing a view button
Source code in apis_core/apis_entities/tables.py
4 5 6 7 8 9 10 |
|
views
EntitiesAutocomplete
Bases: Select2QuerySetView
This endpoint allows us to use autocomplete over multiple model classes.
It takes a parameter entities
which is a list of ContentType natural
keys and searches for the query in all instances of those entities
(using generate_search_filter
, which means it uses a different search
approach for every model).
The return values of the endpoint are then prefixed with the id of the
contenttype of the results, separated by an underscore.
Example: Using this endpoint with the parameters:
?entities=apis_ontology.person&entities=apis_ontology.place&q=ammer
gives you all the persons and places that have ammer
in their names
and labels.
Source code in apis_core/apis_entities/views.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
apis_metainfo
models
RootObject
Bases: GenericModel
, Model
The very root thing that can exist in a given ontology. Several classes inherit from it. By having one overarching super class we gain the advantage of unique identifiers.
Source code in apis_core/apis_metainfo/models.py
7 8 9 10 11 12 13 14 |
|
collections
filters
CollectionsIncludeExcludeFilter
Bases: ModelMultipleChoiceFilter
The CollectionsIncludeExcludeFilter provides to ModelMultipleChoiceFilters that allow to filter model instances that are either in a collection OR (or AND) are not in a collection.
Source code in apis_core/collections/filters.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
models
SkosCollection
Bases: GenericModel
, Model
SKOS collections are labeled and/or ordered groups of SKOS concepts. Collections are useful where a group of concepts shares something in common, and it is convenient to group them under a common label, or where some concepts can be placed in a meaningful order.
Miles, Alistair, and Sean Bechhofer. "SKOS simple knowledge organization system reference. W3C recommendation (2009)."
Source code in apis_core/collections/models.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
SkosCollectionContentObject
Bases: GenericModel
, Model
Throughtable datamodel to connect collections to arbitrary content
Source code in apis_core/collections/models.py
88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
signals
add_to_session_collection(sender, instance, created, raw, using, update_fields, **kwargs)
Add a created apis_core.history model instance to all the SkosCollections
that are listed in the session_collections
session variable.
This needs the 'crum.CurrentRequestUserMiddleware' middleware to
be enabled.
Source code in apis_core/collections/signals.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
templatetags
collections
collection_object_collection(context, obj, skoscollectioncollectionobjects)
Provide a button to change the connection between an object and a collection to point to the collection the collection is in.
Source code in apis_core/collections/templatetags/collections.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
collection_object_collection_by_id(context, obj, *collection_ids)
Wrapper templatetag to allow using collection_object_parent
with
just the ids
of collections.
Source code in apis_core/collections/templatetags/collections.py
59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
collection_session_toggle_by_id(context, collection_id)
Provide a checkbox to toggle if a session collection is active. The checkbox calls the CollectionSessionToggle view.
Source code in apis_core/collections/templatetags/collections.py
86 87 88 89 90 91 92 93 94 95 96 97 |
|
collection_toggle(context, obj, collection)
Provide a button to add or remove a connection between a collection and an object.
Source code in apis_core/collections/templatetags/collections.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
collection_toggle_by_id(context, obj, collectionid)
Wrapper templatetag to allow using collection_toggle
with just the id
of the collection.
Source code in apis_core/collections/templatetags/collections.py
28 29 30 31 32 33 34 35 |
|
views
CollectionObjectCollection
Bases: LoginRequiredMixin
, ContentObjectMixin
, TemplateView
Change the requested CollectionObjects collection to point to the collection the current collection is in.
Source code in apis_core/collections/views.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
CollectionSessionToggle
Bases: LoginRequiredMixin
, TemplateView
Toggle the existence of an SkosCollection in the session_collections
session variable.
This can be used in combination with the
collections.signals.add_to_session_collection
signal, to add objects
to a collection if the collections id is listed in the session variable.
The equivalent templateatag that calls this view is
collections.templatetags.collections.collection_session_toggle_by_id
Source code in apis_core/collections/views.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
CollectionToggle
Bases: LoginRequiredMixin
, ContentObjectMixin
, TemplateView
Toggle a collection - if a CollectionObject connecting the requested object and collection does not exist, then create it. If it does exist, delete it.
Source code in apis_core/collections/views.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
ContentObjectMixin
Setup the ContentType and the object used by a view, based on the
content_type_id
and the object_id
arguments passed in the URL.
Source code in apis_core/collections/views.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
generic
abc
GenericModel
Source code in apis_core/generic/abc.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
get_field_value_after_merge(other, field)
This method finds the value of a field after merging other
into self
.
It first tries to find a merge method that is specific to that field
(merge_{fieldname}) and then tries to find a method that is specific to
the type of the field (merge_{fieldtype})
If neither of those exist, it uses the others field value if the field
in self is not set, otherwise it keeps the value in self.
Source code in apis_core/generic/abc.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
merge_fields(other)
This method iterates through the model fields and uses the
get_field_value_after_merge
method to copy values from other
to self
.
It is called by the merge_with
method.
Source code in apis_core/generic/abc.py
166 167 168 169 170 171 172 173 174 175 176 |
|
api_views
ModelViewSet
Bases: ModelViewSet
API ViewSet for a generic model.
The queryset is overridden by the first match from
the first_member_match
helper.
The serializer class is overridden by the first match from
the first_member_match
helper.
Source code in apis_core/generic/api_views.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
filtersets
GenericFilterSet
Bases: FilterSet
Our GenericFilterSet sets the default form
to be our
GenericFilterSetForm, which is set up to ignore the columns
field
of the form.
Source code in apis_core/generic/filtersets.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
forms
GenericFilterSetForm
Bases: Form
FilterSet form for generic models
Adds a submit button using the django crispy form helper
Adds a columns
selector that lists all the fields from
the model
Source code in apis_core/generic/forms/__init__.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
GenericModelForm
Bases: ModelForm
Model form for generic models Adds a submit button using the django crispy form helper and sets the ModelChoiceFields and ModelMultipleChoiceFields to use autocomplete replacement fields
Source code in apis_core/generic/forms/__init__.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
fields
RowColumnMultiValueField
Bases: MultiValueField
This is a custom MultiValueField that simply shows multiple form
fields in a row. The form fields are passed to the constructor and
the corresponding RowColumnMultiWidget simply iterates through all
the fields and shows them in rows.
Additionaly it is possible to pass a list of labels
that are then
also passed on to the widget, which uses those to add a separate
label to the individual widgets.
Source code in apis_core/generic/forms/fields.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
RowColumnMultiWidget
Bases: MultiWidget
A custom MultiWidget that is meant to be used with the
RowColumnMultiValueField. The widget takes a list of widgets
as a parameter and displays those widgets in columns in one row.
The labels
parameter is used to add a separate label to the
individual widgets.
Source code in apis_core/generic/forms/fields.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
generators
CustomEndpointEnumerator
Bases: EndpointEnumerator
Source code in apis_core/generic/generators.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_api_endpoints(patterns=None, prefix='')
Call the EndpointEnumerator's get_api_endpoints
method to get all
the automatically found endpoints, remove the ones that we want to override
and the add our custom endpoints to this list.
Source code in apis_core/generic/generators.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
helpers
default_search_fields(model, field_names=None)
Retrieve the default model fields to use for a search operation
By default those are all the CharFields and TextFields of a model.
It is also possible to define those fields on the model using the
_default_search_fields
attribute.
The method also takes a field_names
argument to override the list
of fields.
Source code in apis_core/generic/helpers.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
generate_search_filter(model, query, fields_to_search=None, prefix='')
Generate a default search filter that searches for the query
This helper can be used by autocomplete querysets if nothing
fancier is needed.
If the prefix
is set, the field names will be prefixed with that string -
this can be useful if you want to use the generate_search_filter
in a
Q
combined query while searching over multiple models.
Source code in apis_core/generic/helpers.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
mro_paths(model)
cached
Create a list of MRO classes for a Django model
Source code in apis_core/generic/helpers.py
65 66 67 68 69 70 71 72 73 74 75 |
|
split_and_strip_parameter(params)
Clean a URI param list type This method iterates through a list of strings. It looks if the items contain a comma separated list of items and then splits those and also runs strip on all those items. So out of ["foo.bar", "bar.faz, faz.foo"] it creates a list ["foo.bar", "bar.faz", "faz.foo"]
Source code in apis_core/generic/helpers.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
string_to_bool(string='false')
Convert a string to a boolean representing its semantic value
Source code in apis_core/generic/helpers.py
149 150 151 152 153 |
|
template_names_via_mro(model, suffix='')
cached
Use the MRO to generate a list of template names for a model
Source code in apis_core/generic/helpers.py
78 79 80 81 82 83 84 |
|
importers
GenericModelImporter
A generic importer class which provides methods for importing data from a URI and creating a model instance from it.
By default, it fetches a resource and first tries to parse it using our RDF parser. If that fails, it tries to parse it using JSON and then extracts the fields whose keys match the model field names. Projects can inherit from this class and override the default methods or simply write their own from scratch.
Source code in apis_core/generic/importers.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
get_data(drop_unknown_fields=True)
Fetch the data using the request
method and
mangle it using the mangle_data
method.
If the drop_unknown_fields
argument is True,
remove all fields from the data dict that do not
have an equivalent field in the model.
Source code in apis_core/generic/importers.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
renderers
GenericRDFBaseRenderer
Bases: BaseRenderer
Base class to render RDF graphs to various formats.
This renderer expects the serialized data to either be a rdflib grap or
to contain a list of rdflib graphs. If it works with a list of graphs, those
are combined to one graph.
This graph is then serialized and the result is returned. The serialization
format can be set using the rdflib_format
attribute. If this is not set, the
format
attribute of the renderer is used as serialization format (this is the
format as it is used by the Django Rest Framework for content negotiation.
Source code in apis_core/generic/renderers.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
routers
CustomAPIRootView
Bases: APIRootView
The default basic root view for CustomDefaultRouter
This view lists the output of the default APIRootView of the Django Rest Framework. In addition, it injects the routes of the genericmodelapi (those are not hardcoded registered but autogenerated based on the models that inherit from GenericModel).
Source code in apis_core/generic/routers.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
CustomDefaultRouter
Bases: DefaultRouter
The CustomDefaultRouter only diverts from the Django Rest Framework DefaultRouter by setting the APIRootView to our CustomAPIRootView.
Source code in apis_core/generic/routers.py
34 35 36 37 38 39 40 |
|
schema
GenericAutoSchema
Bases: AutoSchema
Add an option to the default drf_spectacular schema that allows to set the tags of a route via the model.
Source code in apis_core/generic/schema.py
4 5 6 7 8 9 10 11 12 13 14 |
|
tables
ActionColumn
Bases: CustomTemplateColumn
A custom template column with some additional attributes for actions.
Source code in apis_core/generic/tables.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
CustomTemplateColumn
Bases: TemplateColumn
A custom template column - the tables.TemplateColumn
class does not allow
to set attributes via class variables. Therefor we use this
CustomTemplateColumn to set some arguments based on class attributes and
override the attributes in child classes.
Source code in apis_core/generic/tables.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
DeleteColumn
Bases: ActionColumn
A column showing a delete button
Source code in apis_core/generic/tables.py
48 49 50 51 52 53 54 |
|
DescriptionColumn
Bases: CustomTemplateColumn
A column showing a model description
Source code in apis_core/generic/tables.py
75 76 77 78 79 80 81 |
|
EditColumn
Bases: ActionColumn
A column showing an edit button
Source code in apis_core/generic/tables.py
57 58 59 60 61 62 63 |
|
GenericTable
Bases: Table
A generic table that contains an edit button column, a delete button column and a description column
Source code in apis_core/generic/tables.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
MoreLessColumn
Bases: TemplateColumn
Useful for displaying long fields. A preview is shown initially with a "Show more" link which is replaced with a "Show less" link when expanded.
Source code in apis_core/generic/tables.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
ViewColumn
Bases: ActionColumn
A column showing a view button
Source code in apis_core/generic/tables.py
66 67 68 69 70 71 72 |
|
tests
setup_test_app(package, label=None)
Setup a Django test app for the provided package to allow test models tables to be created if the containing app has migrations.
This function should be called from app.tests init module and pass along package.
Source code in apis_core/generic/tests/__init__.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
test_generic
TestGeneric
Bases: object
Source code in apis_core/generic/tests/test_generic.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
test_admin_person_views(setup, route, permission, status_code, admin_client)
Admin user should be able to access the person list
Source code in apis_core/generic/tests/test_generic.py
70 71 72 73 74 75 76 |
|
test_anon_person_views(setup, route, permission, status_code, client)
Anon user should not be able to access the person views
Source code in apis_core/generic/tests/test_generic.py
64 65 66 67 68 |
|
test_dummy_table_export_filename(rf, admin_user)
Check if the dummy table provides the correct export filename
Source code in apis_core/generic/tests/test_generic.py
184 185 186 187 |
|
test_person_autocomplete(setup, admin_client)
Check if we find a person using autocomplete
Source code in apis_core/generic/tests/test_generic.py
166 167 168 169 170 171 172 173 174 175 176 177 |
|
test_person_count(setup)
Check if the correct number of persons was created
Source code in apis_core/generic/tests/test_generic.py
58 59 60 |
|
test_person_create(setup, admin_client)
Check if we can create a person using the create route
Source code in apis_core/generic/tests/test_generic.py
112 113 114 115 116 117 118 119 120 121 122 |
|
test_person_delete(setup, admin_client)
Check if we can delete a person using the delete route
Source code in apis_core/generic/tests/test_generic.py
124 125 126 127 128 129 130 |
|
test_person_delete_confirmation(setup, admin_client)
Check if we can delete a person using the delete route
Source code in apis_core/generic/tests/test_generic.py
132 133 134 135 136 137 138 139 140 141 |
|
test_person_delete_redirect(setup, admin_client)
Check if we can delete a person using the delete route
Source code in apis_core/generic/tests/test_generic.py
143 144 145 146 147 148 149 150 |
|
test_person_detail(setup, admin_client)
Check if the details page of a person lists its details
Source code in apis_core/generic/tests/test_generic.py
105 106 107 108 109 110 |
|
test_person_list(setup, admin_client)
Check if the first_name of some person object is listed in the person list
Source code in apis_core/generic/tests/test_generic.py
99 100 101 102 103 |
|
test_person_table_export_filename(rf, admin_user)
Check if the person table provides the correct export filename
Source code in apis_core/generic/tests/test_generic.py
179 180 181 182 |
|
test_person_update(setup, admin_client)
Check if we can update a person
Source code in apis_core/generic/tests/test_generic.py
152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
test_person_user_views(setup, route, permission, status_code, client)
Normal user should not be able to access the person list
Source code in apis_core/generic/tests/test_generic.py
78 79 80 81 82 83 |
|
test_person_user_with_access(setup, route, permission, status_code, client)
Normal user should be able to access the person views after bein granted permission
Source code in apis_core/generic/tests/test_generic.py
85 86 87 88 89 90 91 92 93 94 95 |
|
urls
ContenttypeConverter
A converter that converts from a string representation of a
model (app_label.model
) to the actual Django model class.
Source code in apis_core/generic/urls.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
views
Autocomplete
Bases: GenericModelMixin
, PermissionRequiredMixin
, Select2QuerySetView
Autocomplete view for a generic model.
Access requires the <model>_view
permission.
The queryset is overridden by the first match from
the first_member_match
helper.
Source code in apis_core/generic/views.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
create_object(value)
We try multiple approaches to create a model instance from a value:
* we first test if the value is an URL and if so we expect it to be
something that can be imported using one of the configured importers
and so we pass the value to the import logic.
* if the value is not a string, we try to pass it to the create_from_string
method of the model, if that does exist. Its the models responsibility to
implement this method and the method should somehow know how to create
model instance from the value...
* finally we pass the value to the create_object
method from the DAL
view, which tries to pass it to get_or_create
which likely also fails,
but this is expected and we raise a more useful exception.
Source code in apis_core/generic/views.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
Create
Bases: GenericModelMixin
, PermissionRequiredMixin
, SuccessMessageMixin
, CreateView
Create view for a generic model.
Access requires the <model>_add
permission.
The form class is overridden by the first match from
the first_member_match
helper.
Source code in apis_core/generic/views.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
Delete
Bases: GenericModelMixin
, PermissionRequiredMixin
, DeleteView
Delete view for a generic model.
Access requires the <model>_delete
permission.
Source code in apis_core/generic/views.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
Detail
Bases: GenericModelMixin
, PermissionRequiredMixin
, DetailView
Detail view for a generic model.
Access requires the <model>_view
permission.
Source code in apis_core/generic/views.py
240 241 242 243 244 245 246 |
|
Enrich
Bases: GenericModelMixin
, PermissionRequiredMixin
, FormView
Enrich an entity with data from an external source If so, it uses the proper Importer to get the data from the Uri and provides the user with a form to select the fields that should be updated.
Source code in apis_core/generic/views.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
|
form_valid(form)
Go through all the form fields and extract the ones that
start with update_
and that are set (those are the checkboxes that
select which fields to update).
Then use the importers import_into_instance
method to set those
fields values on the model instance.
Source code in apis_core/generic/views.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
GenericModelMixin
A mixin providing the common functionality for all the views working
with generic
models - that is models that are accessed via the
contenttype framework (using app_label.model
).
It sets the .model
of the view and generates a list of possible template
names (based on the MRO of the model).
If the view has a permission_action_required
attribute, this is used
to set the permission required to access the view for this specific model.
Source code in apis_core/generic/views.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
List
Bases: GenericModelMixin
, PermissionRequiredMixin
, ExportMixin
, SingleTableMixin
, FilterView
List view for a generic model.
Access requires the <model>_view
permission.
It is based on django-filters FilterView and django-tables SingleTableMixin.
The table class is overridden by the first match from
the first_member_match
helper.
The filterset class is overridden by the first match from
the first_member_match
helper.
The queryset is overridden by the first match from
the first_member_match
helper.
Source code in apis_core/generic/views.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_filterset(filterset_class)
We override the get_filterset
method, so we can inject a
columns
selector into the form
Source code in apis_core/generic/views.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
get_table_pagination(table)
Override get_table_pagination
from the tables2 TableMixinBase,
so we can set the paginate_by and the table_pagination value as attribute of the table.
Source code in apis_core/generic/views.py
230 231 232 233 234 235 236 237 |
|
MergeWith
Bases: GenericModelMixin
, PermissionRequiredMixin
, FormView
Generic merge view.
Source code in apis_core/generic/views.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
get_context_data(**kwargs)
The context consists of the two objects that are merged as well as a list of changes. Those changes are presented in the view as a table with diffs
Source code in apis_core/generic/views.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
SelectMergeOrEnrich
Bases: GenericModelMixin
, PermissionRequiredMixin
, FormView
This view provides a simple form that allows to select other entities (also from external sources, if set up) and on form submit redirects to the Enrich view.
Source code in apis_core/generic/views.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
Update
Bases: GenericModelMixin
, PermissionRequiredMixin
, SuccessMessageMixin
, UpdateView
Update view for a generic model.
Access requires the <model>_change
permission.
The form class is overridden by the first match from
the first_member_match
helper.
Source code in apis_core/generic/views.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
history
models
APISHistoricalRecords
Bases: HistoricalRecords
, GenericModel
Source code in apis_core/history/models.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_prev_record()
Get the previous history record for the instance. None
if first.
Source code in apis_core/history/models.py
34 35 36 37 38 39 40 41 42 43 |
|
APISHistoryTableBase
Bases: Model
, GenericModel
Source code in apis_core/history/models.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
tables
DescriptionColumnHistory
Bases: CustomTemplateColumn
A column showing a model description
Source code in apis_core/history/tables.py
7 8 9 10 11 12 13 |
|
OriginalIDColumn
Bases: CustomTemplateColumn
A column showing the original id of a model instance
Source code in apis_core/history/tables.py
16 17 18 19 20 21 22 23 |
|
ResetColumn
Bases: ActionColumn
A column showing a reset button
Source code in apis_core/history/tables.py
26 27 28 29 30 31 32 |
|
tests
test_simple_history
SimpleHistoryTestCase
Bases: TestCase
Test of the simple_history package using the demo project
Source code in apis_core/history/tests/test_simple_history.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
test_history()
Tests the simple version of attributes changed on a models instance.
Source code in apis_core/history/tests/test_simple_history.py
21 22 23 24 25 26 27 28 29 30 |
|
test_history_date()
Test that history is set correctly when not manually set.
Source code in apis_core/history/tests/test_simple_history.py
64 65 66 67 68 69 |
|
test_history_delete_entry()
Tests the deletion of an entry.
Source code in apis_core/history/tests/test_simple_history.py
32 33 34 35 36 |
|
test_history_merge()
Tests the merge function of the Place model. This is still expected to fail.
Source code in apis_core/history/tests/test_simple_history.py
38 39 40 41 42 43 44 45 |
|
test_m2m_save()
Test if m2m profession is saved correctly.
Source code in apis_core/history/tests/test_simple_history.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
relations
filtersets
EntityFilter
Bases: CharFilter
Custom CharFilter that uses the generate_search_filter helper to search in all instances inheriting from RootObject and then uses those results to only list relations that point to one of the results.
Source code in apis_core/relations/filtersets.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
RelationFilterSet
Bases: GenericFilterSet
Override the GenericFilterSet that is created for the Relation model. It does not really make sense to filter for content type id and object id, so we exclude those. Instead, we add a multiple choice filter for object and subject class, that only lists those choices that actually exists (meaning the classes that are actually set as subj or obj in some relation). Additionaly, we add a search filter, that searches in instances connected to relations (this does only work for instances inheriting from RootObject).
Source code in apis_core/relations/filtersets.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
SubjObjClassFilter
Bases: MultipleChoiceFilter
Custom MultipleChoiceFilter * it lists model classes as choices, that are in some way connected to a relation, either as subj or as obj * it filters relations by the content types of the connected subjects and objects
Source code in apis_core/relations/filtersets.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
forms
RelationFilterSetForm
Bases: GenericFilterSetForm
FilterSet form for relations based on GenericFilterSetForm.
Excludes relation_ptr
from the columns selector
Source code in apis_core/relations/forms/__init__.py
132 133 134 135 136 137 138 |
|
RelationForm
Bases: GenericModelForm
This form overrides generic form for relation editing.
Relations have generic relations to subj and obj, but we
hide those ForeignKey form fields and instead show
autocomplete choices fields.
In addition, one can pass a hx_post_route argument to the
form to make the form set the hx-post
attribute to the
given value.
We also pass a reverse
boolean, wich gets passed on
to the htmx POST endpoint using url parameters (the endpoint
can then select the success_url based on the reverse
state).
Source code in apis_core/relations/forms/__init__.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
relation_name
property
A helper method to access the correct name of the relation
__init__(*args, **kwargs)
Initialize the form and replace subj_object_id
and
obj_object_id
fields with a autocomplete widget.
Source code in apis_core/relations/forms/__init__.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
clean()
subj_object_id and obj_object_id can either come from initial values or from the autocomplete. In the former case, the values are simply the primary keys, which is what we want. In the latter case, the values are object instances and we want to set them to the primary keys instead.
Source code in apis_core/relations/forms/__init__.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
utils
get_all_relation_subj_and_obj()
cached
Return the model classes of any model that is in some way connected to a relation - either as obj or as subj
Returns: list[ContentType]: A list of unique ContentTypes for related models.
Source code in apis_core/relations/utils.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
relation_match_target(relation, target)
test if a relation points to a target
this function should not be cached, because the forward
attribute
is an annotation that does not seem to be part of the relation, so
if cached, method could be called with another forward
value and
return the wrong result
Source code in apis_core/relations/utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
urls
Main entry point for APIS routes
utils
authentication
TokenAuthSupportQueryString
Bases: TokenAuthentication
Extend the TokenAuthentication class to support querystring authentication
in the form of "http://www.example.com/?auth_token=
Source code in apis_core/utils/authentication.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
autocomplete
ExternalAutocomplete
This is a helper base class for implementing external
autocomplete classes. get_results(self, q)
method that
returns a list of results usable by the autocomplete view.
This base class implements this get_results
method in a
way that you can inherit from it and just define a list of
adapters
. Those adapters are then used one by one to
add external autocomplete search results.
Source code in apis_core/utils/autocomplete.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
ExternalAutocompleteAdapter
Base class for ExternalAutocompleteAdapters. It provides
the methods used for templating the autocomplete results.
You can pass a template
name to initialization, which
is then used to style the results.
Source code in apis_core/utils/autocomplete.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
LobidAutocompleteAdapter
Bases: ExternalAutocompleteAdapter
This autocomplete adapters queries the lobid autocomplete apis.
See https://lobid.org/gnd/api for details
You can pass a lobid_params
dict which will then be use as GET
request parameters.
Source code in apis_core/utils/autocomplete.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
TypeSenseAutocompleteAdapter
Bases: ExternalAutocompleteAdapter
This autocomplete adapters queries typesense collections on a
typesense server. The collections
variable can either be a
string or a list - if its a string, that collection is queried
directly, if its a list, the adapter uses typesense multi_search
endpoint.
Source code in apis_core/utils/autocomplete.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
fields
NewlineSeparatedListField
Bases: TextField
This field is basically a textfield with a custom widget. It uses the NewlineSeparatedListWidget to provide a simply way for users to enter multiple values without having to think about the separator.
Source code in apis_core/utils/fields.py
6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
helpers
construct_lookup(value)
Helper method to parse input values and construct field lookups (https://docs.djangoproject.com/en/4.2/ref/models/querysets/#field-lookups) Parses user input for wildcards and returns a tuple containing the interpreted django lookup string and the trimmed value E.g.
example
->('__icontains', 'example')
*example*
->('__icontains', 'example')
*example
->('__iendswith', 'example')
example*
->('__istartswith', 'example')
"example"
->('__iexact', 'example')
:param str value: text to be parsed for *
:return: a tuple containing the lookup type and the value without modifiers
Source code in apis_core/utils/helpers.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
datadump_get_queryset(additional_app_labels=[])
This method is loosely based on the dumpdata
admin command.
It iterates throug the relevant app models and exports them using
a serializer and natural foreign keys.
Data exported this way can be reimported into a newly created Django APIS app
Source code in apis_core/utils/helpers.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
get_html_diff(a, b, show_a=True, show_b=True, shorten=0)
Create an colorized html represenation of the difference of two values a and b
If show_a
is True, colorize deletions in a
If show_b
is True, colorize insertions in b
The value of shorten
defines if long parts of strings that contains no change should be shortened
Source code in apis_core/utils/helpers.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
rdf
build_sparql_query(curie)
Build a SPARQL query with language preferences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curie
|
str
|
predicate to filter on as defined in the toml. needs to include the predicate and optionally a lang tag to filter for separated with a comma. Eg "wdt:P122,en". |
required |
Returns:
Type | Description |
---|---|
str
|
A SPARQL query string |
Source code in apis_core/utils/rdf.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
find_graph_matching_config(graph, configs=[])
Go through al list of RDF import configs and return the ones that have filters defined that match the given graph.
Source code in apis_core/utils/rdf.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
find_regex_matching_configs(uri, models=None)
Go through a list of models and return all the rdf configs that are configured in those models that have a regex that matches the given URI.
Source code in apis_core/utils/rdf.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
load_path(path)
Load a tomlfile either from a path or from the directory
triple_configs
in any of the app directories.
Source code in apis_core/utils/rdf.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
resolve(obj, graph)
Look at the value of object and return the parsed value. If the value starts and ens with angle brackets, we interpret it as and transform it to an URI. If the value is simple text we interpret it as an curie and we expand it using the graphs namespace manager. Otherwise we simply return the value
Source code in apis_core/utils/rdf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
settings
get_entity_settings_by_modelname(entity=None)
return the settings for a specific entity or the dict for all entities if no entity is given
Source code in apis_core/utils/settings.py
14 15 16 17 18 19 20 21 22 23 |
|