[Mpuls-commits] r150 - in waska/trunk: . waskaweb/controllers waskaweb/lib waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Sep 12 11:14:00 CEST 2008
Author: teichmann
Date: 2008-09-12 11:13:58 +0200 (Fri, 12 Sep 2008)
New Revision: 150
Modified:
waska/trunk/ChangeLog.txt
waska/trunk/waskaweb/controllers/agency_overview.py
waska/trunk/waskaweb/controllers/case_overview.py
waska/trunk/waskaweb/lib/csv.py
waska/trunk/waskaweb/lib/exportselection.py
waska/trunk/waskaweb/lib/xmlexport.py
waska/trunk/waskaweb/model/case.py
waska/trunk/waskaweb/model/phase_transition.py
Log:
Added selective CSV export. Fixed a bug when exporting anonymized.
Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/ChangeLog.txt 2008-09-12 09:13:58 UTC (rev 150)
@@ -1,3 +1,20 @@
+2008-09-12 Sascha L. Teichmann <sascha.teichmann at intevation.de>
+
+ * waskaweb/controllers/agency_overview.py
+ waskaweb/controllers/case_overview.py: Added selection from session
+ to call. TODO: Adjust GUI.
+
+ * waskaweb/model/case.py: Added selection to library call.
+
+ * waskaweb/model/phase_transition.py: Removed needless function
+
+ * waskaweb/lib/exportselection.py: Fixed bug which prevents anonymisation
+ from working. Added feature to user configurable where clauses because
+ CSV-export works slightly different from Excel/XML.
+
+ * waskaweb/lib/csv.py: Added selection.
+ * waskaweb/lib/xmlexport.py: uses selection correctly now.
+
2008-09-11 Torsten Irlaender <torsten.irlaender at intevation.de>
Modified search for inconsistent cases.
Modified: waska/trunk/waskaweb/controllers/agency_overview.py
===================================================================
--- waska/trunk/waskaweb/controllers/agency_overview.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/controllers/agency_overview.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -351,7 +351,8 @@
try:
if case_ids:
case_bundle = CaseBundle(case_ids)
- csv = case_bundle.exportAsCSV()
+ selection_checker = self.__getSelectionChecker()
+ csv = case_bundle.exportAsCSV(selection_checker)
data = paste.fileapp.DataApp(
csv,
content_type='text/comma-separated-values',
Modified: waska/trunk/waskaweb/controllers/case_overview.py
===================================================================
--- waska/trunk/waskaweb/controllers/case_overview.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/controllers/case_overview.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -799,7 +799,8 @@
try:
if case_ids:
case_bundle = CaseBundle(case_ids)
- csv = case_bundle.exportAsCSV(anonymize)
+ selection_checker = self.__getSelectionChecker()
+ csv = case_bundle.exportAsCSV(selection_checker, anonymize)
data = paste.fileapp.DataApp(
csv,
content_type = 'text/csv',
Modified: waska/trunk/waskaweb/lib/csv.py
===================================================================
--- waska/trunk/waskaweb/lib/csv.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/lib/csv.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -34,39 +34,13 @@
import sys
+from exportselection import SelectorFactory, CasePartsSelection, RG_ALL
+
SEP = "\t"
-SELECT_MASTER_TBL_WHERE = \
-"""SELECT * FROM master_tbl_view
- WHERE %s"""
-
-SELECT_MASTER_ANON = \
-"""SELECT * FROM master_tbl_anonym_view
- WHERE %s"""
-
FETCH_ALL_IDS = \
"""SELECT id FROM master_tbl_view"""
-RG_VIEWS = (
- "rg_kompetenzfestellung_tbl_view",
- "rg_angebote_berufliche_qualifizierung_tbl_view",
- "rg_angebote_berufsvorbereitung_tbl_view",
- "rg_angebote_bildenden_bereich_tbl_view",
- "rg_angebote_lebensbewaeltigung_tbl_view")
-
-RG_VIEWS_ANON = (
- "rg_kompetenzfestellung_tbl_anonym_view",
- "rg_angebote_berufliche_qualifizierung_tbl_anonym_view",
- "rg_angebote_berufsvorbereitung_tbl_anonym_view",
- "rg_angebote_bildenden_bereich_tbl_anonym_view",
- "rg_angebote_lebensbewaeltigung_tbl_anonym_view")
-
-SELECT_RG = \
-"""SELECT * FROM %s WHERE master_id = %d"""
-
-SELECT_RG_WHERE = \
-"""SELECT * FROM %s WHERE %s"""
-
BLACK_LIST = set(['id', 'master_id', 'uuid_id', 'bearbeiter_id'])
def strReplace(x):
@@ -100,7 +74,7 @@
def __init__(self, orig_pos):
RepeatGroup.__init__(self)
self.orig_pos = orig_pos
- self.rgs = [[] for i in range(len(RG_VIEWS))]
+ self.rgs = [[] for i in range(len(RG_ALL))]
def appendRepeatGroup(self, rg, index):
self.rgs[index].append(rg)
@@ -110,13 +84,23 @@
self.cases = None
self.anonymize = anonymize
- def fetchCases(self, cur, ids):
+ def fetchCases(self, cur, ids, selector_factory):
+
case_hash = dict([(x[1], Case(x[0])) for x in enumerate(ids)])
ids.sort()
ids = range_compress(ids)
- where = where_ids(ids)
- cur.execute((self.anonymize and SELECT_MASTER_ANON or SELECT_MASTER_TBL_WHERE) % where)
+ master_where = where_ids(ids)
+ rg_where = where_ids(ids, 'master_id')
+
+ selector = selector_factory.createSelector(master_where, rg_where)
+
+ stmnt = selector.getSelectStatementByView('master_tbl')
+
+ #print >> sys.stderr, "stmnt: %s" % stmnt
+
+ cur.execute(stmnt)
+
headers, used_indices = None, None
while True:
@@ -131,13 +115,11 @@
case_hash[row[0]].setColumns(headers, values)
- where = where_ids(ids, "master_id")
+ for index, view in enumerate(RG_ALL):
- for index, view in enumerate(self.anonymize and RG_VIEWS_ANON or RG_VIEWS):
-
headers, used_indices = None, None
- cur.execute(SELECT_RG_WHERE % (view, where))
+ cur.execute(selector.getSelectStatementByView(view))
while True:
row = cur.fetchone()
@@ -152,11 +134,11 @@
rg.setColumns(headers, values)
case_hash[row[1]].appendRepeatGroup(rg, index)
- self.cases = list(case_hash.itervalues())
+ self.cases = case_hash.values()
self.cases.sort(lambda a, b: cmp(a.orig_pos, b.orig_pos))
def maxRepeatGroups(self):
- mc = [0] * len(RG_VIEWS)
+ mc = [0] * len(RG_ALL)
for rgs in [c.rgs for c in self.cases]:
for i in range(len(mc)):
mc[i] = max(mc[i], len(rgs[i]))
@@ -174,7 +156,7 @@
return ""
case = self.cases[0]
headers = case.headerFields()
- for i in range(len(RG_VIEWS)):
+ for i in range(len(RG_ALL)):
rg = self.noneEmptyRepeatGroup(i)
if rg is None:
continue
@@ -188,7 +170,7 @@
def dumpFields(self, out):
fills = []
- for i in range(len(RG_VIEWS)):
+ for i in range(len(RG_ALL)):
rg = self.noneEmptyRepeatGroup(i)
if rg is None: c = 0
else: c = rg.numFields()
@@ -207,7 +189,7 @@
print >> out, "%s" % SEP.join(map(lambda x: u"%s" % strReplace(x), line))
-def exportAsCSV(cur, out, ids=None, anonymize=False):
+def exportAsCSV(cur, out, ids=None, case_parts=None, anonymize=False):
#from datetime import datetime
#start = datetime.now()
cases = Cases(anonymize)
@@ -218,10 +200,18 @@
row = cur.fetchone()
if row is None: break
ids.append(int(row[0]))
- cases.fetchCases(cur, ids)
+
+ if case_parts is None:
+ case_parts = CasePartsSelection()
+
+ selector_factory = SelectorFactory(case_parts, anonymize)
+
+ cases.fetchCases(cur, ids, selector_factory)
+
cases.maxRepeatGroups()
cases.generateHeader(out)
cases.dumpFields(out)
+
#stop = datetime.now()
#print >> sys.stderr, "export took: %s" % (stop-start)
Modified: waska/trunk/waskaweb/lib/exportselection.py
===================================================================
--- waska/trunk/waskaweb/lib/exportselection.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/lib/exportselection.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -41,6 +41,13 @@
"angebote_berufliche_qualifizierung",
"angebote_lebensbewaeltigung")
+RG_ALL = (
+ "kompetenzfestellung",
+ "angebote_bildenden_bereich",
+ "angebote_berufsvorbereitung",
+ "angebote_berufliche_qualifizierung",
+ "angebote_lebensbewaeltigung")
+
SECTION_MAP = {
'form_section_666': 'page_einverstaendnis', # Einverständniserklärung, Phase
'form_section_0' : 'page_0', # Zuständigkeiten, Eingangsdaten
@@ -125,32 +132,28 @@
class Selector:
- def __init__(self, anonymize=False):
+ def __init__(self, anonymize=False, master_where="id = %(id)s", rg_where="master_id = %(id)s"):
self.views = {}
self.exportDocuments = False
self.exportLogbook = False
self.anonymize = anonymize
+ self.master_where = master_where
+ self.rg_where = rg_where
- def getSelectStatement(self, view):
+ def getSelectStatementByView(self, view):
return self.views.get(view)
- def getSelectStatementByView(self, view):
- if view == 'master_tbl':
- relname = self.anonymize and "master_tbl_anonym_view" or "master_tbl_view"
- else:
- relname = (self.anonymize and "rg_%s_tbl_anonym_view" or "rg_%s_tbl_view") % view
- return self.views.get(relname)
-
def addRepeatGroup(self, name):
relname = (self.anonymize and "rg_%s_tbl_anonym_view" or "rg_%s_tbl_view") % name
- self.views['rg_%s_tbl_view' % name] = \
- "SELECT * FROM %s WHERE master_id = %%(id)s" % relname
+ self.views[name] = "SELECT * FROM %s WHERE %s" % (relname, self.rg_where)
def addMasterTable(self, projection):
+ #print >> sys.stderr, "id: ", id(self), " ", self.anonymize
relname = self.anonymize and "master_tbl_anonym_view" or "master_tbl_view"
- self.views['master_tbl_view'] = "SELECT %s FROM %s WHERE id = %%(id)s" % (
+ self.views['master_tbl'] = "SELECT %s FROM %s WHERE %s" % (
", ".join(projection),
- relname)
+ relname,
+ self.master_where)
class SelectorFactory:
@@ -158,8 +161,8 @@
self.case_parts = case_parts
self.anonymize = anonymize
- def createSelector(self):
- selector = Selector(self.anonymize)
+ def createSelector(self, master_where = "id = %(id)s", rg_where = "master_id = %(id)s"):
+ selector = Selector(self.anonymize, master_where, rg_where)
selected_sections = self.case_parts.allSelectedSections()
# always export einverstaendiserklaerung and phase
selected_sections.insert(0, 'form_section_666')
Modified: waska/trunk/waskaweb/lib/xmlexport.py
===================================================================
--- waska/trunk/waskaweb/lib/xmlexport.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/lib/xmlexport.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -40,7 +40,7 @@
import waskaweb.lib.helpers as h
-from exportselection import RG_UNTERSTUETZUNG, SelectorFactory, CasePartsSelection
+from exportselection import RG_UNTERSTUETZUNG, SelectorFactory, CasePartsSelection, RG_ALL
FETCH_ALL_IDS = \
"""SELECT id FROM master_tbl_view"""
@@ -59,10 +59,6 @@
WHERE master_id = %(id)s
"""
-RG_VIEWS = ["kompetenzfestellung"]
-RG_VIEWS.extend(RG_UNTERSTUETZUNG)
-RG_VIEWS = tuple(RG_VIEWS)
-
BLACK_LIST = set(['id', 'master_id', 'bearbeiter_id'])
USER_LOGIN = re.compile(r"(?:[^_]*)_(?:[^_]*)_(.+)")
@@ -166,9 +162,9 @@
def fetchMasterTable(self, cur):
selector = self.selector
- stmnt = selector.getSelectStatement('master_tbl_view')
+ stmnt = selector.getSelectStatementByView('master_tbl')
if not stmnt:
- print >> sys.stderr, "No SELECT statement for master_tbl_view found"
+ print >> sys.stderr, "No SELECT statement for master_tbl found"
return
cur.execute(stmnt, { 'id': self.master_id })
row = cur.fetchone()
@@ -181,9 +177,8 @@
def fetchRepeatGroups(self, cur):
selector = self.selector
id_dict = { 'id': self.master_id }
- for view in RG_VIEWS:
- viewname = "rg_%s_tbl_view" % view
- stmnt = selector.getSelectStatement(viewname)
+ for view in RG_ALL:
+ stmnt = selector.getSelectStatementByView(view)
if stmnt is None: continue
cur.execute(stmnt, id_dict)
rs = []
Modified: waska/trunk/waskaweb/model/case.py
===================================================================
--- waska/trunk/waskaweb/model/case.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/model/case.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -270,7 +270,7 @@
print >> sys.stderr, "Could not mark Case to delete from bundle"
return num
- def exportAsCSV(self, anonymize=False):
+ def exportAsCSV(self, case_parts=None, anonymize=False):
con, cur = None, None
f = StringIO.StringIO()
Writer = codecs.getwriter('latin-1')
@@ -278,7 +278,7 @@
try:
con = db.getConnection()
cur = con.cursor()
- exportAsCSV(cur, out, self.listDatasetIds(), anonymize)
+ exportAsCSV(cur, out, self.listDatasetIds(), case_parts, anonymize)
out.flush()
bytes = out.getvalue()
out.close()
Modified: waska/trunk/waskaweb/model/phase_transition.py
===================================================================
--- waska/trunk/waskaweb/model/phase_transition.py 2008-09-11 13:42:28 UTC (rev 149)
+++ waska/trunk/waskaweb/model/phase_transition.py 2008-09-12 09:13:58 UTC (rev 150)
@@ -68,8 +68,6 @@
SYMBOLS_PHASE = dict([(i[1], i[0]) for i in PHASE_SYMBOLS.iteritems()])
-def invert_phase_symbols():
- return dict()
PHASE_SUCCESSORS = {
UNKNOWN : [CLEAR_START],
More information about the Mpuls-commits
mailing list