[Mpuls-commits] r702 - in wasko/branches/2.0: . waskaweb/controllers waskaweb/model waskaweb/templates waskaweb/templates/phase waskaweb/tests/functional

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 23 15:02:36 CET 2009


Author: torsten
Date: 2009-11-23 15:02:26 +0100 (Mon, 23 Nov 2009)
New Revision: 702

Added:
   wasko/branches/2.0/waskaweb/controllers/phase.py
   wasko/branches/2.0/waskaweb/model/phase.py
   wasko/branches/2.0/waskaweb/templates/phase/
   wasko/branches/2.0/waskaweb/templates/phase/phase.mako
   wasko/branches/2.0/waskaweb/tests/functional/test_phase.py
Modified:
   wasko/branches/2.0/ChangeLog.txt
Log:
Added new structure for phases


Modified: wasko/branches/2.0/ChangeLog.txt
===================================================================
--- wasko/branches/2.0/ChangeLog.txt	2009-11-23 13:52:07 UTC (rev 701)
+++ wasko/branches/2.0/ChangeLog.txt	2009-11-23 14:02:26 UTC (rev 702)
@@ -10,6 +10,17 @@
 	  annotations from a formed dir located under public. Public can be
 	  configured in a config file.
 
+	Added new structure for phase (Not functional yet)
+
+	* waskaweb/model/phase.py,
+	  waskaweb/tests/functional/test_phase.py,
+	  waskaweb/controllers/phase.py,
+	  waskaweb/templates/phase,
+	  waskaweb/templates/phase/phase.mako: These files wil ideally replace
+	  to old phase-classe. Add a new controller to handle all
+	  phasespecific calls. Unifiy the old phases files in one new
+	  phase-file.
+
 2009-11-18 	Torsten Irlaender	<torsten.irlaender at intevation.de> 
 
 	Implement grouping of choicelists

Added: wasko/branches/2.0/waskaweb/controllers/phase.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/phase.py	2009-11-23 13:52:07 UTC (rev 701)
+++ wasko/branches/2.0/waskaweb/controllers/phase.py	2009-11-23 14:02:26 UTC (rev 702)
@@ -0,0 +1,16 @@
+import logging
+
+from pylons import session, g, c
+from waskaweb.lib.base import *
+from waskaweb.model.phase import PhaseFactory 
+
+log = logging.getLogger(__name__)
+
+class PhaseController(BaseController):
+
+    def index(self, id):
+        return self.overview(id)
+
+    def overview(self, id):
+        c.phases = PhaseFactory().load(id)
+        return render('/phase/phase.mako')

