[Mpuls-commits] r297 - in wasko/trunk: . waskaweb/controllers waskaweb/lib waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 25 09:13:56 CET 2009


Author: teichmann
Date: 2009-02-25 09:13:53 +0100 (Wed, 25 Feb 2009)
New Revision: 297

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/controllers/case.py
   wasko/trunk/waskaweb/lib/search.py
   wasko/trunk/waskaweb/model/case.py
   wasko/trunk/waskaweb/model/casedocument.py
   wasko/trunk/waskaweb/model/phases_factory.py
Log:
Rewrite of the phase transition model to use  the rules now.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/ChangeLog.txt	2009-02-25 08:13:53 UTC (rev 297)
@@ -1,3 +1,30 @@
+2009-02-25	Sascha L. Teichmann <teichmann at intevation.de>
+
+	Rewrite of the phase transition checking model.
+	It does not rely on SQL any more and it is more consistent
+	because of evaluating the rules of the required fields.
+	Phase transition should only be possible if there are
+	no contradictions in the data model. XXX: It still does
+	not work correctly.
+
+	* waskaweb/model/casedocument.py: Build more look-ups
+	  at FormEd tree loading because traversing the tree
+	  over and over again to filter out the rules is not
+	  very efficent.
+
+	* waskaweb/model/phases_factory.py: Removed old SQL stuff
+	  and applies checking the rules to figure out if a
+	  case is consistent.
+
+	* waskaweb/model/case.py: Uses new model now. Removed
+	  some _very_ cruel code which misused the search engine
+	  to figure out if a case is consistent.
+
+	* waskaweb/controllers/case.py: Use new model now.
+
+	* waskaweb/lib/search.py: Removed some ugly code for checking
+	  phases. This lib needs a complete replacement!
+
 2009-02-24	Sascha L. Teichmann <teichmann at intevation.de>
 
 	* waskaweb/lib/renderer.py: Fixed quoting in HTML attributes. This

Modified: wasko/trunk/waskaweb/controllers/case.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case.py	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/waskaweb/controllers/case.py	2009-02-25 08:13:53 UTC (rev 297)
@@ -69,8 +69,8 @@
 from waskaweb.model.data           import FilteredNodeComponentProxy
 from waskaweb.model.logbook        import Logbook, LogbookEntry, LogbookEntryChecker
 
-from waskaweb.model.phases_factory   import phases_pairs
 from waskaweb.model.phases           import Phase
+from waskaweb.model.phases_factory   import RequiredFields
 from waskaweb.model.phase_transition import symbol_phase, phase_neighbors
 
 from waskaweb.lib.db        import db
@@ -587,8 +587,6 @@
     def phase(self, id):
         id     = self._checkInt(id)
         case   = self._loadCase(id)
-        fields = case.getRequiredFields()
-
         phase = case.getState().getPhase()
 
         session_case = session.get('case')
@@ -596,7 +594,9 @@
         mode = session_case and session_case.getMode() or "show" 
         link = lambda ti: '"/case/%s/%d/%s"' % (mode, id, ti.key)
 
-        c.phase_pairs   = phases_pairs(fields, phase, self.getNavigation(), link)
+        rf = RequiredFields(g.formedTree)
+
+        c.phase_pairs   = rf.phases_pairs(phase, self.getNavigation(), link)
         c.current_phase = Phase(phase, True)
 
         c.form_navigation  = self._getFormNavigation()
@@ -635,10 +635,10 @@
 
                 case_session = session.get('case')
 
-                if case_session.isYoungerThan(INCONSISTENCY_CHECK_AFTER):
-                    fields = case.getRequiredFields()
-                    if not fields.isPhaseComplete(new_phase_symbol):
-                        raise StandardError("Phase ist nicht komplett.")
+                #if case_session.isYoungerThan(INCONSISTENCY_CHECK_AFTER):
+                #    fields = case.getRequiredFields()
+                #    if not fields.isPhaseComplete(new_phase_symbol):
+                #        raise StandardError("Phase ist nicht komplett.")
 
                 state.setPhase(new_phase)
 

