[Mpuls-commits] r2228 - in wasko/branches/2.0: . mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 26 12:39:01 CET 2010


Author: bh
Date: 2010-03-26 12:39:00 +0100 (Fri, 26 Mar 2010)
New Revision: 2228

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/model/phase.py
Log:
* mpulsweb/model/phase.py: Fix formatting.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-03-26 11:37:16 UTC (rev 2227)
+++ wasko/branches/2.0/ChangeLog	2010-03-26 11:39:00 UTC (rev 2228)
@@ -1,5 +1,9 @@
 2010-03-26  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/model/phase.py: Fix formatting.
+
+2010-03-26  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/model/phase.py (PhaseFactory.load): Extract common
 	subexpression into local variable.
 

Modified: wasko/branches/2.0/mpulsweb/model/phase.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/phase.py	2010-03-26 11:37:16 UTC (rev 2227)
+++ wasko/branches/2.0/mpulsweb/model/phase.py	2010-03-26 11:39:00 UTC (rev 2228)
@@ -1,25 +1,36 @@
 # -*- coding: utf-8 -*-
+
 import logging
+
 from pylons import session, g, c
-from pylons.i18n import _ 
+from pylons.i18n import _
 
 from formed.instance.backends.postgres import DBFactory as InstanceFactory
+
 from mpulsweb.lib.db import PostgresDBInterface
 
-PHASEFIELD = "phase" # name of the dbfield for phase
 
+# name of the dbfield for phase
+PHASEFIELD = "phase"
+
+
 log = logging.getLogger(__name__)
 
-CASE_NOT_CONSISTENT = "At least the phase '%s' is not in a consistent state and seems to have some missing required fields."
 
+CASE_NOT_CONSISTENT = """At least the phase '%s' is not in a consistent state
+and seems to have some missing required fields."""
+
+
 class ConsistenceCheckException(Exception):
+
     def __init__(self, value):
         self.value = value
 
+
 class PhaseFactory:
 
     def __init__(self):
-        self.phases = PhaseList() 
+        self.phases = PhaseList()
 
     def load(self, id):
         factory = InstanceFactory(g.formedTree, PostgresDBInterface())
@@ -32,8 +43,9 @@
             self.phases.append(Phase(start, end, desc))
         return self.phases
 
+
 class PhaseList(list):
-    
+
     def get_current_phase_id(self):
         '''Returns id of current active phasepart'''
         p = self.get_current_phase()
@@ -42,19 +54,23 @@
     def get_current_phase(self):
         '''Returns current active phasepart'''
         for phase in self:
-            p1, p2 = phase.getStart(), phase.getEnd()
-            if p1.is_active(): return p1
-            if p2.is_active(): return p2
+            p1 = phase.getStart()
+            if p1.is_active():
+                return p1
+            p2 = phase.getEnd()
+            if p2.is_active():
+                return p2
 
-        # Return dummy phase for unknown phase 
+        # Return dummy phase for unknown phase
         p = EndPhasePart('-1', None, None)
         p.phase = '-1'
         return p
 
     def is_valid(self):
-        '''Returns true if all phaseparts up to the current phase are ok. This
-        means all requierd fields are filled out and all checks for rules are
-        ok. Else return False'''
+        '''Returns true if all phaseparts up to the current phase are ok.
+        This means all requierd fields are filled out and all checks for
+        rules are ok. Else return False
+        '''
         try:
             self.check_consistence()
             return True
@@ -65,18 +81,21 @@
         current_phase = self.get_current_phase_id()
         for phases in self:
             p1, p2 = phases.getStart(), phases.getEnd()
-            if p1.id <= current_phase: 
+            if p1.id <= current_phase:
                 if not p1.is_ok(fields):
-                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
-            if p2.id <= current_phase: 
-                if not p2.is_ok(fields): 
-                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT % phases.description)
+                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT
+                                                    % phases.description)
+            if p2.id <= current_phase:
+                if not p2.is_ok(fields):
+                    raise ConsistenceCheckException(CASE_NOT_CONSISTENT
+                                                    % phases.description)
 
