192 |
192 |
193 __docformat__ = "restructuredtext en" |
193 __docformat__ = "restructuredtext en" |
194 _ = unicode |
194 _ = unicode |
195 |
195 |
196 from warnings import warn |
196 from warnings import warn |
|
197 from datetime import datetime, date, time, timedelta |
197 |
198 |
198 from logilab.common.decorators import cached, clear_cache |
199 from logilab.common.decorators import cached, clear_cache |
199 from logilab.common.deprecation import deprecated, class_deprecated |
200 from logilab.common.deprecation import deprecated, class_deprecated |
200 from logilab.common.modutils import cleanup_sys_modules |
201 from logilab.common.modutils import cleanup_sys_modules |
201 |
202 |
202 from rql import RQLHelper |
203 from rql import RQLHelper |
|
204 from yams.constraints import BASE_CONVERTERS |
203 |
205 |
204 from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid, |
206 from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid, |
205 ObjectNotFound, NoSelectableObject, RegistryNotFound, |
207 ObjectNotFound, NoSelectableObject, RegistryNotFound, |
206 CW_EVENT_MANAGER) |
208 CW_EVENT_MANAGER) |
207 from cubicweb.utils import dump_class |
|
208 from cubicweb.vregistry import VRegistry, Registry, class_regid, classid |
209 from cubicweb.vregistry import VRegistry, Registry, class_regid, classid |
209 from cubicweb.rtags import RTAGS |
210 from cubicweb.rtags import RTAGS |
210 |
211 |
211 def clear_rtag_objects(): |
212 def clear_rtag_objects(): |
212 for rtag in RTAGS: |
213 for rtag in RTAGS: |
366 assert len(objects) == 1, objects |
367 assert len(objects) == 1, objects |
367 cls = objects[0] |
368 cls = objects[0] |
368 # make a copy event if cls.__regid__ == etype, else we may have pb for |
369 # make a copy event if cls.__regid__ == etype, else we may have pb for |
369 # client application using multiple connections to different |
370 # client application using multiple connections to different |
370 # repositories (eg shingouz) |
371 # repositories (eg shingouz) |
371 cls = dump_class(cls, etype) |
372 # __autogenerated__ attribute is just a marker |
|
373 cls = type(str(etype), (cls,), {'__autogenerated__': True, |
|
374 '__doc__': cls.__doc__, |
|
375 '__module__': cls.__module__}) |
372 cls.__regid__ = etype |
376 cls.__regid__ = etype |
373 cls.__initialize__(self.schema) |
377 cls.__initialize__(self.schema) |
374 return cls |
378 return cls |
375 |
379 |
376 def fetch_attrs(self, targettypes): |
380 def fetch_attrs(self, targettypes): |
410 continue |
414 continue |
411 views = [view for view in views |
415 views = [view for view in views |
412 if not isinstance(view, class_deprecated)] |
416 if not isinstance(view, class_deprecated)] |
413 try: |
417 try: |
414 view = self._select_best(views, req, rset=rset, **kwargs) |
418 view = self._select_best(views, req, rset=rset, **kwargs) |
415 if view.linkable(): |
419 if view is not None and view.linkable(): |
416 yield view |
420 yield view |
417 except NoSelectableObject: |
|
418 continue |
|
419 except Exception: |
421 except Exception: |
420 self.exception('error while trying to select %s view for %s', |
422 self.exception('error while trying to select %s view for %s', |
421 vid, rset) |
423 vid, rset) |
422 |
424 |
423 VRegistry.REGISTRY_FACTORY['views'] = ViewsRegistry |
425 VRegistry.REGISTRY_FACTORY['views'] = ViewsRegistry |
847 @deprecated('[3.4] use vreg["views"].select(...)') |
849 @deprecated('[3.4] use vreg["views"].select(...)') |
848 def select_view(self, __vid, req, rset=None, **kwargs): |
850 def select_view(self, __vid, req, rset=None, **kwargs): |
849 return self['views'].select(__vid, req, rset=rset, **kwargs) |
851 return self['views'].select(__vid, req, rset=rset, **kwargs) |
850 |
852 |
851 |
853 |
852 import decimal |
854 # XXX unify with yams.constraints.BASE_CONVERTERS? |
853 from datetime import datetime, date, time, timedelta |
855 YAMS_TO_PY = BASE_CONVERTERS.copy() |
854 |
856 YAMS_TO_PY.update({ |
855 YAMS_TO_PY = { # XXX unify with yams.constraints.BASE_CONVERTERS? |
857 'Bytes': Binary, |
856 'String' : unicode, |
|
857 'Bytes': Binary, |
|
858 'Password': str, |
|
859 |
|
860 'Boolean': bool, |
|
861 'Int': int, |
|
862 'Float': float, |
|
863 'Decimal': decimal.Decimal, |
|
864 |
|
865 'Date': date, |
858 'Date': date, |
866 'Datetime': datetime, |
859 'Datetime': datetime, |
867 'TZDatetime': datetime, |
860 'TZDatetime': datetime, |
868 'Time': time, |
861 'Time': time, |
869 'TZTime': time, |
862 'TZTime': time, |
870 'Interval': timedelta, |
863 'Interval': timedelta, |
871 } |
864 }) |
872 |
865 |