merge
authorArthur Lutz <arthur.lutz@logilab.fr>
Mon, 06 Jul 2009 16:57:08 +0200
changeset 41 d721c02cac09
parent 40 7fb387f79e7d (current diff)
parent 39 e9dbdb3aa6cb (diff)
child 42 2ff35a51458d
merge
__pkginfo__.py
--- a/__pkginfo__.py	Wed Jun 17 12:33:13 2009 +0200
+++ b/__pkginfo__.py	Mon Jul 06 16:57:08 2009 +0200
@@ -4,7 +4,7 @@
 distname = "cubicweb-keyword"
 modname = distname.split('-', 1)[1]
 
-numversion = (1, 2, 1)
+numversion = (1, 3, 0)
 version = '.'.join(str(num) for num in numversion)
 
 license = 'LGPL'
--- a/debian/changelog	Wed Jun 17 12:33:13 2009 +0200
+++ b/debian/changelog	Mon Jul 06 16:57:08 2009 +0200
@@ -1,3 +1,9 @@
+cubicweb-keyword (1.3.0-1) unstable; urgency=low
+
+  * new upstream release
+
+ -- Sylvain Thénault <sylvain.thenault@logilab.fr>  Wed, 24 Jun 2009 15:29:01 +0200
+
 cubicweb-keyword (1.2.1-1) DISTRIBUTION; urgency=low
 
   * first public release
--- a/hooks.py	Wed Jun 17 12:33:13 2009 +0200
+++ b/hooks.py	Mon Jul 06 16:57:08 2009 +0200
@@ -7,10 +7,12 @@
 
 from logilab.common.decorators import cached
 
-from cubicweb.common import ValidationError
+from cubicweb import ValidationError
+from cubicweb.selectors import implements
 from cubicweb.server.hooksmanager import Hook
 from cubicweb.server.pool import PreCommitOperation
-from cubicweb.sobjects.notification import ContentAddedView, NotificationView, StatusChangeMixIn
+from cubicweb.sobjects.notification import (ContentAddedView, NotificationView,
+                                            StatusChangeMixIn)
 
 class BeforeKeywordApplicationHook(Hook):
     """
@@ -80,7 +82,7 @@
 
 
 class KeywordNotificationView(NotificationView):
-    accepts = ('Keyword',)
+    __select__ = implements('Keyword')
     msgid_timestamp = True
 
     def recipients(self):
@@ -136,7 +138,7 @@
 
 class KeywordAddedView(ContentAddedView):
     """get notified from new keywords"""
-    accepts = ('Keyword',)
+    __select__ = implements('Keyword')
     content_attr = 'name'
     msgid_timestamp = True
 
--- a/i18n/en.po	Wed Jun 17 12:33:13 2009 +0200
+++ b/i18n/en.po	Mon Jul 06 16:57:08 2009 +0200
@@ -87,9 +87,6 @@
 msgid "classification schemes are used by users to classify entities."
 msgstr ""
 
-msgid "classified objects"
-msgstr ""
-
 msgid "classifies"
 msgstr ""
 
@@ -97,16 +94,16 @@
 msgstr "classified by"
 
 msgid "contentnavigation_addkeywords"
-msgstr ""
+msgstr "add keywords"
 
 msgid "contentnavigation_addkeywords_description"
-msgstr ""
+msgstr "component to add keywords to an entity"
 
 msgid "contentnavigation_keywordsbar"
-msgstr ""
+msgstr "show keywords"
 
 msgid "contentnavigation_keywordsbar_description"
-msgstr ""
+msgstr "component to display keywords of an entity"
 
 msgid "creating Keyword (Keyword included_in Classification %(linkto)s)"
 msgstr "creating keyword for classification scheme %(linkto)s"
@@ -118,15 +115,17 @@
 msgid "detected subkeyword cycle for keyword %(kw)s"
 msgstr ""
 
+msgid ""
+"entity types classified by the classification. Only entity type supporting "
+"the applied_to relation can be selectioned"
+msgstr ""
+
 msgid "included_in"
 msgstr "included in"
 
 msgid "included_in_object"
 msgstr "includes"
 
-msgid "indicates that an entity can be classified under the given scheme"
-msgstr ""
-
 #, python-format
 msgid "keyword %(kw)s cannot be subkeyword of himself"
 msgstr ""
--- a/i18n/fr.po	Wed Jun 17 12:33:13 2009 +0200
+++ b/i18n/fr.po	Mon Jul 06 16:57:08 2009 +0200
@@ -97,9 +97,6 @@
 msgid "classification schemes are used by users to classify entities."
 msgstr "les plans de classement sont utilisés pour classifier les entités"
 
-msgid "classified objects"
-msgstr "entités classifiées"
-
 msgid "classifies"
 msgstr "classe"
 
@@ -107,16 +104,16 @@
 msgstr "classifié par"
 
 msgid "contentnavigation_addkeywords"
-msgstr "composant de navigation pour ajouter des mots-clés"
+msgstr "ajout de mots-clés"
 
 msgid "contentnavigation_addkeywords_description"
-msgstr ""
+msgstr "composant pour ajouter des mots-clés"
 
 msgid "contentnavigation_keywordsbar"
-msgstr ""
+msgstr "affichage des mots-clés"
 
 msgid "contentnavigation_keywordsbar_description"
-msgstr ""
+msgstr "composant de navigation affichant les mots-clés associés à une entité"
 
 msgid "creating Keyword (Keyword included_in Classification %(linkto)s)"
 msgstr "création d'un mot-clé pour le plan de classement %(linkto)s"
@@ -128,16 +125,17 @@
 msgid "detected subkeyword cycle for keyword %(kw)s"
 msgstr "un cycle de sous mot-clé a été détecté pour le mot-clé %(kw)s"
 
+msgid ""
+"entity types classified by the classification. Only entity type supporting "
+"the applied_to relation can be selectioned"
+msgstr ""
+
 msgid "included_in"
 msgstr "inclus dans"
 
 msgid "included_in_object"
 msgstr "inclus"
 
-msgid "indicates that an entity can be classified under the given scheme"
-msgstr ""
-"indique qu'une entité peut être classifier sous le plan de classement donné"
-
 #, python-format
 msgid "keyword %(kw)s cannot be subkeyword of himself"
 msgstr "le mot-clé %(kw)s ne peut être un sous mot-clé de lui même"
@@ -209,6 +207,14 @@
 #~ "\n"
 #~ "L'état du mot-clé %(kw)s et maintenant %(newstate)s\n"
 
+#~ msgid "classified objects"
+#~ msgstr "entités classifiées"
+
+#~ msgid "indicates that an entity can be classified under the given scheme"
+#~ msgstr ""
+#~ "indique qu'une entité peut être classifier sous le plan de classement "
+#~ "donné"
+
 #~ msgid "keyword %(keywords)s doesn't exist"
 #~ msgstr "le mot-clé %(keyword)s n'existe pas"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/data/schema.py	Mon Jul 06 16:57:08 2009 +0200
@@ -0,0 +1,5 @@
+from yams.buildobjs import RelationDefinition
+
+class applied_to(RelationDefinition):
+    subject = 'Keyword'
+    object = ('CWGroup', 'CWUser')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_keyword.py	Mon Jul 06 16:57:08 2009 +0200
@@ -0,0 +1,14 @@
+from logilab.common.testlib import unittest_main
+from cubicweb.devtools.testlib import AutomaticWebTest
+
+class AutomaticWebTest(AutomaticWebTest):
+
+    def to_test_etypes(self):
+        # add cwgroup to test keyword components on entity on which they can be applied
+        return set(('Classification', 'Keyword', 'CWGroup'))
+
+    def list_startup_views(self):
+        return ()
+
+if __name__ == '__main__':
+    unittest_main()
--- a/views.py	Wed Jun 17 12:33:13 2009 +0200
+++ b/views.py	Mon Jul 06 16:57:08 2009 +0200
@@ -11,11 +11,11 @@
 from logilab.common.decorators import monkeypatch
 from logilab.mtconverter import html_escape
 
-from cubicweb.selectors import implements, rql_condition
+from cubicweb.selectors import implements, rql_condition, relation_possible
 from cubicweb.view import EntityView
 from cubicweb.common.mixins import TreePathMixIn
 from cubicweb.web import stdmsgs, uicfg, component
-from cubicweb.web.views import baseviews, basecontrollers
+from cubicweb.web.views import primary, baseviews, basecontrollers
 
 # displayed by the above component
 uicfg.primaryview_section.tag_object_of(('*', 'applied_to', '*'), 'hidden')
@@ -27,7 +27,7 @@
 
 # keyword views ###############################################################
 
-class KeywordPrimaryView(baseviews.PrimaryView):
+class KeywordPrimaryView(primary.PrimaryView):
     __select__ = implements('Keyword')
 
     def cell_call(self, row, col, **kwargs):
@@ -66,13 +66,10 @@
 # keyword component ###########################################################
 
 class KeywordBarVComponent(component.EntityVComponent):
-    """the keywords path bar: display keywords of a tagged entity
-    """
+    """the keywords path bar: display keywords of a tagged entity"""
     id = 'keywordsbar'
-    etype = 'Keyword'
-    rtype = 'applied_to'
-    target = 'subject'
-    #require_permission = 'read'
+    __select__ = component.EntityVComponent.__select__ & \
+                 relation_possible('applied_to', 'object', 'Keyword')
     context = 'header'
     order = 152
     htmlclass = 'navigation'
@@ -82,7 +79,7 @@
         # managers can see all applied keyword, other users will only see validated
         # keywords or their own ones
         if self.req.user.is_in_group('managers'):
-            rset = entity.related(self.rtype, 'object')
+            rset = entity.related('applied_to', 'object')
         else:
             rset = self.cursor.execute('DISTINCT Any K,N WHERE K name N, K applied_to X, X eid %(x)s, '
                                        '(K owned_by U, U eid %(u)s) or (K in_state ST, ST name "keyword validated")',
@@ -99,13 +96,11 @@
 
 class AddKeywordVComponent(component.EntityVComponent):
     """the 'add keyword' component"""
-    __select__ = component.EntityVComponent.__select__ & rql_condition('X is ET, CL classifies ET')
+    id = 'addkeywords'
+    __select__ = component.EntityVComponent.__select__ & \
+                 relation_possible('applied_to', 'object', 'Keyword', action='add') & \
+                 rql_condition('X is ET, CL classifies ET')
 
-    id = 'addkeywords'
-    etype = 'Keyword'
-    rtype = 'applied_to'
-    target = 'subject'
-    require_permission = 'add'
     context = 'header'
     order = 153
     htmlclass = 'navigation'
@@ -135,28 +130,24 @@
 @basecontrollers.jsonize
 def js_add_keywords(self, eid, kwlist):
     msg = self.req._('keywords applied')
-    try:
-        kwrset = self.cursor.execute('Any K,N,C WHERE K is Keyword, K name N, K included_in C, '
-                                     'C classifies ET, X eid %(x)s, X is ET',
-                                     {'x' : eid}, 'x')
-        if not kwrset:
-            return self.req._('No suitable classification scheme found')
-        classification = kwrset[0][2] # XXX what if we have several classifications ?
-        valid_keywords = set(kwname for _, kwname,_ in kwrset)
-        user_keywords = set(kwlist)
-        invalid_keywords = sorted(user_keywords - valid_keywords)
-        kweids = dict( (kwname, str(kweid)) for kweid, kwname, _ in kwrset if kwname in user_keywords )
-        if invalid_keywords:
-            for keyword in invalid_keywords:
-                neweid = self.cursor.execute('INSERT Keyword K: K name %(name)s, K included_in C WHERE C eid %(c)s',
-                                             {'name' : keyword, 'c' : classification}, 'c')[0][0]
-                kweids[keyword] = str(neweid)
-            if not self.req.user.is_in_group('managers'):
-                msg += self.req._(' but keywords %s must be validated') % u', '.join(invalid_keywords)
-        if kweids:
-            self.cursor.execute('SET KW applied_to X WHERE X eid %%(x)s, KW eid IN (%s)'
-                                % ','.join(kweids.values()), {'x' : eid}, 'x')
-    except Exception, ex:
-        self.exception(unicode(ex))
-        return self.req._('A problem occured while applying keywords')
+    kwrset = self.cursor.execute('Any K,N,C WHERE K is Keyword, K name N, K included_in C, '
+                                 'C classifies ET, X eid %(x)s, X is ET',
+                                 {'x' : eid}, 'x')
+    if not kwrset:
+        return self.req._('No suitable classification scheme found')
+    classification = kwrset[0][2] # XXX what if we have several classifications ?
+    valid_keywords = set(kwname for _, kwname,_ in kwrset)
+    user_keywords = set(kwlist)
+    invalid_keywords = sorted(user_keywords - valid_keywords)
+    kweids = dict( (kwname, str(kweid)) for kweid, kwname, _ in kwrset if kwname in user_keywords )
+    if invalid_keywords:
+        for keyword in invalid_keywords:
+            neweid = self.cursor.execute('INSERT Keyword K: K name %(name)s, K included_in C WHERE C eid %(c)s',
+                                         {'name' : keyword, 'c' : classification}, 'c')[0][0]
+            kweids[keyword] = str(neweid)
+        if not self.req.user.is_in_group('managers'):
+            msg += self.req._(' but keywords %s must be validated') % u', '.join(invalid_keywords)
+    if kweids:
+        self.cursor.execute('SET KW applied_to X WHERE X eid %%(x)s, KW eid IN (%s)'
+                            % ','.join(kweids.values()), {'x' : eid}, 'x')
     return msg