[Mpuls-commits] r3832 - in base/trunk: . mpulsweb/controllers mpulsweb/lib mpulsweb/model mpulsweb/public/styles mpulsweb/templates/logbook mpulsweb/templates/privacy/default

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 30 14:49:29 CEST 2010


Author: roland
Date: 2010-09-30 14:49:27 +0200 (Thu, 30 Sep 2010)
New Revision: 3832

Added:
   base/trunk/mpulsweb/templates/logbook/evaluation_typ.mako
Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/logbook.py
   base/trunk/mpulsweb/lib/evaluation.py
   base/trunk/mpulsweb/model/logbook.py
   base/trunk/mpulsweb/public/styles/color3.css
   base/trunk/mpulsweb/templates/logbook/edit_body.mako
   base/trunk/mpulsweb/templates/logbook/evaluation.mako
   base/trunk/mpulsweb/templates/logbook/overview.mako
   base/trunk/mpulsweb/templates/privacy/default/privacy_statement.html
Log:
G121: implemented locating and non locating work

Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/ChangeLog	2010-09-30 12:49:27 UTC (rev 3832)
@@ -1,3 +1,17 @@
+2010-09-30 Roland Geider <roland.geider at intevation.de>
+
+	* mpulsweb/model/logbook.py,
+	  mpulsweb/controllers/logbook.py,
+	  mpulsweb/lib/evaluation.py,
+	  mpulsweb/public/styles/color3.css,
+	  mpulsweb/templates/logbook/edit_body.mako,
+	  mpulsweb/templates/logbook/evaluation_typ.mako,
+	  mpulsweb/templates/logbook/overview.mako,
+	  mpulsweb/templates/logbook/evaluation.mako,
+	  mpulsweb/templates/privacy/default/privacy_statement.html: G121:
+	  implemented locating and non locating work (aufsuchende, nicht
+	  aufsuchende Arbeit) as types in the logbook
+
 2010-09-30  Bernhard Herzog  <bh at intevation.de>
 
 	* mpulsweb/controllers/case.py (CaseController.printAll): Include
@@ -31,6 +45,7 @@
 	  the phase in templates as it can include html "&shy;" to divide long
 	  phasenames.
 
+>>>>>>> .r3831
 2010-09-28  Bernhard Herzog  <bh at intevation.de>
 
 	* mpulsweb/lib/search.py (CaseSearch.get_allowed_viewer_clause):

Modified: base/trunk/mpulsweb/controllers/logbook.py
===================================================================
--- base/trunk/mpulsweb/controllers/logbook.py	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/controllers/logbook.py	2010-09-30 12:49:27 UTC (rev 3832)
@@ -27,8 +27,11 @@
 import sys
 import logging
 import formencode
+import traceback
 from datetime import datetime
 
+from pylons import app_globals as g
+
 from mpulsweb.lib.translation import _, ungettext
 
 from mpulsweb.lib.security import checkRole
@@ -80,13 +83,15 @@
         sort, order = get_sort(request.params)
         id = self._checkInt(id)
 
-        # Load logbook
+        ## Load logbook
         logbook = Logbook()
         logbook.loadById(int(id), sort, order)
         c.logbook = logbook
 
-        # Build evaluation
+        ## Build evaluations
         c.eval_effort = logbook.getEvaluation()
+        c.eval_typ_effort = logbook.getTypEvaluation()
+        
         return render('/logbook/overview.mako')
 
     @checkRole(('cm_ka'))
@@ -117,10 +122,13 @@
         form_defaults = {}
         c.form_errors = {}
 
+        # Set the default values, also for all the "types" from the JSON file
         form_defaults['date'] = entry.getDate()
         form_defaults['time'] = entry.getTime()
         form_defaults['kind'] = entry.getKindAsInt()
         form_defaults['case_id'] = id
