-
Notifications
You must be signed in to change notification settings - Fork 2k
/
_util.html
474 lines (440 loc) · 17.3 KB
/
_util.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<xi:include href="_util_activity_div.html" />
<!--! Herein can be found generic helper methods for a whole bunch of common
templating issues -->
<!--! plural(n, s, p): takes a number, a singular form and a plural form,
returning the appropriate form on the basis of the number specified -->
<py:def function="plural(num, s, p)" py:choose="num">
<py:when test="1">${s}</py:when>
<py:otherwise>${p}</py:otherwise>
</py:def>
<!--! nonempty(val, default): takes a variable string, and returns it or a
fallback 'default' string if it's blank -->
<py:def function="nonempty(val, default)" py:choose="val">
<py:when test="str(val).strip()">${val}</py:when>
<py:otherwise>${default}</py:otherwise>
</py:def>
<!--! List of tags: pass in a collection of tags and this renders the standard
tag listing -->
<ul py:def="tag_list(tags)" class="tags clearfix">
<py:for each="tag in tags">
<li py:if="not tag.get('vocabulary_id')">
${h.link_to(tag['name'], h.url_for(controller='tag', action='read', id=tag['name']))}
</li>
</py:for>
</ul>
<!--! List of tags: pass in a list of tag name and this renders the standard
tag listing -->
<ul py:def="tag_list_from_name(tags)" class="tags clearfix">
<li py:for="tag in tags">
${h.link_to(tag, h.url_for(controller='tag', action='read', id=tag))}
</li>
</ul>
<!--! List of users: pass in a collection of users and this renders the standard
user listing -->
<ul py:def="user_list(users)" class="users">
<li py:for="user in users">
${h.linked_user(user)}
</li>
</ul>
<!--! List of datasets: pass in a collection of tags and this renders the
standard dataset listing -->
<ul py:def="package_list(packages)" class="datasets">
<li py:for="package in packages"
class="${'fullyopen' if (package.isopen() and package.resources) else None}">
<div class="header">
<span class="title">
${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}
</span>
<div class="search_meta">
<py:if test="package.resources">
<ul class="dataset_formats">
<py:for each="resource in package.resources">
<py:if test="resource.format and not resource.format == ''">
<li><a href="${resource.url}"
title="${resource.description}">${resource.format}</a></li>
</py:if>
</py:for>
</ul>
</py:if>
<ul class="openness">
<py:if test="package.isopen()">
<li>
<a href="http://opendefinition.org/okd/" title="This dataset satisfies the Open Definition.">
<img src="http://assets.okfn.org/images/ok_buttons/od_80x15_blue.png" alt="[Open Data]" />
</a>
</li>
</py:if>
<py:if test="not package.isopen()">
<li>
<span class="closed">
${h.icon('lock')} Not Openly Licensed
</span>
</li>
</py:if>
</ul>
</div>
</div>
<div class="extract">
${h.markdown_extract(package.notes)}
</div>
<!--ul py:if="package.tags" class="tags">
<li py:for="tag in package.tags">${tag.name}</li>
</ul-->
</li>
</ul>
<ul py:def="package_list_from_dict(packages)" class="datasets">
<li py:for="package in packages"
class="${'fullyopen' if (package.isopen and package.get('resources')) else None}">
<div class="header">
<span class="title">
${h.link_to(package.get('title') or package.get('name'), h.url_for(controller='package', action='read', id=package.get('name')))}
</span>
<div class="search_meta">
<py:if test="package.resources">
<ul class="dataset_formats">
<py:for each="resource in package.resources">
<py:if test="resource.get('format')">
<li><a href="${resource.get('url')}"
title="${resource.get('description')}">${resource.get('format')}</a></li>
</py:if>
</py:for>
</ul>
</py:if>
<ul class="openness">
<py:if test="package.isopen">
<li>
<a href="http://opendefinition.org/okd/" title="This dataset satisfies the Open Definition.">
<img src="http://assets.okfn.org/images/ok_buttons/od_80x15_blue.png" alt="[Open Data]" />
</a>
</li>
</py:if>
<py:if test="not package.isopen">
<li>
<span class="closed">
${h.icon('lock')} Not Openly Licensed
</span>
</li>
</py:if>
</ul>
</div>
</div>
<div class="extract">
${h.markdown_extract(package.notes)}
</div>
<!--ul py:if="package.tags" class="tags">
<li py:for="tag in package.tags">${tag.name}</li>
</ul-->
</li>
</ul>
<!--! List of dataset groups: pass in a collection of dataset groups
and this renders the standard group listing -->
<table class="table table-bordered table-striped table-condensed groups" py:def="group_list(groups)">
<tr><th>Title</th><th>Number of datasets</th><th>Description</th></tr>
<py:for each="group in groups">
<tr>
<td><a href="${h.url_for(controller='group', action='read', id=group.name)}">${group.display_name}</a></td>
<td>${len(group.packages)}</td>
<td>${h.truncate(group.description, length=80, whole_word=True)}</td>
</tr>
</py:for>
</table>
<!--! List of dataset groups: pass in a collection of dataset groups
and this renders the standard group listing. Same as the above, but using dictionaries -->
<table class="table table-bordered table-striped table-condensed groups" py:def="group_list_from_dict(groups)">
<tr><th>Title</th><th>Number of datasets</th><th>Description</th></tr>
<py:for each="group in groups">
<tr>
<td><a href="${h.url_for( '%s_read' % str(group['type']) , action='read', id=group['name'])}">${group['display_name']}</a></td>
<td>${group['packages']}</td>
<td>${h.truncate(group['description'], length=80, whole_word=True)}</td>
</tr>
</py:for>
</table>
<!--! List of authorization groups: pass in a collection of authorization groups and
this renders the standard group listing -->
<table class="table table-bordered table-striped table-condensed authorization_groups" py:def="authorization_group_list(authorization_groups)">
<tr><th>Title</th><th>Number of members</th></tr>
<py:for each="authorization_group in authorization_groups">
<tr>
<td><a href="${h.url_for(controller='authorization_group', action='read', id=authorization_group.name or authorization_group.id)}">
${authorization_group.name or authorization_group.id}</a>
</td>
<td>${len(authorization_group.users)}</td>
</tr>
</py:for>
</table>
<!--! Dataset openness icons -->
<img py:def="package_license_icon(package)"
src="${h.url_for('/images/icons/door_%s.png' % 'open' if package.isopen() else 'grey')}"
title="License: ${package.license.title if hasattr(package.license, 'title') else '?'}"
alt="${'OPEN' if package.isopen() else 'CLOSED'}" />
<py:def function="package_resources_icon(package)" py:choose="">
<a py:when="package.resources"
href="${h.url_for(controller='package', action='read', id=package.name, anchor='resources')}">
<img src="${h.icon_url('arrow_down')}" title="View dataset resources" alt="DOWNLOAD" />
</a>
<img py:otherwise="" src="${h.icon_url('arrow_down_grey')}" title="No downloadable resources." alt="" />
</py:def>
<py:def function="resource_summary(pkg, res)">
<a href="${h.url_for(controller='package', action='resource_read', id=pkg.id, resource_id=res.id)}">
${h.resource_display_name(res)}
</a>
</py:def>
<!--! Used by group listing -->
<py:def function="package_summary(pkg)">
<a href="${h.url_for(controller='package', action='read', id=pkg.name)}">
${pkg.name} - ${pkg.title}
</a>
</py:def>
<div py:def="package_rating(pkg)" class="rating-group">
<py:choose test="">
<div py:when="c.num_ratings" class="inline-rating">
<ul class="stars default${'%i' % (c.current_rating or 0)}star">
<li class="${name}" py:for="number,name in enumerate(['one', 'two', 'three', 'four', 'five'])"></li>
</ul>
${'%0.1f (%i rating%s)' % (c.current_rating, c.num_ratings, ('s' if c.num_ratings != 1 else ''))}
</div>
<py:otherwise>no ratings yet</py:otherwise>
</py:choose>
–
rate it now
<div class="inline-rating">
<ul class="stars default0star">
<py:for each="number,name in zip(range(1,6), ['one', 'two', 'three', 'four', 'five'])">
<li class="${name}">
<a href="${h.url_for(controller='package',action='rate',id=c.pkg.name,rating=number)}" title="${number} Star">${number}</a>
</li>
</py:for>
</ul>
</div>
</div><!--! /rating-group -->
<table class="table table-bordered table-striped table-condensed" py:def="authz_form_table(id, roles, users, user_role_dict)">
<tr>
<th> User </th>
<py:for each="role in roles">
<th> ${role} </th>
</py:for>
</tr>
<py:for each="user in users">
<tr>
<td>
${h.linked_user(user)}
</td>
<py:for each="role in roles">
<td>
<input type="hidden" name="${ h.literal( '%s$%s' % (user,role)) }" value="submitted"/>
<py:choose>
<py:when test="user_role_dict[(user,role)]">
<input type="checkbox"
name="${ h.literal( '%s$%s' % (user,role)) }"
checked='checked'/>
</py:when>
<py:otherwise>
<input type="checkbox"
name="${ h.literal( '%s$%s' % (user,role)) }"
/>
</py:otherwise>
</py:choose>
</td>
</py:for>
</tr>
</py:for>
</table>
<!--! Copy and paste of above table. Only difference when created was the h.linked_user for the -->
<!--! table rows. How to combine the two? -->
<table class="table table-bordered table-striped table-condensed" py:def="authz_form_group_table(id, roles, users, user_role_dict)">
<tr>
<th>User Group</th>
<py:for each="role in roles">
<th> ${role} </th>
</py:for>
</tr>
<py:for each="user in users">
<tr>
<td>
${h.linked_authorization_group(user)}
</td>
<py:for each="role in roles">
<td>
<input type="hidden" name="${ h.literal( '%s$%s' % (user,role)) }" value="submitted"/>
<py:choose>
<py:when test="user_role_dict[(user,role)]">
<input type="checkbox"
name="${ h.literal( '%s$%s' % (user,role)) }"
checked='checked'/>
</py:when>
<py:otherwise>
<input type="checkbox"
name="${ h.literal( '%s$%s' % (user,role)) }"
/>
</py:otherwise>
</py:choose>
</td>
</py:for>
</tr>
</py:for>
</table>
<table class="table table-bordered table-striped table-condensed" py:def="authz_add_table(roles)">
<tr>
<th>User</th>
<py:for each="role in roles">
<th> ${role} </th>
</py:for>
</tr>
<tr>
<td>
<input type="textbox" name="new_user_name" class="autocomplete-user" />
</td>
<py:for each="role in roles">
<td>
<input type="hidden" name="${ h.literal( '%s' % role) }" value="submitted"/>
<input type="checkbox" name="${ h.literal( '%s' % role) }"/>
</td>
</py:for>
</tr>
</table>
<!--! again, copy-and-paste of above, this time to attach different autocompletion -->
<table class="table table-bordered table-striped table-condensed" py:def="authz_add_group_table(roles)">
<tr>
<th>User Group</th>
<py:for each="role in roles">
<th> ${role} </th>
</py:for>
</tr>
<tr>
<td>
<input type="textbox" name="new_user_name" class="autocomplete-authzgroup" />
</td>
<py:for each="role in roles">
<td>
<input type="hidden" name="${ h.literal( '%s' % role) }" value="submitted"/>
<input type="checkbox" name="${ h.literal( '%s' % role) }"/>
</td>
</py:for>
</tr>
</table>
<table class="table table-bordered table-striped table-condensed" py:def="revision_list(revisions, allow_compare=False)">
<tr>
<th>Revision</th><th>Timestamp</th><th>Author</th><th>Entity</th><th>Log Message</th>
</tr>
<tr
class="state-${revision.state}"
py:for="revision in revisions"
>
<td>
${
h.link_to(revision.id,
h.url_for(
controller='revision',
action='read',
id=revision.id)
)
}
<py:if test="c.revision_change_state_allowed">
<div class="actions">
<form
method="POST"
action="${h.url_for(controller='revision',
action='edit',
id=revision.id)}"
id="undelete-${revision.id}"
>
<py:if test="revision.state!='deleted'">
<input type="hidden" name="action" value="delete"/>
<input type="submit" name="submit" value="Delete" class="btn btn-small" />
</py:if>
<py:if test="revision.state=='deleted'">
<input type="hidden" name="action" value="undelete"/>
<input type="submit" name="submit" value="Undelete" class="btn btn-small" />
</py:if>
</form>
</div>
</py:if>
</td>
<td>${h.render_datetime(revision.timestamp, with_hours=True)}</td>
<td>${h.linked_user(revision.author)}</td>
<td>
<py:for each="pkg in revision.packages">
<a href="${h.url_for(controller='package', action='read', id=pkg.name)}">${pkg.name}</a>
</py:for>
<py:for each="grp in revision.groups">
<a href="${h.url_for(controller='group', action='read', id=grp.name)}">${grp.name}</a>
</py:for>
</td>
<td>${revision.message}</td>
</tr>
</table>
<table class="table table-bordered table-striped table-condensed" py:def="revision_list_from_dict(revisions, allow_compare=False)">
<tr>
<th>Revision</th><th>Timestamp</th><th>Author</th><th>Entity</th><th>Log Message</th>
</tr>
<tr
class="state-${revision['state']}"
py:for="revision in revisions"
>
<td>
${
h.link_to(revision['id'],
h.url_for(
controller='revision',
action='read',
id=revision['id'])
)
}
<py:if test="c.revision_change_state_allowed">
<div class="actions">
<form
method="POST"
action="${h.url_for(controller='revision',
action='edit',
id=revision['id'])}"
>
<py:if test="revision['state']!='deleted'">
<button type="submit" name="action" value="delete" class="btn btn-small">Delete</button>
</py:if>
<py:if test="revision['state']=='deleted'">
<button type="submit" name="action" value="undelete" class="btn btn-small">Undelete</button>
</py:if>
</form>
</div>
</py:if>
</td>
<td>${revision['timestamp']}</td>
<td>${h.linked_user(revision['author'])}</td>
<td>
<py:for each="pkg in revision['packages']">
<a href="${h.url_for(controller='package', action='read', id=pkg)}">${pkg}</a>
</py:for>
<py:for each="grp in revision['groups']">
<a href="${h.url_for(controller='group', action='read', id=grp)}">${grp}</a>
</py:for>
</td>
<td>${revision['message']}</td>
</tr>
</table>
<!--! jsConditionalForIe(ieVersion, tagContent, matchOperator): takes a
IE version number, a tag or other HTML code that will be wrapped inside
a IE conditional comment, and the comparison operator (lt, lte, etc..
see http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx)
returning Genshi stream ready to be shown in a template.
NOTE:
Internet Explorer Conditional Import are confused as Genshi comments
and python variables and method calls are not executed if inside them.
This function helps to output tags with Python code inside conditional
comments, eg ${h.url_for_static()} -->
<?python
from genshi import HTML
def jsConditionalForIe(ieVersion, tagContent, matchOperator = 'lt'):
html = HTML('<!--[if ' + matchOperator + ' IE ' + str(ieVersion) + ''']>
''' + tagContent + '''
<![endif]-->''')
return html
?>
</html>