Merge lp:~allanlesage/qlbr/django-templates-instead-of-mako into lp:qlbr
- django-templates-instead-of-mako
- Merge into trunk
Proposed by
Allan LeSage
Status: | Merged |
---|---|
Merged at revision: | 47 |
Proposed branch: | lp:~allanlesage/qlbr/django-templates-instead-of-mako |
Merge into: | lp:qlbr |
Diff against target: |
358 lines (+94/-137) 3 files modified
qlbr/templates/qlbr/qa-default.html (+25/-76) qlbr/urls.py (+1/-4) qlbr/views.py (+68/-57) |
To merge this branch: | bzr merge lp:~allanlesage/qlbr/django-templates-instead-of-mako |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Max Brustkern (community) | Approve | ||
Review via email: mp+195308@code.launchpad.net |
Commit message
Switch from to mako to Django templating.
Description of the change
This is the flip to Django templates instead of mako--having compared the html this is pretty close :) , may need a few tweaks. I found that the colors at the beginning of qa-default.mako weren't needed?
To post a comment you must log in.
- 48. By Allan LeSage
-
Merged trunk.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'qlbr/templates' |
2 | === added directory 'qlbr/templates/qlbr' |
3 | === renamed file 'qa-default.mako' => 'qlbr/templates/qlbr/qa-default.html' |
4 | --- qa-default.mako 2013-11-06 22:06:48 +0000 |
5 | +++ qlbr/templates/qlbr/qa-default.html 2013-11-14 20:47:08 +0000 |
6 | @@ -1,48 +1,9 @@ |
7 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
8 | -<% |
9 | - import json |
10 | - importance_color = { |
11 | - "Unknown" : "importance-unknown", |
12 | - "Critical" : "importance-critical", |
13 | - "High" : "importance-high", |
14 | - "Medium" : "importance-medium", |
15 | - "Low" : "importance-low", |
16 | - "Wishlist" : "importance-wishlist", |
17 | - "Undecided" : "importance-undecided" |
18 | - } |
19 | - status_color = { |
20 | - "New" : "status-new", |
21 | - "Incomplete" : "status-incomplete", |
22 | - "Confirmed" : "status-confirmed", |
23 | - "Triaged" : "status-triaged", |
24 | - "In Progress" : "status-in_progress", |
25 | - "Fix Committed" : "status-fix_committed", |
26 | - "Fix Released" : "status-fix_released", |
27 | - "Invalid" : "status-invalid", |
28 | - "Won't Fix" : "status-wont_fix", |
29 | - "Opinion" : "status-opinion", |
30 | - "Expired" : "status-expired", |
31 | - "Unknown" : "status-unknown" |
32 | - } |
33 | - |
34 | - targets = {} |
35 | - for bugid in tasks: |
36 | - for task in tasks[bugid]: |
37 | - target = task['target'] |
38 | - name = task['target_display_name'] |
39 | - if target in targets: |
40 | - if target != name: |
41 | - targets[target] = name |
42 | - else: |
43 | - targets[target] = name |
44 | - |
45 | - target_report_order = sorted([(targets[target], target) for target in targets]) |
46 | -%> |
47 | <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> |
48 | |
49 | <head> |
50 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
51 | - <title>${report_title}</title> |
52 | + <title>{{ report_title }}</title> |
53 | |
54 | <link title="light" rel="stylesheet" href="http://people.canonical.com/~kernel/reports/css/light-style.css" type="text/css" media="print, projection, screen" /> |
55 | <link title="dark" rel="stylesheet" href="http://people.canonical.com/~kernel/reports/css/dark-style.css" type="text/css" media="print, projection, screen" /> |
56 | @@ -133,11 +94,10 @@ |
57 | |
58 | <div class="outermost"> |
59 | <div class="title"> |
60 | - ${report_title} |
61 | + {{ report_title }} |
62 | </div> |
63 | |
64 | -% if datefilter: |
65 | - <div> |
66 | + {% if datefilter %}<div> |
67 | <form name="datefilter"> |
68 | <table width="100%"> |
69 | <tr><td colspan="4">Created within:</td></tr> |
70 | @@ -148,14 +108,12 @@ |
71 | <td width="50"> <input type="radio" name="date" onclick="date_handler(this, 'date', true)" checked value="-1" /> Unlimited </td></tr> |
72 | </table> |
73 | </form> |
74 | - </div> |
75 | -% endif |
76 | + </div>{% endif %} |
77 | |
78 | -% for target_display_name, target in target_report_order: |
79 | - <% id = target %> |
80 | - <div class="section" id="${id}"> |
81 | - <div class="section-heading">${target_display_name}</div> |
82 | - <table id="${id}" class="tablesorter" border="0" cellpadding="0" cellspacing="1" width="100%%"> |
83 | + {% for target_display_name, target in target_report_order %} |
84 | + <div class="section" id="{{ target }}"> |
85 | + <div class="section-heading">{{ target_display_name }}</div> |
86 | + <table id="{{ target }}" class="tablesorter" border="0" cellpadding="0" cellspacing="1" width="100%%"> |
87 | <thead> |
88 | <tr> |
89 | <th width="40">Bug</th> |
90 | @@ -173,8 +131,7 @@ |
91 | </tbody> |
92 | </table> |
93 | </div> |
94 | -% endfor |
95 | - <br /> |
96 | + {% endfor %}<br /> |
97 | <br /> |
98 | <div> |
99 | <br /> |
100 | @@ -206,7 +163,7 @@ |
101 | <table width="100%%" cellspacing="0" cellpadding="0"> |
102 | <tr> |
103 | <td> |
104 | - ${timestamp} |
105 | + {{ timestamp }} |
106 | </td> |
107 | <td align="right"> |
108 | |
109 | @@ -267,9 +224,8 @@ |
110 | type: 'numeric' |
111 | }); |
112 | $(function() { |
113 | - % for _target_display_name, target in target_report_order: |
114 | - <% id = target %> |
115 | - $("#${id}").tablesorter({ |
116 | + {% for _target_display_name, target in target_report_order %} |
117 | + $("#{{ target }}").tablesorter({ |
118 | headers: { |
119 | 3: { |
120 | sorter:'importance' |
121 | @@ -280,7 +236,7 @@ |
122 | }, |
123 | widgets: ['zebra'] |
124 | }); |
125 | - % endfor |
126 | + {% endfor %} |
127 | }); |
128 | </script> |
129 | |
130 | @@ -290,7 +246,7 @@ |
131 | var task_status = ["New", "Incomplete", "Confirmed", "Fix Released", "Triaged", "Won't Fix", "In Progress", "Opinion", "Fix Committed", "Invalid"]; |
132 | var assignees = []; |
133 | var date_filter = -1; |
134 | - var jd = ${json.dumps(tasks, sort_keys=True, indent=4)}; |
135 | + var jd = {% autoescape off %}{{ tasks_json_dump }}{% endautoescape %}; |
136 | var first_time = true; |
137 | |
138 | var importance_color = { |
139 | @@ -320,10 +276,9 @@ |
140 | |
141 | var targets_id_list = []; |
142 | var targets_name_list = []; |
143 | - % for _target_display_name, target in target_report_order: |
144 | - targets_id_list.push("${target}"); |
145 | - targets_name_list.push("${target}"); |
146 | - % endfor |
147 | + {% for _target_display_name, target in target_report_order %}targets_id_list.push("{{ target }}"); |
148 | + targets_name_list.push("{{ target }}"); |
149 | + {% endfor %} |
150 | |
151 | function series_handler(chkbx, grp, update_table) { |
152 | series = []; |
153 | @@ -402,16 +357,12 @@ |
154 | |
155 | function update_tables() { |
156 | var tables = { |
157 | - % for _target_display_name, target in target_report_order: |
158 | - "${target}" : false, |
159 | - % endfor |
160 | - }; |
161 | + {% for _target_display_name, target in target_report_order %}"{{ target }}" : false, |
162 | + {% endfor %}}; |
163 | |
164 | var oddness = { |
165 | - % for _target_display_name, target in target_report_order: |
166 | - "${target}" : true, |
167 | - % endfor |
168 | - }; |
169 | + {% for _target_display_name, target in target_report_order %}"{{ target }}" : true, |
170 | + {% endfor %}}; |
171 | |
172 | $.each(jd, function(bid, tasks) { |
173 | $.each(tasks, function(index, task) { |
174 | @@ -425,13 +376,13 @@ |
175 | fail = true; |
176 | } |
177 | |
178 | -% if datefilter: |
179 | +{% if datefilter %} |
180 | if (!fail && date_filter != -1) { |
181 | if (task.age > date_filter) { |
182 | fail = true; |
183 | } |
184 | } |
185 | -% endif |
186 | +{% endif %} |
187 | s = ""; |
188 | if (!fail) { |
189 | if (oddness[task.target]) { |
190 | @@ -488,10 +439,8 @@ |
191 | series_handler(null, null, false); |
192 | importance_handler(null, null, false); |
193 | status_handler(null, null, false); |
194 | -% if datefilter: |
195 | - date_handler(null, null, false); |
196 | -% endif |
197 | - update_tables(); |
198 | + {% if datefilter %}date_handler(null, null, false); |
199 | + {% endif %}update_tables(); |
200 | }); |
201 | </script> |
202 | |
203 | |
204 | === modified file 'qlbr/urls.py' |
205 | --- qlbr/urls.py 2013-11-13 21:22:57 +0000 |
206 | +++ qlbr/urls.py 2013-11-14 20:47:08 +0000 |
207 | @@ -4,10 +4,7 @@ |
208 | admin.autodiscover() |
209 | |
210 | urlpatterns = patterns('', |
211 | - # Examples: |
212 | - # url(r'^$', 'qlbr.views.home', name='home'), |
213 | - # url(r'^qlbr/', include('qlbr.foo.urls')), |
214 | - |
215 | + url(r'^$', 'qlbr.views.index', name='index'), |
216 | url(r'^admin/doc/', include('django.contrib.admindocs.urls')), |
217 | url(r'^admin/', include(admin.site.urls)), |
218 | ) |
219 | |
220 | === renamed file 'qlbr/management/commands/generate_static_report.py' => 'qlbr/views.py' |
221 | --- qlbr/management/commands/generate_static_report.py 2013-11-12 23:33:00 +0000 |
222 | +++ qlbr/views.py 2013-11-14 20:47:08 +0000 |
223 | @@ -1,67 +1,78 @@ |
224 | -#!/usr/bin/env python |
225 | |
226 | import datetime |
227 | +import json |
228 | import re |
229 | |
230 | -from django.core.management.base import BaseCommand |
231 | +from django.shortcuts import render |
232 | from mako.template import Template |
233 | |
234 | from qlbr import TZ |
235 | from qlbr.models import Task |
236 | |
237 | |
238 | -class Command(BaseCommand): |
239 | - |
240 | - def handle(self, *args, **options): |
241 | - tasks = {} |
242 | - for task in Task.objects.iterator(): |
243 | - bugid = task.bug.bug_id |
244 | - report_task = { |
245 | - 'title': task.bug.title, |
246 | - 'taglist': task.bug.tag_list, |
247 | - 'date_created': task.date_created.isoformat(), |
248 | - 'age': (datetime.datetime.now(TZ) - task.date_created).days, |
249 | - 'importance': task.importance, |
250 | - 'status': task.status, |
251 | - 'web_link': task.web_link, |
252 | - 'duplicate_link': '', |
253 | - 'owner': task.owner.display_name, |
254 | - 'triaged': task.triaged |
255 | - } |
256 | - dupe_of = task.bug.duplicate_of |
257 | - if dupe_of: |
258 | - report_task['duplicate_link'] = ('<a href="{}">{}</a>' |
259 | - .format(task.web_link, bugid)) |
260 | - report_task['owner'] += ' (dup)' |
261 | - bugid = dupe_of.bug_id |
262 | - report_task['web_link'] = dupe_of.web_link |
263 | - report_task['triaged'] = dupe_of.triaged |
264 | - |
265 | - # Pilfered from collect-bug-data in lp:arsenal |
266 | - m = re.search('(\S+)\s\(.*\)', task.bug_target_name) |
267 | - if m is not None: |
268 | - report_task['target'] = m.group(1) |
269 | - else: |
270 | - report_task['target'] = task.bug_target_name |
271 | - m = re.search('(\S+)\s\(.*\)', task.bug_target_display_name) |
272 | - if m is not None: |
273 | - report_task['target_display_name'] = m.group(1) |
274 | - else: |
275 | - report_task['target_display_name'] = task.bug_target_display_name |
276 | - |
277 | - report_task['target'] = report_task['target'].replace('.', '') |
278 | - if task.assignee: |
279 | - report_task['assignee'] = task.assignee.display_name |
280 | - else: |
281 | - report_task['assignee'] = 'Unassigned' |
282 | - if bugid not in tasks: |
283 | - tasks[bugid] = [] |
284 | - tasks[bugid].append(report_task) |
285 | - |
286 | - template = Template(filename='qa-default.mako') |
287 | - open('test.html', 'w').write(template.render( |
288 | - report_title='Test', |
289 | - tasks=tasks, |
290 | - timestamp=datetime.datetime.now().isoformat(), |
291 | - datefilter=True |
292 | - )) |
293 | +def index(request): |
294 | + |
295 | + tasks = {} |
296 | + for task in Task.objects.iterator(): |
297 | + bugid = task.bug.bug_id |
298 | + report_task = { |
299 | + 'title': task.bug.title, |
300 | + 'taglist': task.bug.tag_list, |
301 | + 'date_created': task.date_created.isoformat(), |
302 | + 'age': (datetime.datetime.now(TZ) - task.date_created).days, |
303 | + 'importance': task.importance, |
304 | + 'status': task.status, |
305 | + 'web_link': task.web_link, |
306 | + 'duplicate_link': '', |
307 | + 'owner': task.owner.display_name, |
308 | + 'triaged': task.triaged |
309 | + } |
310 | + dupe_of = task.bug.duplicate_of |
311 | + if dupe_of: |
312 | + report_task['duplicate_link'] = ('<a href="{}">{}</a>' |
313 | + .format(task.web_link, bugid)) |
314 | + report_task['owner'] += ' (dup)' |
315 | + bugid = dupe_of.bug_id |
316 | + report_task['web_link'] = dupe_of.web_link |
317 | + report_task['triaged'] = dupe_of.triaged |
318 | + |
319 | + # Pilfered from collect-bug-data in lp:arsenal |
320 | + m = re.search('(\S+)\s\(.*\)', task.bug_target_name) |
321 | + if m is not None: |
322 | + report_task['target'] = m.group(1) |
323 | + else: |
324 | + report_task['target'] = task.bug_target_name |
325 | + m = re.search('(\S+)\s\(.*\)', task.bug_target_display_name) |
326 | + if m is not None: |
327 | + report_task['target_display_name'] = m.group(1) |
328 | + else: |
329 | + report_task['target_display_name'] = task.bug_target_display_name |
330 | + |
331 | + report_task['target'] = report_task['target'].replace('.', '') |
332 | + if task.assignee: |
333 | + report_task['assignee'] = task.assignee.display_name |
334 | + else: |
335 | + report_task['assignee'] = 'Unassigned' |
336 | + if bugid not in tasks: |
337 | + tasks[bugid] = [] |
338 | + tasks[bugid].append(report_task) |
339 | + |
340 | + targets = {} |
341 | + for bugid in tasks: |
342 | + for task in tasks[bugid]: |
343 | + target = task['target'] |
344 | + name = task['target_display_name'] |
345 | + if target in targets: |
346 | + if target != name: |
347 | + targets[target] = name |
348 | + else: |
349 | + targets[target] = name |
350 | + target_report_order = sorted([(targets[target], target) for target in targets]) |
351 | + tasks_json_dump = json.dumps(tasks, sort_keys=True, indent=4) |
352 | + context = {'report_title': 'Test', |
353 | + 'tasks': tasks, |
354 | + 'timestamp': datetime.datetime.now().isoformat(), |
355 | + 'datefilter': True, |
356 | + 'target_report_order': target_report_order, |
357 | + 'tasks_json_dump': tasks_json_dump} |
358 | + return render(request, 'qlbr/qa-default.html', context) |
The target_report_order business could be handled as part of the task loop probably, but we can come back to that later. Looks good to me.