+        for num, typ in enumerate(g.mpuls_config.get('logbook', 'types')):
+            form_defaults[typ.get('db_field')] = -1  #only if it's a drop-down!
 
         form = render('/logbook/new.mako')
         return formencode.htmlfill.render(form,
@@ -154,7 +162,8 @@
         try:
             log.debug("New Logbook entry from case %s" % checker.getCaseId())
             logbook = Logbook(checker.getCaseId())
-            logbook.addEntry(checker.getLogbookEntry())
+            entry = checker.getLogbookEntry()
+            logbook.addEntry(entry)
             logbook.store(session['USER_AUTHORIZED'].id)
             c.url_ok = url_for(controller='/logbook', action='index',
                                id=session['case'].id)
@@ -169,6 +178,7 @@
                                id=session['case'].id)
             return render('/logbook/dialogs/failed_create_logbook_entry.mako')
 
+
     @checkRole('cm_ka')
     def edit(self, id):
         id = self._checkInt(id)
@@ -181,8 +191,9 @@
             entry_data['date'] = entry.getDate()
             entry_data['time'] = entry.getTime()
             entry_data['duration'] = entry.getDuration()
-            entry_data['kind'] = entry.getKindAsInt()
+            entry_data['art'] = entry.getKindAsInt()
             entry_data['notice'] = entry.getNotice()
+            entry_data['typ'] = entry.getTyp()
             entry_data['short_notice'] = entry.getShortNotice()
             c.entry = entry
             form = render('/logbook/edit.mako')
@@ -226,6 +237,7 @@
             entry = checker.getLogbookEntry()
             entry.setId(id)
             entry.storeForUser(session['USER_AUTHORIZED'].id)
