1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """vcard import / export |
|
19 |
|
20 """ |
|
21 __docformat__ = "restructuredtext en" |
|
22 |
|
23 from cubicweb.predicates import is_instance |
|
24 from cubicweb.view import EntityView |
|
25 |
|
26 from cubicweb import _ |
|
27 |
|
28 VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'} |
|
29 |
|
30 class VCardCWUserView(EntityView): |
|
31 """export a person information as a vcard""" |
|
32 __regid__ = 'vcard' |
|
33 title = _('vcard') |
|
34 templatable = False |
|
35 content_type = 'text/x-vcard' |
|
36 __select__ = is_instance('CWUser') |
|
37 |
|
38 def set_request_content_type(self): |
|
39 """overriden to set a .vcf filename""" |
|
40 self._cw.set_content_type(self.content_type, filename='vcard.vcf') |
|
41 |
|
42 def cell_call(self, row, col): |
|
43 self.vcard_header() |
|
44 self.vcard_content(self.cw_rset.complete_entity(row, col)) |
|
45 self.vcard_footer() |
|
46 |
|
47 def vcard_header(self): |
|
48 self.w(u'BEGIN:vcard\n') |
|
49 self.w(u'VERSION:3.0\n') |
|
50 |
|
51 def vcard_footer(self): |
|
52 self.w(u'NOTE:this card has been generated by CubicWeb\n') |
|
53 self.w(u'END:vcard\n') |
|
54 |
|
55 def vcard_content(self, entity): |
|
56 who = u'%s %s' % (entity.surname or '', |
|
57 entity.firstname or '') |
|
58 w = self.w |
|
59 w(u'FN:%s\n' % who) |
|
60 w(u'N:%s;;;;\n' % entity.login) |
|
61 w(u'TITLE:%s\n' % who) |
|
62 for email in entity.use_email: |
|
63 w(u'EMAIL;TYPE=INTERNET:%s\n' % email.address) |
|
64 |
|
65 from logilab.common.deprecation import class_renamed |
|
66 VCardEuserView = VCardEUserView = class_renamed('VCardEuserView', VCardCWUserView) |
|