equal
deleted
inserted
replaced
1 """hooks to handle attributes mapped to a custom storage |
|
2 """ |
|
3 from cubicweb.server.hook import Hook |
|
4 from cubicweb.server.sources.storages import ETYPE_ATTR_STORAGE |
|
5 |
|
6 |
|
7 class BFSSHook(Hook): |
|
8 """abstract class for bytes file-system storage hooks""" |
|
9 __abstract__ = True |
|
10 category = 'bfss' |
|
11 |
|
12 |
|
13 class PreAddEntityHook(BFSSHook): |
|
14 """""" |
|
15 __regid__ = 'bfss_add_entity' |
|
16 events = ('before_add_entity', ) |
|
17 |
|
18 def __call__(self): |
|
19 etype = self.entity.__regid__ |
|
20 for attr in ETYPE_ATTR_STORAGE.get(etype, ()): |
|
21 ETYPE_ATTR_STORAGE[etype][attr].entity_added(self.entity, attr) |
|
22 |
|
23 class PreUpdateEntityHook(BFSSHook): |
|
24 """""" |
|
25 __regid__ = 'bfss_update_entity' |
|
26 events = ('before_update_entity', ) |
|
27 |
|
28 def __call__(self): |
|
29 etype = self.entity.__regid__ |
|
30 for attr in ETYPE_ATTR_STORAGE.get(etype, ()): |
|
31 ETYPE_ATTR_STORAGE[etype][attr].entity_updated(self.entity, attr) |
|
32 |
|
33 class PreDeleteEntityHook(BFSSHook): |
|
34 """""" |
|
35 __regid__ = 'bfss_delete_entity' |
|
36 events = ('before_delete_entity', ) |
|
37 |
|
38 def __call__(self): |
|
39 etype = self.entity.__regid__ |
|
40 for attr in ETYPE_ATTR_STORAGE.get(etype, ()): |
|
41 ETYPE_ATTR_STORAGE[etype][attr].entity_deleted(self.entity, attr) |
|