Modified: wasko/trunk/waskaweb/lib/search.py
===================================================================
--- wasko/trunk/waskaweb/lib/search.py	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/waskaweb/lib/search.py	2009-02-25 08:13:53 UTC (rev 297)
@@ -31,10 +31,10 @@
 import sys
 import re
 from datetime import datetime
-from threading import Lock
+
 from waskaweb.lib.db import db
-from waskaweb.model.phases_factory import RequiredFields
 import psycopg2.extras
+
 from waskaweb.lib.base import session, g, h, config 
 
 SAVE_SEARCH = re.compile(r'[^\w:;\-\. ]', re.UNICODE)
@@ -80,8 +80,6 @@
       AND %s
     ORDER BY %s %s"""
 
-INCONSISTENCY_LOCK = None
-INCONSISTENCY_TYPE_QUERY = None
 INCONSISTENCY_CHECK_AFTER = '2008-08-31'
 
 SEARCH_AGENCY_SQL = \
@@ -97,27 +95,9 @@
 group by fkz
 ORDER BY %s %s"""
 
-
 def build_inconsistency_type_querys():
+    return {}
 
-    # TODO: 5,6 seems to be obsolete as this inconsistency will be covered by
-    # the phases
-    querys = {'1': 'm.erstgespraech is NULL', 
-              '2': 'm.erstgespraech::timestamp > now()',
-              '3': 'm.erstgespraech::timestamp > m.datum_cm_ende::timestamp',
-              '4': 'm.datum_cm_ende::timestamp > now()',
-              '5': '(m.cm_end_art <> -1 AND m.datum_cm_ende is NULL)',
-              '6': '(m.cm_end_art = -1 AND m.datum_cm_ende is not NULL)',
-              '7': '(m.phase = -1)'}
-
-    #Now fetch more inconsistencys based on phases
-    rf = RequiredFields()
-    rf.extractRequiredFields(g.formedTree)
-    sql = rf.getSQLWhereClauses()
-    for s,q in sql:
-        querys[s] = q 
-    return querys
-
 class Search:
     def __init__(self):
         pass
@@ -147,8 +127,8 @@
                             #if key == 'field':
                             #    field, operator, fvalue = [x.strip() for x in value.split(" ")]
                             #    fields[field] = fvalue
-                            if key in ['inconsistency', 'bad']:
-                                bad_types.append(value)
+                            #if key in ['inconsistency', 'bad']:
+                            #    bad_types.append(value)
                             else:
                                 options[key] = value
                     except ValueError, err :
@@ -247,18 +227,7 @@
         #Identify bad cases
         bad_query = []
 
-        global INCONSISTENCY_LOCK 
-        INCONSISTENCY_LOCK= Lock()
-        global INCONSISTENCY_TYPE_QUERY
-        INCONSISTENCY_LOCK.acquire()
-        try:
-            try:
-                if not INCONSISTENCY_TYPE_QUERY:
-                    INCONSISTENCY_TYPE_QUERY = build_inconsistency_type_querys()
-            except:
-                INCONSISTENCY_TYPE_QUERY = {}
-        finally:
-            INCONSISTENCY_LOCK.release()
+        INCONSISTENCY_TYPE_QUERY = {} # remove this
 
         for type_id in bad_types:
             query = INCONSISTENCY_TYPE_QUERY.get(str(type_id))

Modified: wasko/trunk/waskaweb/model/case.py
===================================================================
--- wasko/trunk/waskaweb/model/case.py	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/waskaweb/model/case.py	2009-02-25 08:13:53 UTC (rev 297)
@@ -53,7 +53,6 @@
 from waskaweb.model.document import listDocuments 
 
 from waskaweb.model.phase_transition import phase_description
-from waskaweb.model.phases_factory   import RequiredFields, phases_pairs
 
 from waskaweb.lib.helpers import dd_mm_yyyy_HH_MM, dd_mm_YYYY
 