+
             c.success_for = LOGBOOK_ENTRY_SAVE_SUCCESS
             c.success_text = LOGBOOK_ENTRY_SAVE_SUCCESS_TEXT
             c.url_ok = url_for(controller='/logbook', action='index',
@@ -275,5 +287,7 @@
         logbook.loadById(id)
         c.logbook = logbook
         return render('/logbook/overview_print.mako')
+    
+    
 
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: base/trunk/mpulsweb/lib/evaluation.py
===================================================================
--- base/trunk/mpulsweb/lib/evaluation.py	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/lib/evaluation.py	2010-09-30 12:49:27 UTC (rev 3832)
@@ -23,29 +23,45 @@
 # the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
 # European Social Fund resources.
 
+import logging
+import datetime
 
 from pylons import app_globals as g
 
 from mpulsweb.lib.helpers import timedelta_in_minutes
 from mpulsweb.lib.db import db
 
+log = logging.getLogger(__name__)
 
 class LogbookEvaluation:
 
     """Zeitaufwände aus dem Logbuch aller Fälle"""
 
     def __init__(self, id):
+        self.id = id
+        
         self.sql = """SELECT
             sum(coalesce(l.dauer, '0 second'::interval)) AS dauer,
             count(l.id) AS anzahl, l.art, m.id
             FROM ka_logbuch_tbl_view l
             JOIN master_tbl_eval_total_view m
             ON m.id = l.master_id
-            WHERE l.master_id = %s
+            WHERE l.master_id = %(id)s
             AND l.art <> '0'
             GROUP BY l.art, m.id
             ORDER BY l.art
-        """ % id
+        """ % {'id': id}
+        
+        self.sql_typ = """SELECT
+            sum(coalesce(l.dauer, '0 second'::interval)) AS dauer,
+            count(l.id) AS anzahl, l.%(table)s, m.id
+            FROM ka_logbuch_tbl_view l
+            JOIN master_tbl_eval_total_view m
+            ON m.id = l.master_id
+            WHERE l.master_id = %(id)s
+            GROUP BY l.%(table)s, m.id
+            ORDER BY l.%(table)s
+        """ % {'table': 'typ', 'id': id}
 
     def perform(self):
         unique_cases = []
@@ -96,5 +112,37 @@
                 raise
         finally:
             db.recycleConnection(conn, cur)
+    
+    
+    def perform_type_evaluation(self):
+        """ Perform an evaluation on the "typ" field of logbooks"""
+        try:
+            conn = db.getConnection()
+            cur = conn.cursor()
+            cur.execute(self.sql_typ)
+            rows = cur.fetchall()
+            
+            # Initiate statistical data. Then iterate thorugh the data to
+            # generate the real ones. Bit ugly.
+            result = {'total': [], 'types':[]}
+            total = {'amount': 0, 'time': 0, 'percent': 100}
+            
+            for row in rows:
+                total['amount'] = total['amount'] + row[1]
+                total['time'] = total['time'] + timedelta_in_minutes(row[0]) / 60
+            
+            for row in rows:
+                if total['time']: # don't count if no time given
+                    percent = timedelta_in_minutes(row[0]) / total['time'] / 60 * 100.0
+                    result['types'].append({'typ': row[2],
+                                'time' : timedelta_in_minutes(row[0]) / 60,
+                                'percent': percent,
+                                'amount' : row[1]})
+            result['total'] = total
+            
+            return result
+        finally:
+            db.recycleConnection(conn, cur)
 
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: base/trunk/mpulsweb/model/logbook.py
===================================================================
--- base/trunk/mpulsweb/model/logbook.py	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/model/logbook.py	2010-09-30 12:49:27 UTC (rev 3832)
@@ -42,13 +42,13 @@
 
 ALLOWED_SORTING = ['name', 'art', 'dauer', 'datum', 'asc', 'desc', 'bearbeiter']
 LOAD_LOGBOOK = """
-SELECT l.id AS id, datum, bearbeiter, art, kurz_notiz, notiz, dauer
+SELECT l.id AS id, datum, bearbeiter, art, kurz_notiz, notiz, dauer, typ
 FROM ka_logbuch_tbl_view l WHERE l.master_id = %s
 ORDER BY %s %s
 """
 
 LOAD_LOGBOOK_BY_ID = """
-SELECT l.id AS id, datum, bearbeiter, art, kurz_notiz, notiz, dauer
+SELECT l.id AS id, datum, bearbeiter, art, kurz_notiz, notiz, dauer, typ
 FROM ka_logbuch_tbl_view l WHERE l.id = %(mid)s
 """
 
@@ -66,7 +66,8 @@
     art        = %(kind)s,
     kurz_notiz = %(short_notice)s,
     notiz      = %(notice)s,
-    dauer      = %(duration)s
+    dauer      = %(duration)s,
+    typ        = %(typ)s
 WHERE id = %(id)s
 """
 
@@ -101,6 +102,7 @@
         self.kurz_notiz = None
         self.notiz = None
         self.dauer = None
+        self.typ = None
 
     def setByRow(self, row):
         self.id = row[0]
@@ -110,6 +112,7 @@
         self.kurz_notiz = row[4] and h.ensure_unicode(row[4]) or None
         self.notiz = row[5] and h.ensure_unicode(row[5]) or None
         self.dauer = row[6]
+        self.typ = row[7]
 
     def loadById(self, id):
         self.id = id
@@ -151,6 +154,12 @@
     def setKind(self, art):
         self.art = art
 
+    def setTyp(self, typ):
+        self.typ = typ
+
+    def getTyp(self):
+        return self.typ
+
     def getShortNotice(self, empty='-/-'):
         if self.kurz_notiz is not None:
             return self.kurz_notiz
@@ -189,12 +198,22 @@
                 raise StandardError("Cannot create log book entry")
             self.id = row[0]
 
+        log.debug("captain's logbook, stardate 124.97: %s" % (UPDATE_LOGBOOK_ENTRY %
+                    {"date": self.datum,
+                     "kind": self.art,
+                     "short_notice": self.kurz_notiz,
+                     "notice": self.notiz,
+                     "duration": self.dauer,
+                     "typ": self.typ,
+                     "id": self.id}))
+                     
         cur.execute(UPDATE_LOGBOOK_ENTRY,
                     {"date": self.datum,
                      "kind": self.art,
                      "short_notice": self.kurz_notiz,
                      "notice": self.notiz,
                      "duration": self.dauer,
+                     "typ": self.typ,
                      "id": self.id})
 
     def storeForUser(self, uid):
@@ -204,6 +223,7 @@
                     "short_notice": self.kurz_notiz,
                     "notice": self.notiz,
                     "duration": self.dauer,
+                    "typ": self.typ,
                     "id": self.id})
 
 
@@ -236,9 +256,12 @@
                     sort_field = 'datum'
                     sort_order = 'desc'
                 cur.execute(LOAD_LOGBOOK % (mid, sort_field, sort_order))
