author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 16 Dec 2009 09:11:00 +0100 | |
branch | stable |
changeset 4124 | 8f2f5f0a89e7 |
parent 3689 | deb13e88e037 |
child 3720 | 5376aaadd16b |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""overrides some base views for cubicweb on google appengine |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
10 |
from logilab.mtconverter import xml_escape |
0 | 11 |
|
12 |
from cubicweb import typed_eid |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
431
diff
changeset
|
13 |
from cubicweb.selectors import one_line_rset, match_search_state, accept |
0 | 14 |
from cubicweb.schema import display_name |
15 |
from cubicweb.common.view import StartupView, EntityView |
|
16 |
from cubicweb.web import Redirect |
|
17 |
from cubicweb.web.views import vid_from_rset |
|
18 |
||
1131
544609e83317
pylint cleanup, no more need for mx datetime conversion
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
19 |
from google.appengine.api import mail |
0 | 20 |
|
21 |
||
22 |
class SearchForAssociationView(EntityView): |
|
23 |
"""view called by the edition view when the user asks |
|
24 |
to search for something to link to the edited eid |
|
25 |
""" |
|
26 |
id = 'search-associate' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
27 |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
28 |
__select__ = one_line_rset() & match_search_state('linksearch') & accept |
0 | 29 |
|
30 |
def cell_call(self, row, col): |
|
31 |
entity = self.entity(0, 0) |
|
32 |
role, eid, rtype, etype = self.req.search_state[1] |
|
33 |
assert entity.eid == typed_eid(eid) |
|
34 |
rset = entity.unrelated(rtype, etype, role, ordermethod='fetch_order') |
|
35 |
vid = vid_from_rset(self.req, rset, self.schema) |
|
36 |
self.w(u'<div id="search-associate-content">') |
|
37 |
self.pagination(self.req, rset, w=self.w) |
|
38 |
self.wview(vid, rset) |
|
39 |
self.w(u'</div>') |
|
40 |
||
41 |
||
42 |
class SchemaImageView(StartupView): |
|
43 |
id = 'schemagraph' |
|
44 |
binary = True |
|
45 |
content_type = 'image/png' |
|
46 |
def call(self): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
47 |
"""display global schema information""" |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
48 |
skipmeta = int(self.req.form.get('skipmeta', 1)) |
0 | 49 |
if skipmeta: |
50 |
url = self.build_url('data/schema.png') |
|
51 |
else: |
|
52 |
url = self.build_url('data/metaschema.png') |
|
53 |
raise Redirect(url) |
|
54 |
||
55 |
||
56 |
from cubicweb.web.views.baseviews import MetaDataView |
|
57 |
||
58 |
class GAEMetaDataView(MetaDataView): |
|
59 |
show_eid = False |
|
60 |
||
61 |
||
62 |
from cubicweb.web.views.startup import ManageView |
|
63 |
||
64 |
def entity_types_no_count(self, eschemas): |
|
65 |
"""return a list of formatted links to get a list of entities of |
|
66 |
a each entity's types |
|
67 |
""" |
|
68 |
req = self.req |
|
69 |
for eschema in eschemas: |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
70 |
if eschema.final or not (eschema.has_perm(req, 'read') or |
0 | 71 |
eschema.has_local_role('read')): |
72 |
continue |
|
73 |
etype = eschema.type |
|
74 |
label = display_name(req, etype, 'plural') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
view = self.vreg.select('views', 'list', req, req.etype_rset(etype)) |
0 | 76 |
url = view.url() |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2381
diff
changeset
|
77 |
etypelink = u' <a href="%s">%s</a>' % (xml_escape(url), label) |
0 | 78 |
yield (label, etypelink, self.add_entity_link(eschema, req)) |
79 |
||
80 |
ManageView.entity_types = entity_types_no_count |
|
81 |
||
82 |
||
83 |
from cubicweb.web.views.basecontrollers import SendMailController |
|
84 |
||
85 |
def sendmail(self, recipient, subject, body): |
|
86 |
sender = '%s <%s>' % ( |
|
87 |
self.req.user.dc_title() or self.config['sender-name'], |
|
88 |
self.req.user.get_email() or self.config['sender-addr']) |
|
89 |
mail.send_mail(sender=sender, to=recipient, |
|
90 |
subject=subject, body=body) |
|
91 |
||
92 |
SendMailController.sendmail = sendmail |