[Mpuls-commits] r606 - in wasko/branches/1.0: . waskaweb/lib waskaweb/templates
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Sep 22 14:24:47 CEST 2009
Author: torsten
Date: 2009-09-22 14:24:43 +0200 (Tue, 22 Sep 2009)
New Revision: 606
Added:
wasko/branches/1.0/waskaweb/lib/config.py
Modified:
wasko/branches/1.0/ChangeLog.txt
wasko/branches/1.0/production_wsgi.ini
wasko/branches/1.0/waskaweb/lib/app_globals.py
wasko/branches/1.0/waskaweb/templates/main.mako
Log:
Load json based config file and list available evaluations
Modified: wasko/branches/1.0/ChangeLog.txt
===================================================================
--- wasko/branches/1.0/ChangeLog.txt 2009-09-16 14:56:53 UTC (rev 605)
+++ wasko/branches/1.0/ChangeLog.txt 2009-09-22 12:24:43 UTC (rev 606)
@@ -1,3 +1,15 @@
+2009-09-22 Torsten Irlaender <torsten.irlaender at intevation.de>
+
+ Read jason-based configuration-files. List evaluations based on
+ configfile.
+
+ * production_wsgi.ini: Adding var to define json config
+ * waskaweb/lib/config.py,
+ waskaweb/lib/app_globals.py: Read config file on server startup and
+ make it available under mpuls_config.
+ * waskaweb/templates/main.mako: List available evaluations based on
+ configfile.
+
2009-09-09 Frank Koormann <frank.koormann at intevation.de>
Release 1.0.7
Modified: wasko/branches/1.0/production_wsgi.ini
===================================================================
--- wasko/branches/1.0/production_wsgi.ini 2009-09-16 14:56:53 UTC (rev 605)
+++ wasko/branches/1.0/production_wsgi.ini 2009-09-22 12:24:43 UTC (rev 606)
@@ -49,6 +49,11 @@
#beaker.cache.data_dir = %(here)s/data/cache
#beaker.session.data_dir = %(here)s/data/sessions
+# You can provide a user specific configuration for the mpuls server.
+# In this file you can configure various things like the database connection,
+# enable or disable modules etc.
+#mpuls_config=%(here)s/myconfig.json
+
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised.
Modified: wasko/branches/1.0/waskaweb/lib/app_globals.py
===================================================================
--- wasko/branches/1.0/waskaweb/lib/app_globals.py 2009-09-16 14:56:53 UTC (rev 605)
+++ wasko/branches/1.0/waskaweb/lib/app_globals.py 2009-09-22 12:24:43 UTC (rev 606)
@@ -22,6 +22,8 @@
# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
# European Social Fund resources.
"""The application's Globals object"""
+import pylons
+import logging
from pylons import config
from waskaweb.model.io.document import openDocument
@@ -31,6 +33,7 @@
import waskaweb.lib.security as security
from waskaweb.lib.timelog import setupTimeLogging
+from waskaweb.lib.config import MpulsConfig
import os, sys, traceback
@@ -38,6 +41,8 @@
from waskaweb.model.casedocument import CaseDocument
from waskaweb.model.nodecomponents import RootNode
+log = logging.getLogger(__name__)
+
class CaseDocumentFactory(NodeFactory):
def reduce(self, ctx):
@@ -73,6 +78,18 @@
print >> sys.stderr, "Could not open Helpfile"
self.helpData = None
+ # Load mpuls configuration
+ config_file = pylons.config['app_conf'].get('mpuls_config', 'mpuls.json')
+ if config_file:
+ if not os.path.isabs(config_file):
+ root = pylons.config.get('pylons.paths').get('root')
+ config_file = os.path.join(root, '..', config_file)
+
+
+ log.info("reading configfile: %s" % config_file)
+ self.config_path = os.path.dirname(config_file)
+ self.mpuls_config = MpulsConfig(config_file)
+
# data for database connections
host = config.get('db_host')
Added: wasko/branches/1.0/waskaweb/lib/config.py
===================================================================
--- wasko/branches/1.0/waskaweb/lib/config.py 2009-09-16 14:56:53 UTC (rev 605)
+++ wasko/branches/1.0/waskaweb/lib/config.py 2009-09-22 12:24:43 UTC (rev 606)
@@ -0,0 +1,316 @@
+# -*- coding: utf-8 -*-
+#
+# (c) 2008 by Intevation GmbH
+# This is Free software under the GPLv3.
+# See LICENSE comming with the source of 'mpuls'
+# for details.
+#
+# author: Torsten Irländer <torsten.irlaender at intevation.de>
+#
+
+
+import os.path, datetime
+import pylons
+import logging
+
+import sys
+
+import simplejson as json
+
+log = logging.getLogger(__name__)
+
+def get_revision():
+ return "0.8"
+
+def get_path(dir, file):
+ try:
+ if os.path.isabs(file): return file
+ return os.path.join(pylons.config.get('pylons.paths').get('static_files'), dir, file)
+ except:
+ return None # path building will fail on initial server start/restart
+ # as pylonspath is empty
+
+def merge(a, b):
+ '''recursive merge b into a. a is default, b is userdefined'''
+ changes = []
+ for ka, va in a.iteritems():
+ try:
+ vb = b[ka]
+ except KeyError, err:
+ continue
+ if type(vb) == dict and type(va) == dict:
+ merge(va, vb)
+ elif vb != va:
+ changes.append((ka, vb))
+ a.update(changes)
+
+class MpulsConfig(object):
+
+ def __init__(self, filename = None):
+
+ self.config = self.build_defaults()
+
+ if filename and os.path.isfile(filename):
+ try:
+ f = None
+ try:
+ f = open(filename, "rb")
+ cfg = json.load(f)
+ finally:
+ if f: f.close()
+ merge(self.config, cfg)
+ except:
+ log.error("I/O error processing config file '%s'." % filename)
+
+ def build_defaults(self):
+ '''Set default configuration. This is function should be calles if
+ there is no config file'''
+
+ sections = {}
+
+ def set(section_key, item_key, item):
+ try:
+ section = sections[section_key]
+ except KeyError:
+ section = {}
+ sections[section_key] = section
+ section[item_key] = item
+
+ set('common', 'name', 'mpuls - Evaluationserver')
+ set('common', 'shortname', 'evalmpuls')
+ set('common', 'version', 'rev. %s' % get_revision())
+ set('common', 'releasedate', '21.09.2009')
+ set('common', 'lang', 'en')
+ set('common', 'agencyname', 'Evaluationserver')
+
+ # Leave empty for default values
+ set('paths', 'public', '')
+ set('paths', 'i18n', '')
+ set('paths', 'addons', '')
+ set('paths', 'templates', '')
+
+ set('database', 'url', 'gruenkern.pult.intevation.de')
+ set('database', 'port', '5432')
+ set('database', 'name', 'waskoauswertung')
+ set('database', 'login', 'auswertung')
+ set('database', 'pass', 'wae1Foo1')
+
+ #set('database', 'url', 'localhost')
+ #set('database', 'port', '9999')
+ #set('database', 'name', 'auswertung')
+ #set('database', 'login', 'intevation')
+
+ set('database', 'nameschema', 'ka_%s_db')
+ set('database', 'userschema', 'ka_%s_%s')
+ set('database', 'namefromssl', '0')
+ set('database', 'mappingfile', get_path('mappings', 'waska-fkz-mapping.csv'))
+
+ # AEGENCYDATA
+ # --------
+ # 1. Elementary fields.
+ # Every case consists of various fields. Some of the fields are
+ # elementary fields, which are essential for the workflow and should
+ # not be changed! Changing them would result in further changes in
+ # application logic. In other words the application rely on the fact
+ # that the following fields are present.
+ elementary_list = ['id' 'name', 'count', 'federalstate']
+ set('agency-fields', 'elementary', elementary_list)
+
+ # 2. Individual fields.
+ # Beside the elemtary fields there are some indiviual fields which can
+ # be defined here, and depends on the concrete usecase of mpuls. In
+ # most cases these fields will hold the name, the address and some other
+ # general information on the case.
+ individual_list = []
+ set('agency-fields', 'individual', individual_list)
+ tostr_list = ['fkz', 'count']
+ set('agency-fields', 'tostr', tostr_list)
+
+ # 3. Overview
+
+ # Search options
+ # Phase
+ p1 = {'Unbekannt': -1}
+ phases = [p1]
+ set('search', 'phases', phases)
+
+ te1 = {'Keine Angabe': -1}
+ types_ending = [te1]
+ set('search', 'types_ending', types_ending)
+ set('search', 'default-start-date', datetime.date(2008,9,1))
+ #set('search', 'default-end-date', datetime.date.today())
+ set('search', 'default-end-date', datetime.date(2009,8,31))
+
+ # Define which fields of the case will be available in the overviewpage
+ overview_list = ['id', 'count', 'federalstate', 'name']
+ set('case-fields', 'overview', overview_list)
+
+ agency_bw = ['abc']
+ agency_by = []
+ agency_be = []
+ agency_bb = []
+ agency_hb = []
+ agency_hh = []
+ agency_he = []
+ agency_mv = []
+ agency_ni = []
+ agency_nw = []
+ agency_rp = []
+ agency_sl = []
+ agency_sn = []
+ agency_st = []
+ agency_sh = []
+ agency_th = []
+
+ agency_mapping = {
+ 'BW':agency_bw,
+ 'BY':agency_by,
+ 'BE':agency_be,
+ 'BB':agency_bb,
+ 'HB':agency_hb,
+ 'HH':agency_hh,
+ 'HE':agency_he,
+ 'MV':agency_mv,
+ 'NI':agency_ni,
+ 'NW':agency_nw,
+ 'RP':agency_rp,
+ 'SL':agency_sl,
+ 'SN':agency_sn,
+ 'ST':agency_st,
+ 'SH':agency_sh,
+ 'TH':agency_th
+ }
+ country_mapping = {
+ 'BW': 'Baden-Württemberg',
+ 'BY': 'Bayern',
+ 'BE': 'Berlin',
+ 'BB': 'Brandenburg',
+ 'HB': 'Bremen',
+ 'HH': 'Hamburg',
+ 'HE': 'Hessen',
+ 'MV': 'Mecklenburg-Vorpommern',
+ 'NI': 'Niedersachsen',
+ 'NW': 'Nordrhein-Westfalen',
+ 'RP': 'Rheinland-Pfalz',
+ 'SL': 'Saarland',
+ 'SN': 'Sachsen',
+ 'ST': 'Sachsen-Anhalt',
+ 'SH': 'Schleswig-Holstein',
+ 'TH': 'Thüringen'
+ }
+
+ set('agency', 'agency-mapping', agency_mapping)
+ set('agency', 'country-mapping', country_mapping)
+ set('agency', 'name-mappingfile', get_path('mappings', 'waska-fkz-name-mapping.csv'))
+ set('agency', 'fkz-mappingfile', get_path('mappings', 'waska-fkz-mapping.csv'))
+
+
+ # 4. Field Mapping
+ # Mpuls uses fixed names for common used fields in the application
+ # which may vary from the actual names in the database. This is the
+ # right place to define the mapping between the mpuls-intern names and
+ # the db-names. Please note, that these mapping will also be used for
+ # saving data! This may cause problems.
+
+ # Elementary fields.
+ set('agency-fields-mapping', 'id', 'a.fkz')
+ set('agency-fields-mapping', 'count', 'count(m.id)')
+ set('agency-fields-mapping', 'federalstate', 'b.kurz')
+ set('agency-fields-mapping', 'name', 'a.name')
+ set('agency-fields-mapping', 'typeending', 'm.cm_end_art')
+ set('agency-fields-mapping', 'date_phase0_start', 'm.erstgespraech')
+ set('agency-fields-mapping', 'date_phase0_end', 'coalesce(m.datum_cm_start, now())')
+ set('agency-fields-mapping', 'date_phase1_start', 'm.erstgespraech')
+ set('agency-fields-mapping', 'date_phase1_end', 'coalesce(m.datum_cm_start, now())')
+ set('agency-fields-mapping', 'date_phase2_start', 'm.datum_cm_start')
+ set('agency-fields-mapping', 'date_phase2_end', 'coalesce(m.datum_cm_ende, now())')
+ set('agency-fields-mapping', 'date_phase3_start', 'm.datum_cm_start')
+ set('agency-fields-mapping', 'date_phase3_end', 'coalesce(m.datum_cm_ende, now())')
+ set('agency-fields-mapping', 'date_phase4_start', 'm.nbetr_start')
+ set('agency-fields-mapping', 'date_phase4_end', 'coalesce(m.nbetr_ende, now())')
+ set('agency-fields-mapping', 'date_phase5_start', 'm.nbetr_start')
+ set('agency-fields-mapping', 'date_phase5_end', 'coalesce(m.nbetr_ende, now())')
+ set('agency-fields-mapping', 'date_phase6_start', 'm.nbetr_start')
+ set('agency-fields-mapping', 'date_phase6_end', 'coalesce(m.nbetr_ende, now())')
+ set('agency-fields-mapping', 'date_phase7_start', 'm.nbetr_start')
+ set('agency-fields-mapping', 'date_phase7_end', 'coalesce(m.nbetr_ende, now())')
+
+ # Individual fields
+
+ # PHASES
+ # --------
+ # Available Phases:
+ phases = []
+ set('phases', 'phases', phases)
+
+ # Description of phases
+ description = {}
+ set('phases', 'description', description)
+
+ # Phasepairs
+ pairs =[]
+ set('phases', 'pairs', pairs)
+ set('phases', 'pairss', [])
+ symbols = []
+ set('phases', 'symbols', symbols)
+
+ # Succenssors and Predesessors
+ successors = []
+ set('phases', 'successors', successors)
+
+ # EVALUATIONS
+ # ------------
+ #
+ dummy = {'name': 'Analyse', 'id': '4', 'config': 'eval_analyse.xml'}
+ enabled_evaluations = [dummy]
+ set('evaluations', 'enabled', enabled_evaluations)
+ set('evaluations', 'default-start-date-field', 'erstgespraech')
+ set('evaluations', 'default-end-date-field', 'coalesce(datum_cm_ende, now())')
+
+ return sections
+
+ def is_enabled(self, section, name):
+ try:
+ return self.get(section, name) == '1'
+ except:
+ log.error('Error on checking config (%s, %s)' % (section, name))
+ return False
+
+ def get(self, section, name):
+ try:
+ return self.config[section][name]
+ except KeyError:
+ log.error('Error on checking config (%s, %s)' % (section, name))
+ return ''
+
+ def get_app_name(self):
+ return self.get('common', 'name')
+
+ def get_app_shortname(self):
+ return self.get('common', 'shortname')
+
+ def get_app_version(self):
+ return self.get('common', 'version')
+
+ def get_releasedate(self):
+ return self.get('common', 'releasedate')
+
+ def get_overview_fields(self):
+ return list(self.get('case-fields', 'overview'))
+
+ def get_elementary_fields(self):
+ return list(self.get('case-fields', 'elementary'))
+
+ def get_individual_fields(self):
+ return list(self.get('case-fields', 'individual'))
+
+ def get_fieldname(self, key, mapping='case-fields-mapping'):
+ '''Returns the mapped name of database field for a given mpuls internal
+ datafield. If the field is not mapable return the key'''
+ if not mapping: mapping = 'case-fields-mapping'
+ try:
+ return self.config[mapping][key]
+ except KeyError:
+ return key
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
Modified: wasko/branches/1.0/waskaweb/templates/main.mako
===================================================================
--- wasko/branches/1.0/waskaweb/templates/main.mako 2009-09-16 14:56:53 UTC (rev 605)
+++ wasko/branches/1.0/waskaweb/templates/main.mako 2009-09-22 12:24:43 UTC (rev 606)
@@ -70,15 +70,16 @@
<li><a href="${h.url_for(controller='/case', action='new')}"> ${_('menu_cm_link_new')}</a> </li>
<li><a href="${h.url_for(controller='/case', action='importCase')}"> ${_('menu_cm_link_import')}</a> </li>
% endif
- <li><a href="${h.url_for(controller='/evaluate', action='evaluateAdele')}">Zwischenbericht</a></li>
- ##<li><a href="${h.url_for(controller='/evaluate', action='evaluate', id=1, reset=1)}"> ${_('cm_actions_link_evaluate')}</a></li>
- ##%if session.get('hascaseerrors'):
- ##<li><a href="${h.url_for(controller='/case_overview', action='listBadCases')}">Inkonsistente Fallakten</a></li>
- ##%endif
</ul>
</div>
</div>
% endif
+ <div class="menu">
+ <div class="actions">
+ <h1>${_('Evaluations')}</h1>
+ ${self.buildEvaluations()}
+ </div>
+ </div>
<div class="menu_spacer">
<div class="actions">
</div>
@@ -104,6 +105,14 @@
% endif
</%def>
+<%def name="buildEvaluations()">
+ <ul>
+ % for eval in g.mpuls_config.get('evaluations', 'enabled'):
+ <li><a href="/evaluate/evaluate/${eval.get('id')}">${eval.get('name')}</a></li>
+ % endfor
+ </ul>
+</%def>
+
<%def name="buildFormErrors(labels=None)">
<% formular_labels = labels or {} %>
% if len(c.form_errors) > 0:
More information about the Mpuls-commits
mailing list