cubicweb/web/test/data/cubicweb_tag/views.py
changeset 12519 aff5d3498f68
equal deleted inserted replaced
12518:12e8b65146d9 12519:aff5d3498f68
       
     1 from cubicweb.web import component
       
     2 from cubicweb.web.views import ajaxcontroller
       
     3 
       
     4 
       
     5 @ajaxcontroller.ajaxfunc
       
     6 def tag_entity(self, eid, taglist):
       
     7     execute = self._cw.execute
       
     8     # get list of tag for this entity
       
     9     tagged_by = set(tagname for (tagname,) in
       
    10                     execute('Any N WHERE T name N, T tags X, X eid %(x)s',
       
    11                             {'x': eid}))
       
    12     for tagname in taglist:
       
    13         tagname = tagname.strip()
       
    14         if not tagname or tagname in tagged_by:
       
    15             continue
       
    16         tagrset = execute('Tag T WHERE T name %(name)s', {'name': tagname})
       
    17         if tagrset:
       
    18             rql = 'SET T tags X WHERE T eid %(t)s, X eid %(x)s'
       
    19             execute(rql, {'t': tagrset[0][0], 'x': eid})
       
    20         else:
       
    21             rql = 'INSERT Tag T: T name %(name)s, T tags X WHERE X eid %(x)s'
       
    22             execute(rql, {'name': tagname, 'x': eid})
       
    23 
       
    24 
       
    25 class TagsBox(component.AjaxEditRelationCtxComponent):
       
    26     __regid__ = 'tags_box'
       
    27     rtype = 'tags'
       
    28     role = 'object'