|
1 """vcard import / export |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 """ |
|
7 __docformat__ = "restructuredtext en" |
|
8 |
|
9 from cubicweb.common.view import EntityView |
|
10 |
|
11 VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'} |
|
12 |
|
13 class VCardEUserView(EntityView): |
|
14 """export a person information as a vcard""" |
|
15 id = 'vcard' |
|
16 title = _('vcard') |
|
17 templatable = False |
|
18 content_type = 'text/x-vcard' |
|
19 accepts = ('EUser',) |
|
20 |
|
21 |
|
22 def set_request_content_type(self): |
|
23 """overriden to set a .vcf filename""" |
|
24 self.req.set_content_type(self.content_type, filename='vcard.vcf') |
|
25 |
|
26 def cell_call(self, row, col): |
|
27 self.vcard_header() |
|
28 self.vcard_content(self.complete_entity(row, col)) |
|
29 self.vcard_footer() |
|
30 |
|
31 def vcard_header(self): |
|
32 self.w(u'BEGIN:vcard\n') |
|
33 self.w(u'VERSION:3.0\n') |
|
34 |
|
35 def vcard_footer(self): |
|
36 self.w(u'NOTE:this card has been generated by CubicWeb\n') |
|
37 self.w(u'END:vcard\n') |
|
38 |
|
39 def vcard_content(self, entity): |
|
40 who = u'%s %s' % (entity.surname or '', |
|
41 entity.firstname or '') |
|
42 w = self.w |
|
43 w(u'FN:%s\n' % who) |
|
44 w(u'N:%s;;;;\n' % entity.login) |
|
45 w(u'TITLE:%s\n' % who) |
|
46 for email in entity.use_email: |
|
47 w(u'EMAIL;TYPE=INTERNET:%s\n' % email.address) |
|
48 |
|
49 from logilab.common.deprecation import class_renamed |
|
50 VCardEuserView = class_renamed('VCardEuserView', VCardEUserView) |