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