-            except:
-                print cur.query
+            except Exception, e:
+                log.debug("excepion while trying to do this: %s" % cur.query)
+                log.debug("this is what went wront: %s" % e)
+            
             while True:
+                print "getting results"
                 row = cur.fetchone()
                 if not row:
                     break
@@ -275,7 +298,11 @@
         eval = LogbookEvaluation(self.mid)
         return eval.perform()
 
+    def getTypEvaluation(self):
+        eval = LogbookEvaluation(self.mid)
+        return eval.perform_type_evaluation()
 
+
 class LogbookEntryChecker:
 
     def __init__(self, params, check_case_id=True):
@@ -310,7 +337,9 @@
                 except ValueError:
                     errors.append("Fallnummer is keine Ganzzahl.")
 
-        art = params.getone('kind')
+        art = params.getone('art')
+        #for num, typ in enumerate(g.mpuls_config.get('logbook', 'types')):
+            #art = params.getone(typ.get('db_field'))
         if art is None:
             errors.append("Die Art des Eintrages wurde nicht angegeben.")
         else:
@@ -346,6 +375,13 @@
         if not kurz_notiz:
             kurz_notiz = None
 
+        try:
+            typ = params.getone('typ')
+            if not typ:
+                typ = None
+        except:
+            typ = None
+
         self.errors = errors
 
         entry = LogbookEntry()
@@ -361,6 +397,8 @@
             entry.setShortNotice(kurz_notiz)
         if not notiz is None:
             entry.setNotice(notiz)
+        if not typ is None:
+            entry.setTyp(typ)
 
     def hasErrors(self):
         return len(self.errors) > 0

Modified: base/trunk/mpulsweb/public/styles/color3.css
===================================================================
--- base/trunk/mpulsweb/public/styles/color3.css	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/public/styles/color3.css	2010-09-30 12:49:27 UTC (rev 3832)
@@ -129,16 +129,23 @@
 }
 
 .table_row_h, .table_row_v, .table_row_v_12 {
-	background:#d5d5d5; /**/
+	background: #babdb6; /**/
 
 }
 
+.background_very_slight{
+    background-color: #eeeeec;
+}
+
+.background_slight{
+    background-color: #d3d7cf;
+}
+
 .table_row_v, .table_row_v_2 {
 	/*border-left:0.5pt solid;*/
 }
 
 .table_header_h th, .table_header_h{
-	background:#d5d5d5; /**/
 	border-bottom:1px solid;
 }
 
