~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/browser/vocabulary.py

Merged db-devel into replication.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
51
51
from lp.registry.model.pillaraffiliation import IHasAffiliation
52
52
from lp.registry.model.sourcepackagename import getSourcePackageDescriptions
53
 
from lp.services.features import getFeatureFlag
54
53
from lp.soyuz.interfaces.archive import IArchive
55
54
 
56
55
# XXX: EdwinGrubbs 2009-07-27 bug=405476
156
155
            super(PersonPickerEntrySourceAdapter, self)
157
156
                .getPickerEntries(term_values, context_object))
158
157
 
159
 
        personpicker_affiliation_enabled = kwarg.get(
160
 
                                    'personpicker_affiliation_enabled', False)
161
158
        affiliated_context = IHasAffiliation(context_object, None)
162
 
        if (affiliated_context is not None
163
 
            and personpicker_affiliation_enabled):
 
159
        if affiliated_context is not None:
164
160
            # If a person is affiliated with the associated_object then we
165
161
            # can display a badge.
166
162
            badges = affiliated_context.getAffiliationBadges(term_values)
172
168
                             label=badge_info.label,
173
169
                             role=badge_info.role))
174
170
 
175
 
        picker_expander_enabled = kwarg.get('picker_expander_enabled', False)
176
171
        for person, picker_entry in izip(term_values, picker_entries):
177
 
            if picker_expander_enabled:
178
 
                picker_entry.details = []
 
172
            picker_entry.details = []
179
173
 
180
174
            if person.preferredemail is not None:
181
175
                if person.hide_email_addresses:
187
181
                        picker_entry.description = '<email address hidden>'
188
182
 
189
183
            picker_entry.metadata = get_person_picker_entry_metadata(person)
190
 
            enhanced_picker_enabled = kwarg.get(
191
 
                                            'enhanced_picker_enabled', False)
192
 
            if enhanced_picker_enabled:
193
 
                # We will display the person's name (launchpad id) after their
194
 
                # displayname.
195
 
                picker_entry.alt_title = person.name
196
 
                # We will linkify the person's name so it can be clicked to
197
 
                # open the page for that person.
198
 
                picker_entry.alt_title_link = canonical_url(
199
 
                                                person, rootsite='mainsite')
200
 
                # We will display the person's irc nick(s) after their email
201
 
                # address in the description text.
202
 
                irc_nicks = None
203
 
                if person.ircnicknames:
204
 
                    irc_nicks = ", ".join(
205
 
                        [IRCNicknameFormatterAPI(ircid).displayname()
206
 
                        for ircid in person.ircnicknames])
207
 
                if irc_nicks and not picker_expander_enabled:
208
 
                    if picker_entry.description:
209
 
                        picker_entry.description = ("%s (%s)" %
210
 
                            (picker_entry.description, irc_nicks))
211
 
                    else:
212
 
                        picker_entry.description = "%s" % irc_nicks
213
 
                if picker_expander_enabled:
214
 
                    if irc_nicks:
215
 
                        picker_entry.details.append(irc_nicks)
216
 
                    if person.is_team:
217
 
                        picker_entry.details.append(
218
 
                            'Team members: %s' % person.all_member_count)
219
 
                    else:
220
 
                        picker_entry.details.append(
221
 
                            'Member since %s' % DateTimeFormatterAPI(
222
 
                                person.datecreated).date())
 
184
            # We will display the person's name (launchpad id) after their
 
185
            # displayname.
 
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')
 
191
            # We will display the person's irc nick(s) after their email
 
192
            # address in the description text.
 
193
            irc_nicks = None
 
194
            if person.ircnicknames:
 
195
                irc_nicks = ", ".join(
 
196
                    [IRCNicknameFormatterAPI(ircid).displayname()
 
197
                    for ircid in person.ircnicknames])
 
198
            if irc_nicks:
 
199
                picker_entry.details.append(irc_nicks)
 
200
            if person.is_team:
 
201
                picker_entry.details.append(
 
202
                    'Team members: %s' % person.all_member_count)
 
203
            else:
 
204
                picker_entry.details.append(
 
205
                    'Member since %s' % DateTimeFormatterAPI(
 
206
                        person.datecreated).date())
223
207
        return picker_entries
224
208
 
225
209
 
257
241
                .getPickerEntries(term_values, context_object, **kwarg))
258
242
        for target, picker_entry in izip(term_values, entries):
259
243
            picker_entry.description = self.getDescription(target)
260
 
            enhanced = bool(getFeatureFlag(
261
 
                'disclosure.target_picker_enhancements.enabled'))
262
 
            if enhanced:
263
 
                picker_entry.details = []
264
 
                summary = picker_entry.description
265
 
                if len(summary) > 45:
266
 
                    index = summary.rfind(' ', 0, 45)
267
 
                    first_line = summary[0:index + 1]
268
 
                    second_line = summary[index:]
269
 
                else:
270
 
                    first_line = summary
271
 
                    second_line = ''
 
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:]
 
250
            else:
 
251
                first_line = summary
 
252
                second_line = ''
272
253
 
273
 
                if len(second_line) > 90:
274
 
                    index = second_line.rfind(' ', 0, 90)
275
 
                    second_line = second_line[0:index + 1]
276
 
                picker_entry.description = first_line
277
 
                if second_line:
278
 
                    picker_entry.details.append(second_line)
279
 
                picker_entry.alt_title = target.name
280
 
                picker_entry.alt_title_link = canonical_url(
281
 
                    target, rootsite='mainsite')
282
 
                picker_entry.target_type = self.target_type
283
 
                maintainer = self.getMaintainer(target)
284
 
                if maintainer is not None:
285
 
                    picker_entry.details.append(
286
 
                        'Maintainer: %s' % self.getMaintainer(target))
 
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
 
258
            if second_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))
287
268
        return entries
288
269
 
289
270
 
404
385
    def __init__(self, context, request):
405
386
        self.context = context
406
387
        self.request = request
407
 
        self.enhanced_picker_enabled = bool(
408
 
            getFeatureFlag('disclosure.picker_enhancements.enabled'))
409
 
        self.picker_expander_enabled = bool(
410
 
            getFeatureFlag('disclosure.picker_expander.enabled'))
411
 
        self.personpicker_affiliation_enabled = bool(
412
 
            getFeatureFlag('disclosure.personpicker_affiliation.enabled'))
413
388
 
414
389
    def __call__(self):
415
390
        name = self.request.form.get('name')
466
441
        for adapter_class, term_values in picker_entry_terms.items():
467
442
            picker_entries = adapter_cache[adapter_class].getPickerEntries(
468
443
                term_values,
469
 
                self.context,
470
 
                enhanced_picker_enabled=self.enhanced_picker_enabled,
471
 
                picker_expander_enabled=self.picker_expander_enabled,
472
 
                personpicker_affiliation_enabled=(
473
 
                    self.personpicker_affiliation_enabled))
 
444
                self.context)
474
445
            for term_value, picker_entry in izip(term_values, picker_entries):
475
446
                picker_term_entries[term_value] = picker_entry
476
447