changeset 2713:c9baa61473a9

Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
author Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
date Sun, 10 Aug 2014 01:59:26 +0530
parents 61c91995f121
children 8bdd34c2cb74
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/items/ticket.py
diffstat 3 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sun Aug 10 01:48:42 2014 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sun Aug 10 01:59:26 2014 +0530
@@ -53,7 +53,7 @@
                             RequiredPassword, Checkbox, InlineCheckbox, Select, Names,
                             Tags, Natural, Hidden, MultiSelect, Enum, Subscriptions,
                             validate_name, NameNotValidError)
-from MoinMoin.items import BaseChangeForm, Item, NonExistent, NameNotUniqueError, FieldNotUniqueError
+from MoinMoin.items import BaseChangeForm, Item, NonExistent, NameNotUniqueError, FieldNotUniqueError, get_itemtype_specific_tags
 from MoinMoin.items.content import content_registry
 from MoinMoin import user, util
 from MoinMoin.constants.keys import *
@@ -2298,7 +2298,7 @@
         elif time_sorting == u'old':
             sortedby.append(sorting.FieldFacet(u'mtime', reverse=False))
         results = searcher.search(q, limit=None, sortedby=sortedby)
-        tags = list(searcher.field_terms(TAGS))
+        tags = get_itemtype_specific_tags(ITEMTYPE_TICKET)
         return render_template('tickets.html',
                                results=results,
                                query=query,
--- a/MoinMoin/items/__init__.py	Sun Aug 10 01:48:42 2014 +0530
+++ b/MoinMoin/items/__init__.py	Sun Aug 10 01:59:26 2014 +0530
@@ -51,7 +51,7 @@
     CONTENTTYPE, SIZE, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
     HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID, NAMESPACE,
     UFIELDS_TYPELIST, UFIELDS, TRASH,
-    ACTION_SAVE, ACTION_REVERT, ACTION_TRASH, ACTION_RENAME
+    ACTION_SAVE, ACTION_REVERT, ACTION_TRASH, ACTION_RENAME, TAGS, LATEST_REVS
 )
 from MoinMoin.constants.namespaces import NAMESPACE_ALL
 from MoinMoin.constants.contenttypes import CHARSET, CONTENTTYPE_NONEXISTENT
@@ -267,6 +267,18 @@
 MixedIndexEntry = namedtuple('MixedIndexEntry', 'relname fullname meta hassubitems')
 
 
+def get_itemtype_specific_tags(itemtype):
+    """
+    Returns the tags of a specific itemtype
+    """
+    with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher:
+        items = searcher.search(Term(ITEMTYPE, itemtype), limit=None)
+        tags = set()
+        for item in items:
+            tags.update(item[TAGS])
+        return tags
+
+
 class NameNotUniqueError(ValueError):
     """
     An item with the same name exists.
--- a/MoinMoin/items/ticket.py	Sun Aug 10 01:48:42 2014 +0530
+++ b/MoinMoin/items/ticket.py	Sun Aug 10 01:59:26 2014 +0530
@@ -25,9 +25,8 @@
 from MoinMoin.constants.keys import (ITEMTYPE, CONTENTTYPE, ITEMID, CURRENT,
                                      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 import Item, Contentful, register, BaseModifyForm, get_itemtype_specific_tags
 from MoinMoin.items.content import NonExistentContent
-from MoinMoin.constants.keys import LATEST_REVS, TAGS
 
 
 ITEMTYPE_TICKET = u'ticket'
@@ -194,15 +193,15 @@
 
         # XXX When creating new item, suppress the "foo doesn't exist. Create it?" dummy content
         data_rendered = None if is_new else Markup(self.content._render_data())
-        with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher:
-            suggested_tags = list(searcher.field_terms(TAGS))
 
-            return render_template(self.submit_template if is_new else self.modify_template,
-                                   is_new=is_new,
-                                   closed=closed,
-                                   item_name=self.name,
-                                   data_rendered=data_rendered,
-                                   form=form,
-                                   suggested_tags=suggested_tags,
-                                   item=self,
-                                  )
+        suggested_tags = get_itemtype_specific_tags(ITEMTYPE_TICKET)
+
+        return render_template(self.submit_template if is_new else self.modify_template,
+                               is_new=is_new,
+                               closed=closed,
+                               item_name=self.name,
+                               data_rendered=data_rendered,
+                               form=form,
+                               suggested_tags=suggested_tags,
+                               item=self,
+                              )