author | sylvain.thenault@logilab.fr |
Tue, 28 Apr 2009 16:22:00 +0200 | |
branch | tls-sprint |
changeset 1508 | 45632d28ace3 |
parent 1498 | 2c6eec0b46b9 |
child 1554 | 3a3263df6cdd |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for email addresses entities |
2 |
||
3 |
:organization: Logilab |
|
1151 | 4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
9 |
from logilab.mtconverter import html_escape |
|
10 |
||
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
11 |
from cubicweb.selectors import implements |
0 | 12 |
from cubicweb.common import Unauthorized |
13 |
from cubicweb.web.views import baseviews |
|
1151 | 14 |
|
0 | 15 |
|
16 |
class EmailAddressPrimaryView(baseviews.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 |
|
0 | 23 |
def render_entity_attributes(self, entity, siderelations): |
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 |
||
56 |
def render_entity_relations(self, entity, siderelations): |
|
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 |
|
67 |
def render_entity_attributes(self, entity, siderelations): |
|
68 |
self.w(u'<h5>') |
|
69 |
entity.view('oneline', w=self.w) |
|
70 |
self.w(u'</h5>') |
|
71 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
72 |
|
0 | 73 |
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
|
74 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
75 |
|
0 | 76 |
def cell_call(self, row, col, **kwargs): |
77 |
entity = self.entity(row, col) |
|
78 |
if entity.reverse_primary_email: |
|
79 |
self.w(u'<b>') |
|
80 |
if entity.alias: |
|
81 |
self.w(u'%s <' % html_escape(entity.alias)) |
|
82 |
self.w('<a href="%s">%s</a>' % (html_escape(entity.absolute_url()), |
|
83 |
html_escape(entity.display_address()))) |
|
84 |
if entity.alias: |
|
85 |
self.w(u'>\n') |
|
86 |
if entity.reverse_primary_email: |
|
87 |
self.w(u'</b>') |
|
88 |
||
89 |
class EmailAddressMailToView(baseviews.OneLineView): |
|
90 |
"""A one line view that builds a user clickable URL for an email with |
|
91 |
'mailto:'""" |
|
92 |
||
93 |
id = 'mailto' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
94 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
95 |
|
0 | 96 |
def cell_call(self, row, col, **kwargs): |
97 |
entity = self.entity(row, col) |
|
98 |
if entity.reverse_primary_email: |
|
99 |
self.w(u'<b>') |
|
100 |
if entity.alias: |
|
101 |
mailto = u'%s <%s>' % (entity.alias, entity.display_address()) |
|
102 |
elif entity.reverse_use_email: |
|
103 |
mailto = "mailto:%s <%s>" % \ |
|
104 |
(entity.reverse_use_email[0].dc_title(), |
|
105 |
entity.display_address()) |
|
106 |
else: |
|
107 |
mailto = "mailto:%s" % entity.display_address() |
|
108 |
self.w(u'<a href="%s">%s</a>' % (html_escape(mailto), |
|
109 |
html_escape(entity.display_address()))) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
110 |
|
0 | 111 |
if entity.alias: |
112 |
self.w(u'>\n') |
|
113 |
if entity.reverse_primary_email: |
|
114 |
self.w(u'</b>') |
|
115 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
116 |
|
0 | 117 |
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
|
118 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
119 |
|
0 | 120 |
def cell_call(self, row, col, **kwargs): |
121 |
self.w(self.entity(row, col).display_address()) |