author | sylvain.thenault@logilab.fr |
Wed, 15 Apr 2009 17:30:03 +0200 | |
branch | tls-sprint |
changeset 1373 | 5e6abf61636d |
parent 889 | 609edca88406 |
child 1398 | 5fe84a5f7035 |
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 |
||
16 |
class VCardEUserView(EntityView): |
|
17 |
"""export a person information as a vcard""" |
|
18 |
id = 'vcard' |
|
19 |
title = _('vcard') |
|
20 |
templatable = False |
|
21 |
content_type = 'text/x-vcard' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
22 |
__select__ = implements('EUser') |
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 |
|
52 |
VCardEuserView = class_renamed('VCardEuserView', VCardEUserView) |