|
1 """overrides some base views for cubicweb on google appengine |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 """ |
|
7 __docformat__ = "restructuredtext en" |
|
8 |
|
9 from os.path import join |
|
10 |
|
11 from logilab.mtconverter import html_escape |
|
12 from logilab.common.decorators import cached |
|
13 |
|
14 from cubicweb import typed_eid |
|
15 from cubicweb.schema import display_name |
|
16 from cubicweb.common.view import StartupView, EntityView |
|
17 from cubicweb.common.selectors import (onelinerset_selector, searchstate_selector, |
|
18 accept_selector) |
|
19 from cubicweb.web import Redirect |
|
20 from cubicweb.web.views import vid_from_rset |
|
21 from cubicweb.goa.db import rset_from_objs |
|
22 |
|
23 from google.appengine.api import datastore, mail |
|
24 |
|
25 from main import APPLROOT |
|
26 |
|
27 |
|
28 class SearchForAssociationView(EntityView): |
|
29 """view called by the edition view when the user asks |
|
30 to search for something to link to the edited eid |
|
31 """ |
|
32 id = 'search-associate' |
|
33 |
|
34 __selectors__ = (onelinerset_selector, searchstate_selector, accept_selector) |
|
35 accepts = ('Any',) |
|
36 search_states = ('linksearch',) |
|
37 |
|
38 def cell_call(self, row, col): |
|
39 entity = self.entity(0, 0) |
|
40 role, eid, rtype, etype = self.req.search_state[1] |
|
41 assert entity.eid == typed_eid(eid) |
|
42 rset = entity.unrelated(rtype, etype, role, ordermethod='fetch_order') |
|
43 vid = vid_from_rset(self.req, rset, self.schema) |
|
44 self.w(u'<div id="search-associate-content">') |
|
45 self.pagination(self.req, rset, w=self.w) |
|
46 self.wview(vid, rset) |
|
47 self.w(u'</div>') |
|
48 |
|
49 |
|
50 class SchemaImageView(StartupView): |
|
51 id = 'schemagraph' |
|
52 binary = True |
|
53 content_type = 'image/png' |
|
54 def call(self): |
|
55 """display global schema information""" |
|
56 skipmeta = not int(self.req.form.get('withmeta', 0)) |
|
57 if skipmeta: |
|
58 url = self.build_url('data/schema.png') |
|
59 else: |
|
60 url = self.build_url('data/metaschema.png') |
|
61 raise Redirect(url) |
|
62 |
|
63 |
|
64 from cubicweb.web.views.baseviews import MetaDataView |
|
65 |
|
66 class GAEMetaDataView(MetaDataView): |
|
67 show_eid = False |
|
68 |
|
69 |
|
70 from cubicweb.web.views.startup import ManageView |
|
71 |
|
72 def entity_types_no_count(self, eschemas): |
|
73 """return a list of formatted links to get a list of entities of |
|
74 a each entity's types |
|
75 """ |
|
76 req = self.req |
|
77 for eschema in eschemas: |
|
78 if eschema.is_final() or not (eschema.has_perm(req, 'read') or |
|
79 eschema.has_local_role('read')): |
|
80 continue |
|
81 etype = eschema.type |
|
82 label = display_name(req, etype, 'plural') |
|
83 view = self.vreg.select_view('list', req, req.etype_rset(etype)) |
|
84 url = view.url() |
|
85 etypelink = u' <a href="%s">%s</a>' % (html_escape(url), label) |
|
86 yield (label, etypelink, self.add_entity_link(eschema, req)) |
|
87 |
|
88 ManageView.entity_types = entity_types_no_count |
|
89 |
|
90 |
|
91 from cubicweb.web.views.basecontrollers import SendMailController |
|
92 |
|
93 def sendmail(self, recipient, subject, body): |
|
94 sender = '%s <%s>' % ( |
|
95 self.req.user.dc_title() or self.config['sender-name'], |
|
96 self.req.user.get_email() or self.config['sender-addr']) |
|
97 mail.send_mail(sender=sender, to=recipient, |
|
98 subject=subject, body=body) |
|
99 |
|
100 SendMailController.sendmail = sendmail |