author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 18 Jun 2009 09:38:32 +0200 | |
branch | stable |
changeset 2115 | c48ff1d0acc4 |
parent 1977 | 606923dff11b |
child 3408 | c92170fca813 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""vcard import / export |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
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:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
10
diff
changeset
|
10 |
from cubicweb.selectors import implements |
889 | 11 |
from cubicweb.view import EntityView |
0 | 12 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
13 |
_ = unicode |
10
36d1e8d715af
Add _ declaration as unicode.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
14 |
|
0 | 15 |
VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'} |
16 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
889
diff
changeset
|
17 |
class VCardCWUserView(EntityView): |
0 | 18 |
"""export a person information as a vcard""" |
19 |
id = 'vcard' |
|
20 |
title = _('vcard') |
|
21 |
templatable = False |
|
22 |
content_type = 'text/x-vcard' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
23 |
__select__ = implements('CWUser') |
0 | 24 |
|
25 |
def set_request_content_type(self): |
|
26 |
"""overriden to set a .vcf filename""" |
|
27 |
self.req.set_content_type(self.content_type, filename='vcard.vcf') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
28 |
|
0 | 29 |
def cell_call(self, row, col): |
30 |
self.vcard_header() |
|
31 |
self.vcard_content(self.complete_entity(row, col)) |
|
32 |
self.vcard_footer() |
|
33 |
||
34 |
def vcard_header(self): |
|
35 |
self.w(u'BEGIN:vcard\n') |
|
36 |
self.w(u'VERSION:3.0\n') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
37 |
|
0 | 38 |
def vcard_footer(self): |
39 |
self.w(u'NOTE:this card has been generated by CubicWeb\n') |
|
40 |
self.w(u'END:vcard\n') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
41 |
|
0 | 42 |
def vcard_content(self, entity): |
43 |
who = u'%s %s' % (entity.surname or '', |
|
44 |
entity.firstname or '') |
|
45 |
w = self.w |
|
46 |
w(u'FN:%s\n' % who) |
|
47 |
w(u'N:%s;;;;\n' % entity.login) |
|
48 |
w(u'TITLE:%s\n' % who) |
|
49 |
for email in entity.use_email: |
|
50 |
w(u'EMAIL;TYPE=INTERNET:%s\n' % email.address) |
|
51 |
||
52 |
from logilab.common.deprecation import class_renamed |
|
1416 | 53 |
VCardEuserView = VCardEUserView = class_renamed('VCardEuserView', VCardCWUserView) |