author | sylvain.thenault@logilab.fr |
Wed, 13 May 2009 17:00:08 +0200 | |
branch | tls-sprint |
changeset 1788 | d6e6ad70e50a |
parent 1639 | 375c857aa0f5 |
child 1977 | 606923dff11b |
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 |
1639 | 13 |
from cubicweb.web.views import baseviews, primary |
1151 | 14 |
|
1639 | 15 |
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
|
16 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
17 |
|
0 | 18 |
def cell_call(self, row, col, skipeids=None): |
19 |
self.skipeids = skipeids |
|
20 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
21 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
22 |
def render_entity_attributes(self, entity): |
0 | 23 |
self.w(u'<h3>') |
24 |
entity.view('oneline', w=self.w) |
|
25 |
if not entity.canonical: |
|
26 |
canonemailaddr = entity.canonical_form() |
|
27 |
if canonemailaddr: |
|
28 |
self.w(u' (<i>%s</i>)' % canonemailaddr.view('oneline')) |
|
29 |
self.w(u'</h3>') |
|
30 |
elif entity.identical_to: |
|
31 |
self.w(u'</h3>') |
|
32 |
identicaladdr = [e.view('oneline') for e in entity.identical_to] |
|
33 |
self.field('identical_to', ', '.join(identicaladdr)) |
|
34 |
else: |
|
35 |
self.w(u'</h3>') |
|
36 |
try: |
|
37 |
persons = entity.reverse_primary_email |
|
38 |
except Unauthorized: |
|
39 |
persons = [] |
|
40 |
if persons: |
|
41 |
emailof = persons[0] |
|
42 |
self.field(display_name(self.req, 'primary_email', 'object'), emailof.view('oneline')) |
|
43 |
pemaileid = emailof.eid |
|
44 |
else: |
|
45 |
pemaileid = None |
|
46 |
try: |
|
47 |
emailof = 'use_email' in self.schema and entity.reverse_use_email or () |
|
48 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
|
49 |
except Unauthorized: |
|
50 |
emailof = [] |
|
51 |
if emailof: |
|
52 |
emailofstr = ', '.join(e.view('oneline') for e in emailof) |
|
53 |
self.field(display_name(self.req, 'use_email', 'object'), emailofstr) |
|
54 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
55 |
def render_entity_relations(self, entity): |
0 | 56 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
57 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
58 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
59 |
self.w(u'</div>') |
|
60 |
||
61 |
||
62 |
class EmailAddressShortPrimaryView(EmailAddressPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
63 |
__select__ = implements('EmailAddress') |
0 | 64 |
id = 'shortprimary' |
65 |
title = None # hidden view |
|
1639 | 66 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
67 |
def render_entity_attributes(self, entity): |
0 | 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()) |