author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 04 Nov 2011 17:16:15 +0100 | |
changeset 8058 | a536053b0588 |
parent 7737 | db6d296cc66f |
child 8190 | 2a3c1b787688 |
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 |
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
|
25 |
from cubicweb.selectors import is_instance |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
26 |
from cubicweb import Unauthorized |
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
|
27 |
from cubicweb.web import uicfg |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
28 |
from cubicweb.web.views import baseviews, primary, ibreadcrumbs |
1151 | 29 |
|
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
|
30 |
_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
|
31 |
_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
|
32 |
_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
|
33 |
|
1639 | 34 |
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
|
35 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
36 |
|
0 | 37 |
def cell_call(self, row, col, skipeids=None): |
38 |
self.skipeids = skipeids |
|
39 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
40 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
41 |
def render_entity_attributes(self, entity): |
0 | 42 |
self.w(u'<h3>') |
43 |
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
|
44 |
if entity.prefered: |
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' (<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
|
46 |
self.w(u'</h3>') |
0 | 47 |
try: |
48 |
persons = entity.reverse_primary_email |
|
49 |
except Unauthorized: |
|
50 |
persons = [] |
|
51 |
if persons: |
|
52 |
emailof = persons[0] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
53 |
self.field(display_name(self._cw, 'primary_email', 'object'), emailof.view('oneline')) |
0 | 54 |
pemaileid = emailof.eid |
55 |
else: |
|
56 |
pemaileid = None |
|
57 |
try: |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
58 |
emailof = 'use_email' in self._cw.vreg.schema and entity.reverse_use_email or () |
0 | 59 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
60 |
except Unauthorized: |
|
61 |
emailof = [] |
|
62 |
if emailof: |
|
63 |
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
|
64 |
self.field(display_name(self._cw, 'use_email', 'object'), emailofstr) |
0 | 65 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
66 |
def render_entity_relations(self, entity): |
0 | 67 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
68 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
69 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
70 |
self.w(u'</div>') |
|
71 |
||
72 |
||
73 |
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
|
74 |
__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
|
75 |
__regid__ = 'shortprimary' |
0 | 76 |
title = None # hidden view |
1639 | 77 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
78 |
def render_entity_attributes(self, entity): |
0 | 79 |
self.w(u'<h5>') |
80 |
entity.view('oneline', w=self.w) |
|
81 |
self.w(u'</h5>') |
|
82 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
83 |
|
0 | 84 |
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
|
85 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
86 |
|
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
87 |
def entity_call(self, entity, **kwargs): |
0 | 88 |
if entity.reverse_primary_email: |
89 |
self.w(u'<b>') |
|
90 |
if entity.alias: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
91 |
self.w(u'%s <' % xml_escape(entity.alias)) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
92 |
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
|
93 |
xml_escape(entity.display_address()))) |
0 | 94 |
if entity.alias: |
95 |
self.w(u'>\n') |
|
96 |
if entity.reverse_primary_email: |
|
97 |
self.w(u'</b>') |
|
98 |
||
3220
11b6016e3970
cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3204
diff
changeset
|
99 |
|
0 | 100 |
class EmailAddressMailToView(baseviews.OneLineView): |
101 |
"""A one line view that builds a user clickable URL for an email with |
|
102 |
'mailto:'""" |
|
103 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
104 |
__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
|
105 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
106 |
|
7737
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
107 |
def entity_call(self, entity, **kwargs): |
0 | 108 |
if entity.reverse_primary_email: |
109 |
self.w(u'<b>') |
|
110 |
if entity.alias: |
|
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
111 |
alias = entity.alias |
0 | 112 |
elif entity.reverse_use_email: |
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
113 |
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
|
114 |
else: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
115 |
alias = None |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
116 |
if alias: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
117 |
mailto = "mailto:%s <%s>" % (alias, entity.display_address()) |
0 | 118 |
else: |
119 |
mailto = "mailto:%s" % entity.display_address() |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
120 |
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
|
121 |
xml_escape(entity.display_address()))) |
0 | 122 |
if entity.reverse_primary_email: |
123 |
self.w(u'</b>') |
|
124 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
125 |
|
4362
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
126 |
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
|
127 |
__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
|
128 |
|
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
else: |
db6d296cc66f
[web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
133 |
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
|
134 |
|
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
135 |
|
0 | 136 |
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
|
137 |
__select__ = is_instance('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
138 |
|
0 | 139 |
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
|
140 |
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
|
141 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
142 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
143 |
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
|
144 |
__select__ = is_instance('EmailAddress') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
145 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
146 |
def parent_entity(self): |
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
147 |
return self.entity.email_of |