author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 29 Jul 2009 09:08:26 +0200 | |
changeset 2550 | 4e009026a0f0 |
parent 2312 | af4d8f75c5db |
child 2789 | 39712da6f397 |
child 2996 | 866a2c135c33 |
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 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
10 |
from logilab.mtconverter import xml_escape |
0 | 11 |
|
2305
8f6dbe884700
import display_name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2164
diff
changeset
|
12 |
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
|
13 |
from cubicweb.selectors import implements |
0 | 14 |
from cubicweb.common import Unauthorized |
1639 | 15 |
from cubicweb.web.views import baseviews, primary |
1151 | 16 |
|
1639 | 17 |
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
|
18 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
19 |
|
0 | 20 |
def cell_call(self, row, col, skipeids=None): |
21 |
self.skipeids = skipeids |
|
22 |
super(EmailAddressPrimaryView, self).cell_call(row, col) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
23 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
24 |
def render_entity_attributes(self, entity): |
0 | 25 |
self.w(u'<h3>') |
26 |
entity.view('oneline', w=self.w) |
|
27 |
if not entity.canonical: |
|
28 |
canonemailaddr = entity.canonical_form() |
|
29 |
if canonemailaddr: |
|
30 |
self.w(u' (<i>%s</i>)' % canonemailaddr.view('oneline')) |
|
31 |
self.w(u'</h3>') |
|
32 |
elif entity.identical_to: |
|
33 |
self.w(u'</h3>') |
|
34 |
identicaladdr = [e.view('oneline') for e in entity.identical_to] |
|
35 |
self.field('identical_to', ', '.join(identicaladdr)) |
|
36 |
else: |
|
37 |
self.w(u'</h3>') |
|
38 |
try: |
|
39 |
persons = entity.reverse_primary_email |
|
40 |
except Unauthorized: |
|
41 |
persons = [] |
|
42 |
if persons: |
|
43 |
emailof = persons[0] |
|
44 |
self.field(display_name(self.req, 'primary_email', 'object'), emailof.view('oneline')) |
|
45 |
pemaileid = emailof.eid |
|
46 |
else: |
|
47 |
pemaileid = None |
|
48 |
try: |
|
49 |
emailof = 'use_email' in self.schema and entity.reverse_use_email or () |
|
50 |
emailof = [e for e in emailof if not e.eid == pemaileid] |
|
51 |
except Unauthorized: |
|
52 |
emailof = [] |
|
53 |
if emailof: |
|
54 |
emailofstr = ', '.join(e.view('oneline') for e in emailof) |
|
55 |
self.field(display_name(self.req, 'use_email', 'object'), emailofstr) |
|
56 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
57 |
def render_entity_relations(self, entity): |
0 | 58 |
for i, email in enumerate(entity.related_emails(self.skipeids)): |
59 |
self.w(u'<div class="%s">' % (i%2 and 'even' or 'odd')) |
|
60 |
email.view('oneline', w=self.w, contexteid=entity.eid) |
|
61 |
self.w(u'</div>') |
|
62 |
||
63 |
||
64 |
class EmailAddressShortPrimaryView(EmailAddressPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
65 |
__select__ = implements('EmailAddress') |
0 | 66 |
id = 'shortprimary' |
67 |
title = None # hidden view |
|
1639 | 68 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
69 |
def render_entity_attributes(self, entity): |
0 | 70 |
self.w(u'<h5>') |
71 |
entity.view('oneline', w=self.w) |
|
72 |
self.w(u'</h5>') |
|
73 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
74 |
|
0 | 75 |
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
|
76 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
77 |
|
0 | 78 |
def cell_call(self, row, col, **kwargs): |
79 |
entity = self.entity(row, col) |
|
80 |
if entity.reverse_primary_email: |
|
81 |
self.w(u'<b>') |
|
82 |
if entity.alias: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
83 |
self.w(u'%s <' % xml_escape(entity.alias)) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
84 |
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
|
85 |
xml_escape(entity.display_address()))) |
0 | 86 |
if entity.alias: |
87 |
self.w(u'>\n') |
|
88 |
if entity.reverse_primary_email: |
|
89 |
self.w(u'</b>') |
|
90 |
||
91 |
class EmailAddressMailToView(baseviews.OneLineView): |
|
92 |
"""A one line view that builds a user clickable URL for an email with |
|
93 |
'mailto:'""" |
|
94 |
||
95 |
id = 'mailto' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
96 |
__select__ = implements('EmailAddress') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
97 |
|
0 | 98 |
def cell_call(self, row, col, **kwargs): |
99 |
entity = self.entity(row, col) |
|
100 |
if entity.reverse_primary_email: |
|
101 |
self.w(u'<b>') |
|
102 |
if entity.alias: |
|
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
103 |
alias = entity.alias |
0 | 104 |
elif entity.reverse_use_email: |
2164
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
105 |
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
|
106 |
else: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
107 |
alias = None |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
108 |
if alias: |
e3aeb6e6c3bb
fix email address'mailto view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
109 |
mailto = "mailto:%s <%s>" % (alias, entity.display_address()) |
0 | 110 |
else: |
111 |
mailto = "mailto:%s" % entity.display_address() |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
112 |
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
|
113 |
xml_escape(entity.display_address()))) |
0 | 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()) |