author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 25 Mar 2010 14:49:24 +0100 | |
branch | stable |
changeset 5018 | 2f2d9bc6dca4 |
parent 4252 | 6c4f109c2b03 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""vcard import / export |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
10
diff
changeset
|
10 |
from cubicweb.selectors import implements |
889 | 11 |
from cubicweb.view import EntityView |
0 | 12 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
13 |
_ = unicode |
10
36d1e8d715af
Add _ declaration as unicode.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
14 |
|
0 | 15 |
VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'} |
16 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
889
diff
changeset
|
17 |
class VCardCWUserView(EntityView): |
0 | 18 |
"""export a person information as a vcard""" |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
19 |
__regid__ = 'vcard' |
0 | 20 |
title = _('vcard') |
21 |
templatable = False |
|
22 |
content_type = 'text/x-vcard' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1416
diff
changeset
|
23 |
__select__ = implements('CWUser') |
0 | 24 |
|
25 |
def set_request_content_type(self): |
|
26 |
"""overriden to set a .vcf filename""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
27 |
self._cw.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
|
28 |
|
0 | 29 |
def cell_call(self, row, col): |
30 |
self.vcard_header() |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
31 |
self.vcard_content(self.cw_rset.complete_entity(row, col)) |
0 | 32 |
self.vcard_footer() |
33 |
||
34 |
def vcard_header(self): |
|
35 |
self.w(u'BEGIN:vcard\n') |
|
36 |
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
|
37 |
|
0 | 38 |
def vcard_footer(self): |
39 |
self.w(u'NOTE:this card has been generated by CubicWeb\n') |
|
40 |
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
|
41 |
|
0 | 42 |
def vcard_content(self, entity): |
43 |
who = u'%s %s' % (entity.surname or '', |
|
44 |
entity.firstname or '') |
|
45 |
w = self.w |
|
46 |
w(u'FN:%s\n' % who) |
|
47 |
w(u'N:%s;;;;\n' % entity.login) |
|
48 |
w(u'TITLE:%s\n' % who) |
|
49 |
for email in entity.use_email: |
|
50 |
w(u'EMAIL;TYPE=INTERNET:%s\n' % email.address) |
|
51 |
||
52 |
from logilab.common.deprecation import class_renamed |
|
1416 | 53 |
VCardEuserView = VCardEUserView = class_renamed('VCardEuserView', VCardCWUserView) |