changeset 413:a499441249af

Fixes sorting by day for templates. * Adds a string attribute 'startisoday' to the Entry object, so it can be used by jinja2's sort and groupby filters.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 03 May 2017 13:35:58 +0200 (2017-05-03)
parents cc56bc1fd56b
children 69ef6f89e930
files TODO getan/project.py getan/templates/zeiterfassung2
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Wed May 03 12:59:37 2017 +0200
+++ b/TODO	Wed May 03 13:35:58 2017 +0200
@@ -7,9 +7,6 @@
 20160912 BER: Better code: states.py: classes EditEntryState and 
   AdjustEntryState have same methods exit() and set_focus(), maybe join them?
 
-20151130 BER: templates/zeiterfassung2: Really sort by date, right now the 
-  sorting it sometimes skewed if the week wraps around the end of the month.
-
 Older:
 
 - Create a 'Help-Widget' to give the user an information about all possible
--- a/getan/project.py	Wed May 03 12:59:37 2017 +0200
+++ b/getan/project.py	Wed May 03 13:35:58 2017 +0200
@@ -4,6 +4,11 @@
 # (c) 2008, 2009, 2010 by
 #   Sascha L. Teichmann <sascha.teichmann@intevation.de>
 #   Ingo Weinzierl <ingo.weinzierl@intevation.de>
+# (c) 2017 by Intevation GmbH
+# Authors:
+#  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+#  * Ingo Weinzierl <ingo.weinzierl@intevation.de>
+#  ' Bernhard Reiter <bernhard.reiter@intevation.de>
 #
 # This is Free Software licensed unter the terms of GPLv3 or later.
 # For details see LICENSE coming with the source of 'getan'.
@@ -92,6 +97,11 @@
         self.desc = desc
         self.workpackage = "-"
 
+        # we add this attribute for use in jinja2 templates,
+        # as filters like sort() or groupby() work only on attributes
+        # and sorting or grouping by day is common for reporting
+        self.startisoday = start.date().isoformat()
+
         # carefully handle non unicode string
         # urwid seems to have some issue with plain str
         if self.desc and not isinstance(self.desc, unicode):
--- a/getan/templates/zeiterfassung2	Wed May 03 12:59:37 2017 +0200
+++ b/getan/templates/zeiterfassung2	Wed May 03 13:35:58 2017 +0200
@@ -1,7 +1,7 @@
 {% for proj in projects %}
 {%- if proj.entries %}
 ## category: {{ proj.key }} ({{ proj.desc }})
-{% for grouper, gentries in proj.entries|sort(attribute='start')|groupby('start.day') %}
+{% for grouper, gentries in proj.entries|sort(attribute='startisoday')|groupby('startisoday') %}
 {#- grouper will contain the attribute used for groupby() -#}
 
 {% for ggrouper, ggentries in gentries|groupby('workpackage') %}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)