cubicweb/web/test/data/cubicweb_tag/views.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Tue, 19 Mar 2019 13:17:47 +0100
changeset 12519 aff5d3498f68
permissions -rw-r--r--
[web/test] drop dependency on third party cubes Drop dependency on cubicweb-file, cubicweb-blog and cubicweb-tag for cubicweb/web/test Copy required parts of cubes (schema, entities, views and hooks) into cubicweb/web/test/data/cubicweb-<cube> that make tests pass.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12519
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     1
from cubicweb.web import component
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     2
from cubicweb.web.views import ajaxcontroller
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     3
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     4
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     5
@ajaxcontroller.ajaxfunc
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     6
def tag_entity(self, eid, taglist):
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     7
    execute = self._cw.execute
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     8
    # get list of tag for this entity
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
     9
    tagged_by = set(tagname for (tagname,) in
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    10
                    execute('Any N WHERE T name N, T tags X, X eid %(x)s',
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    11
                            {'x': eid}))
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    12
    for tagname in taglist:
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    13
        tagname = tagname.strip()
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    14
        if not tagname or tagname in tagged_by:
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    15
            continue
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    16
        tagrset = execute('Tag T WHERE T name %(name)s', {'name': tagname})
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    17
        if tagrset:
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    18
            rql = 'SET T tags X WHERE T eid %(t)s, X eid %(x)s'
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    19
            execute(rql, {'t': tagrset[0][0], 'x': eid})
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    20
        else:
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    21
            rql = 'INSERT Tag T: T name %(name)s, T tags X WHERE X eid %(x)s'
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    22
            execute(rql, {'name': tagname, 'x': eid})
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    23
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    24
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    25
class TagsBox(component.AjaxEditRelationCtxComponent):
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    26
    __regid__ = 'tags_box'
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    27
    rtype = 'tags'
aff5d3498f68 [web/test] drop dependency on third party cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
diff changeset
    28
    role = 'object'