[Mpuls-commits] r93 - in waska/trunk: . waskaweb/controllers waskaweb/lib waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Aug 28 07:23:57 CEST 2008
Author: teichmann
Date: 2008-08-28 07:23:56 +0200 (Thu, 28 Aug 2008)
New Revision: 93
Modified:
waska/trunk/ChangeLog.txt
waska/trunk/waskaweb/controllers/case.py
waska/trunk/waskaweb/lib/needed.py
waska/trunk/waskaweb/model/case.py
Log:
Load required fields from database.
Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt 2008-08-27 16:56:00 UTC (rev 92)
+++ waska/trunk/ChangeLog.txt 2008-08-28 05:23:56 UTC (rev 93)
@@ -1,3 +1,12 @@
+2008-08-28 Sascha L. Teichmann <sascha.teichmann at intevation.de>
+
+ * waskaweb/model/case.py: Load required fields via
+ case object now.
+
+ * waskaweb/controllers/case.py: use case object.
+
+ * waskaweb/lib/needed.py: Make required fields a class.
+
2008-08-27 Sascha L. Teichmann <sascha.teichmann at intevation.de>
* waskaweb/lib/needed.py: New. extracting required fields
Modified: waska/trunk/waskaweb/controllers/case.py
===================================================================
--- waska/trunk/waskaweb/controllers/case.py 2008-08-27 16:56:00 UTC (rev 92)
+++ waska/trunk/waskaweb/controllers/case.py 2008-08-28 05:23:56 UTC (rev 93)
@@ -49,8 +49,6 @@
CreateLogbookForm, \
EditLogbookForm
-from waskaweb.lib.needed import extractRequiredFields
-
from waskaweb.lib.helpers import dd_mm_YYYY, HH_MM
from waskaweb.model.repeatgroup import AidObject, AidList
@@ -676,9 +674,9 @@
@checkRole(('admin_ka', 'cm_ka'))
def phase(self, id):
- id = self._checkInt(id)
- case = self._loadCase(id)
- fields = extractRequiredFields(g.formedTree)
+ id = self._checkInt(id)
+ case = self._loadCase(id)
+ fields = case.getRequiredFields()
return render('/casemanagement/phase.mako')
@checkRole('cm_ka')
Modified: waska/trunk/waskaweb/lib/needed.py
===================================================================
--- waska/trunk/waskaweb/lib/needed.py 2008-08-27 16:56:00 UTC (rev 92)
+++ waska/trunk/waskaweb/lib/needed.py 2008-08-28 05:23:56 UTC (rev 93)
@@ -30,35 +30,94 @@
import sys
-def extractRequiredFields(document):
+IS_FILLED = \
+"""(%(name)s IS NOT NULL
+ AND %(name)s != get_default_value('master_tbl', '%(name)s'))
+"""
- phases = {}
+SELECT = \
+''' SELECT %s FROM master_tbl_view WHERE id = %%(id)s
+'''
- all = []
-
- for nc in document.walk():
- 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":
- phases.setdefault(phase, []).append(nc)
- else:
- # TODO: Fix formed tree
- if p[0] == "required":
- all.append(nc)
+BLACKLIST = set([
+ u'datum_ende_beratung',
+ u'foerderbedarf'])
- for a in all:
- for v in phases.itervalues():
- v.append(a)
+class RequiredFields:
- for k in sorted(phases.iterkeys()):
- print >> sys.stderr, "phase '%s': %s" % (k, ', '.join([nc.getName() for nc in phases[k]]))
+ def __init__(self):
+ self.phases = {}
+
+ def extractRequiredFields(self, document):
+
+ phases = {}
+
+ all = []
- return phases
+ for nc in document.walk():
+ 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":
+ phases.setdefault(phase, []).append([nc, None])
+ else:
+ # TODO: Fix formed tree
+ if p[0] == "required":
+ all.append([nc, None])
+ for a in all:
+ for v in phases.itervalues():
+ v.append(a)
+
+ #for k in sorted(phases.iterkeys()):
+ # print >> sys.stderr, "phase '%s': %s" % (
+ # k, ', '.join([nc[0].getName() for nc in phases[k]]))
+
+ self.phases = phases
+
+ return phases
+
+ def checkIfFilled(self, ds_id, cur):
+ fields = {}
+ idx = 0
+ for f in self.phases.itervalues():
+ for l in f:
+ name = l[0].getName()
+ if name in BLACKLIST:
+ print >> sys.stderr, "blacklist: %s" % name
+ continue
+ if not fields.has_key(name):
+ fields[name] = idx
+ idx += 1
+
+ all = fields.items()
+ all.sort(cmp = lambda a, b: cmp(a[1], b[1]))
+
+ select_terms = []
+ for a in all:
+ select_terms.append(IS_FILLED % { 'name': a[0] })
+
+ select = SELECT % ', '.join(select_terms)
+
+ #print >> sys.stderr, '%s' % select
+
+ 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
+
+
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
Modified: waska/trunk/waskaweb/model/case.py
===================================================================
--- waska/trunk/waskaweb/model/case.py 2008-08-27 16:56:00 UTC (rev 92)
+++ waska/trunk/waskaweb/model/case.py 2008-08-28 05:23:56 UTC (rev 93)
@@ -44,6 +44,7 @@
from waskaweb.lib.csv import exportAsCSV
from waskaweb.lib.excel import exportAsXLS
from waskaweb.lib.xmlexport import exportAsXML
+from waskaweb.lib.needed import RequiredFields
from waskaweb.lib.base import session, g, h, config
import waskaweb.lib.filters as F
from waskaweb.lib.pdfimporter import asXFA, FieldExtractor
@@ -322,7 +323,6 @@
db.recycleConnection(con, cur)
-
class CaseOverview:
def __init__(self, search_str=None):
self.ds_list = []
@@ -1014,6 +1014,17 @@
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.checkIfFilled(self.id, cur) and rf or None
+ finally:
+ db.recycleConnection(con, cur)
+
class State(object):
'''This class store the state and the last accesstime of the case.
Possible states are:
More information about the Mpuls-commits
mailing list