author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 11 Jun 2010 13:00:19 +0200 | |
branch | stable |
changeset 5733 | d00d1fab42af |
parent 5426 | 0d4853a6e5ee |
child 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:
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/>. |
0 | 18 |
"""Specific views for email addresses entities |
19 |
||
20 |
""" |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
0 | 24 |
|
2305
8f6dbe884700
import display_name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2164
diff
changeset
|
25 |
from cubicweb.schema import display_name |
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
26 |
from cubicweb.selectors import implements |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
27 |
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
|
28 |
from cubicweb.web import uicfg |
1639 | 29 |
from cubicweb.web.views import baseviews, primary |
1151 | 30 |
|
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
|
31 |
_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
|
32 |
_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
|
33 |
_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
|
34 |
|
1639 | 35 |
class EmailAddressPrimaryView(primary.PrimaryView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
36 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
37 |
|
0 | 38 |
def cell_call(self, row, col, skipeids=None): |
39 |
self.skipeids = skipeids |
|
40 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
41 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
42 |
def render_entity_attributes(self, entity): |
0 | 43 |
self.w(u'<h3>') |
44 |
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
|
45 |
if entity.prefered: |
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' (<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
|
47 |
self.w(u'</h3>') |
0 | 48 |
try: |
49 |
persons = entity.reverse_primary_email |
|
50 |
except Unauthorized: |
|
51 |
persons = [] |
|
52 |
if persons: |
|
53 |
emailof = persons[0] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
54 |
self.field(display_name(self._cw, 'primary_email', 'object'), emailof.view('oneline')) |
0 | 55 |
pemaileid = emailof.eid |
56 |
else: |
|
57 |
pemaileid = None |
|
58 |
try: |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
59 |
emailof = 'use_email' in self._cw.vreg.schema and entity.reverse_use_email or () |
0 | 60 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
61 |
except Unauthorized: |
|
62 |
emailof = [] |
|
63 |
if emailof: |
|
64 |
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
|
65 |
self.field(display_name(self._cw, 'use_email', 'object'), emailofstr) |
0 | 66 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
67 |
def render_entity_relations(self, entity): |
0 | 68 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
69 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
70 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
71 |
self.w(u'</div>') |
|
72 |
||
73 |
||
74 |
class EmailAddressShortPrimaryView(EmailAddressPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
75 |
__select__ = implements('EmailAddress') |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
76 |
__regid__ = 'shortprimary' |
0 | 77 |
title = None # hidden view |
1639 | 78 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
79 |
def render_entity_attributes(self, entity): |
0 | 80 |
self.w(u'<h5>') |
81 |
entity.view('oneline', w=self.w) |
|
82 |
self.w(u'</h5>') |
|
83 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
84 |
|
0 | 85 |
class EmailAddressOneLineView(baseviews.OneLineView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
86 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
87 |
|
0 | 88 |
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
|
89 |
entity = self.cw_rset.get_entity(row, col) |
0 | 90 |
if entity.reverse_primary_email: |
91 |
self.w(u'<b>') |
|
92 |
if entity.alias: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
93 |
self.w(u'%s <' % xml_escape(entity.alias)) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
94 |
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
|
95 |
xml_escape(entity.display_address()))) |
0 | 96 |
if entity.alias: |
97 |
self.w(u'>\n') |
|
98 |
if entity.reverse_primary_email: |
|
99 |
self.w(u'</b>') |
|
100 |
||
3220
11b6016e3970
cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3204
diff
changeset
|
101 |
|
0 | 102 |
class EmailAddressMailToView(baseviews.OneLineView): |
103 |
"""A one line view that builds a user clickable URL for an email with |
|
104 |
'mailto:'""" |
|
105 |
||
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
106 |
__regid__ = 'mailto' |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
107 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
108 |
|
0 | 109 |
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
|
110 |
entity = self.cw_rset.get_entity(row, col) |
0 | 111 |
if entity.reverse_primary_email: |
112 |
self.w(u'<b>') |
|
113 |
if entity.alias: |
|
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
114 |
alias = entity.alias |
0 | 115 |
elif entity.reverse_use_email: |
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
116 |
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
|
117 |
else: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
118 |
alias = None |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
119 |
if alias: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
120 |
mailto = "mailto:%s <%s>" % (alias, entity.display_address()) |
0 | 121 |
else: |
122 |
mailto = "mailto:%s" % entity.display_address() |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
123 |
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
|
124 |
xml_escape(entity.display_address()))) |
0 | 125 |
if entity.reverse_primary_email: |
126 |
self.w(u'</b>') |
|
127 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
128 |
|
4362
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
129 |
class EmailAddressInContextView(baseviews.InContextView): |
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
130 |
__select__ = implements('EmailAddress') |
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
131 |
|
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
132 |
def cell_call(self, row, col, **kwargs): |
817851a77e27
incontext view of EmailAddress is a mailto: link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
133 |
self.wview('mailto', self.cw_rset, row=row, col=col, **kwargs) |
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): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
137 |
__select__ = implements('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()) |