[Getan-commits] [PATCH 3 of 3] Add list of all entries to the template context
Wald Commits
scm-commit at wald.intevation.org
Mon Jan 26 14:11:11 CET 2015
# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1422277724 -3600
# Node ID 9a0dba03d16cee6b1af4f6f8ccb95833c4d14f59
# Parent 23eea2dbb5eb36c37b16fac395d6de35f0b0ba2b
Add list of all entries to the template context
This allows to render output for entries without having to iterate over the
projects.
diff -r 23eea2dbb5eb -r 9a0dba03d16c getan/template.py
--- a/getan/template.py Mon Jan 26 14:06:37 2015 +0100
+++ b/getan/template.py Mon Jan 26 14:08:44 2015 +0100
@@ -33,10 +33,10 @@
return d.strftime("%d.%m.%Y")
-def total_time(projects):
+def duration(entries):
total = timedelta(0)
- for proj in projects:
- total += proj.get_total_duration()
+ for entry in entries:
+ total += entry.get_duration()
return total
@@ -91,6 +91,7 @@
env = Environment(loader=loader)
env.filters["human_time"] = human_time
env.filters["date_format"] = date_format
+ env.filters["duration"] = duration
template_name = template or "wochenbericht"
template = env.get_template(template_name)
@@ -111,7 +112,12 @@
if not empty_projects:
projects = [project for project in projects if project.entries]
+ entries = []
+ for project in projects:
+ entries.extend(project.entries)
+
context = dict()
+ context["entries"] = entries
context["project"] = project
context["projects"] = projects
context["user"] = user
@@ -121,6 +127,6 @@
context["current_week"] = c_week
context["current_year"] = c_year
context["unix_week"] = u_week
- context["total_time"] = total_time(projects)
+ context["total_time"] = duration(entries)
context["today"] = date.today()
return template.render(context)
More information about the Getan-commits
mailing list