Mercurial > getan
changeset 389:9a0dba03d16c
Add list of all entries to the template context
This allows to render output for entries without having to iterate over the
projects.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 26 Jan 2015 14:08:44 +0100 (2015-01-26) |
parents | 23eea2dbb5eb |
children | da9a400848fd |
files | getan/template.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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)