author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 30 Jul 2010 10:09:31 +0200 | |
changeset 6041 | 31776723c0c5 |
parent 5556 | 9ab2b4c74baf |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6041
31776723c0c5
[index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
18 |
"""overrides some base views for cubicweb on google appengine""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
22 |
from logilab.mtconverter import xml_escape |
0 | 23 |
|
24 |
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
|
25 |
from cubicweb.selectors import one_line_rset, match_search_state, accept |
0 | 26 |
from cubicweb.schema import display_name |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
27 |
from cubicweb.view import StartupView, EntityView |
0 | 28 |
from cubicweb.web import Redirect |
29 |
from cubicweb.web.views import vid_from_rset |
|
30 |
||
1131
544609e83317
pylint cleanup, no more need for mx datetime conversion
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
31 |
from google.appengine.api import mail |
0 | 32 |
|
33 |
||
34 |
class SearchForAssociationView(EntityView): |
|
35 |
"""view called by the edition view when the user asks |
|
36 |
to search for something to link to the edited eid |
|
37 |
""" |
|
38 |
id = 'search-associate' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
39 |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
40 |
__select__ = one_line_rset() & match_search_state('linksearch') & accept |
0 | 41 |
|
42 |
def cell_call(self, row, col): |
|
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2381
diff
changeset
|
43 |
entity = self.rset.get_entity(0, 0) |
0 | 44 |
role, eid, rtype, etype = self.req.search_state[1] |
45 |
assert entity.eid == typed_eid(eid) |
|
46 |
rset = entity.unrelated(rtype, etype, role, ordermethod='fetch_order') |
|
47 |
vid = vid_from_rset(self.req, rset, self.schema) |
|
48 |
self.w(u'<div id="search-associate-content">') |
|
49 |
self.pagination(self.req, rset, w=self.w) |
|
50 |
self.wview(vid, rset) |
|
51 |
self.w(u'</div>') |
|
52 |
||
53 |
||
54 |
class SchemaImageView(StartupView): |
|
55 |
id = 'schemagraph' |
|
56 |
binary = True |
|
57 |
content_type = 'image/png' |
|
58 |
def call(self): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
59 |
"""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
|
60 |
skipmeta = int(self.req.form.get('skipmeta', 1)) |
0 | 61 |
if skipmeta: |
62 |
url = self.build_url('data/schema.png') |
|
63 |
else: |
|
64 |
url = self.build_url('data/metaschema.png') |
|
65 |
raise Redirect(url) |
|
66 |
||
67 |
||
68 |
from cubicweb.web.views.baseviews import MetaDataView |
|
69 |
||
70 |
class GAEMetaDataView(MetaDataView): |
|
71 |
show_eid = False |
|
72 |
||
73 |
||
74 |
from cubicweb.web.views.startup import ManageView |
|
75 |
||
76 |
def entity_types_no_count(self, eschemas): |
|
77 |
"""return a list of formatted links to get a list of entities of |
|
78 |
a each entity's types |
|
79 |
""" |
|
80 |
req = self.req |
|
81 |
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
|
82 |
if eschema.final or not (eschema.has_perm(req, 'read') or |
0 | 83 |
eschema.has_local_role('read')): |
84 |
continue |
|
85 |
etype = eschema.type |
|
86 |
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
|
87 |
view = self.vreg.select('views', 'list', req, req.etype_rset(etype)) |
0 | 88 |
url = view.url() |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2381
diff
changeset
|
89 |
etypelink = u' <a href="%s">%s</a>' % (xml_escape(url), label) |
6041
31776723c0c5
[index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
90 |
if eschema.has_perm(req, 'add'): |
31776723c0c5
[index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
91 |
yield (label, etypelink, self.add_entity_link(etype)) |
0 | 92 |
|
93 |
ManageView.entity_types = entity_types_no_count |
|
94 |
||
95 |
||
96 |
from cubicweb.web.views.basecontrollers import SendMailController |
|
97 |
||
98 |
def sendmail(self, recipient, subject, body): |
|
99 |
sender = '%s <%s>' % ( |
|
100 |
self.req.user.dc_title() or self.config['sender-name'], |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
101 |
self.req.user.cw_adapt_to('IEmailable').get_email() or self.config['sender-addr']) |
0 | 102 |
mail.send_mail(sender=sender, to=recipient, |
103 |
subject=subject, body=body) |
|
104 |
||
105 |
SendMailController.sendmail = sendmail |