web/views/euser.py
changeset 555 b40d885ba7a4
parent 523 f01cfce2e8d2
child 556 64d26324d3eb
equal deleted inserted replaced
554:f412343c89ad 555:b40d885ba7a4
    11 
    11 
    12 from cubicweb.schema import display_name
    12 from cubicweb.schema import display_name
    13 from cubicweb.web import INTERNAL_FIELD_VALUE
    13 from cubicweb.web import INTERNAL_FIELD_VALUE
    14 from cubicweb.web.form import EntityForm
    14 from cubicweb.web.form import EntityForm
    15 from cubicweb.web.views.baseviews import PrimaryView, EntityView
    15 from cubicweb.web.views.baseviews import PrimaryView, EntityView
       
    16    
       
    17 try:
       
    18     from hashlib import sha1 as sha
       
    19 
       
    20 except ImportError:
       
    21     from sha import sha
    16 
    22 
    17 class EUserPrimaryView(PrimaryView):
    23 class EUserPrimaryView(PrimaryView):
    18     accepts = ('EUser',)
    24     accepts = ('EUser',)
    19     skip_attrs = ('firstname', 'surname')
    25     skip_attrs = ('firstname', 'surname')
    20     
    26     
    29         return entity.name()
    35         return entity.name()
    30 
    36 
    31     def is_side_related(self, rschema, eschema):
    37     def is_side_related(self, rschema, eschema):
    32         return  rschema.type in ['interested_in', 'tags', 
    38         return  rschema.type in ['interested_in', 'tags', 
    33                                  'todo_by', 'bookmarked_by',
    39                                  'todo_by', 'bookmarked_by',
    34                                  ]
       
    35 
       
    36 class FoafView(EntityView):
    40 class FoafView(EntityView):
    37     id = 'foaf'
    41     id = 'foaf'
    38     accepts = ('EUser',)
    42     accepts = ('EUser',)
    39     title = _('foaf')
    43     title = _('foaf')
    40     templatable = False
    44     templatable = False
    41     content_type = 'text/xml'
    45     content_type = 'text/xml'
    42 
    46 
    43     def call(self):
    47     def call(self):
    44         self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding)
    48         self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding)
    45         self.w(u'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n')
    49         self.w(u'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n')
       
    50         self.w(u'xmlns:rdfs="http://www.w3org/2000/01/rdf-schema#"\n')
    46         self.w(u'xmlns:foaf="http://xmlns.com/foaf/0.1/">\n')
    51         self.w(u'xmlns:foaf="http://xmlns.com/foaf/0.1/">\n')
    47         for i in xrange(self.rset.rowcount):
    52         for i in xrange(self.rset.rowcount):
    48             self.cell_call(i, 0)
    53             self.cell_call(i, 0)
    49         self.w(u'</rdf:RDF>\n')
    54         self.w(u'</rdf:RDF>\n')
    50 
    55 
    51     def cell_call(self, row, col):
    56     def cell_call(self, row, col):
    52         entity = self.complete_entity(row, col)
    57         entity = self.complete_entity(row, col)
    53         self.w(u'<foaf:Person>\n')
    58         self.w(u'''<foaf:PersonalProfileDocument rdf:about="">
       
    59                       <foaf:maker rdf:resource="%s"/>
       
    60                       <foaf:primaryTopic rdf:resource="%s"/>
       
    61                    </foaf:PersonalProfileDocument>''' % (entity.absolute_url(), entity.absolute_url()))
       
    62                       
       
    63         self.w(u'<foaf:Person rdf:ID="%s">\n' % entity.eid)
    54         self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title()))
    64         self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title()))
    55         if entity.surname:
    65         if entity.surname:
    56             self.w(u'<foaf:surname>%s</foaf:surname>\n'
    66             self.w(u'<foaf:family_name>%s</foaf:family_name>\n'
    57                    % html_escape(entity.surname))
    67                    % html_escape(entity.surname))
    58         if entity.firstname:
    68         if entity.firstname:
    59             self.w(u'<foaf:firstname>%s</foaf:firstname>\n'
    69             self.w(u'<foaf:givenname>%s</foaf:givenname>\n'
    60                    % html_escape(entity.firstname))
    70                    % html_escape(entity.firstname))
    61         emailaddr = entity.get_email()
    71         emailaddr = entity.get_email()
    62         if emailaddr:
    72         if emailaddr:
    63             self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr))
    73             m = hashlib.sha1()
       
    74             m.update(html_escape(emailaddr))
       
    75             crypt_sha1 = m.hexdigest()
       
    76             self.w(u'<foaf:mbox_sha1sum>%s</foaf:mbox_sha1sum>\n' % crypt_sha1)
    64         self.w(u'</foaf:Person>\n')
    77         self.w(u'</foaf:Person>\n')
    65 
    78 
    66 
    79 
    67 class EditGroups(EntityForm):
    80 class EditGroups(EntityForm):
    68     """displays a simple euser / egroups editable table"""
    81     """displays a simple euser / egroups editable table"""