author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Mon, 16 Feb 2009 16:24:24 +0100 | |
branch | tls-sprint |
changeset 630 | 66ff0b2f7d03 |
parent 619 | 9efa2cc9c02c |
child 631 | 99f5852f8604 |
child 926 | 6d3d693c0ad5 |
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): |
|
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
|
43 |
self.w('''<?xml version="1.0" encoding="%s"?> |
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') |
|
523 | 70 |
|
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
|
71 |
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
|
72 |
id = 'foaf_usable' |
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
|
73 |
|
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 |
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
|
75 |
self.cell_call(0, 0) |
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 |
|
0 | 77 |
class EditGroups(EntityForm): |
78 |
"""displays a simple euser / egroups editable table""" |
|
79 |
||
80 |
id = 'editgroups' |
|
81 |
accepts = ('EUser',) |
|
82 |
||
83 |
def call(self): |
|
84 |
self.req.add_css('cubicweb.acl.css') |
|
85 |
_ = self.req._ |
|
86 |
self.w(u'<form id="editgroup" method="post" action="edit">') |
|
87 |
self.w(u'<table id="groupedit">\n') |
|
88 |
self.w(u'<tr>') |
|
89 |
self.w(u'<th>%s</th>' % display_name(self.req, 'EUser')) |
|
90 |
self.w(u''.join(u'<th>%s</th>' % _(gname) for geid, gname in self.egroups)) |
|
91 |
self.w(u'</tr>') |
|
92 |
for row in xrange(len(self.rset)): |
|
93 |
self.build_table_line(row) |
|
94 |
self.w(u'</table>') |
|
95 |
self.w(u'<fieldset>') |
|
96 |
self.w(self.button_cancel()) |
|
97 |
self.w(self.button_ok()) |
|
98 |
self.w(u'</fieldset>') |
|
99 |
self.w(u'</form>') |
|
100 |
||
101 |
||
102 |
def build_table_line(self, row): |
|
103 |
euser = self.entity(row) |
|
104 |
euser_groups = [group.name for group in euser.in_group] |
|
105 |
if euser_groups: |
|
106 |
self.w(u'<tr>') |
|
107 |
else: |
|
108 |
self.w(u'<tr class="nogroup">') |
|
109 |
self.w(u'<th><fieldset>') |
|
110 |
self.w(u'<input type="hidden" name="eid" value="%s" />' % euser.eid) |
|
111 |
self.w(u'<input type="hidden" name="__type:%s" value="EUser" />' % euser.eid) |
|
112 |
# this should not occur (for now) since in_group relation is mandatory |
|
113 |
if not euser_groups: |
|
114 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s">' % |
|
115 |
(euser.eid, INTERNAL_FIELD_VALUE)) |
|
116 |
self.w(euser.dc_title()) |
|
117 |
self.w(u'</fieldset></th>') |
|
118 |
for geid, gname in self.egroups: |
|
119 |
self.w(u'<td><fieldset>') |
|
120 |
if gname in euser_groups: |
|
121 |
self.w(u'<input type="hidden" name="edits-in_group:%s" value="%s" />' % |
|
122 |
(euser.eid, geid)) |
|
123 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" checked="checked" />' % |
|
124 |
(euser.eid, geid)) |
|
125 |
else: |
|
126 |
self.w(u'<input type="checkbox" name="in_group:%s" value="%s" />' % |
|
127 |
(euser.eid, geid)) |
|
128 |
self.w(u'</fieldset></td>') |
|
129 |
self.w(u'</tr>\n') |
|
130 |
||
131 |
||
132 |
@property |
|
133 |
@cached |
|
134 |
def egroups(self): |
|
135 |
groups = self.req.execute('Any G, N ORDERBY N WHERE G is EGroup, G name N') |
|
136 |
return [(geid, gname) for geid, gname in groups.rows if gname != 'owners'] |
|
137 |
||
138 |