fairdm.core.forms#

Base form, the manager-only fields mixin, the keyword form and the concept drop-down shared by the core forms.

Module Contents#

Classes#

ManagerOnlyFieldsMixin

Leave the fields that decide who gets into a record out of its form, for anyone who cannot manage it.

BaseForm

Model form that accepts the request and drops declared fields missing from Meta.fields.

KeywordForm

Edit a record’s free keywords: words a person types, with no vocabulary behind them.

CollectionOrderIterator

Yield a concept field’s choices in the order of the collection it is limited to.

ConceptSelectField

A concept field drawn as a drop-down of the concepts it offers.

API#

class ManagerOnlyFieldsMixin#

Leave the fields that decide who gets into a record out of its form, for anyone who cannot manage it.

Visibility and the record a record sits under (a project’s owner, a dataset’s project, a sample’s or measurement’s dataset) change who holds rights over it, so only someone who can manage it is offered them. A form for a new record leaves nothing out.

Attributes: manager_only_fields: The names of the fields to leave out.

manager_only_fields: tuple[str, ...]#

()

withhold_manager_only_fields(request)#

Remove the manager-only fields unless the request’s user can manage the record.

Args: request: The current request, or None, which counts as someone who cannot manage it.

class BaseForm(*args, **kwargs)#

Bases: django.forms.ModelForm

Model form that accepts the request and drops declared fields missing from Meta.fields.

Args: *args: Positional arguments passed to ModelForm. **kwargs: Keyword arguments passed to ModelForm. request is removed first and sets self.request and self.user.

Initialization

class KeywordForm(*args, **kwargs)#

Bases: django.forms.ModelForm

Edit a record’s free keywords: words a person types, with no vocabulary behind them.

Keywords chosen from a controlled vocabulary are not offered here and are left as they are when the form is saved.

Args: *args: Passed to ModelForm. **kwargs: Passed to ModelForm. The model is taken from instance when given.

Initialization

class Meta#
fields: ClassVar[list[str]]#

[]

save(commit=True)#

Save the free keywords, leaving the record’s vocabulary keywords alone.

class CollectionOrderIterator(field)#

Bases: django.forms.models.ModelChoiceIterator

Yield a concept field’s choices in the order of the collection it is limited to.

A field with no collection lists its concepts by name.

Initialization

class ConceptSelectField(*args, model_field=None, **kwargs)#

Bases: controlled_vocabularies.forms.DeclinesAdminRelatedWrapperMixin, django.forms.ModelChoiceField

A concept field drawn as a drop-down of the concepts it offers.

For a short, closed list such as the description, date and identifier types, in place of the search box a concept field renders by default. Pass it as the form_class of a ConceptField’s form field. Each concept is shown by its name in the reading language.

Args: *args: Passed to ModelChoiceField. model_field: The ConceptField the form field was built from. **kwargs: Passed to ModelChoiceField.

Initialization

iterator#

None

label_from_instance(obj)#

Return the concept’s name in the reading language.