Added: wasko/branches/2.0/waskaweb/model/phase.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/phase.py	2009-11-23 13:52:07 UTC (rev 701)
+++ wasko/branches/2.0/waskaweb/model/phase.py	2009-11-23 14:02:26 UTC (rev 702)
@@ -0,0 +1,128 @@
+# -*- coding: utf-8 -*-
+from pylons import session, g, c
+
+class PhaseFactory:
+
+    def __init__(self):
+        self.phases = PhaseList() 
+
+    def load(self, id):
+        for p in g.mpuls_config.get('phases', 'phases'):
+            desc  = g.mpuls_config.get('phases', 'description')[0].get(p)
+            start = PhasePart(g.mpuls_config.get('phases', 'pairs')[0].get(p)[0])
+            end   = PhasePart(g.mpuls_config.get('phases', 'pairs')[0].get(p)[1])
+            self.phases.append(Phase(start, end, desc))
+        return self.phases
+
+class PhaseList(list):
+    pass
+
+class Phase:
+
+    def __init__(self, start, end, description):
+        self.start       = start
+        self.end         = end
+        self.description = description
+
+    def getStart(self):
+        return self.start
+
+    def getEnd(self):
+        return self.end
+
+    def getDuration(self):
+        #t1 = self.start.getTime()
+        #t2 = self.end.getTime()
+        #if not t1 or not t2: return None
+        #return t2 - t1
+        pass
+
+    def getDescription(self):
+        return self.description
+
+    def isRunning(self):
+        return True
+        #return self.start.isRunning() or self.end.isRunning()
+
+class PhasePart:
+    def __init__(self, id):
+        self.id = id
+        self.condition = Condition()
+
+    def getLinks(self):
+        return ""
+
+    def getTime(self):
+        return ""
+
+    def isOk(self):
+        return self.condition.isOk()
+
+class Condition:
+
+    def __init__(self):
+        self.ok = False
+        self.requiredFields = []
+
+    def isOk(self):
+        return self.ok
+
+#class Phase:
+#
+#    def __init__(self, phase, running = False, complete = False, time = None, links = ""):
+#        self.phase    = phase
+#        self.running  = running
+#        self.complete = complete
+#        self.time     = time
+#        self.links    = links
+#        self.preds    = []
+#
+#    def isNeighbor(self, other):
+#        return phase_neighbors(self.phase, other.phase)
+#
+#    def isRunning(self):
+#        return self.running
+#
+#    def addPredecessor(self, pred):
+#        self.preds.append(pred)
+#
+#    def getLabel(self):
+#        return phase_symbol(self.phase)
+#
+#    def getDescription(self):
+#        return phase_description(self.phase)
+#
+#    def isComplete(self):
+#        return self.complete
+#
+#    def isRecursiveComplete(self):
+#        if not self.complete:
+#            return False
+#
+#        for pred in self.preds:
+#            if not pred.isRecursiveComplete():
+#                return False
+#
+#        return True
+#
+#    def hasPredecessor(self, other):
+#        #for p in self.preds:
+#        #    if other.phase == p.phase or p.hasPredecessor(other): return True
+#        #return False
+#        predecessors = phase_predecessors_path(self.phase)
+#        return other.phase in predecessors
+#
+#    def hasSuccessor(self, other):
+#        successors = phase_successors_path(self.phase)
+#        return other.phase in successors
+#
+#    def getTime(self):
+#        if str(self.time) != '0001-01-01':
+#            return self.time
+#        return None
+#
+#    def getLinks(self):
+#        return self.links
+
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Added: wasko/branches/2.0/waskaweb/templates/phase/phase.mako
===================================================================
--- wasko/branches/2.0/waskaweb/templates/phase/phase.mako	2009-11-23 13:52:07 UTC (rev 701)
+++ wasko/branches/2.0/waskaweb/templates/phase/phase.mako	2009-11-23 14:02:26 UTC (rev 702)
@@ -0,0 +1,102 @@
+## -*- coding: utf-8 -*-
+<%inherit file="../casemanagement/main.mako" />
+<%def name="buildNavipath()">
+  ${parent.buildNavipath()}
+  <li><a href="/case/">${_('cm_np_root')}</a></li>
+  <li><a href="/case/select/${session.get('case').id}">${_('cm_np_select')}</a></li>
+  <li><a href="#">${_('case_cm_phase')}</a></li>
+</%def>
+
+% if c.global_warnings:
+<div class="form_errors">${c.global_warnings}</div>
+% endif
+
+<div class="waska_form">
+<h2>${_('case_cm_phase')}</h2>
+<form method="POST" action="${h.url_for(controller='/phase', action='setAction')}">
+  <input type="hidden" name="case_id" value="${session.get('case').id}">
+  <table id="cmphases">
+    <% is_allowed = h.hasRole(('cm_ka',)) %>
+    <tr>
+      <th class="table_header_h" width="18%">${_('cm_info_phase')}</th>
+      <th class="table_header_h" width="3%">&nbsp;</th>
+      <th class="table_header_h" width="44%">${_('case_cm_phase_required_fields')}</th>
+      <th class="table_header_h" width="15%">${_('case_cm_phase_time')}</th>
+      <th style="text-align:right" class="table_header_h" width="20%">
+      % if is_allowed:
+      ${_('case_cm_phase_change')}
+      % endif
+      </th>
+    </tr>
+    % for num, phase in enumerate(c.phases): 
+    <% p1, p2 = phase.getStart(), phase.getEnd()  %>
+    <tr>
+      <td rowspan="2" class="cm_phase_state ${(num%2) and 'table_row_h' or ''}">
+        ${phase.getDescription()}
+      </td>
+      % if p1.isOk():
+      <td class="cm_phase_state_valid cm_phase_state ${(num%2) and 'table_row_h' or ''}"></td>
+      % else:
+      <td class="cm_phase_state_invalid cm_phase_state ${(num%2) and 'table_row_h' or ''}"></td>
+      % endif
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">${p1.getLinks()}</td>
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">${p1.getTime()}</td>
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">
+        % if p1.isOk():
+          Action ok
+        % else:
+          Action nok
+        % endif
+      </td>
+    </tr>
+    <tr>
+      % if p2.isOk():
+      <td class="cm_phase_state_valid cm_phase_state ${(num%2) and 'table_row_h' or ''}"></td>
+      % else:
+      <td class="cm_phase_state_invalid cm_phase_state ${(num%2) and 'table_row_h' or ''}"></td>
+      % endif
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">${p2.getLinks()}</td>
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">${p2.getTime()}</td>
+      <td class=" cm_phase_state ${(num%2) and 'table_row_h' or ''}">
+        % if p2.isOk():
+          Action ok
+        % else:
+          Action nok
+        % endif
+      </td>
+    </tr>
+    % endfor
+  </table>
+</form>
+</div>
+####
+#### DAUER DER PHASEN
+####
+##<div>
+##  <h2>Dauer der Phasen</h2>
+##  <table>
+##    <tr>
+##      <th class="table_header_h">Phase</th>
+##      <th style="text-align:right" class="table_header_h">Dauer in Wochen</th>
+##    </tr>
+##    <% total = None %>
+##    % for phase_pair in c.phase_pairs:
+##    <tr>
+##      <td>${phase_pair.getDescription()}</td>
+##      <td style="text-align:right">
+##      <% 
+##        t = phase_pair.getDuration();
+##        if t: total = total and (total + t) or t
+##      %>
+##      ${h.timedelta_in_weeks(t, '-/-')}
+##      </td>
+##    </tr>
+##    % endfor
+##    <tr>
+##      <td style="border-top:1px solid"><strong>Gesamt</strong></td>
+##      <td style="border-top:1px solid; text-align:right">
+##        <strong>${h.timedelta_in_weeks(total, '-/-')}</strong>
+##      </td>
+##    </tr>
+##  </table>
+##</div>

Added: wasko/branches/2.0/waskaweb/tests/functional/test_phase.py
===================================================================
--- wasko/branches/2.0/waskaweb/tests/functional/test_phase.py	2009-11-23 13:52:07 UTC (rev 701)
+++ wasko/branches/2.0/waskaweb/tests/functional/test_phase.py	2009-11-23 14:02:26 UTC (rev 702)
@@ -0,0 +1,7 @@
+from waskaweb.tests import *
+
+class TestPhaseController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url_for(controller='phase'))
+        # Test response...



More information about the Mpuls-commits mailing list