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