changeset 2613:f0cc5ebc5192

Now summary is also shown along with itemid initials in dropdown lists of tickets
author Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
date Fri, 30 May 2014 11:46:19 +0530
parents 36e0756c78a6
children 9d04f5a42445
files MoinMoin/forms.py MoinMoin/items/ticket.py
diffstat 2 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/forms.py	Tue May 27 22:22:55 2014 +0530
+++ b/MoinMoin/forms.py	Fri May 30 11:46:19 2014 +0530
@@ -351,15 +351,8 @@
     @classmethod
     def _get_choice_specs(cls):
         revs = flaskg.storage.search(cls._query, **cls._query_args)
-        key = cls.properties['label_meta_key']
-
-        def get_label(rev):
-            label = rev.meta[key]
-            if isinstance(label, list):
-                label = label[0]
-            return label
-        
-        choices = [(rev.meta[ITEMID], get_label(rev)) for rev in revs]
+        label_getter = cls.properties['label_getter']
+        choices = [(rev.meta[ITEMID], label_getter(rev)) for rev in revs]
         if cls.optional:
             choices.append((u'', cls.properties['empty_label']))
         return choices
--- a/MoinMoin/items/ticket.py	Tue May 27 22:22:55 2014 +0530
+++ b/MoinMoin/items/ticket.py	Fri May 30 11:46:19 2014 +0530
@@ -23,7 +23,7 @@
                             Reference, BackReference, SelectSubmit)
 from MoinMoin.storage.middleware.protecting import AccessDenied
 from MoinMoin.constants.keys import (ITEMTYPE, CONTENTTYPE, ITEMID, CURRENT,
-                                     SUPERSEDED_BY, SUBSCRIPTIONS, DEPENDS_ON, NAME)
+                                     SUPERSEDED_BY, SUBSCRIPTIONS, DEPENDS_ON, NAME,  SUMMARY)
 from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
 from MoinMoin.items import Item, Contentful, register, BaseModifyForm
 from MoinMoin.items.content import NonExistentContent
@@ -35,8 +35,31 @@
 TICKET_QUERY = Term(ITEMTYPE, ITEMTYPE_TICKET)
 
 Rating = SmallNatural.using(optional=True).with_properties(lower=1, upper=5)
-OptionalTicketReference = Reference.to(TICKET_QUERY).using(optional=True).with_properties(label_meta_key=ITEMID)
-OptionalUserReference = Reference.to(USER_QUERY).using(optional=True).with_properties(empty_label='(Nobody)', label_meta_key=NAME)
+
+
+def get_itemid_short_summary(rev):
+    return '{itemid} ({summary})'.format(itemid=rev.meta[ITEMID][:4], summary=rev.meta[SUMMARY][:50])
+
+
+def get_name(rev):
+    return rev.meta[NAME][0]
+
+
+OptionalTicketReference = Reference.to(
+    TICKET_QUERY,
+).using(
+    optional=True,
+).with_properties(
+    label_getter=get_itemid_short_summary,
+)
+OptionalUserReference = Reference.to(
+    USER_QUERY,
+).using(
+    optional=True,
+).with_properties(
+    empty_label='(Nobody)',
+    label_getter=get_name,
+)
 
 
 class TicketMetaForm(Form):