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