[Mpuls-commits] r1732 - in wasko/branches/2.0: jmdweb/model mpulsweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Feb 24 11:45:47 CET 2010
Author: torsten
Date: 2010-02-24 11:45:45 +0100 (Wed, 24 Feb 2010)
New Revision: 1732
Added:
wasko/branches/2.0/mpulsweb/model/phase.py
Removed:
wasko/branches/2.0/jmdweb/model/phase.py
Log:
Moved phasemodel to mpulsbase
Deleted: wasko/branches/2.0/jmdweb/model/phase.py
===================================================================
--- wasko/branches/2.0/jmdweb/model/phase.py 2010-02-24 10:45:32 UTC (rev 1731)
+++ wasko/branches/2.0/jmdweb/model/phase.py 2010-02-24 10:45:45 UTC (rev 1732)
@@ -1,140 +0,0 @@
-# -*- coding: utf-8 -*-
-import logging
-from pylons import session, g, c
-from pylons.i18n import _
-
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
-from mpulsweb.lib.db import PostgresDBInterface
-
-log = logging.getLogger(__name__)
-
-class PhaseFactory:
-
- def __init__(self):
- self.phases = PhaseList()
-
- def load(self, id):
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
- it = factory.loadInstanceTreeByIdentifier(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], it)
- end = PhasePart(g.mpuls_config.get('phases', 'pairs')[0].get(p)[1], it)
- 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, it):
- self.id = id
- self.fields = []
- pfields = g.mpuls_config.get('phases', 'fields')[0]
- for phasepart, fields in pfields.iteritems():
- if phasepart == id:
- for field in fields:
- name = field.get('name')
- page = field.get('page')
- rules = field.get('rules', [])
- if name:
- self.fields.append(Field(name, page, rules, it))
-
- def getLinks(self):
- out = []
- if len(self.fields) > 0:
- for field in self.fields:
- out.append(field.get_link())
- else:
- out.append(_('No required fields found'))
- return ", ".join(out)
-
- def getTime(self):
- return ""
-
- def is_ok(self):
- for field in self.fields:
- if not field.is_ok(): return False
- return True
-
-class Field:
- def __init__(self, name, page, rules, it):
- self.name = name
- self.page = page
- self.it = it
- self.conditions = []
-
- case_id = self.it.getRootNode().getIdentifier()
- 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:
- expr = condition.get('expr')
- msg = condition.get('msg')
- self.conditions.append(Condition(field, expr, msg))
-
- def get_link(self):
- out = []
- case_id = session['case'].id
- style = "ok" and self.is_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)
-
- def is_ok(self):
- for c in self.conditions:
- if not c.is_ok():
- return False
- return True
-
-class Condition:
-
- def __init__(self, field, expr, msg):
- self.field = field
- self.expr = expr
- self.msg = msg
-
- def is_ok(self):
- '''Returns True if expr is valid for the current value in field
- identified with name'''
- return self.evaluate()
-
- def evaluate(self):
- meta = self.field.getMeta()
- value = self.field.getValue()
- if self.expr == "isset":
- if value not in [-1, "-1", None, ""]: return True
- return False
-
-# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
Copied: wasko/branches/2.0/mpulsweb/model/phase.py (from rev 1729, wasko/branches/2.0/jmdweb/model/phase.py)
Property changes on: wasko/branches/2.0/mpulsweb/model/phase.py
___________________________________________________________________
Name: svn:mergeinfo
+
More information about the Mpuls-commits
mailing list