fairdm.contrib.contributors.forms.profile#
The forms a person or an organization is edited with, and the field their lists are typed into.
Module Contents#
Classes#
A list of short entries typed one per line into a text area. |
|
What the person and organization editing forms share. |
|
The page where a person edits their own profile. |
|
The page where an organization’s owner or an administrator edits its profile. |
Functions#
List the ISO 639-1 languages by name in the active language. |
API#
- class LinesField(*, entry_validator=None, max_entries=50, **kwargs)#
Bases:
django.forms.CharFieldA list of short entries typed one per line into a text area.
The cleaned value is a list. Blank lines are dropped, surrounding spaces are trimmed and an entry typed twice is kept once, where it was first typed.
Args: entry_validator: Called with each entry. A
ValidationErrorit raises is reported for the first entry at fault, with the entry in the error’sparams. max_entries: The most entries the field accepts. **kwargs: Passed toCharField.Attributes: entry_validator: The per-entry validator, or None. max_entries: The most entries the field accepts.
Initialization
- default_error_messages#
None
- prepare_value(value)#
Show a list one entry per line.
- to_python(value)#
Split the text into a list of distinct, trimmed entries.
Args: value: The submitted text.
Returns: The entries in the order first typed, empty when nothing was typed.
- validate(value)#
Refuse an empty list when required, and the first entry the validator rejects.
Args: value: The cleaned list.
Raises: ValidationError: The field is required and empty, has too many entries, or an entry is not valid.
- language_choices()#
List the ISO 639-1 languages by name in the active language.
Returns:
(code, name)pairs sorted by name. A code Django has no name for is shown as written.
- class ProfileForm(*args, **kwargs)#
Bases:
fairdm.forms.ModelFormWhat the person and organization editing forms share.
The editing page supplies the
<form>tag and the buttons, so the crispy helper draws neither.sectionsgroups the fields under headings, andget_layoutdraws them. A stored record can fail the model’s validation on a field the form does not carry, such as a malformed identifier. Django refuses to attach that error to a missing field and raises, so it is reported on the form as a whole instead.Args: *args: Passed to
ModelForm. **kwargs: Passed toModelForm.Attributes: sections:
(heading, rows)pairs, in page order. A row is a field name, or a tuple of field names drawn side by side on a wide screen. A heading of None draws the rows with no fieldset and no heading, which is how a form’s first group is drawn: a heading at the very top of a form reads as a stray divider.Initialization
- sections: tuple#
()
- get_layout()#
Group the fields under the headings
sectionsnames.A field the form does not carry is left out, and a section left with no field is not drawn. A field no section names, as a portal’s subclass may add, follows the last section.
Returns: The crispy layout.
- get_section(heading, rows, placed)#
Build one section from the fields the form carries.
Args: heading: The section’s heading, or None to draw the rows on their own. rows: Field names, or tuples of names that share a row. placed: The names already drawn, added to as this section draws its own.
Returns: The layout objects to draw: one fieldset, the bare rows when there is no heading, or nothing when the form carries none of the section’s fields.
- class PersonProfileForm(*args, **kwargs)#
Bases:
fairdm.contrib.contributors.forms.profile.ProfileFormThe page where a person edits their own profile.
A portal adds or drops fields by subclassing this form and naming the subclass in
FAIRDM_PROFILE_FORMS.Args: *args: Passed to
ModelForm. **kwargs: Passed toModelForm.Attributes: image: The photo. Ticking the clear box removes it. first_name: The given name, as citations use it. last_name: The family name, as citations use it. name: The name the person is publicly known by. alternative_names: Other names, one per line. profile: The biography. links: Web addresses, one per line. lang: The languages the person works in.
Initialization
- image#
‘ImageField(…)’
- alternative_names#
‘LinesField(…)’
- links#
‘LinesField(…)’
- lang#
‘MultipleChoiceField(…)’
- class Meta#
- model#
None
- fields#
[‘image’, ‘first_name’, ‘last_name’, ‘name’, ‘alternative_names’, ‘profile’, ‘links’, ‘lang’]
- labels#
None
- help_texts#
None
- sections#
((None, [(‘first_name’, ‘last_name’), ‘name’, ‘alternative_names’]), ())
- clean_lang()#
Keep each language once, in the order chosen.
- class OrganizationProfileForm(*args, **kwargs)#
Bases:
fairdm.contrib.contributors.forms.profile.ProfileFormThe page where an organization’s owner or an administrator edits its profile.
The website and the other links are two fields over the one stored list of links, the website first. A portal adds or drops fields by subclassing this form and naming the subclass in
FAIRDM_PROFILE_FORMS.Args: *args: Passed to
ModelForm. **kwargs: Passed toModelForm.Attributes: image: The logo. Ticking the clear box removes it. name: The organization’s name. alternative_names: Other names, one per line. parent: The organization this one is part of. The organization itself and any organization beneath it are refused. location: The organization’s point in WGS 84, typed as a latitude and a longitude. website: The first stored link. Clearing it promotes the next link on reopening. links: The other web addresses, one per line.
Initialization
- image#
‘ImageField(…)’
- alternative_names#
‘LinesField(…)’
- parent#
‘OrganizationChoiceField(…)’
- location#
‘LocationField(…)’
- website#
‘CharField(…)’
- links#
‘LinesField(…)’
- class Meta#
- model#
None
- fields#
[‘image’, ‘name’, ‘alternative_names’, ‘type’, ‘parent’, ‘city’, ‘country’, ‘location’, ‘profile’, ‘…
- labels#
None
- help_texts#
None
- sections#
((None, [‘image’, ‘name’, ‘alternative_names’, (‘type’, ‘parent’)]), (), (), ())
- clean_location()#
Keep the point of the cleaned location, which the model field takes.
- clean()#
Store the website first among the links, and no link twice.