@@ -1031,17 +1030,6 @@
             ps.keepUndefined()
         self.getState().setState(1)
 
-    def getRequiredFields(self):
-        con, cur = None, None
-        try:
-            con = db.getConnection()
-            cur = con.cursor()
-            rf = RequiredFields()
-            rf.extractRequiredFields(g.formedTree)
-            return rf.loadFromDatabase(self.id, cur) and rf or None
-        finally:
-            db.recycleConnection(con, cur)
-
     def getFirstMeeting(self):
         return self.first_name
 
@@ -1176,10 +1164,11 @@
     def phasesAreConsistent(self):
         '''Returns True when the required fields for the current phase are
         complete and there are no other inconsistencys. Else False'''
-        case = CaseFactory().loadById(self.master_id) # Ugly we need to load the case here :(
-        rf = case.getRequiredFields()
+        #case = CaseFactory().loadById(self.master_id) # Ugly we need to load the case here :(
         cf = self.getPhase()
-        p_pairs = phases_pairs(rf, cf)
+        rf = RequiredFields(g.formedTree)
+        p_pairs = rf.phases_pairs(cf)
+
         for pair in p_pairs:
             p1, p2 = pair.getStart(), pair.getEnd()
             # Find current phase
@@ -1189,10 +1178,10 @@
                 return False 
         # Check other inconsistency
         # Search all cases with are inconsistent and then check if the current case is among them
-        user = session['USER_AUTHORIZED']
-        search_str = "state:1;state:2;state:4;state:5;bad:1;bad:2;bad:3;bad:4;bad:5;bad:6;bad:7;own:%s;standin:%s" % (user.id, user.id)
-        error_cases = Set(c.id for c in CaseOverview().search(search_str))
-        if case.id in error_cases: return False
+        #user = session['USER_AUTHORIZED']
+        #search_str = "state:1;state:2;state:4;state:5;bad:1;bad:2;bad:3;bad:4;bad:5;bad:6;bad:7;own:%s;standin:%s" % (user.id, user.id)
+        #error_cases = Set(c.id for c in CaseOverview().search(search_str))
+        #if case.id in error_cases: return False
         return True
 
     def getAccessTime(self, format=None):

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-02-25 08:13:53 UTC (rev 297)
@@ -71,9 +71,23 @@
 
     def __init__(self, root=None):
         Document.__init__(self, root)
+
+        self.all_rules = list(self.findAllByClass(RuleLeaf))
+
         collector = WidgetCollector()
         self.visit(collector.visitor)
 
+        self.buildNameToWidget(collector)
+        self.buildWidgetsToPages(collector)
+        self.buildVarToRules()
+        self.buildPhases(collector)
+
+    def buildNameToWidget(self, collector):
+        self.widgets = dict([
+            (w.getName(), w) 
+            for w in collector.widgets if w.getName()])
+
+    def buildWidgetsToPages(self, collector):
         widgets2pages = {}
         for widget in collector.widgets:
             page = widget
@@ -83,8 +97,64 @@
                 widgets2pages[widget.getName()] = page.getName()
 
         self.widgets2pages = widgets2pages
-        self.widgets = dict([(w.getName(), w) for w in collector.widgets if w.getName()])
 
