[Mpuls-commits] r2101 - wasko/branches/2.0/jmdweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Mar 24 13:01:42 CET 2010
Author: torsten
Date: 2010-03-24 13:01:40 +0100 (Wed, 24 Mar 2010)
New Revision: 2101
Modified:
wasko/branches/2.0/jmdweb/controllers/evaluate.py
Log:
* jmdweb/controllers/evaluate.py (get_phase_dates): New helper
function to get start and end datefields for a given phase.
* jmdweb/controllers/evaluate.py (get_search_options): Get default
dates from config file in case no dates are submitted. Use new helper
function get_phase_date. Removed handling of type of ending. Use
configuration of default selected phases.
Modified: wasko/branches/2.0/jmdweb/controllers/evaluate.py
===================================================================
--- wasko/branches/2.0/jmdweb/controllers/evaluate.py 2010-03-24 11:52:22 UTC (rev 2100)
+++ wasko/branches/2.0/jmdweb/controllers/evaluate.py 2010-03-24 12:01:40 UTC (rev 2101)
@@ -26,44 +26,60 @@
return path
return None
+def get_phase_dates(id):
+ '''Helper function to get start and end dates of phases ready to use in
+ SQL-Statements for evaluation based on the configuration. Note that
+ enddates will have a coalesce clause.'''
+ sdate, edate = None, None
+ log.debug('Phase: %s.' % id)
+ pair = g.mpuls_config.get('phases', 'pairs')[0].get(id)
+ log.debug('Getting start and end date for phase %s.' % pair)
+ for d in g.mpuls_config.get('phases', 'dates'):
+ for k,v in d.iteritems():
+ if k == pair[0]:
+ sdate = v
+ elif k == pair[1]:
+ edate = "coalesce(%s, now())" % v
+ log.debug('sdate: %s, edate: %s' % (sdate, edate))
+ return sdate, edate
+
+
def get_search_options(soptions=None, id=None):
options = {}
options['id'] = id
if soptions:
- options['start_date'] = soptions.get('start_date') or datetime.date(2009,9,1)
- options['end_date'] = soptions.get('end_date') or datetime.date.today()
+ options['start_date'] = soptions.get('start_date') or \
+ g.mpuls_config.get('search', 'default-start-date')
+ options['end_date'] = soptions.get('end_date') or \
+ g.mpuls_config.get('search', 'default-end-date')
phase = [int(p) for p in soptions.get('phase')]
+
if len(phase) == 1 and -1 in phase:
- options['start_date_field'] = g.mpuls_config.get('evaluations', 'default-start-date-field')
- options['end_date_field'] = g.mpuls_config.get('evaluations', 'default-end-date-field')
+ options['start_date_field'] = None
+ options['end_date_field'] = None
else:
- options['start_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % min(phase))
- options['end_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_end' % max(phase))
-
- options['phase'] = max(phase)
+ options['start_date_field'] = get_phase_dates(min(phase))[0]
+ options['end_date_field'] = get_phase_dates(max(phase))[1]
+ options['phase'] = max(phase) #TODO: Why max?
options['sqlwhere'] = soptions.get('sqlwhere') or None
options['sql'] = soptions.get('sql') or None
else:
# set default evaluation options.
- options['phase'] = 1
+ options['phase'] = g.mpuls_config.get('evaluations', 'default-phases')
options['start_date'] = g.mpuls_config.get('search', 'default-start-date')
options['end_date'] = g.mpuls_config.get('search', 'default-end-date')
- options['start_date_field'] = g.mpuls_config.get('evaluations', 'default-start-date-field')
- options['end_date_field'] = g.mpuls_config.get('evaluations', 'default-end-date-field')
-
options['typelist'] = c.evalconfig.get_evaluations()
- phases = []
- for p in g.mpuls_config.get('search', 'phases'):
- pt = [t for t in p.values() if int(t) >= 0]
- phases.extend(pt)
- options['phase'] = phases
+ #phases = []
+ #for p in g.mpuls_config.get('search', 'phases'):
+ # pt = [t for t in p.values() if int(t) >= 0]
+ # phases.extend(pt)
+ #options['phase'] = phases
# convert dates to locale
options['start_date'] = format_date(options['start_date'])
options['end_date'] = format_date(options['end_date'])
-
return options
class EvaluateController(BaseController):
@@ -98,13 +114,11 @@
# If user selects adele-evaluation render page with disabled configuration elements.
# Change default params
if id == '0':
- c.evaloptions['phase'] = '2'
- c.evaloptions['start_date_field'] = ['datum_cm_start']
- c.evaloptions['end_date_field'] = ['datum_cm_end']
+ c.evaloptions['phase'] = g.mpuls_config.get('evaluations', 'adele-phases')
form = render('/evaluation/evaluate_adele.mako')
else:
form = render('/evaluation/evaluate.mako')
- return formencode.htmlfill.render(unicode(form, 'utf-8'), \
+ return formencode.htmlfill.render(form, \
defaults=c.evaloptions, \
errors={}, \
auto_insert_errors=False)
@@ -129,10 +143,9 @@
if phase:
for p in phase:
if int(p) >= 0: # phase is unknown -> has no start and endphase
- sdf = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % p)
- edf = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_end' % p)
+ sdf, edf = get_phase_dates(p)
suc = get_phasesuccessors(p)
- all_phases.extend(suc)
+ all_phases.extend(p)
tdates.append("('%s'::date <= %s AND '%s'::date >= %s AND phase IN (%s) )" % (params.get('start_date'), edf, params.get('end_date'), sdf, ",".join(["%s" % s for s in suc])))
else:
tdates.append('phase IN (-1)')
@@ -143,23 +156,15 @@
dates.append("TRUE")
dates.append(' )')
- # Type of ending
- ending = " TRUE "
- endingdate = " TRUE "
- if params['ending'] and params.get('start_date') != 'None' and params.get('end_date') != 'None':
- enddatefield = g.mpuls_config.get('agency-fields-mapping', 'date_phase3_end')
- endingdate = "( '%s'::date <= %s AND %s <= '%s'::date )" % (params['start_date'], enddatefield, enddatefield, params['end_date'])
- ending = "cm_end_art in ( %s )" % ", ".join(['%s' % e for e in params['ending']])
+ params['sql'] = "SELECT %%(fields)s from master_tbl_eval_total_view m WHERE %s " % ("".join(dates))
- params['sql'] = "SELECT %%(fields)s from master_tbl_eval_total_view m WHERE %s AND %s AND %s" % ("".join(dates), ending, endingdate)
-
#Datefields
if all_phases:
- params['start_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % min(all_phases))
- params['end_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % max(all_phases))
+ params['start_date_field'] = get_phase_dates(min(all_phases))[0]
+ params['end_date_field'] = get_phase_dates(max(all_phases))[1]
else:
- params['start_date_field'] = g.mpuls_config.get('evaluations', 'default-start-date-field')
- params['end_date_field'] = g.mpuls_config.get('evaluations', 'default-end-date-field')
+ params['start_date_field'] = None
+ params['end_date_field'] = None
return params
@@ -192,7 +197,7 @@
form_errors = error.error_dict or {}
c.evaloptions = get_search_options(session.get('evaluation.options'), id)
form = render('/evaluation/evaluate.mako')
- return formencode.htmlfill.render(unicode(form, 'utf-8'), \
+ return formencode.htmlfill.render(form, \
defaults=form_result, \
errors=form_errors, \
auto_insert_errors=False)
@@ -217,7 +222,7 @@
session['evaluation.params'] = eval_params
session.save()
form = render('/evaluation/result.mako')
- return formencode.htmlfill.render(unicode(form, 'utf-8'), \
+ return formencode.htmlfill.render(form, \
defaults=form_result, \
errors=form_errors, \
auto_insert_errors=False)
@@ -249,8 +254,7 @@
evalset.evaluate()
return evalset.export(EvaluationExportXML())
except:
- log.error(_('Error: Evaluation failed'))
- log.error(traceback.print_exc())
+ log.exception(_('XML Export failed'))
finally:
db.recycleConnection(conn, cur)
@@ -277,7 +281,6 @@
evalset.evaluate()
return evalset.export(EvaluationExportCSV())
except:
- log.error(_('Error: Evaluation failed'))
- log.error(traceback.print_exc())
+ log.exception(_('CSV Export failed'))
finally:
db.recycleConnection(conn, cur)
More information about the Mpuls-commits
mailing list