fairdm.contrib.contributors.plugins.shared#

The Contributors tab of a project, dataset, sample or measurement, and the pages it leads to.

Every page opens only when the record’s overview would, and a page that changes anything asks whether the viewer can manage the record on every request. The changes themselves are made by Crediting.

Module Contents#

Classes#

AffiliationChoice

The choice of which organization a person is credited from on one record.

NewPersonForm

A person typed in by hand: two names, and no email address.

NewOrganizationForm

An organization typed in by hand: a name, and optionally a city, a country and a website.

ContributionPage

What every page of the tab shares: the record, its kind and who may manage it.

ContributionAdd

Add a contributor: one already in the portal, one looked up in a registry, or a new one.

ContributionAddPerson

Add a person: from the portal, from ORCID, or entered by hand, with their affiliation.

ContributionAddOrganization

Add an organization: from the portal, from ROR, or entered by hand.

ContributionEdit

Set a contributor’s contribution roles and, for a person, their level.

ContributionRemove

Confirm, then remove a contributor and whatever they held through being listed.

ContributionMove

Move a contributor one place up or down among the people, or among the organizations.

ContributionList

List a record’s people and organizations, each in their own order, with the controls.

Functions#

level_choices

Return the three levels as the edit page draws them, marking those below floor.

API#

level_choices(record, floor=None)#

Return the three levels as the edit page draws them, marking those below floor.

class AffiliationChoice(*args, person=None, credit=None, suggested='', **kwargs)#

Bases: django.forms.Form

The choice of which organization a person is credited from on one record.

The person’s own affiliations are offered, the primary one selected to begin with. Any other organization can be named, and none can be chosen. The two fields keep the names the c-contribution.affiliation component draws.

Args: person: The person, when they are already in the portal. credit: The person’s contribution on the record, when it is being edited. suggested: An organization name to offer, such as an employer from ORCID.

Initialization

affiliation#

‘CharField(…)’

affiliation_name#

‘CharField(…)’

static held_by(person)#

List a person’s affiliations as options, the current primary first.

Args: person: The person, or None.

Returns: One {"value", "organization", "note"} dictionary per affiliation.

clean_affiliation()#

Accept one of the person’s affiliations, another organization, or none.

clean()#

Refuse another organization chosen without a name.

property problem#

The first message about what is wrong with the choice, or None.

organization()#

Return the organization chosen, making it when it is named and not in the portal.

Call it inside the transaction that saves the credit, so that an organization made for a save that is then refused is not kept.

Returns: The organization, or None when none was chosen.

choice()#

Shape the choice for the component that draws it.

Returns: The options, which one is selected, the name typed for another organization, and every organization name for the suggestions. What a refused form held is kept.

class NewPersonForm(*args, **kwargs)#

Bases: django.forms.Form

A person typed in by hand: two names, and no email address.

A person whose name a profile already has is offered those profiles first: same_name holds them, and the form is not valid until confirmed is sent.

Initialization

given#

‘CharField(…)’

family#

‘CharField(…)’

confirmed#

‘BooleanField(…)’

clean()#

Offer the profiles that share the name, unless the field errors come first.

name()#

Return the full name the two names make.

save()#

Make the person, with no account.

Returns: The saved person: active, not claimed, with an unusable password.

class NewOrganizationForm(*args, **kwargs)#

Bases: django.forms.Form

An organization typed in by hand: a name, and optionally a city, a country and a website.

An organization is never made when one of that name is in the portal: same_name holds the existing one and the form is not valid. The country is a name or a code from the country field’s own list.

Initialization

name#

‘CharField(…)’

city#

‘CharField(…)’

country#

‘CharField(…)’

website#

‘URLField(…)’

clean_country()#

Resolve a country name or code to the code the field stores.

clean()#

Offer the organization that already has the name, and make no second.

save()#

Make the organization.

Returns: The saved organization.

class ContributionPage(**kwargs)#

Bases: fairdm.contrib.plugins.Plugin, fairdm.views.FairDMTemplateView

What every page of the tab shares: the record, its kind and who may manage it.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

manager_only#

False

access()#

What people may do on this record.

property overview#

The overview plugin of the record’s kind, whose check decides who may open the record.

dispatch(request, *args, **kwargs)#

Answer as the overview does when the record is closed to the viewer, then refuse a page for changing contributors to anyone who may not manage the record.

property list_url#

The address of the record’s Contributors tab.

get_contribution()#

Return the contribution named in the address, on this record only.

describe(contribution, held=None)#

Work out everything the pages say about one contributor on this record.

Args: contribution: The contribution, with its real contributor already read when many are described together. held: What RecordAccess.levels_for gave for the contributor, when the levels of everyone listed were read in one query.

Returns: What the pages say about the contributor.

can_see_levels()#

Whether the viewer may be told what people may do: only someone who can manage.

credited_from()#

Map each organization on the record to the people credited here from it.

get_context_data(**kwargs)#

Add the record’s kind, the tab’s address and whether the viewer may manage.