+
 class Phase:
 
     def __init__(self, start, end, description):
-        self.start       = start
-        self.end         = end
+        self.start = start
+        self.end = end
         self.description = description
 
     def getStart(self):
@@ -88,7 +107,8 @@
     def getDuration(self):
         t1 = self.start.getTime()
         t2 = self.end.getTime()
-        if not t1 or not t2: return None
+        if not t1 or not t2:
+            return None
         return t2 - t1
 
     def getDescription(self):
@@ -97,7 +117,9 @@
     def isRunning(self):
         return self.start.is_active()
 
+
 class PhasePart:
+
     def __init__(self, id, phase, it):
         self.id = id
         self.phase = phase
@@ -105,7 +127,7 @@
         self.date = None
         self.fields = []
         pfields = g.mpuls_config.get('phases', 'fields')[0]
-        for phasepart, fields in pfields.iteritems():          
+        for phasepart, fields in pfields.iteritems():
             if phasepart == id:
                 for field in fields:
                     name = field.get('name')
@@ -124,7 +146,7 @@
             # Get date on which this phasepart was started
             pdates = g.mpuls_config.get('phases', 'dates')
             for dates in pdates:
-                for phasepart, field in dates.iteritems():          
+                for phasepart, field in dates.iteritems():
                     if phasepart == id:
                         realid = "%s:%s" % (field, case_id)
                         field = it.getItem(realid)
@@ -140,7 +162,7 @@
         return ", ".join(out)
 
     def getTime(self):
-        return self.date 
+        return self.date
 
     def is_active(self):
         return self.active
@@ -150,19 +172,28 @@
 
     def is_ok(self, fields=None):
         for field in self.fields:
-            if not fields: # No fields provided -> checkall
-                if not field.is_ok(): return False
+            if not fields:
+                # No fields provided -> checkall
+                if not field.is_ok():
+                    return False
             elif field.name in fields:
-                if not field.is_ok(): return False
-        return True 
+                if not field.is_ok():
+                    return False
+        return True
 
+
 class StartPhasePart(PhasePart):
+
     pass
 
+
 class EndPhasePart(PhasePart):
+
     pass
 
+
 class Field:
+
     def __init__(self, name, page, rules, it):
         self.name = name
         self.page = page
@@ -173,9 +204,9 @@
         real_id = "%s:%s" % (self.name, case_id)
         field = self.it.getItem(real_id)
         if field:
-            meta = field.getMeta() 
-            self.label = meta.getDescription() 
-            for condition in rules: 
+            meta = field.getMeta()
+            self.label = meta.getDescription()
+            for condition in rules:
                 expr = condition.get('expr')
                 msg = condition.get('msg')
                 self.conditions.append(Condition(field, expr, msg))
@@ -183,9 +214,9 @@
     def get_link(self):
         out = []
         case_id = session['case'].id
-        style = self.is_ok() and "ok" or "error"  
-        out.append('<a class="%s" href="/formularpage/select/%s:%s#%s">' 
-            % (style, self.page, case_id, self.name))
+        style = self.is_ok() and "ok" or "error"
+        out.append('<a class="%s" href="/formularpage/select/%s:%s#%s">'
+                   % (style, self.page, case_id, self.name))
         out.append('%s' % self.label)
         out.append('</a>')
         return "".join(out)
@@ -194,12 +225,13 @@
         for c in self.conditions:
             if not c.is_ok():
                 return False
-        return True 
+        return True
 
+
 class Condition:
 
     def __init__(self, field, expr, msg):
-        self.field = field 
+        self.field = field
         self.expr = expr
         self.msg = msg
 
@@ -209,10 +241,11 @@
         return self.evaluate()
 
     def evaluate(self):
-        meta  = self.field.getMeta()
+        meta = self.field.getMeta()
         value = self.field.getValue()
         if self.expr == "isset":
-            if value not in [-1, "-1", None, ""]: return True
+            if value not in [-1, "-1", None, ""]:
+                return True
         return False
 
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list