launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04279
[Merge] lp:~wallyworld/launchpad/vocab-meta into lp:launchpad
Ian Booth has proposed merging lp:~wallyworld/launchpad/vocab-meta into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/vocab-meta/+merge/67960
This branch is 1 of 3. Once reviewed, I will be landing the 3rd branch only.
The end goal is to dynamically update the "Remove" link text on the person picker to say "Remove team" is the current field value is a team and "Remove person" if the current field value is a person. The text can be specified in the picker config if required, as is the case for the bug assignee picker.
== Implementation ==
This branch adds an extra "meta" attribute to the picker entry values produced by HugeVocabularyJSONView(). The meta property is option. For person vocabs, the PersonPickerEntryAdapter will provide meta="person" for people and meta="team" for teams. The meta attribute will ultimately be used by the javascript to determine what text to use for the remove link. The meta value concept is generic and can be extended to include other bespoke data later if required.
== Tests ==
Update vocabulary-json.txt
== Lint ==
Checking for conflicts and issues in changed files.
Linting changed files:
lib/canonical/launchpad/doc/vocabulary-json.txt
lib/lp/app/browser/vocabulary.py
./lib/canonical/launchpad/doc/vocabulary-json.txt
1: narrative uses a moin header.
213: want exceeds 78 characters.
--
https://code.launchpad.net/~wallyworld/launchpad/vocab-meta/+merge/67960
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/vocab-meta into lp:launchpad.
=== modified file 'lib/canonical/launchpad/doc/vocabulary-json.txt'
--- lib/canonical/launchpad/doc/vocabulary-json.txt 2011-06-21 06:56:33 +0000
+++ lib/canonical/launchpad/doc/vocabulary-json.txt 2011-07-14 12:56:36 +0000
@@ -61,6 +61,7 @@
"api_uri": "/~guadamen",
"css": "sprite team",
"link_css": "js-action",
+ "meta": "team",
"title": "GuadaMen",
"value": "guadamen"
}
@@ -92,6 +93,7 @@
"api_uri": "/~commercial-admins",
"css": "sprite team",
"link_css": "js-action",
+ "meta": "team",
"title": "Commercial Subscription Admins",
"value": "commercial-admins"
}
@@ -112,6 +114,7 @@
"api_uri": "/~launchpad-buildd-admins",
"css": "sprite team",
"link_css": "js-action",
+ "meta": "team",
"title": "Launchpad Buildd Admins",
"value": "launchpad-buildd-admins"
}
@@ -144,6 +147,7 @@
"css": "sprite person",
"description": "<email address hidden>",
"link_css": "js-action",
+ "meta": "person",
"title": "Sample Person",
"value": "name12"
}
@@ -185,6 +189,7 @@
"css": "sprite person",
"description": "<email address hidden>",
"link_css": "js-action",
+ "meta": "person",
"title": "Sample Person",
"value": "name12"
}
@@ -207,6 +212,7 @@
"css": "sprite person",
"description": "<email address hidden> (mark on irc.freenode.net)",
"link_css": "js-action",
+ "meta": "person",
"title": "Mark Shuttleworth",
"value": "mark"
}
=== modified file 'lib/lp/app/browser/vocabulary.py'
--- lib/lp/app/browser/vocabulary.py 2011-06-29 14:38:05 +0000
+++ lib/lp/app/browser/vocabulary.py 2011-07-14 12:56:36 +0000
@@ -8,6 +8,7 @@
__all__ = [
'HugeVocabularyJSONView',
'IPickerEntry',
+ 'get_person_picker_entry_meta',
]
import simplejson
@@ -63,6 +64,7 @@
alt_title_link = Attribute('URL used for anchor on alt title')
link_css = Attribute('CSS Class for links')
badges = Attribute('List of badge img attributes')
+ meta = Attribute('Meta info about the entry')
class PickerEntry:
@@ -71,7 +73,7 @@
def __init__(self, description=None, image=None, css=None, alt_title=None,
title_link=None, alt_title_link=None, link_css='js-action',
- badges=None, api_uri=None):
+ badges=None, meta=None):
self.description = description
self.image = image
self.css = css
@@ -80,6 +82,7 @@
self.alt_title_link = alt_title_link
self.link_css = link_css
self.badges = badges
+ self.meta = meta
@adapter(Interface)
@@ -108,6 +111,13 @@
return extra
+def get_person_picker_entry_meta(picker_entry):
+ """Return the picker entry meta for a given result value."""
+ if picker_entry and IPerson.providedBy(picker_entry):
+ return "team" if picker_entry.is_team else "person"
+ return None
+
+
@adapter(IPerson)
class PersonPickerEntryAdapter(DefaultPickerEntryAdapter):
"""Adapts IPerson to IPickerEntry."""
@@ -136,6 +146,7 @@
except Unauthorized:
extra.description = '<email address hidden>'
+ extra.meta = get_person_picker_entry_meta(person)
if enhanced_picker_enabled:
# We will display the person's name (launchpad id) after their
# displayname.
@@ -278,6 +289,8 @@
entry['link_css'] = picker_entry.link_css
if picker_entry.badges is not None:
entry['badges'] = picker_entry.badges
+ if picker_entry.meta is not None:
+ entry['meta'] = picker_entry.meta
result.append(entry)
self.request.response.setHeader('Content-type', 'application/json')