+    def buildVarToRules(self):
+        var2rules = {}
+        for rule in self.all_rules:
+            expr = rule.getExpr()
+            vars = expr.getDependencies()
+            for var in vars:
+                var2rules.setdefault(var, []).append(rule)
+        self.var2rules = var2rules
+
+    def buildPhases(self, collector):
+
+        all, all_times = [], []
+
+        phases, times = {}, {}
+
+        for nc in collector.widgets:
+            flags = nc.getFlags()
+            if flags is None: continue
+            for pair in flags.split(';'):
+                pair = pair.strip()
+                if not pair: continue
+                p = [p.strip() for p in pair.split(':')]
+                if len(p) > 1:
+                    kind, phase = p[0], p[1]
+                    if kind == "required":
+                        for p in [p.strip() for p in phase.split(',')]:
+                            if p: phases.setdefault(p, []).append(nc)
+                    elif kind == "time":
+                        for p in [p.strip() for p in phase.split(',')]:
+                            if p: times.setdefault(p, []).append(nc)
+                else:
+                    # TODO: Fix formed tree
+                    if p[0] == "required":
+                        all.append(nc)
+                    elif p[0] == "time":
+                        all_times.append(nc)
+
+        for a in all:
+            for v in phases.itervalues():
+                v.append(a)
+
+        for t in all_times:
+            for v in times.itervalues():
+                v.append(t)
+
+        self.phases_vars = phases
+        self.time_vars   = times
+
+    def getPhaseVars(self, phase):
+        return self.phases_vars.get(phase)
+
+    def getTimeVars(self, phase):
+        return self.time_vars.get(phase)
+
+    def getRulesForVariable(self, var):
+        return self.var2rules.get(var)
+
     def getPageStore(self, name, ds_id=None, no_data=False):
 
         if no_data: # XXX: urcan mode!
@@ -107,6 +177,12 @@
         page_store = self.getPageStore(page_name, ds_id)
         return page_store.getData(name)
 
