author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Jun 2009 16:41:09 +0200 | |
branch | stable |
changeset 2055 | e4283fc56873 |
parent 1977 | 606923dff11b |
child 2164 | e3aeb6e6c3bb |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for email addresses entities |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1639
diff
changeset
|
4 |
:copyright: 2001-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:
1639
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
12 |
from cubicweb.selectors import implements |
0 | 13 |
from cubicweb.common import Unauthorized |
1639 | 14 |
from cubicweb.web.views import baseviews, primary |
1151 | 15 |
|
1639 | 16 |
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
|
17 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
18 |
|
0 | 19 |
def cell_call(self, row, col, skipeids=None): |
20 |
self.skipeids = skipeids |
|
21 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
22 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
23 |
def render_entity_attributes(self, entity): |
0 | 24 |
self.w(u'<h3>') |
25 |
entity.view('oneline', w=self.w) |
|
26 |
if not entity.canonical: |
|
27 |
canonemailaddr = entity.canonical_form() |
|
28 |
if canonemailaddr: |
|
29 |
self.w(u' (<i>%s</i>)' % canonemailaddr.view('oneline')) |
|
30 |
self.w(u'</h3>') |
|
31 |
elif entity.identical_to: |
|
32 |
self.w(u'</h3>') |
|
33 |
identicaladdr = [e.view('oneline') for e in entity.identical_to] |
|
34 |
self.field('identical_to', ', '.join(identicaladdr)) |
|
35 |
else: |
|
36 |
self.w(u'</h3>') |
|
37 |
try: |
|
38 |
persons = entity.reverse_primary_email |
|
39 |
except Unauthorized: |
|
40 |
persons = [] |
|
41 |
if persons: |
|
42 |
emailof = persons[0] |
|
43 |
self.field(display_name(self.req, 'primary_email', 'object'), emailof.view('oneline')) |
|
44 |
pemaileid = emailof.eid |
|
45 |
else: |
|
46 |
pemaileid = None |
|
47 |
try: |
|
48 |
emailof = 'use_email' in self.schema and entity.reverse_use_email or () |
|
49 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
|
50 |
except Unauthorized: |
|
51 |
emailof = [] |
|
52 |
if emailof: |
|
53 |
emailofstr = ', '.join(e.view('oneline') for e in emailof) |
|
54 |
self.field(display_name(self.req, 'use_email', 'object'), emailofstr) |
|
55 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
56 |
def render_entity_relations(self, entity): |
0 | 57 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
58 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
59 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
60 |
self.w(u'</div>') |
|
61 |
||
62 |
||
63 |
class EmailAddressShortPrimaryView(EmailAddressPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
64 |
__select__ = implements('EmailAddress') |
0 | 65 |
id = 'shortprimary' |
66 |
title = None # hidden view |
|
1639 | 67 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
68 |
def render_entity_attributes(self, entity): |
0 | 69 |
self.w(u'<h5>') |
70 |
entity.view('oneline', w=self.w) |
|
71 |
self.w(u'</h5>') |
|
72 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
73 |
|
0 | 74 |
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
|
75 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
76 |
|
0 | 77 |
def cell_call(self, row, col, **kwargs): |
78 |
entity = self.entity(row, col) |
|
79 |
if entity.reverse_primary_email: |
|
80 |
self.w(u'<b>') |
|
81 |
if entity.alias: |
|
82 |
self.w(u'%s <' % html_escape(entity.alias)) |
|
83 |
self.w('<a href="%s">%s</a>' % (html_escape(entity.absolute_url()), |
|
84 |
html_escape(entity.display_address()))) |
|
85 |
if entity.alias: |
|
86 |
self.w(u'>\n') |
|
87 |
if entity.reverse_primary_email: |
|
88 |
self.w(u'</b>') |
|
89 |
||
90 |
class EmailAddressMailToView(baseviews.OneLineView): |
|
91 |
"""A one line view that builds a user clickable URL for an email with |
|
92 |
'mailto:'""" |
|
93 |
||
94 |
id = 'mailto' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
95 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
96 |
|
0 | 97 |
def cell_call(self, row, col, **kwargs): |
98 |
entity = self.entity(row, col) |
|
99 |
if entity.reverse_primary_email: |
|
100 |
self.w(u'<b>') |
|
101 |
if entity.alias: |
|
102 |
mailto = u'%s <%s>' % (entity.alias, entity.display_address()) |
|
103 |
elif entity.reverse_use_email: |
|
104 |
mailto = "mailto:%s <%s>" % \ |
|
105 |
(entity.reverse_use_email[0].dc_title(), |
|
106 |
entity.display_address()) |
|
107 |
else: |
|
108 |
mailto = "mailto:%s" % entity.display_address() |
|
109 |
self.w(u'<a href="%s">%s</a>' % (html_escape(mailto), |
|
110 |
html_escape(entity.display_address()))) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
111 |
|
0 | 112 |
if entity.alias: |
113 |
self.w(u'>\n') |
|
114 |
if entity.reverse_primary_email: |
|
115 |
self.w(u'</b>') |
|
116 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
117 |
|
0 | 118 |
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
|
119 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
120 |
|
0 | 121 |
def cell_call(self, row, col, **kwargs): |
122 |
self.w(self.entity(row, col).display_address()) |