Bases: DomainObject
An agent (e.g. a researcher or institution) that contributes to a package.
Source code in ckanext/attribution/model/agent.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 | class Agent(DomainObject):
"""
An agent (e.g. a researcher or institution) that contributes to a package.
"""
@property
def display_name(self):
if self.agent_type == 'person':
return ' '.join(
[self.given_names, self.family_name]
if self.given_names_first
else [self.family_name, self.given_names]
)
elif self.agent_type == 'org':
name = self.name
if self.location is not None:
name += ' ({0})'.format(self.location)
return name
else:
return self.name
@property
def standardised_name(self):
"""
Name in a standardised format.
:returns: full name (family name first) for person names, just name for other
"""
if self.agent_type == 'person':
return ', '.join([self.family_name, self.given_names])
else:
return self.name
@property
def citation_name(self):
return self.display_name if self.agent_type == 'person' else self.name
@property
def external_id_url(self):
if self.external_id is None:
return
external_scheme_dict = toolkit.get_action('attribution_controlled_lists')(
{}, {'lists': ['agent_external_id_schemes']}
)['agent_external_id_schemes']
return external_scheme_dict[self.external_id_scheme]['url'].format(
self.external_id
)
@property
def affiliations(self):
return [
{'agent': a.other_agent(self.id), 'affiliation': a}
for a in self._affiliations
]
def package_affiliations(self, pkg_id):
return [
a
for a in self.affiliations
if a['affiliation'].package_id is None
or a['affiliation'].package_id == pkg_id
]
def package_order(self, pkg_id):
try:
citation = next(
c
for c in self.contribution_activities
if c.package
and (c.package.id == pkg_id or c.package.name == pkg_id)
and c.activity == '[citation]'
)
except StopIteration:
return -1
return citation.order
@property
def sort_name(self):
return self.family_name if self.agent_type == 'person' else self.name
def as_dict(self):
agent_dict = super(Agent, self).as_dict()
agent_dict['display_name'] = self.display_name
agent_dict['standardised_name'] = self.standardised_name
agent_dict['external_id_url'] = self.external_id_url
return agent_dict
|
standardised_name
property
Name in a standardised format.
Returns:
| Type |
Description |
|
|
full name (family name first) for person names, just name for other
|