author | David Douard <david.douard@logilab.fr> |
Mon, 22 Jul 2013 15:38:11 +0200 | |
branch | stable |
changeset 9176 | 8139f82c8bbe |
parent 8665 | e65af61bde7d |
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
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:
4362
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
18 |
"""Specific views for email addresses entities""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
22 |
from logilab.mtconverter import xml_escape |
0 | 23 |
|
2305
8f6dbe884700
import display_name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2164
diff
changeset
|
24 |
from cubicweb.schema import display_name |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7737
diff
changeset
|
25 |
from cubicweb.predicates import is_instance |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
26 |
from cubicweb import Unauthorized |
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
27 |
from cubicweb.web.views import uicfg, baseviews, primary, ibreadcrumbs |
1151 | 28 |
|
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4362
diff
changeset
|
29 |
_pvs = uicfg.primaryview_section |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4362
diff
changeset
|
30 |
_pvs.tag_subject_of(('*', 'use_email', '*'), 'attributes') |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4362
diff
changeset
|
31 |
_pvs.tag_subject_of(('*', 'primary_email', '*'), 'hidden') |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4362
diff
changeset
|
32 |
|
1639 | 33 |
class EmailAddressPrimaryView(primary.PrimaryView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
34 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
35 |
|
0 | 36 |
def cell_call(self, row, col, skipeids=None): |
37 |
self.skipeids = skipeids |
|
38 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
39 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
40 |
def render_entity_attributes(self, entity): |
0 | 41 |
self.w(u'<h3>') |
42 |
entity.view('oneline', w=self.w) |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
43 |
if entity.prefered: |
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
44 |
self.w(u' (<i>%s</i>)' % entity.prefered.view('oneline')) |
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
45 |
self.w(u'</h3>') |
0 | 46 |
try: |
47 |
persons = entity.reverse_primary_email |
|
48 |
except Unauthorized: |
|
49 |
persons = [] |
|
50 |
if persons: |
|
51 |
emailof = persons[0] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
52 |
self.field(display_name(self._cw, 'primary_email', 'object'), emailof.view('oneline')) |
0 | 53 |
pemaileid = emailof.eid |
54 |
else: |
|
55 |
pemaileid = None |
|
56 |
try: |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
57 |
emailof = 'use_email' in self._cw.vreg.schema and entity.reverse_use_email or () |
0 | 58 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
59 |
except Unauthorized: |
|
60 |
emailof = [] |
|
61 |
if emailof: |
|
62 |
emailofstr = ', '.join(e.view('oneline') for e in emailof) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
63 |
self.field(display_name(self._cw, 'use_email', 'object'), emailofstr) |
0 | 64 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
65 |
def render_entity_relations(self, entity): |
0 | 66 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
67 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
68 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
69 |
self.w(u'</div>') |
|
70 |
||
71 |
||
72 |
class EmailAddressShortPrimaryView(EmailAddressPrimaryView): |
|
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
73 |
__select__ = is_instance('EmailAddress') |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
74 |
__regid__ = 'shortprimary' |
0 | 75 |
title = None # hidden view |
1639 | 76 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
77 |
def render_entity_attributes(self, entity): |
0 | 78 |
self.w(u'<h5>') |
79 |
entity.view('oneline', w=self.w) |
|
80 |
self.w(u'</h5>') |
|
81 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
82 |
|
0 | 83 |
class EmailAddressOneLineView(baseviews.OneLineView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
84 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
85 |
|
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
86 |
def entity_call(self, entity, **kwargs): |
0 | 87 |
if entity.reverse_primary_email: |
88 |
self.w(u'<b>') |
|
89 |
if entity.alias: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
90 |
self.w(u'%s <' % xml_escape(entity.alias)) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
91 |
self.w('<a href="%s">%s</a>' % (xml_escape(entity.absolute_url()), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
92 |
xml_escape(entity.display_address()))) |
0 | 93 |
if entity.alias: |
94 |
self.w(u'>\n') |
|
95 |
if entity.reverse_primary_email: |
|
96 |
self.w(u'</b>') |
|
97 |
||
3220
11b6016e3970
cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3204
diff
changeset
|
98 |
|
0 | 99 |
class EmailAddressMailToView(baseviews.OneLineView): |
100 |
"""A one line view that builds a user clickable URL for an email with |
|
101 |
'mailto:'""" |
|
102 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
103 |
__regid__ = 'mailto' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
104 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
105 |
|
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
106 |
def entity_call(self, entity, **kwargs): |
0 | 107 |
if entity.reverse_primary_email: |
108 |
self.w(u'<b>') |
|
109 |
if entity.alias: |
|
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
110 |
alias = entity.alias |
0 | 111 |
elif entity.reverse_use_email: |
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
112 |
alias = entity.reverse_use_email[0].dc_title() |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
113 |
else: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
114 |
alias = None |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
115 |
if alias: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
116 |
mailto = "mailto:%s <%s>" % (alias, entity.display_address()) |
0 | 117 |
else: |
118 |
mailto = "mailto:%s" % entity.display_address() |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
119 |
self.w(u'<a href="%s">%s</a>' % (xml_escape(mailto), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
120 |
xml_escape(entity.display_address()))) |
0 | 121 |
if entity.reverse_primary_email: |
122 |
self.w(u'</b>') |
|
123 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
124 |
|
4362
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
125 |
class EmailAddressInContextView(baseviews.InContextView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
126 |
__select__ = is_instance('EmailAddress') |
4362
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
127 |
|
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
128 |
def cell_call(self, row, col, **kwargs): |
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
129 |
if self._cw.vreg.config['mangle-emails']: |
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
130 |
self.wview('oneline', self.cw_rset, row=row, col=col, **kwargs) |
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
131 |
else: |
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
132 |
self.wview('mailto', self.cw_rset, row=row, col=col, **kwargs) |
4362
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
133 |
|
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
134 |
|
0 | 135 |
class EmailAddressTextView(baseviews.TextView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
136 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
137 |
|
0 | 138 |
def cell_call(self, row, col, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
139 |
self.w(self.cw_rset.get_entity(row, col).display_address()) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
140 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
141 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
142 |
class EmailAddressIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
143 |
__select__ = is_instance('EmailAddress') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
144 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
145 |
def parent_entity(self): |
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
146 |
return self.entity.email_of |