web/views/cwuser.py
author sylvain.thenault@logilab.fr
Tue, 05 May 2009 19:31:00 +0200
branchtls-sprint
changeset 1699 f61402624f7b
parent 1639 375c857aa0f5
child 1720 14c9a0a1aca1
permissions -rw-r--r--
import cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""Specific views for users
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
     9
from logilab.mtconverter import html_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
692
800592b8d39b replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 688
diff changeset
    11
from cubicweb.selectors import one_line_rset, implements, match_user_groups
765
8fda14081686 kill Form, EntityForm and AnyRsetForm
sylvain.thenault@logilab.fr
parents: 753
diff changeset
    12
from cubicweb.view import EntityView
1288
0d0f09c36bba fix some euser rcategories, drop editgroup form which 1. is unused 2. has no advantage vs muledit of users
sylvain.thenault@logilab.fr
parents: 1153
diff changeset
    13
from cubicweb.web import uicfg, action
1639
375c857aa0f5 import from primary
sylvain.thenault@logilab.fr
parents: 1604
diff changeset
    14
from cubicweb.web.views import primary
557
8bb60606e5ad small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 556
diff changeset
    15
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    16
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    17
uicfg.rcategories.tag_relation('secondary', ('CWUser', 'firstname', '*'), 'subject')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    18
uicfg.rcategories.tag_relation('secondary', ('CWUser', 'surname', '*'), 'subject')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    19
uicfg.rcategories.tag_relation('metadata', ('CWUser', 'last_login_time', '*'), 'subject')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    20
uicfg.rcategories.tag_relation('primary', ('CWUser', 'in_group', '*'), 'subject')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    21
uicfg.rcategories.tag_relation('generated', ('*', 'owned_by', 'CWUser'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    22
uicfg.rcategories.tag_relation('generated', ('*', 'created_by', 'CWUser'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    23
uicfg.rcategories.tag_relation('metadata', ('*', 'bookmarked_by', 'CWUser'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    24
uicfg.rmode.tag_relation('create', ('*', 'in_group', 'CWGroup'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    25
uicfg.rmode.tag_relation('link', ('*', 'owned_by', 'CWUser'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    26
uicfg.rmode.tag_relation('link', ('*', 'created_by', 'CWUser'), 'object')
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1517
diff changeset
    27
uicfg.rmode.tag_relation('create', ('*', 'bookmarked_by', 'CWUser'), 'object')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1545
diff changeset
    28
uicfg.rdisplay.tag_attribute({}, 'CWUser', 'firstname')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1545
diff changeset
    29
uicfg.rdisplay.tag_attribute({}, 'CWUser', 'surname')
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    30
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 985
diff changeset
    31
1288
0d0f09c36bba fix some euser rcategories, drop editgroup form which 1. is unused 2. has no advantage vs muledit of users
sylvain.thenault@logilab.fr
parents: 1153
diff changeset
    32
class UserPreferencesEntityAction(action.Action):
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    33
    id = 'prefs'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    34
    __select__ = (one_line_rset() & implements('CWUser') &
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    35
                  match_user_groups('owners', 'managers'))
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    36
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    37
    title = _('preferences')
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    38
    category = 'mainactions'
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    39
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    40
    def url(self):
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    41
        login = self.rset.get_entity(self.row or 0, self.col or 0).login
1545
53d3d783370f some typos
Florent <florent@secondweb.fr>
parents: 1533
diff changeset
    42
        return self.build_url('cwuser/%s'%login, vid='epropertiesform')
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    43
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    44
1639
375c857aa0f5 import from primary
sylvain.thenault@logilab.fr
parents: 1604
diff changeset
    45
class CWUserPrimaryView(primary.PrimaryView):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    46
    __select__ = implements('CWUser')
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    47
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def content_title(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        return entity.name()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
1517
sylvain.thenault@logilab.fr
parents: 1508
diff changeset
    51
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    52
class FoafView(EntityView):
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    53
    id = 'foaf'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    54
    __select__ = implements('CWUser')
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    56
    title = _('foaf')
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    57
    templatable = False
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    58
    content_type = 'text/xml'
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    59
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    60
    def call(self):
950
8ac01018f499 require unicode
sylvain.thenault@logilab.fr
parents: 926
diff changeset
    61
        self.w(u'''<?xml version="1.0" encoding="%s"?>
619
9efa2cc9c02c adding foaf_usable views to supports reusing foaf fragment in other views (for instance sioc view)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 586
diff changeset
    62
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
9efa2cc9c02c adding foaf_usable views to supports reusing foaf fragment in other views (for instance sioc view)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 586
diff changeset
    63
         xmlns:rdfs="http://www.w3org/2000/01/rdf-schema#"
9efa2cc9c02c adding foaf_usable views to supports reusing foaf fragment in other views (for instance sioc view)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 586
diff changeset
    64
         xmlns:foaf="http://xmlns.com/foaf/0.1/"> '''% self.req.encoding)
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    65
        for i in xrange(self.rset.rowcount):
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    66
            self.cell_call(i, 0)
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    67
        self.w(u'</rdf:RDF>\n')
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    68
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    69
    def cell_call(self, row, col):
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    70
        entity = self.complete_entity(row, col)
555
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    71
        self.w(u'''<foaf:PersonalProfileDocument rdf:about="">
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    72
                      <foaf:maker rdf:resource="%s"/>
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    73
                      <foaf:primaryTopic rdf:resource="%s"/>
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    74
                   </foaf:PersonalProfileDocument>''' % (entity.absolute_url(), entity.absolute_url()))
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    75
        self.w(u'<foaf:Person rdf:ID="%s">\n' % entity.eid)
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    76
        self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title()))
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    77
        if entity.surname:
555
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    78
            self.w(u'<foaf:family_name>%s</foaf:family_name>\n'
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    79
                   % html_escape(entity.surname))
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    80
        if entity.firstname:
555
b40d885ba7a4 new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 523
diff changeset
    81
            self.w(u'<foaf:givenname>%s</foaf:givenname>\n'
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    82
                   % html_escape(entity.firstname))
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    83
        emailaddr = entity.get_email()
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    84
        if emailaddr:
586
09ec2839e447 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 568
diff changeset
    85
            self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr))
09ec2839e447 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 568
diff changeset
    86
        self.w(u'</foaf:Person>\n')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    87
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    88
from logilab.common.deprecation import class_renamed
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1288
diff changeset
    89
EUserPrimaryView = class_renamed('EUserPrimaryView', CWUserPrimaryView)