author | sylvain.thenault@logilab.fr |
Wed, 08 Apr 2009 11:52:10 +0200 | |
branch | tls-sprint |
changeset 1288 | 0d0f09c36bba |
parent 1153 | 6a7636b32a97 |
child 1398 | 5fe84a5f7035 |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for users |
2 |
||
3 |
:organization: Logilab |
|
523 | 4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
523 | 9 |
from logilab.mtconverter import html_escape |
0 | 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 |
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
|
14 |
from cubicweb.web.views.baseviews import PrimaryView |
557 | 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 |
|
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
|
17 |
uicfg.rcategories.set_rtag('secondary', 'firstname', 'subject', 'EUser') |
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
|
18 |
uicfg.rcategories.set_rtag('secondary', 'surname', 'subject', 'EUser') |
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
|
19 |
uicfg.rcategories.set_rtag('metadata', 'last_login_time', 'subject', 'EUser') |
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
|
20 |
uicfg.rcategories.set_rtag('primary', 'in_group', 'subject', 'EUser') |
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
|
21 |
uicfg.rcategories.set_rtag('generated', 'owned_by', 'object', otype='EUser') |
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
|
22 |
uicfg.rcategories.set_rtag('generated', 'created_by', 'object', otype='EUser') |
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
|
23 |
uicfg.rcategories.set_rtag('metadata', 'bookmarked_by', 'object', otype='EUser') |
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
|
24 |
uicfg.rinlined.set_rtag(True, 'use_email', 'subject', 'EUser') |
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
|
25 |
uicfg.rmode.set_rtag('create', 'in_group', 'subject', 'EGroup') |
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
|
26 |
uicfg.rmode.set_rtag('link', 'owned_by', 'object', 'EUser') |
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
|
27 |
uicfg.rmode.set_rtag('link', 'created_by', 'object', 'EUser') |
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
|
28 |
uicfg.rmode.set_rtag('create', 'bookmarked_by', 'object', 'EUser') |
1151 | 29 |
|
30 |
||
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
|
31 |
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
|
32 |
id = 'prefs' |
753
17d38f000bea
some minor __select__ composition fixes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
33 |
__select__ = (one_line_rset() & implements('EUser') & |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
34 |
match_user_groups('owners', 'managers')) |
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
|
35 |
|
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
|
36 |
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
|
37 |
category = 'mainactions' |
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 |
|
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
|
39 |
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
|
40 |
login = self.rset.get_entity(self.row or 0, self.col or 0).login |
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 |
return self.build_url('euser/%s'%login, vid='epropertiesform') |
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
|
42 |
|
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 |
|
0 | 44 |
class EUserPrimaryView(PrimaryView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
45 |
__select__ = implements('EUser') |
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
|
46 |
|
0 | 47 |
skip_attrs = ('firstname', 'surname') |
48 |
||
49 |
def iter_relations(self, entity): |
|
50 |
# don't want to display user's entities |
|
51 |
for rschema, targetschemas, x in super(EUserPrimaryView, self).iter_relations(entity): |
|
52 |
if x == 'object' and rschema.type in ('owned_by', 'for_user'): |
|
53 |
continue |
|
54 |
yield rschema, targetschemas, x |
|
55 |
||
56 |
def content_title(self, entity): |
|
57 |
return entity.name() |
|
58 |
||
59 |
def is_side_related(self, rschema, eschema): |
|
60 |
return rschema.type in ['interested_in', 'tags', |
|
61 |
'todo_by', 'bookmarked_by', |
|
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
|
62 |
|
556 | 63 |
] |
523 | 64 |
class FoafView(EntityView): |
65 |
id = 'foaf' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
66 |
__select__ = implements('EUser') |
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
|
67 |
|
523 | 68 |
title = _('foaf') |
69 |
templatable = False |
|
70 |
content_type = 'text/xml' |
|
71 |
||
72 |
def call(self): |
|
950 | 73 |
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
|
74 |
<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
|
75 |
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
|
76 |
xmlns:foaf="http://xmlns.com/foaf/0.1/"> '''% self.req.encoding) |
523 | 77 |
for i in xrange(self.rset.rowcount): |
78 |
self.cell_call(i, 0) |
|
79 |
self.w(u'</rdf:RDF>\n') |
|
80 |
||
81 |
def cell_call(self, row, col): |
|
82 |
entity = self.complete_entity(row, col) |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
83 |
self.w(u'''<foaf:PersonalProfileDocument rdf:about=""> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
84 |
<foaf:maker rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
85 |
<foaf:primaryTopic rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
86 |
</foaf:PersonalProfileDocument>''' % (entity.absolute_url(), entity.absolute_url())) |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
87 |
self.w(u'<foaf:Person rdf:ID="%s">\n' % entity.eid) |
523 | 88 |
self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title())) |
89 |
if entity.surname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
90 |
self.w(u'<foaf:family_name>%s</foaf:family_name>\n' |
523 | 91 |
% html_escape(entity.surname)) |
92 |
if entity.firstname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
93 |
self.w(u'<foaf:givenname>%s</foaf:givenname>\n' |
523 | 94 |
% html_escape(entity.firstname)) |
95 |
emailaddr = entity.get_email() |
|
96 |
if emailaddr: |
|
586 | 97 |
self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr)) |
98 |
self.w(u'</foaf:Person>\n') |