-
Notifications
You must be signed in to change notification settings - Fork 2k
/
_util.html
320 lines (286 loc) · 12.7 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
<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=""
>
<div py:def="markdown_editor(fieldname,value,id,placeholder)" class="markdown-editor">
<ul class="button-row">
<li><button class="btn js-markdown-edit depressed">Edit</button></li>
<li><button class="btn js-markdown-preview">Preview</button></li>
</ul>
<div>
<textarea class="markdown-input" name="${fieldname}" id="${id}" placeholder="${placeholder}">${value}</textarea>
</div>
<div class="markdown-preview" style="display: none;"></div>
<span class="hints">You can use <a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown formatting</a> here.</span>
</div>
<!--! 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['display_name'], h.url_for(controller='tag', action='read', id=tag['name']))}
</li>
</py:for>
</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 -->
<py:def function="package_list(packages)">
${package_list_from_dict(h.convert_to_dict('package', packages))}
</py:def>
<py:def function="package_list_from_dict(packages)">
${h.snippet('snippets/package_list.html', packages=packages)}
</py:def>
<!--! 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 scope="col">Title</th><th scope="col">Number of datasets</th><th scope="col">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 scope="col">Title</th><th scope="col">Number of datasets</th><th scope="col">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 scope="col">Title</th><th scope="col">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>
<py:def function="related_summary(related, allow_delete)">
<li id="related-item-${related.id}" class="span3">
<div class="thumbnail">
<button py:if="allow_delete and h.check_access('related_delete',{'id': '%s' % related.id})" class="close" data-action="delete" data-related-id="${related.id}">×</button>
<a href="${h.url_for('related_read', id=related.id)}" class="image">
<img src="${related.image_url}" width="210" py:if="related.image_url" />
<img src="/images/photo-placeholder.png" width="210" py:if="not related.image_url" />
</a>
<span style="display:none;">${related.view_count}</span>
<div class="caption">
<h5 class="heading" title="${related.title}">${h.markdown_extract(related.title, extract_length=30)}</h5>
<div class="description" data-truncate="55" py:if="related.description">${h.markdown_extract(related.description, extract_length=1000)}</div>
<i class="empty" py:if="not related.description">No description for this item</i>
<p class="read-more"><a href="${h.url_for('related_read', id=related.id)}">View this ${related.type}</a></p>
</div>
</div>
</li>
</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 scope="col"> User </th>
<py:for each="role in roles">
<th scope="col"> ${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 scope="col">User Group</th>
<py:for each="role in roles">
<th scope="col"> ${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 scope="col">User</th>
<py:for each="role in roles">
<th scole="col"> ${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 scope="col">User Group</th>
<py:for each="role in roles">
<th scope="col"> ${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>
<py:def function="revision_list(revisions, allow_compare=False)">
${revision_list_from_dict(h.convert_to_dict('revisions', revisions), allow_compare=allow_compare)}
</py:def>
<py:def function="revision_list_from_dict(revisions, allow_compare=False)">
${h.snippet('snippets/revision_list.html', revisions=revisions, allow_compare=allow_compare)}
</py:def>
<!--! 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>