+    def getPhasePairs(self, current_phase, navigation = None, link = None):
+        return ()
+
+    def getAllRules(self):
+        return self.all_rules
+
     def warningsOnPage(self, page, ds_id):
         """ Generates a dictionary of warnings that should be displayed
             on a given page.
@@ -117,7 +193,7 @@
 
         warnings = {}
 
-        for r in self.findAllByClass(RuleLeaf):
+        for r in self.all_rules:
             mark, expr = r.getMark(), r.getExpr()
             if not mark or not expr: continue
             # warnings only

Modified: wasko/trunk/waskaweb/model/phases_factory.py
===================================================================
--- wasko/trunk/waskaweb/model/phases_factory.py	2009-02-24 15:13:01 UTC (rev 296)
+++ wasko/trunk/waskaweb/model/phases_factory.py	2009-02-25 08:13:53 UTC (rev 297)
@@ -31,35 +31,17 @@
 from waskaweb.model.phases           import *
 from waskaweb.model.phase_transition import *
 
-from waskaweb.model.data             import PageNode, WidgetCollector, DateLeaf
+from waskaweb.model.data             import PageNode, WidgetCollector, DateLeaf, RuleLeaf
 
-IS_FILLED = \
-"""(%(name)s IS NOT NULL
-    AND (get_default_value('master_tbl', '%(name)s') IS NULL
-        OR %(name)s <> get_default_value('master_tbl', '%(name)s')))
-"""
-IS_FILLED_DATE = \
-"""(%(name)s IS NOT NULL
-    AND (get_default_value('master_tbl', '%(name)s') IS NULL
-        OR %(name)s::date <> get_default_value('master_tbl', '%(name)s')::date))
-"""
+import re
 
-IS_NOT_FILLED = \
-"""(NOT (%(name)s IS NOT NULL
-    AND (get_default_value('master_tbl', '%(name)s') IS NULL
-        OR %(name)s <> get_default_value('master_tbl', '%(name)s'))))
-"""
+from cgi import escape
 
-IS_NOT_FILLED_DATE = \
-"""(NOT (%(name)s IS NOT NULL
-    AND (get_default_value('master_tbl', '%(name)s') IS NULL
-        OR %(name)s::date <> get_default_value('master_tbl', '%(name)s')::date)))
-"""
+PAIRS = (
+    (CLEAR_START, CLEAR_ENDE, u"Eingangs-<wbr />Dokumentation"),
+    (CM_START,    CM_ENDE,    u"Case<wbr />Management"),
+    (NB_START,    NB_ENDE,    u"Nach&shy;betreuung"))
 
-SELECT = \
-''' SELECT %s FROM master_tbl_view WHERE id = %%(id)s
-'''
-
 def description(nc):
     p = nc
     while p:
@@ -71,272 +53,155 @@
     return nc.getName()
 
 def page(nc):
-    p = nc.parent
+    p = nc
     while p:
         if isinstance(p, PageNode):
             return p
         p = p.parent
     return p
 
-def lookup_item(item, navigation, link):
-    if navigation and link:
-        p = page(item)
-        if p:
-            ti = navigation.findTreeItemByPageName(p.getName())
-            if ti: return link(ti)
-    return '"/case/required/%s" target="_blank"' % item.getName()
-
 class RequiredFields:
 
-    def __init__(self):
-        self.phases = {}
+    def __init__(self, formed):
+        self.formed          = formed
+        self.phase_times     = {}
+        self.missing_cache   = {}
+        self.rule_eval_cache = {}
 
-    def extractRequiredFields(self, document):
+    def getPhaseTime(self, phase):
+        try:
+            return self.phase_times[phase]
+        except KeyError:
+            try:
+                time_vars = self.formed.getTimeVars(phase)
+                if not time_vars: return None
+                pt = [self.formed.getData(x) for x in time_vars]
+                if pt: pt = pt[0]
+                else:  pt = None
+                self.phase_times[phase] = pt
+            except KeyError:
+                return None
+            return pt
 
-        phases, times,  = {}, {}
+    def isPhaseComplete(self, phase):
+        return bool(self.missingFields(phase))
 
-        all, all_times = [], []
+    def missingFields(self, phase):
 
-        collector = WidgetCollector()
-        document.visit(collector.visitor)
-        for nc in collector.widgets:
-            flags = nc.getFlags()
-            if flags is None: continue
-            for pair in flags.split(';'):
-                pair = pair.strip()
-                if not pair: continue
-                p = [p.strip() for p in pair.split(':')]
-                if len(p) > 1:
-                    kind, phase = p[0], p[1]
-                    if kind == "required":
-                        for p in [p.strip() for p in phase.split(',')]:
-                            if p: phases.setdefault(p, []).append([nc, None])
-                    elif kind == "time":
-                        for p in [p.strip() for p in phase.split(',')]:
-                            if p: times.setdefault(p, []).append([nc, None])
-                else:
-                    # TODO: Fix formed tree
-                    if p[0] == "required":
-                        all.append([nc, None])
-                    elif p[0] == "time":
-                        all_times.append([nc, None])
+        vars = self.formed.getPhaseVars(phase)
+        if not vars: return []
 
-        for a in all:
-            for v in phases.itervalues():
-                v.append(a)
+        try:
+            return self.missing_cache[phase]
+        except KeyError:
+            pass
 
-        for t in all_times:
-            for v in times.itervalues():
-                v.append(t)
+        getData = self.formed.getData
 
-        for v in phases.itervalues():
-            v.sort(cmp=lambda a, b: cmp(description(a[0]), description(b[0])))
+        missing = []
+        self.missing_cache[phase] = missing
+        for var in vars:
+            var_name = var.getName()
+            try:
+                result = self.rule_eval_cache[var_name]
+            except KeyError:
+                rules = self.formed.getRulesForVariable(
+                    var_name)
+                if not rules: continue
+                result = True
+                for rule in rules:
+                    expr   = rule.getExpr()
+                    deps   = expr.getDependencies()
+                    params = dict((v, getData(v)) for v in deps)
+                    try:
+                        result = expr.eval(params)
+                    except:
+                        result = False
+                    if not result: break
 
-        self.phases = phases
-        self.times  = times
-        return phases
+                self.rule_eval_cache[var_name] = result
+                if not result:
+                    missing.append(var)
+        return missing
 
-    def loadTimes(self, ds_id, cur):
-        fields = {}
-        idx = 0
-        for f in self.times.itervalues():
-            for l in f:
-                name = l[0].getName()
-                if not fields.has_key(name):
-                    fields[name] = idx
-                    idx += 1
+    def getLinkListForPhase(self, phase, navigation=None, link=None):
 
-        all = fields.items()
+        if not navigation and not link: return u""
 
-        if not all: return True
+        missing = self.missingFields(phase)
 
-        all.sort(cmp = lambda a, b: cmp(a[1], b[1]))
-
-        select = SELECT % ', '.join([a[0] for a in all])
-
-        cur.execute(select, { 'id': ds_id })
-        row = cur.fetchone()
-        if not row: return False
-
-        for a in all:
-            fields[a[0]] = row[a[1]]
-
-        for a in self.times.itervalues():
-            for b in a:
-                b[1] = fields.get(b[0].getName())
-
-        return True
-
-    def loadFromDatabase(self, ds_id, cur):
-        return self.loadFilled(ds_id, cur) and self.loadTimes(ds_id, cur) and True or False
-
-
-    def getSQLWhereClauses(self):
-        """ returns list of tuples (<symbol of phase>, <sql where clause>). The
-        where clause will return cases with inconsistencies for the current
-        state."""
-        clauses = []
-        # Iterate over all phases
-        for symbol in self.phases.keys():
-
-            # for each phase build a dict of predecessor of the current phase
-            predecessor_phases = {}
-            phase_id = symbol_phase(symbol)
-            for id in phase_predecessors_path(phase_id, include_root=True):
-                if id == -1: continue #ignore "unknown" phase
-                predecessor_phases[phase_symbol(id)] = self.phases.get(phase_symbol(id))
-            # now build the where clause to check if the current phase is
-            # consistent.
-            where_parts = []
-            for s, v in predecessor_phases.iteritems():
-                try:
-                    select_terms = []
-                    for name in [i[0].getName() for i in v]:
-                        if isinstance(i[0], DateLeaf):
-                            select_terms.append(IS_NOT_FILLED_DATE % {'name': name})
-                        else:
-                            select_terms.append(IS_NOT_FILLED % {'name': name})
-                    part = " OR ".join(select_terms)
-                except:
-                    pass
-                where_parts.append(part)
-            where = "(phase = %s AND ((%s))) " % (phase_id, " OR ".join(where_parts))
-            clauses.append((symbol, where))
-        return clauses
-
-    def loadFilled(self, ds_id, cur):
-        fields = {}
-        fields_type = {}
-        idx = 0
-        for f in self.phases.itervalues():
-            for l in f:
-                name = l[0].getName()
-                if not fields.has_key(name):
-                    fields[name] = idx
-                    fields_type[name] = l[0] 
-                    idx += 1
-
-        all = fields.items()
-
-        if not all: return True
-
-        all.sort(cmp = lambda a, b: cmp(a[1], b[1]))
-
-        select_terms = []
-        for a in all:
-            if isinstance(fields_type.get(a[0]), DateLeaf):
-                select_terms.append(IS_FILLED_DATE % { 'name': a[0] })
-            else:
-                select_terms.append(IS_FILLED % { 'name': a[0] })
-
-        select = SELECT % ', '.join(select_terms)
-        cur.execute(select, { 'id': ds_id })
-        row = cur.fetchone()
-        if not row: return False
-
-        for a in all:
-            fields[a[0]] = row[a[1]]
-
-        for a in self.phases.itervalues():
-            for b in a:
-                b[1] = fields.get(b[0].getName())
-
-        return True
-
-    def getPhase(self, phase):
-        return self.phases.get(phase)
-
-
-    def getPhaseTime(self, phase):
-        try:
-            return self.times[phase][0][1]
-        except KeyError:
-            return None
-
-    def isPhaseComplete(self, phase):
-        try:
-            for l in self.phases[phase]:
-                if not l[1]:
-                    return False
-        except KeyError:
-            return False
-
-        return True
-
-    def getLinkListForPhase(self, phase, navigation = None, link = None):
-        try:
-            phase = self.phases[phase]
-        except KeyError:
-            return u""
-
         out = []
 
-        for a in phase:
-            warn = (not a[1]) and ' class="required_missing"' or ""
-            l = '<a href=%s %s>%s</a>' % (
-                lookup_item(a[0], navigation, link),
-                warn, 
-                description(a[0]))
-            out.append(l)
+        used_pages = set()
 
-        return ',\n'.join(out)
+        for var in missing:
+            p = page(var)
+            p_name = p.getName()
+            if p_name in used_pages: continue
+            tree_item = navigation.findTreeItemByPageName(p_name)
+            if not tree_item: continue
+            tree_item = tree_item.deepest_item()
+            l = link(tree_item)
+            out.append('<a href=%s>%s</a>' % (
+                l, escape(description(p)).replace(' ', '&nbsp;')))
+            used_pages.add(p_name)
 
-PAIRS = (
-    (CLEAR_START,    CLEAR_ENDE,    u"Eingangs-<wbr />Dokumentation"),
-    (CM_START,       CM_ENDE,       u"Case<wbr />Management"),
-    (NB_START,       NB_ENDE,       u"Nach&shy;betreuung"))
+        return u", ".join(out)
 
-def phases_pairs(required_fields, current_phase, navigation = None, link = None):
+    def phases_pairs(self, current_phase, navigation=None, link=None):
 
-    pairs = []
+        pairs = []
 
-    all = {}
+        all = {}
 
-    symbol = phase_symbol(current_phase)
-    cur_phase = Phase(
-                current_phase,
-                True,
-                required_fields.isPhaseComplete(symbol),
-                required_fields.getPhaseTime(symbol),
-                required_fields.getLinkListForPhase(symbol, navigation, link))
+        symbol = phase_symbol(current_phase)
 
-    for p1, p2, description in PAIRS:
+        cur_phase = Phase(
+            current_phase,
+            True,
+            self.isPhaseComplete(symbol),
+            self.getPhaseTime(symbol),
+            self.getLinkListForPhase(symbol, navigation, link))
 
-        symbol = phase_symbol(p1)
+        for p1, p2, description in PAIRS:
 
-        start = Phase(
-            p1,
-            p1 == current_phase,
-            required_fields.isPhaseComplete(symbol),
-            required_fields.getPhaseTime(symbol),
-            required_fields.getLinkListForPhase(symbol, navigation, link))
+            symbol = phase_symbol(p1)
 
-        all[p1] = start
+            start = Phase(
+                p1,
+                p1 == current_phase,
+                self.isPhaseComplete(symbol),
+                self.getPhaseTime(symbol),
+                self.getLinkListForPhase(symbol, navigation, link))
 
-        symbol = phase_symbol(p2)
+            all[p1] = start
 
-        ende = Phase(
-            p2,
-            p2 == current_phase,
-            required_fields.isPhaseComplete(symbol),
-            required_fields.getPhaseTime(symbol),
-            required_fields.getLinkListForPhase(symbol, navigation, link))
+            symbol = phase_symbol(p2)
 
-        all[p2] = ende
+            ende = Phase(
+                p2,
+                p2 == current_phase,
+                self.isPhaseComplete(symbol),
+                self.getPhaseTime(symbol),
+                self.getLinkListForPhase(symbol, navigation, link))
 
+            all[p2] = ende
 
-        # Only add phases which are on the path of the current phase
-        #pairs.append(PhasePair(start, ende, description))
-        if cur_phase.hasSuccessor(start) or cur_phase.hasPredecessor(start) or current_phase == p1: 
-            pairs.append(PhasePair(start, ende, description))
 
-    for p in all.itervalues():
-        for pred in phase_predecessors(p.phase):
-            try:
-                p.addPredecessor(all[pred])
-            except KeyError:
-                pass
+            # Only add phases which are on the path of the current phase
+            #pairs.append(PhasePair(start, ende, description))
+            if cur_phase.hasSuccessor(start) \
+            or cur_phase.hasPredecessor(start) \
+            or current_phase == p1: 
+                pairs.append(PhasePair(start, ende, description))
 
-    return pairs
+        for p in all.itervalues():
+            for pred in phase_predecessors(p.phase):
+                try:
+                    p.addPredecessor(all[pred])
+                except KeyError:
+                    pass
 
+        return pairs
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list