class ContributionAdd(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionPage

Add a contributor: one already in the portal, one looked up in a registry, or a new one.

One page holds all three ways in as tabs that switch in the browser. via in the address or the form says which tab to open: portal, registry or new. The portal search reads q and the registry search reads rq, so each tab keeps its own search. A registry that cannot be reached leaves the other two ways working.

Attributes: is_person: Whether the page adds a person rather than an organization. registry_class: Orcid or Ror. form_class: The form behind the by-hand way. results_shown: The most matches the portal search lists.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

manager_only#

True

is_person#

True

registry_class#

None

form_class#

None

results_shown#

20

property via#

Which tab is open.

registry()#

The registry behind the page’s second tab.

search_portal(term)#

Find the people or organizations in the portal whose name matches.

Args: term: Part of a name.

Returns: The matches up to results_shown, and whether there are more.

choice_for(way, choice, **fresh)#

Shape the organization choice a tab draws.

Args: way: The tab, portal or new. choice: The bound AffiliationChoice of a refused request, or None. **fresh: Arguments for a new AffiliationChoice when the request was not refused on this tab.

Returns: What c-contribution.affiliation draws.

chosen_record(record, choice)#

Describe the registry record the manager has chosen, with the organization choice.

Args: record: The record fetched from the registry. choice: The bound AffiliationChoice of a refused request, or None.

Returns: What the chosen step of the registry tab draws.

search_registry(adding, record, choice)#

Fill in the registry tab: the chosen record, or the matches of the search.

A registry that cannot be reached leaves the tab with nothing and says so.

Args: adding: What the page draws, which this adds to. record: A record already fetched for a refused request, or None. choice: The bound AffiliationChoice of a refused request, or None.

get_context_data(**kwargs)#

Add which tab is open, each tab’s search and matches, and any chosen record.

Args: **kwargs: What a refused request hands back: form, choice, record, errors, values and registry_unavailable.

add(make, choice=None)#

Add the contributor last, at the view level, and go on to their edit page.

The contributor is made, the organization made and the credit written in one transaction, so a refusal leaves nothing behind.

Args: make: A function that returns the contributor, making them if they are new. choice: The valid AffiliationChoice of a person, or None.

refuse(**kwargs)#

Draw the page again with what was entered and what is wrong with it.

add_from_portal()#

Add a contributor who is already in the portal.

The page for people answers 404 for anything that is not a person, and the page for organizations for anything that is not an organization.

add_from_registry()#

Add the record the manager chose, fetched again by its identifier.

Nothing the form carries but the identifier is read. A registry that cannot be reached answers 200 with the tab saying so, and nothing is made.

add_by_hand()#

Make a contributor from the form, or draw the page again with what is wrong.

post(request, *args, **kwargs)#

Add someone from the portal, from a registry record, or from the form.

class ContributionAddPerson(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionAdd

Add a person: from the portal, from ORCID, or entered by hand, with their affiliation.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘add-person’

template_name#

‘contributors/plugins/contribution_add_person.html’

page_title#

‘gettext_lazy(…)’

class ContributionAddOrganization(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionAdd

Add an organization: from the portal, from ROR, or entered by hand.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘add-organization’

template_name#

‘contributors/plugins/contribution_add_organization.html’

page_title#

‘gettext_lazy(…)’

is_person#

False

registry_class#

None

form_class#

None

class ContributionEdit(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionPage

Set a contributor’s contribution roles and, for a person, their level.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘int:pk/edit’

manager_only#

True

template_name#

‘contributors/plugins/contribution_edit.html’

page_title#

‘gettext_lazy(…)’

get_context_data(**kwargs)#

Add the contributor, the roles on offer and the levels that may be chosen.

post(request, *args, **kwargs)#

Save the roles and the level together, or neither.

class ContributionRemove(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionPage

Confirm, then remove a contributor and whatever they held through being listed.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘int:pk/remove’

manager_only#

True

template_name#

‘contributors/plugins/contribution_remove.html’

page_title#

‘gettext_lazy(…)’

get_context_data(**kwargs)#

Add the contributor and whether removing them would leave nobody to manage.

post(request, *args, **kwargs)#

Remove the contributor unless the service refuses, and draw the page again if it does.

class ContributionMove(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionPage

Move a contributor one place up or down among the people, or among the organizations.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘int:pk/move’

manager_only#

True

http_method_names#

[‘post’]

post(request, *args, **kwargs)#

Move the contributor one place in the direction posted, then return to their row.

Returns: A redirect to the tab at the moved contributor, or a 400 when the direction is neither up nor down.

class ContributionList(**kwargs)#

Bases: fairdm.contrib.contributors.plugins.shared.ContributionPage

List a record’s people and organizations, each in their own order, with the controls.

Initialization

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

url_path#

‘contributors’

template_name#

‘contributors/plugins/contribution_list.html’

page_title#

‘gettext_lazy(…)’

extra_views#

None

get_page_subtitle()#

Name the record the contributors belong to.

get_context_data(**kwargs)#

Add the people, the organizations and, for a manager, access held from above.