web/views/vcard.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1416 67e3e9d93f2c
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from cubicweb.selectors import implements
     9 from cubicweb.selectors import implements
    10 from cubicweb.view import EntityView
    10 from cubicweb.view import EntityView
    11 
    11 
    12 _ = unicode 
    12 _ = unicode
    13 
    13 
    14 VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'}
    14 VCARD_PHONE_TYPES = {'home': 'HOME', 'office': 'WORK', 'mobile': 'CELL', 'fax': 'FAX'}
    15 
    15 
    16 class VCardCWUserView(EntityView):
    16 class VCardCWUserView(EntityView):
    17     """export a person information as a vcard"""
    17     """export a person information as a vcard"""
    18     id = 'vcard'
    18     id = 'vcard'
    19     title = _('vcard')
    19     title = _('vcard')
    20     templatable = False
    20     templatable = False
    21     content_type = 'text/x-vcard'
    21     content_type = 'text/x-vcard'
    22     __select__ = implements('CWUser')        
    22     __select__ = implements('CWUser')
    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)