--- a/entities/adapters.py Tue Dec 15 08:55:58 2015 +0100
+++ b/entities/adapters.py Wed Dec 09 16:32:57 2015 +0100
@@ -1,4 +1,4 @@
-# copyright 2010-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2010-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -18,19 +18,15 @@
"""some basic entity adapter implementations, for interfaces used in the
framework itself.
"""
-
-__docformat__ = "restructuredtext en"
from cubicweb import _
from itertools import chain
-from warnings import warn
from hashlib import md5
from logilab.mtconverter import TransformError
from logilab.common.decorators import cached
-from cubicweb import ValidationError, view, ViolatedConstraint
-from cubicweb.schema import CONSTRAINTS
+from cubicweb import ValidationError, view, ViolatedConstraint, UniqueTogetherError
from cubicweb.predicates import is_instance, relation_possible, match_exception
@@ -63,8 +59,8 @@
NOTE: the dictionary keys should match the list returned by the
`allowed_massmail_keys` method.
"""
- return dict( (attr, getattr(self.entity, attr))
- for attr in self.allowed_massmail_keys() )
+ return dict((attr, getattr(self.entity, attr))
+ for attr in self.allowed_massmail_keys())
class INotifiableAdapter(view.EntityAdapter):
@@ -156,24 +152,27 @@
if role == 'subject':
for entity_ in getattr(entity, rschema.type):
merge_weight_dict(words, entity_.cw_adapt_to('IFTIndexable').get_words())
- else: # if role == 'object':
+ else: # if role == 'object':
for entity_ in getattr(entity, 'reverse_%s' % rschema.type):
merge_weight_dict(words, entity_.cw_adapt_to('IFTIndexable').get_words())
return words
+
def merge_weight_dict(maindict, newdict):
for weight, words in newdict.items():
maindict.setdefault(weight, []).extend(words)
+
class IDownloadableAdapter(view.EntityAdapter):
"""interface for downloadable entities"""
__regid__ = 'IDownloadable'
__abstract__ = True
- def download_url(self, **kwargs): # XXX not really part of this interface
+ def download_url(self, **kwargs): # XXX not really part of this interface
"""return a URL to download entity's content
- It should be a unicode object containing url-encoded ASCII."""
+ It should be a unicode object containing url-encoded ASCII.
+ """
raise NotImplementedError
def download_content_type(self):
@@ -192,6 +191,7 @@
"""return actual data (bytes) of the downloadable content"""
raise NotImplementedError
+
# XXX should propose to use two different relations for children/parent
class ITreeAdapter(view.EntityAdapter):
"""This adapter provides a tree interface.
@@ -339,7 +339,7 @@
try:
# check we are not jumping to another tree
if (adapter.tree_relation != self.tree_relation or
- adapter.child_role != self.child_role):
+ adapter.child_role != self.child_role):
break
entity = adapter.parent()
adapter = entity.cw_adapt_to('ITree')
@@ -377,7 +377,6 @@
# error handling adapters ######################################################
-from cubicweb import UniqueTogetherError
class IUserFriendlyError(view.EntityAdapter):
__regid__ = 'IUserFriendlyError'
@@ -408,13 +407,14 @@
__select__ = match_exception(ViolatedConstraint)
def raise_user_exception(self):
- _ = self._cw._
cstrname = self.exc.cstrname
eschema = self.entity.e_schema
for rschema, attrschema in eschema.attribute_definitions():
rdef = rschema.rdef(eschema, attrschema)
for constraint in rdef.constraints:
- if cstrname == 'cstr' + md5((eschema.type + rschema.type + constraint.type() + (constraint.serialize() or '')).encode('ascii')).hexdigest():
+ if cstrname == 'cstr' + md5(
+ (eschema.type + rschema.type + constraint.type() +
+ (constraint.serialize() or '')).encode('ascii')).hexdigest():
break
else:
continue