author | sylvain.thenault@logilab.fr |
Thu, 26 Mar 2009 20:54:40 +0100 | |
branch | tls-sprint |
changeset 1153 | 6a7636b32a97 |
parent 1151 | b20677336ee6 |
child 1288 | 0d0f09c36bba |
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 |
||
9 |
from logilab.common.decorators import cached |
|
523 | 10 |
from logilab.mtconverter import html_escape |
0 | 11 |
|
12 |
from cubicweb.schema import display_name |
|
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
|
13 |
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
|
14 |
from cubicweb.view import EntityView |
0 | 15 |
from cubicweb.web import INTERNAL_FIELD_VALUE |
765
8fda14081686
kill Form, EntityForm and AnyRsetForm
sylvain.thenault@logilab.fr
parents:
753
diff
changeset
|
16 |
from cubicweb.web.form import FormMixIn |
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
|
17 |
from cubicweb.web.action import Action |
523 | 18 |
from cubicweb.web.views.baseviews import PrimaryView, EntityView |
1153 | 19 |
from cubicweb.web.views.editforms import AutomaticEntityForm |
1151 | 20 |
from cubicweb.web.views.boxes import EditBox |
557 | 21 |
|
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
|
22 |
|
1151 | 23 |
AutomaticEntityForm.rcategories.set_rtag('secondary', 'firstname', 'subject', 'EUser') |
24 |
AutomaticEntityForm.rcategories.set_rtag('secondary', 'surname', 'subject', 'EUser') |
|
25 |
AutomaticEntityForm.rcategories.set_rtag('metadata', 'last_login_time', 'subject', 'EUser') |
|
26 |
AutomaticEntityForm.rcategories.set_rtag('primary', 'in_group', 'subject', 'EUser') |
|
27 |
AutomaticEntityForm.rcategories.set_rtag('generated', 'owned_by', 'object', 'EUser') |
|
28 |
AutomaticEntityForm.rcategories.set_rtag('metadata', 'created_by', 'object', 'EUser') |
|
29 |
AutomaticEntityForm.rcategories.set_rtag('metadata', 'bookmarked_by', 'object', 'EUser') |
|
30 |
AutomaticEntityForm.rinlined.set_rtag(True, 'use_email', 'subject', 'EUser') |
|
31 |
||
32 |
EditBox.rmode.set_rtag('create', 'in_group', 'subject', 'EGroup') |
|
33 |
EditBox.rmode.set_rtag('link', 'owned_by', 'object', 'EUser') |
|
34 |
EditBox.rmode.set_rtag('link', 'created_by', 'object', 'EUser') |
|
35 |
EditBox.rmode.set_rtag('create', 'bookmarked_by', 'object', 'EUser') |
|
36 |
||
37 |
||
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
|
38 |
class UserPreferencesEntityAction(Action): |
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 |
id = 'prefs' |
753
17d38f000bea
some minor __select__ composition fixes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
40 |
__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
|
41 |
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
|
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 |
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
|
44 |
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
|
45 |
|
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 |
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
|
47 |
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
|
48 |
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
|
49 |
|
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
|
50 |
|
0 | 51 |
class EUserPrimaryView(PrimaryView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
52 |
__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
|
53 |
|
0 | 54 |
skip_attrs = ('firstname', 'surname') |
55 |
||
56 |
def iter_relations(self, entity): |
|
57 |
# don't want to display user's entities |
|
58 |
for rschema, targetschemas, x in super(EUserPrimaryView, self).iter_relations(entity): |
|
59 |
if x == 'object' and rschema.type in ('owned_by', 'for_user'): |
|
60 |
continue |
|
61 |
yield rschema, targetschemas, x |
|
62 |
||
63 |
def content_title(self, entity): |
|
64 |
return entity.name() |
|
65 |
||
66 |
def is_side_related(self, rschema, eschema): |
|
67 |
return rschema.type in ['interested_in', 'tags', |
|
68 |
'todo_by', 'bookmarked_by', |
|
556 | 69 |
] |
523 | 70 |
class FoafView(EntityView): |
71 |
id = 'foaf' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
72 |
__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
|
73 |
|
523 | 74 |
title = _('foaf') |
75 |
templatable = False |
|
76 |
content_type = 'text/xml' |
|
77 |
||
78 |
def call(self): |
|
950 | 79 |
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
|
80 |
<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
|
81 |
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
|
82 |
xmlns:foaf="http://xmlns.com/foaf/0.1/"> '''% self.req.encoding) |
523 | 83 |
for i in xrange(self.rset.rowcount): |
84 |
self.cell_call(i, 0) |
|
85 |
self.w(u'</rdf:RDF>\n') |
|
86 |
||
87 |
def cell_call(self, row, col): |
|
88 |
entity = self.complete_entity(row, col) |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
89 |
self.w(u'''<foaf:PersonalProfileDocument rdf:about=""> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
90 |
<foaf:maker rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
91 |
<foaf:primaryTopic rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
92 |
</foaf:PersonalProfileDocument>''' % (entity.absolute_url(), entity.absolute_url())) |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
93 |
self.w(u'<foaf:Person rdf:ID="%s">\n' % entity.eid) |
523 | 94 |
self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title())) |
95 |
if entity.surname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
96 |
self.w(u'<foaf:family_name>%s</foaf:family_name>\n' |
523 | 97 |
% html_escape(entity.surname)) |
98 |
if entity.firstname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
99 |
self.w(u'<foaf:givenname>%s</foaf:givenname>\n' |
523 | 100 |
% html_escape(entity.firstname)) |
101 |
emailaddr = entity.get_email() |
|
102 |
if emailaddr: |
|
586 | 103 |
self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr)) |
104 |
self.w(u'</foaf:Person>\n') |
|
523 | 105 |
|
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
|
106 |
|
765
8fda14081686
kill Form, EntityForm and AnyRsetForm
sylvain.thenault@logilab.fr
parents:
753
diff
changeset
|
107 |
class EditGroups(FormMixIn, EntityView): |
0 | 108 |
"""displays a simple euser / egroups editable table""" |
109 |
||
110 |
id = 'editgroups' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
111 |
__select__ = implements('EUser') |
0 | 112 |
|
113 |
def call(self): |
|
114 |
self.req.add_css('cubicweb.acl.css') |
|
115 |
_ = self.req._ |
|
116 |
self.w(u'<form id="editgroup" method="post" action="edit">') |
|
117 |
self.w(u'<table id="groupedit">\n') |
|
118 |
self.w(u'<tr>') |
|
119 |
self.w(u'<th>%s</th>' % display_name(self.req, 'EUser')) |
|
120 |
self.w(u''.join(u'<th>%s</th>' % _(gname) for geid, gname in self.egroups)) |
|
121 |
self.w(u'</tr>') |
|
122 |
for row in xrange(len(self.rset)): |
|
123 |
self.build_table_line(row) |
|
124 |
self.w(u'</table>') |
|
125 |
self.w(u'<fieldset>') |
|
126 |
self.w(self.button_cancel()) |
|
127 |
self.w(self.button_ok()) |
|
128 |
self.w(u'</fieldset>') |
|
129 |
self.w(u'</form>') |
|
130 |
||
131 |
||
132 |
def build_table_line(self, row): |
|
133 |
euser = self.entity(row) |
|
134 |
euser_groups = [group.name for group in euser.in_group] |
|
135 |
if euser_groups: |
|
136 |
self.w(u'<tr>') |
|
137 |
else: |
|
138 |
self.w(u'<tr class="nogroup">') |
|
139 |
self.w(u'<th><fieldset>') |
|
140 |
self.w(u'<input type="hidden" name="eid" value="%s" />' % euser.eid) |
|
141 |
self.w(u'<input type="hidden" name="__type:%s" value="EUser" />' % euser.eid) |
|
142 |
# this should not occur (for now) since in_group relation is mandatory |
|
143 |
if not euser_groups: |
|
144 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s">' % |
|
145 |
(euser.eid, INTERNAL_FIELD_VALUE)) |
|
146 |
self.w(euser.dc_title()) |
|
147 |
self.w(u'</fieldset></th>') |
|
148 |
for geid, gname in self.egroups: |
|
149 |
self.w(u'<td><fieldset>') |
|
150 |
if gname in euser_groups: |
|
151 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s" />' % |
|
152 |
(euser.eid, geid)) |
|
153 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" checked="checked" />' % |
|
154 |
(euser.eid, geid)) |
|
155 |
else: |
|
156 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" />' % |
|
157 |
(euser.eid, geid)) |
|
158 |
self.w(u'</fieldset></td>') |
|
159 |
self.w(u'</tr>\n') |
|
160 |
||
161 |
||
162 |
@property |
|
163 |
@cached |
|
164 |
def egroups(self): |
|
165 |
groups = self.req.execute('Any G, N ORDERBY N WHERE G is EGroup, G name N') |
|
166 |
return [(geid, gname) for geid, gname in groups.rows if gname != 'owners'] |
|
167 |
||
168 |