author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 29 Apr 2009 19:48:27 +0200 | |
branch | tls-sprint |
changeset 1559 | c4d4851bd18b |
parent 1416 | 67e3e9d93f2c |
child 1802 | d628defebc17 |
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 |
|
10
36d1e8d715af
Add _ declaration as unicode.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
12 |
_ = unicode |
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' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
889
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') |
|
27 |
||
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') |
|
36 |
||
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') |
|
40 |
||
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) |