author | Rabah Meradi <rabah.meradi@logilab.fr> |
Fri, 24 Jul 2015 13:40:36 +0200 | |
changeset 11599 | f8ba6ea94af9 |
parent 11598 | 2dc0b0db2329 |
child 11600 | 473754eac7c1 |
permissions | -rw-r--r-- |
11596
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
2 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
3 |
|
11599
f8ba6ea94af9
[refactoring] Move EntityResource and ETypeResource to a separate module
Rabah Meradi <rabah.meradi@logilab.fr>
parents:
11598
diff
changeset
|
4 |
from pyramid.httpexceptions import HTTPNotFound |
f8ba6ea94af9
[refactoring] Move EntityResource and ETypeResource to a separate module
Rabah Meradi <rabah.meradi@logilab.fr>
parents:
11598
diff
changeset
|
5 |
from pyramid.view import view_config |
f8ba6ea94af9
[refactoring] Move EntityResource and ETypeResource to a separate module
Rabah Meradi <rabah.meradi@logilab.fr>
parents:
11598
diff
changeset
|
6 |
from pyramid_cubicweb.resources import EntityResource, ETypeResource |
11596
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
7 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
8 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
9 |
class MatchIsETypePredicate(object): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
10 |
def __init__(self, matchname, config): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
self.matchname = matchname |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
12 |
self.etypes = frozenset( |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
13 |
k.lower() for k in config.registry['cubicweb.registry']['etypes']) |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
14 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
def text(self): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
return 'match_is_etype = %s' % self.matchname |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
18 |
phash = text |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
def __call__(self, info, request): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
21 |
return info['match'][self.matchname].lower() in \ |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
22 |
request.registry['cubicweb.registry'].case_insensitive_etypes |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
23 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
@view_config( |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
26 |
route_name='cwentities', |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
27 |
context=EntityResource, |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
28 |
request_method='DELETE') |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
29 |
def delete_entity(context, request): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
30 |
context.rset.one().cw_delete() |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
31 |
request.response.status_int = 204 |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
32 |
return request.response |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
33 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
34 |
|
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
35 |
def includeme(config): |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
36 |
config.add_route_predicate('match_is_etype', MatchIsETypePredicate) |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
37 |
config.add_route( |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
38 |
'cwentities', '/{etype}/*traverse', |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
39 |
factory=ETypeResource.from_match('etype'), match_is_etype='etype') |
1f2570f1d72a
[routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
40 |
config.scan(__name__) |