equal
deleted
inserted
replaced
29 self.cache_creation_date = _now |
29 self.cache_creation_date = _now |
30 self.latest_cache_lookup = _now |
30 self.latest_cache_lookup = _now |
31 |
31 |
32 CACHE_REGISTRY = {} |
32 CACHE_REGISTRY = {} |
33 |
33 |
34 class AppRsetObject(VObject): |
34 class AppObject(VObject): |
35 """This is the base class for CubicWeb application objects |
35 """This is the base class for CubicWeb application objects |
36 which are selected according to a request and result set. |
36 which are selected according to a request and result set. |
37 |
37 |
38 Classes are kept in the vregistry and instantiation is done at selection |
38 Classes are kept in the vregistry and instantiation is done at selection |
39 time. |
39 time. |
54 """ |
54 """ |
55 __select__ = yes() |
55 __select__ = yes() |
56 |
56 |
57 @classmethod |
57 @classmethod |
58 def registered(cls, reg): |
58 def registered(cls, reg): |
59 super(AppRsetObject, cls).registered(reg) |
59 super(AppObject, cls).registered(reg) |
60 cls.vreg = reg.vreg |
60 cls.vreg = reg.vreg |
61 cls.schema = reg.schema |
61 cls.schema = reg.schema |
62 cls.config = reg.config |
62 cls.config = reg.config |
63 cls.register_properties() |
63 cls.register_properties() |
64 return cls |
64 return cls |
71 def selected(cls, *args, **kwargs): |
71 def selected(cls, *args, **kwargs): |
72 """by default web app objects are usually instantiated on |
72 """by default web app objects are usually instantiated on |
73 selection according to a request, a result set, and optional |
73 selection according to a request, a result set, and optional |
74 row and col |
74 row and col |
75 """ |
75 """ |
76 assert len(args) <= 2 |
|
77 return cls(*args, **kwargs) |
76 return cls(*args, **kwargs) |
78 |
77 |
79 # Eproperties definition: |
78 # Eproperties definition: |
80 # key: id of the property (the actual CWProperty key is build using |
79 # key: id of the property (the actual CWProperty key is build using |
81 # <registry name>.<obj id>.<property id> |
80 # <registry name>.<obj id>.<property id> |
109 if not isinstance(selector, tuple): |
108 if not isinstance(selector, tuple): |
110 selector = (selector,) |
109 selector = (selector,) |
111 return selector |
110 return selector |
112 |
111 |
113 def __init__(self, req=None, rset=None, row=None, col=None, **extra): |
112 def __init__(self, req=None, rset=None, row=None, col=None, **extra): |
114 super(AppRsetObject, self).__init__() |
113 super(AppObject, self).__init__() |
115 self.req = req |
114 self.req = req |
116 self.rset = rset |
115 self.rset = rset |
117 self.row = row |
116 self.row = row |
118 self.col = col |
117 self.col = col |
119 self.extra_kwargs = extra |
118 self.extra_kwargs = extra |
339 def ensure_ro_rql(self, rql): |
338 def ensure_ro_rql(self, rql): |
340 """raise an exception if the given rql is not a select query""" |
339 """raise an exception if the given rql is not a select query""" |
341 first = rql.split(' ', 1)[0].lower() |
340 first = rql.split(' ', 1)[0].lower() |
342 if first in ('insert', 'set', 'delete'): |
341 if first in ('insert', 'set', 'delete'): |
343 raise Unauthorized(self.req._('only select queries are authorized')) |
342 raise Unauthorized(self.req._('only select queries are authorized')) |
344 |
|
345 |
|
346 class AppObject(AppRsetObject): |
|
347 """base class for application objects which are not selected |
|
348 according to a result set, only by their identifier. |
|
349 |
|
350 Those objects may not have req, rset and cursor set. |
|
351 """ |
|
352 |
|
353 @classmethod |
|
354 def selected(cls, *args, **kwargs): |
|
355 """by default web app objects are usually instantiated on |
|
356 selection |
|
357 """ |
|
358 return cls(*args, **kwargs) |
|
359 |
|
360 def __init__(self, req=None, rset=None, **kwargs): |
|
361 self.req = req |
|
362 self.rset = rset |
|
363 self.__dict__.update(kwargs) |
|