author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Fri, 10 Apr 2009 11:32:32 +0200 | |
changeset 1333 | 85d1bc9da0ad |
parent 950 | 8ac01018f499 |
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 |
|
13 |
from cubicweb.web import INTERNAL_FIELD_VALUE |
|
14 |
from cubicweb.web.form import EntityForm |
|
523 | 15 |
from cubicweb.web.views.baseviews import PrimaryView, EntityView |
557 | 16 |
|
0 | 17 |
class EUserPrimaryView(PrimaryView): |
18 |
accepts = ('EUser',) |
|
19 |
skip_attrs = ('firstname', 'surname') |
|
20 |
||
21 |
def iter_relations(self, entity): |
|
22 |
# don't want to display user's entities |
|
23 |
for rschema, targetschemas, x in super(EUserPrimaryView, self).iter_relations(entity): |
|
24 |
if x == 'object' and rschema.type in ('owned_by', 'for_user'): |
|
25 |
continue |
|
26 |
yield rschema, targetschemas, x |
|
27 |
||
28 |
def content_title(self, entity): |
|
29 |
return entity.name() |
|
30 |
||
31 |
def is_side_related(self, rschema, eschema): |
|
32 |
return rschema.type in ['interested_in', 'tags', |
|
33 |
'todo_by', 'bookmarked_by', |
|
556 | 34 |
] |
523 | 35 |
class FoafView(EntityView): |
36 |
id = 'foaf' |
|
37 |
accepts = ('EUser',) |
|
38 |
title = _('foaf') |
|
39 |
templatable = False |
|
40 |
content_type = 'text/xml' |
|
41 |
||
42 |
def call(self): |
|
950 | 43 |
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
|
44 |
<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
|
45 |
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
|
46 |
xmlns:foaf="http://xmlns.com/foaf/0.1/"> '''% self.req.encoding) |
523 | 47 |
for i in xrange(self.rset.rowcount): |
48 |
self.cell_call(i, 0) |
|
49 |
self.w(u'</rdf:RDF>\n') |
|
50 |
||
51 |
def cell_call(self, row, col): |
|
52 |
entity = self.complete_entity(row, col) |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
53 |
self.w(u'''<foaf:PersonalProfileDocument rdf:about=""> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
54 |
<foaf:maker rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
55 |
<foaf:primaryTopic rdf:resource="%s"/> |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
56 |
</foaf:PersonalProfileDocument>''' % (entity.absolute_url(), entity.absolute_url())) |
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
57 |
|
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
58 |
self.w(u'<foaf:Person rdf:ID="%s">\n' % entity.eid) |
523 | 59 |
self.w(u'<foaf:name>%s</foaf:name>\n' % html_escape(entity.dc_long_title())) |
60 |
if entity.surname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
61 |
self.w(u'<foaf:family_name>%s</foaf:family_name>\n' |
523 | 62 |
% html_escape(entity.surname)) |
63 |
if entity.firstname: |
|
555
b40d885ba7a4
new foaf version
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
523
diff
changeset
|
64 |
self.w(u'<foaf:givenname>%s</foaf:givenname>\n' |
523 | 65 |
% html_escape(entity.firstname)) |
66 |
emailaddr = entity.get_email() |
|
67 |
if emailaddr: |
|
586 | 68 |
self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr)) |
69 |
self.w(u'</foaf:Person>\n') |
|
926
6d3d693c0ad5
removing foaf_usable
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
619
diff
changeset
|
70 |
|
0 | 71 |
class EditGroups(EntityForm): |
72 |
"""displays a simple euser / egroups editable table""" |
|
73 |
||
74 |
id = 'editgroups' |
|
75 |
accepts = ('EUser',) |
|
76 |
||
77 |
def call(self): |
|
78 |
self.req.add_css('cubicweb.acl.css') |
|
79 |
_ = self.req._ |
|
80 |
self.w(u'<form id="editgroup" method="post" action="edit">') |
|
81 |
self.w(u'<table id="groupedit">\n') |
|
82 |
self.w(u'<tr>') |
|
83 |
self.w(u'<th>%s</th>' % display_name(self.req, 'EUser')) |
|
84 |
self.w(u''.join(u'<th>%s</th>' % _(gname) for geid, gname in self.egroups)) |
|
85 |
self.w(u'</tr>') |
|
86 |
for row in xrange(len(self.rset)): |
|
87 |
self.build_table_line(row) |
|
88 |
self.w(u'</table>') |
|
89 |
self.w(u'<fieldset>') |
|
90 |
self.w(self.button_cancel()) |
|
91 |
self.w(self.button_ok()) |
|
92 |
self.w(u'</fieldset>') |
|
93 |
self.w(u'</form>') |
|
94 |
||
95 |
||
96 |
def build_table_line(self, row): |
|
97 |
euser = self.entity(row) |
|
98 |
euser_groups = [group.name for group in euser.in_group] |
|
99 |
if euser_groups: |
|
100 |
self.w(u'<tr>') |
|
101 |
else: |
|
102 |
self.w(u'<tr class="nogroup">') |
|
103 |
self.w(u'<th><fieldset>') |
|
104 |
self.w(u'<input type="hidden" name="eid" value="%s" />' % euser.eid) |
|
105 |
self.w(u'<input type="hidden" name="__type:%s" value="EUser" />' % euser.eid) |
|
106 |
# this should not occur (for now) since in_group relation is mandatory |
|
107 |
if not euser_groups: |
|
108 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s">' % |
|
109 |
(euser.eid, INTERNAL_FIELD_VALUE)) |
|
110 |
self.w(euser.dc_title()) |
|
111 |
self.w(u'</fieldset></th>') |
|
112 |
for geid, gname in self.egroups: |
|
113 |
self.w(u'<td><fieldset>') |
|
114 |
if gname in euser_groups: |
|
115 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s" />' % |
|
116 |
(euser.eid, geid)) |
|
117 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" checked="checked" />' % |
|
118 |
(euser.eid, geid)) |
|
119 |
else: |
|
120 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" />' % |
|
121 |
(euser.eid, geid)) |
|
122 |
self.w(u'</fieldset></td>') |
|
123 |
self.w(u'</tr>\n') |
|
124 |
||
125 |
||
126 |
@property |
|
127 |
@cached |
|
128 |
def egroups(self): |
|
129 |
groups = self.req.execute('Any G, N ORDERBY N WHERE G is EGroup, G name N') |
|
130 |
return [(geid, gname) for geid, gname in groups.rows if gname != 'owners'] |
|
131 |
||
132 |