@@ -148,7 +155,7 @@
 }
 
 .formed-radiomatrix th {
-	background:#d5d5d5; 
+	background: #d5d5d5; 
 }
 
 .odd {

Modified: base/trunk/mpulsweb/templates/logbook/edit_body.mako
===================================================================
--- base/trunk/mpulsweb/templates/logbook/edit_body.mako	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/templates/logbook/edit_body.mako	2010-09-30 12:49:27 UTC (rev 3832)
@@ -31,20 +31,16 @@
 </fieldset>
 <fieldset>
 <legend>Eintrag</legend>
+
 Bearbeiter/in: ${session.get('USER_AUTHORIZED').shortenedName()}
+% for num, typ in enumerate(g.mpuls_config.get('logbook', 'types')):
 <div class="w100">
-  <label for="kind">Art des Eintrags:</label><br>
-  <select name='kind' id='kind'>
-    % for cat in g.mpuls_config.get('logbook', 'categories'):
-      <optgroup label="${h.escape(cat.get('name'))}">
-        % for item in cat.get('items'):
-          <option value="${item}">
-            ${h.escape(g.mpuls_config.get('logbook', 'descriptions')[0].get(item))}
-          </option>
-        % endfor
-      </optgroup>
-    % endfor
+  <label for="typ${num}">${typ.get('label')}:</label><br>
+  <select name="${typ.get('db_field')}" id="typ${num}">
+  ${h.literal("".join(h.render_logbook_typeoptions(typ)))}
   </select>
+  </div>
+% endfor
   % if c.form_errors.get('short_notice'):
     <label for="short_notice" class="error_font">Nennung Sonstiges:</label><br>
     <input type="text" class="field error_box" name="short_notice" id="short_notice" maxlength="80"/>

Modified: base/trunk/mpulsweb/templates/logbook/evaluation.mako
===================================================================
--- base/trunk/mpulsweb/templates/logbook/evaluation.mako	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/templates/logbook/evaluation.mako	2010-09-30 12:49:27 UTC (rev 3832)
@@ -6,7 +6,7 @@
     <th class="table_header_h table_width_mid_s num">Aufwand (Minuten)</th>
   </tr>
   % for num, category in enumerate(g.mpuls_config.get('logbook', 'categories')):
-    <tr>
+    <tr class="background_slight">
       <td>
         <b>${h.escape(category.get('name'))}:</b>
       </td>
@@ -42,4 +42,4 @@
       <b>${c.eval_effort['sum_all'][1]}</b>
     </td>
   </tr>
-</table>
+</table>
\ No newline at end of file

Added: base/trunk/mpulsweb/templates/logbook/evaluation_typ.mako
===================================================================
--- base/trunk/mpulsweb/templates/logbook/evaluation_typ.mako	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/templates/logbook/evaluation_typ.mako	2010-09-30 12:49:27 UTC (rev 3832)
@@ -0,0 +1,49 @@
+## -*- coding: utf-8 -*-
+<%def name="get_typ_name(id)">
+    % for types in g.mpuls_config.get('logbook', 'types')[1]['options']:
+        % if unicode(types[0]) == unicode(id):
+            ${types[1]}
+        % endif
+    % endfor
+</%def>
+
+% if len(g.mpuls_config.get('logbook', 'types')) > 1:
+<table class="evaluation">
+    <tr>
+        <th class="table_header_h ">Art</th>
+        <th class="table_header_h table_width_mid_s num">Anzahl der Kontakte</th>
+        <th class="table_header_h table_width_mid_s num">Aufwand in Stunden</th>
+        <th class="table_header_h table_width_mid_s num">in Prozent</th>
+    </tr>
+    % for class_statistic in c.eval_typ_effort['types']:
+    <tr>
+        <td style="padding-left:1em;">
+            ${get_typ_name(class_statistic['typ'])}
+        </td>
+        <td class="num">
+            ${"%.f" % class_statistic['amount']}
+        </td>
+        <td class="num">
+            ${"%.f" % class_statistic['time']}
+        </td>
+        <td class="num">
+            ${"%.1f" % class_statistic['percent']}
+        </td>
+    </tr>
+    % endfor
+    <tr class="table_row_v_12">
+        <td>
+            <b>GESAMT</b>
+        </td>
+        <td class="num">
+            ${"%.f" % c.eval_typ_effort['total']['amount']}
+        </td>
+        <td class="num">
+            ${"%.f" % c.eval_typ_effort['total']['time']}
+        </td>
+        <td class="num">
+            ${c.eval_typ_effort['total']['percent']}
+        </td>
+    </tr>
+</table>
+% endif
\ No newline at end of file

Modified: base/trunk/mpulsweb/templates/logbook/overview.mako
===================================================================
--- base/trunk/mpulsweb/templates/logbook/overview.mako	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/templates/logbook/overview.mako	2010-09-30 12:49:27 UTC (rev 3832)
@@ -105,3 +105,4 @@
 </table>
 <h3>Auswertung</h3>
 <%include file="/logbook/evaluation.mako"/>
+<%include file="/logbook/evaluation_typ.mako"/>

Modified: base/trunk/mpulsweb/templates/privacy/default/privacy_statement.html
===================================================================
--- base/trunk/mpulsweb/templates/privacy/default/privacy_statement.html	2010-09-30 12:43:37 UTC (rev 3831)
+++ base/trunk/mpulsweb/templates/privacy/default/privacy_statement.html	2010-09-30 12:49:27 UTC (rev 3832)
@@ -12,6 +12,7 @@
 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
 <meta http-equiv="content-style-type" content="text/css">
 <meta http-equiv="expires" content="0">
+<link rel="shortcut icon" type="image/x-icon" href="/images/mpuls.ico">
 <link href="${h.url_for('/styles/all.css')}" media="all" rel="stylesheet" 
       type="text/css">
 <link href="${h.url_for('/styles/print.css')}" media="screen" rel="stylesheet" 



More information about the Mpuls-commits mailing list