comparison getan/template.py @ 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
parents a805aaed97dd
children cc56bc1fd56b
comparison
equal deleted inserted replaced
388:23eea2dbb5eb 389:9a0dba03d16c
31 31
32 def date_format(d): 32 def date_format(d):
33 return d.strftime("%d.%m.%Y") 33 return d.strftime("%d.%m.%Y")
34 34
35 35
36 def total_time(projects): 36 def duration(entries):
37 total = timedelta(0) 37 total = timedelta(0)
38 for proj in projects: 38 for entry in entries:
39 total += proj.get_total_duration() 39 total += entry.get_duration()
40 return total 40 return total
41 41
42 42
43 def unix_week(week, year=None): 43 def unix_week(week, year=None):
44 """Convert iso week to unix week 44 """Convert iso week to unix week
89 PackageLoader("getan")]) 89 PackageLoader("getan")])
90 90
91 env = Environment(loader=loader) 91 env = Environment(loader=loader)
92 env.filters["human_time"] = human_time 92 env.filters["human_time"] = human_time
93 env.filters["date_format"] = date_format 93 env.filters["date_format"] = date_format
94 env.filters["duration"] = duration
94 95
95 template_name = template or "wochenbericht" 96 template_name = template or "wochenbericht"
96 template = env.get_template(template_name) 97 template = env.get_template(template_name)
97 98
98 backend = Backend(database) 99 backend = Backend(database)
109 project.load_entries(year, u_week) 110 project.load_entries(year, u_week)
110 111
111 if not empty_projects: 112 if not empty_projects:
112 projects = [project for project in projects if project.entries] 113 projects = [project for project in projects if project.entries]
113 114
115 entries = []
116 for project in projects:
117 entries.extend(project.entries)
118
114 context = dict() 119 context = dict()
120 context["entries"] = entries
115 context["project"] = project 121 context["project"] = project
116 context["projects"] = projects 122 context["projects"] = projects
117 context["user"] = user 123 context["user"] = user
118 context["database"] = database 124 context["database"] = database
119 context["year"] = year 125 context["year"] = year
120 context["week"] = week 126 context["week"] = week
121 context["current_week"] = c_week 127 context["current_week"] = c_week
122 context["current_year"] = c_year 128 context["current_year"] = c_year
123 context["unix_week"] = u_week 129 context["unix_week"] = u_week
124 context["total_time"] = total_time(projects) 130 context["total_time"] = duration(entries)
125 context["today"] = date.today() 131 context["today"] = date.today()
126 return template.render(context) 132 return template.render(context)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)