[entity] introduce a new 'adapters' registry
This changeset introduces the notion in adapters (as in Zope Component Architecture)
in a cubicweb way, eg using a specific registry of appobjects.
This allows nicer code structure, by avoid clutering entity classes and moving
code usually specific to a place of the ui (or something else) together with the
code that use the interface.
We don't use actual interface anymore, they are implied by adapters (which
may be abstract), whose reg id is an interface name.
Appobjects that used to 'implements(IFace)' should now be rewritten by:
* coding an IFaceAdapter(EntityAdapter) defining (implementing if desired)
the interface, usually with __regid__ = 'IFace'
* use "adaptable('IFace')" as selector instead
Also, the implements_adapter_compat decorator eases backward compatibility
with adapter's methods that may still be found on entities implementing
the interface.
Notice that unlike ZCA, we don't support automatic adapters chain (yagni?).
All interfaces defined in cubicweb have been turned into adapters, also
some new ones have been introduced to cleanup Entity / AnyEntity classes
namespace. At the end, the pluggable mixins mecanism should disappear in
favor of adapters as well.
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""overrides some base views for cubicweb on google appengine
"""
__docformat__ = "restructuredtext en"
from logilab.mtconverter import xml_escape
from cubicweb import typed_eid
from cubicweb.selectors import one_line_rset, match_search_state, accept
from cubicweb.schema import display_name
from cubicweb.view import StartupView, EntityView
from cubicweb.web import Redirect
from cubicweb.web.views import vid_from_rset
from google.appengine.api import mail
class SearchForAssociationView(EntityView):
"""view called by the edition view when the user asks
to search for something to link to the edited eid
"""
id = 'search-associate'
__select__ = one_line_rset() & match_search_state('linksearch') & accept
def cell_call(self, row, col):
entity = self.rset.get_entity(0, 0)
role, eid, rtype, etype = self.req.search_state[1]
assert entity.eid == typed_eid(eid)
rset = entity.unrelated(rtype, etype, role, ordermethod='fetch_order')
vid = vid_from_rset(self.req, rset, self.schema)
self.w(u'<div id="search-associate-content">')
self.pagination(self.req, rset, w=self.w)
self.wview(vid, rset)
self.w(u'</div>')
class SchemaImageView(StartupView):
id = 'schemagraph'
binary = True
content_type = 'image/png'
def call(self):
"""display global schema information"""
skipmeta = int(self.req.form.get('skipmeta', 1))
if skipmeta:
url = self.build_url('data/schema.png')
else:
url = self.build_url('data/metaschema.png')
raise Redirect(url)
from cubicweb.web.views.baseviews import MetaDataView
class GAEMetaDataView(MetaDataView):
show_eid = False
from cubicweb.web.views.startup import ManageView
def entity_types_no_count(self, eschemas):
"""return a list of formatted links to get a list of entities of
a each entity's types
"""
req = self.req
for eschema in eschemas:
if eschema.final or not (eschema.has_perm(req, 'read') or
eschema.has_local_role('read')):
continue
etype = eschema.type
label = display_name(req, etype, 'plural')
view = self.vreg.select('views', 'list', req, req.etype_rset(etype))
url = view.url()
etypelink = u' <a href="%s">%s</a>' % (xml_escape(url), label)
yield (label, etypelink, self.add_entity_link(eschema, req))
ManageView.entity_types = entity_types_no_count
from cubicweb.web.views.basecontrollers import SendMailController
def sendmail(self, recipient, subject, body):
sender = '%s <%s>' % (
self.req.user.dc_title() or self.config['sender-name'],
self.req.user.cw_adapt_to('IEmailable').get_email() or self.config['sender-addr'])
mail.send_mail(sender=sender, to=recipient,
subject=subject, body=body)
SendMailController.sendmail = sendmail