94
86
self.link_css = link_css
95
87
self.badges = badges
96
88
self.metadata = metadata
97
self.target_type = target_type
100
class IPickerEntrySource(Interface):
101
"""An adapter used to convert vocab terms to picker entries."""
103
def getPickerEntries(term_values, context_object, **kwarg):
104
"""Return picker entries for the specified term values.
106
:param term_values: a collection of vocab term values
107
:param context_object: the current context used to determine any
108
affiliation for the resulting picker entries. eg a picker used to
109
select a bug task assignee will have context_object set to the bug
114
91
@adapter(Interface)
115
class DefaultPickerEntrySourceAdapter(object):
116
"""Adapts Interface to IPickerEntrySource."""
92
class DefaultPickerEntryAdapter(object):
93
"""Adapts Interface to IPickerEntry."""
118
implements(IPickerEntrySource)
95
implements(IPickerEntry)
120
97
def __init__(self, context):
121
98
self.context = context
123
def getPickerEntries(self, term_values, context_object, **kwarg):
124
"""See `IPickerEntrySource`"""
126
for term_value in term_values:
127
extra = PickerEntry()
128
if hasattr(term_value, 'summary'):
129
extra.description = term_value.summary
130
display_api = ObjectImageDisplayAPI(term_value)
131
image_url = display_api.custom_icon_url() or None
132
css = display_api.sprite_css() or 'sprite bullet'
133
if image_url is not None:
134
extra.image = image_url
137
entries.append(extra)
100
def getPickerEntry(self, associated_object, **kwarg):
101
""" Construct a PickerEntry for the context of this adapter.
103
The associated_object represents the context for which the picker is
104
being rendered. eg a picker used to select a bug task assignee will
105
have associated_object set to the bug task.
107
extra = PickerEntry()
108
if hasattr(self.context, 'summary'):
109
extra.description = self.context.summary
110
display_api = ObjectImageDisplayAPI(self.context)
111
extra.css = display_api.sprite_css()
112
if extra.css is None:
113
extra.css = 'sprite bullet'
141
117
def get_person_picker_entry_metadata(picker_entry):
148
124
@adapter(IPerson)
149
class PersonPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
150
"""Adapts IPerson to IPickerEntrySource."""
152
def getPickerEntries(self, term_values, context_object, **kwarg):
153
"""See `IPickerEntrySource`"""
155
super(PersonPickerEntrySourceAdapter, self)
156
.getPickerEntries(term_values, context_object))
158
affiliated_context = IHasAffiliation(context_object, None)
159
if affiliated_context is not None:
160
# If a person is affiliated with the associated_object then we
125
class PersonPickerEntryAdapter(DefaultPickerEntryAdapter):
126
"""Adapts IPerson to IPickerEntry."""
128
def getPickerEntry(self, associated_object, **kwarg):
129
person = self.context
130
extra = super(PersonPickerEntryAdapter, self).getPickerEntry(
133
enhanced_picker_enabled = kwarg.get('enhanced_picker_enabled', False)
134
if enhanced_picker_enabled:
135
# If the person is affiliated with the associated_object then we
161
136
# can display a badge.
162
badges = affiliated_context.getAffiliationBadges(term_values)
163
for picker_entry, badges in izip(picker_entries, badges):
164
picker_entry.badges = []
165
for badge_info in badges:
166
picker_entry.badges.append(
167
dict(url=badge_info.url,
168
label=badge_info.label,
169
role=badge_info.role))
171
for person, picker_entry in izip(term_values, picker_entries):
172
picker_entry.details = []
174
if person.preferredemail is not None:
175
if person.hide_email_addresses:
176
picker_entry.description = '<email address hidden>'
179
picker_entry.description = person.preferredemail.email
181
picker_entry.description = '<email address hidden>'
183
picker_entry.metadata = get_person_picker_entry_metadata(person)
137
badge_info = IHasAffiliation(
138
associated_object).getAffiliationBadge(person)
141
dict(url=badge_info.url, alt=badge_info.alt_text)]
143
picker_expander_enabled = kwarg.get('picker_expander_enabled', False)
144
if picker_expander_enabled:
147
if person.preferredemail is not None:
148
if person.hide_email_addresses:
149
extra.description = '<email address hidden>'
152
extra.description = person.preferredemail.email
154
extra.description = '<email address hidden>'
156
extra.metadata = get_person_picker_entry_metadata(person)
157
if enhanced_picker_enabled:
184
158
# We will display the person's name (launchpad id) after their
186
picker_entry.alt_title = person.name
187
# We will linkify the person's name so it can be clicked to
188
# open the page for that person.
189
picker_entry.alt_title_link = canonical_url(
190
person, rootsite='mainsite')
160
extra.alt_title = person.name
161
# We will linkify the person's name so it can be clicked to open
162
# the page for that person.
163
extra.alt_title_link = canonical_url(person, rootsite='mainsite')
191
164
# We will display the person's irc nick(s) after their email
192
165
# address in the description text.
195
168
irc_nicks = ", ".join(
196
169
[IRCNicknameFormatterAPI(ircid).displayname()
197
170
for ircid in person.ircnicknames])
199
picker_entry.details.append(irc_nicks)
201
picker_entry.details.append(
202
'Team members: %s' % person.all_member_count)
204
picker_entry.details.append(
205
'Member since %s' % DateTimeFormatterAPI(
206
person.datecreated).date())
207
return picker_entries
171
if irc_nicks and not picker_expander_enabled:
172
if extra.description:
173
extra.description = ("%s (%s)" %
174
(extra.description, irc_nicks))
176
extra.description = "%s" % irc_nicks
177
if picker_expander_enabled:
179
extra.details.append(irc_nicks)
181
extra.details.append(
182
'Team members: %s' % person.all_member_count)
184
extra.details.append(
185
'Member since %s' % DateTimeFormatterAPI(
186
person.datecreated).date())
210
191
@adapter(IBranch)
211
class BranchPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
212
"""Adapts IBranch to IPickerEntrySource."""
214
def getPickerEntries(self, term_values, context_object, **kwarg):
215
"""See `IPickerEntrySource`"""
217
super(BranchPickerEntrySourceAdapter, self)
218
.getPickerEntries(term_values, context_object, **kwarg))
219
for branch, picker_entry in izip(term_values, entries):
220
picker_entry.description = branch.bzr_identity
224
class TargetPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
225
"""Adapt targets (Product, Package, Distribution) to PickerEntrySource."""
229
def getDescription(self, target):
230
"""Gets the description data for target picker entries."""
233
def getMaintainer(self, target):
234
"""Gets the maintainer information for the target picker entry."""
237
def getPickerEntries(self, term_values, context_object, **kwarg):
238
"""See `IPickerEntrySource`"""
240
super(TargetPickerEntrySourceAdapter, self)
241
.getPickerEntries(term_values, context_object, **kwarg))
242
for target, picker_entry in izip(term_values, entries):
243
picker_entry.description = self.getDescription(target)
244
picker_entry.details = []
245
summary = picker_entry.description
246
if len(summary) > 45:
247
index = summary.rfind(' ', 0, 45)
248
first_line = summary[0:index + 1]
249
second_line = summary[index:]
254
if len(second_line) > 90:
255
index = second_line.rfind(' ', 0, 90)
256
second_line = second_line[0:index + 1]
257
picker_entry.description = first_line
259
picker_entry.details.append(second_line)
260
picker_entry.alt_title = target.name
261
picker_entry.alt_title_link = canonical_url(
262
target, rootsite='mainsite')
263
picker_entry.target_type = self.target_type
264
maintainer = self.getMaintainer(target)
265
if maintainer is not None:
266
picker_entry.details.append(
267
'Maintainer: %s' % self.getMaintainer(target))
192
class BranchPickerEntryAdapter(DefaultPickerEntryAdapter):
193
"""Adapts IBranch to IPickerEntry."""
195
def getPickerEntry(self, associated_object, **kwarg):
196
branch = self.context
197
extra = super(BranchPickerEntryAdapter, self).getPickerEntry(
199
extra.description = branch.bzr_identity
271
203
@adapter(ISourcePackageName)
272
class SourcePackageNamePickerEntrySourceAdapter(
273
DefaultPickerEntrySourceAdapter):
274
"""Adapts ISourcePackageName to IPickerEntrySource."""
276
def getPickerEntries(self, term_values, context_object, **kwarg):
277
"""See `IPickerEntrySource`"""
279
super(SourcePackageNamePickerEntrySourceAdapter, self)
280
.getPickerEntries(term_values, context_object, **kwarg))
281
for sourcepackagename, picker_entry in izip(term_values, entries):
282
descriptions = getSourcePackageDescriptions([sourcepackagename])
283
picker_entry.description = descriptions.get(
284
sourcepackagename.name, "Not yet built")
288
@adapter(IDistributionSourcePackage)
289
class DistributionSourcePackagePickerEntrySourceAdapter(
290
TargetPickerEntrySourceAdapter):
291
"""Adapts IDistributionSourcePackage to IPickerEntrySource."""
293
target_type = "package"
295
def getMaintainer(self, target):
296
"""See `TargetPickerEntrySource`"""
299
def getDescription(self, target):
300
"""See `TargetPickerEntrySource`"""
301
if target.binary_names:
302
description = ', '.join(target.binary_names)
304
description = 'Not yet built.'
307
def getPickerEntries(self, term_values, context_object, **kwarg):
308
this = super(DistributionSourcePackagePickerEntrySourceAdapter, self)
309
entries = this.getPickerEntries(term_values, context_object, **kwarg)
310
for picker_entry in entries:
311
picker_entry.alt_title = None
315
@adapter(IProjectGroup)
316
class ProjectGroupPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
317
"""Adapts IProduct to IPickerEntrySource."""
319
target_type = "project group"
321
def getMaintainer(self, target):
322
"""See `TargetPickerEntrySource`"""
323
return target.owner.displayname
325
def getDescription(self, target):
326
"""See `TargetPickerEntrySource`"""
327
return target.summary
331
class ProductPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
332
"""Adapts IProduct to IPickerEntrySource."""
334
target_type = "project"
336
def getMaintainer(self, target):
337
"""See `TargetPickerEntrySource`"""
338
return target.owner.displayname
340
def getDescription(self, target):
341
"""See `TargetPickerEntrySource`"""
342
return target.summary
345
@adapter(IDistribution)
346
class DistributionPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
348
target_type = "distribution"
350
def getMaintainer(self, target):
351
"""See `TargetPickerEntrySource`"""
353
return target.currentseries.owner.displayname
354
except AttributeError:
357
def getDescription(self, target):
358
"""See `TargetPickerEntrySource`"""
359
return target.summary
204
class SourcePackageNamePickerEntryAdapter(DefaultPickerEntryAdapter):
205
"""Adapts ISourcePackageName to IPickerEntry."""
207
def getPickerEntry(self, associated_object, **kwarg):
208
sourcepackagename = self.context
210
SourcePackageNamePickerEntryAdapter, self).getPickerEntry(
212
descriptions = getSourcePackageDescriptions([sourcepackagename])
213
extra.description = descriptions.get(
214
sourcepackagename.name, "Not yet built")
362
218
@adapter(IArchive)
363
class ArchivePickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
364
"""Adapts IArchive to IPickerEntrySource."""
219
class ArchivePickerEntryAdapter(DefaultPickerEntryAdapter):
220
"""Adapts IArchive to IPickerEntry."""
366
def getPickerEntries(self, term_values, context_object, **kwarg):
367
"""See `IPickerEntrySource`"""
369
super(ArchivePickerEntrySourceAdapter, self)
370
.getPickerEntries(term_values, context_object, **kwarg))
371
for archive, picker_entry in izip(term_values, entries):
372
picker_entry.description = '%s/%s' % (
373
archive.owner.name, archive.name)
222
def getPickerEntry(self, associated_object, **kwarg):
223
archive = self.context
224
extra = super(ArchivePickerEntryAdapter, self).getPickerEntry(
226
extra.description = '%s/%s' % (archive.owner.name, archive.name)
377
230
class HugeVocabularyJSONView: