--- a/cubicweb_keyword/entities.py Fri Apr 12 10:02:58 2019 +0200
+++ b/cubicweb_keyword/entities.py Fri Apr 12 10:05:58 2019 +0200
@@ -6,12 +6,13 @@
"""
__docformat__ = "restructuredtext en"
-from logilab.common.deprecation import deprecated
+from logilab.common.deprecation import deprecated
from cubicweb.entities import AnyEntity, fetch_config, adapters
from cubicweb.view import EntityAdapter
from cubicweb.predicates import is_instance
+
class Classification(AnyEntity):
__regid__ = 'Classification'
fetch_attrs, cw_fetch_order = fetch_config(['name'])
@@ -75,7 +76,7 @@
"""ITree + IBreadcrumbs implementation"""
try:
return self.entity.related(self.tree_relation, self.child_role,
- entities=True)[0]
+ entities=True)[0]
except (KeyError, IndexError):
return self.classification
@@ -116,6 +117,7 @@
for entity in child.cw_adapt_to('ITree').recurse_children(_done):
yield entity
+
class CodeKeyword(Keyword):
__regid__ = 'CodeKeyword'
rest_attr = 'code'
--- a/cubicweb_keyword/hooks.py Fri Apr 12 10:02:58 2019 +0200
+++ b/cubicweb_keyword/hooks.py Fri Apr 12 10:05:58 2019 +0200
@@ -42,6 +42,7 @@
parent = self._cw.entity_from_eid(self.eidto)
SetDescendantOfKeywordOp(self._cw, parent=parent, entity=entity)
+
class SetIncludedInRelationHook(Hook):
"""sets the included_in relation on a subkeyword if not already set
"""
@@ -71,7 +72,7 @@
parent = self._cw.entity_from_eid(self.eidto)
for parent in chain([parent], parent.cw_adapt_to('ITree').iterparents()):
self._cw.execute('DELETE K descendant_of P WHERE K eid %(k)s, '
- 'P eid %(p)s', {'p': parent.eid, 'k': self.eidfrom})
+ 'P eid %(p)s', {'p': parent.eid, 'k': self.eidfrom})
## operations #################################################################
@@ -92,8 +93,8 @@
{'subkw': subkw.eid, 'kw': kw.eid}})
else:
cnx.execute('SET SK included_in C WHERE SK eid %(x)s, '
- 'SK subkeyword_of K, K included_in C',
- {'x': subkw.eid})
+ 'SK subkeyword_of K, K included_in C',
+ {'x': subkw.eid})
def check_cycle(self):
parents = set([self.eidto])
--- a/cubicweb_keyword/views.py Fri Apr 12 10:02:58 2019 +0200
+++ b/cubicweb_keyword/views.py Fri Apr 12 10:05:58 2019 +0200
@@ -92,12 +92,13 @@
def call(self, **kwargs):
self.w(SKOS_OPENING_ROOT)
for i in xrange(self.rset.rowcount):
- self.cell_call(i, 0)
+ self.cell_call(i, 0)
self.w(SKOS_CLOSING_ROOT)
def cell_call(self, row, col):
self.wview('skositemview', self.rset, row=row, col=col)
+
class SkosItemView(EntityView):
__regid__ = 'skositemview'
content_type = 'application/xml'
@@ -148,12 +149,13 @@
w(u'<div class="%s hidden" id="%s"></div>\n' % (
self.cssclass, self.domid))
+
class AddKeywordVComponent(component.EntityCtxComponent):
"""the 'add keyword' component"""
__regid__ = 'addkeywords'
__select__ = component.EntityCtxComponent.__select__ & \
- relation_possible('applied_to', 'object', 'Keyword', action='add') & \
- rql_condition('X is ET, CL classifies ET')
+ relation_possible('applied_to', 'object', 'Keyword', action='add') & \
+ rql_condition('X is ET, CL classifies ET')
context = 'header'
order = 153
@@ -246,6 +248,7 @@
# add some classification schema related methods to the Jsoncontroller ########
+
@ajaxfunc(output_type='json')
def js_possible_keywords(self, eid):
rql = ('DISTINCT Any N WHERE K is Keyword, K name N, NOT K applied_to X, '
@@ -253,6 +256,7 @@
rset = self.cursor.execute(rql, {'x': eid, 'u': self._cw.user.eid}, 'x')
return [name for (name,) in rset]
+
@ajaxfunc(output_type='json')
def js_add_keywords(self, eid, kwlist):
msg = self._cw._('keywords applied')
--- a/test/data/schema.py Fri Apr 12 10:02:58 2019 +0200
+++ b/test/data/schema.py Fri Apr 12 10:05:58 2019 +0200
@@ -1,5 +1,6 @@
from yams.buildobjs import RelationDefinition
+
class applied_to(RelationDefinition):
subject = 'Keyword'
object = ('CWUser', 'CWGroup')
--- a/test/test_descendant_of.py Fri Apr 12 10:02:58 2019 +0200
+++ b/test/test_descendant_of.py Fri Apr 12 10:05:58 2019 +0200
@@ -115,7 +115,7 @@
kw5_eid = ce('Keyword', name=u'kw5', subkeyword_of=kw4_eid, included_in=self.classif1_eid).eid
cnx.execute('SET K3 subkeyword_of K2 WHERE K3 eid %(kw3)s, K2 eid %(kw2)s',
{'kw3': kw3_eid, 'kw2': kw2_eid})
- cnx.commit();
+ cnx.commit()
kw3 = cnx.find('Keyword', eid=kw3_eid).one()
self.assertCountEqual([kw.name for kw in kw3.descendant_of], ['kw1', 'kw2'])
cnx.execute('SET K3 subkeyword_of K4 WHERE K3 eid %(kw3)s, K4 eid %(kw4)s',
@@ -198,6 +198,7 @@
cnx.execute('SET K4 descendant_of K5 WHERE K4 eid %(kw4)s, K5 eid %(kw5)s',
{'kw4': kw4.eid, 'kw5': kw5.eid})
+
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
--- a/test/test_keyword.py Fri Apr 12 10:02:58 2019 +0200
+++ b/test/test_keyword.py Fri Apr 12 10:05:58 2019 +0200
@@ -1,6 +1,7 @@
from logilab.common.testlib import unittest_main
from cubicweb.devtools.testlib import AutomaticWebTest
+
class AutomaticWebTest(AutomaticWebTest):
no_auto_populate = ('Keyword', 'CodeKeyword')
ignored_relations = set(('descendant_of',))
@@ -12,5 +13,6 @@
def list_startup_views(self):
return ()
+
if __name__ == '__main__':
unittest_main()
--- a/test/test_security.py Fri Apr 12 10:02:58 2019 +0200
+++ b/test/test_security.py Fri Apr 12 10:05:58 2019 +0200
@@ -1,5 +1,6 @@
from cubicweb.devtools.testlib import CubicWebTC
+
class SecurityTC(CubicWebTC):
def setup_database(self):
with self.admin_access.cnx() as cnx:
@@ -12,6 +13,7 @@
with self.new_access("anon").cnx() as cnx:
cnx.execute('Any X ORDERBY Z WHERE X modification_date Z, K eid %(k)s, K applied_to X', {'k': self.kw1_eid})
+
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()