[Mpuls-commits] r553 - in wasko/trunk/waskaweb: controllers lib model templates/casemanagement
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Jul 28 14:41:32 CEST 2009
Author: torsten
Date: 2009-07-28 14:41:28 +0200 (Tue, 28 Jul 2009)
New Revision: 553
Modified:
wasko/trunk/waskaweb/controllers/case.py
wasko/trunk/waskaweb/lib/navigation.py
wasko/trunk/waskaweb/model/case.py
wasko/trunk/waskaweb/templates/casemanagement/digest_body.mako
Log:
Make the loading of the digest work again
Modified: wasko/trunk/waskaweb/controllers/case.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case.py 2009-07-28 09:10:14 UTC (rev 552)
+++ wasko/trunk/waskaweb/controllers/case.py 2009-07-28 12:41:28 UTC (rev 553)
@@ -177,18 +177,22 @@
def load_case(id):
'''Return a case object'''
+ print "l1"
factory = CaseFactory()
case = factory.loadById(id)
-
+ print "l2"
# New session code
session_case = case.getSessionCase()
session['case'] = session_case
+ print "l3"
open_folders = []
navigation = get_navigation(id)
+ print "l4"
session['navigation.tree'] = navigation
session['navigation.openfolders'] = open_folders
session.save()
+ print "l5"
return case
def checkPrivacyStatement(context='select'):
@@ -389,20 +393,26 @@
# 1. Create a new case
factory = CaseFactory()
case = factory.createNew(data=form_result)
+ print "7"
statement = case.getPrivacyStatement()
+ print "8"
# 2. Do we want to sign the statement?
if form_result.get('statement_signed'):
statement.sign()
+ print "9"
self.__init_case(case.id)
+ print "10"
load_case(case.id)
+ print "11"
except formencode.Invalid, error:
c.form_result = error.value
c.form_errors = error.error_dict or {}
return render('/casemanagement/new.mako')
+ print "12"
return self.select(str(case.id))
@checkRole('cm_ka')
@@ -568,62 +578,62 @@
if page_id is None: raise HTTPNotFound()
return self.select_item(page_id)
- @checkRole('cm_ka')
- def save(self):
- case_session = session.get('case')
- try:
- ti = self.getNavigation().getTreeItem(request.params["page"])
- except:
- ti = None
+ #@checkRole('cm_ka')
+ #def save(self):
+ # case_session = session.get('case')
+ # try:
+ # ti = self.getNavigation().getTreeItem(request.params["page"])
+ # except:
+ # ti = None
- if ti is None:
- redirect_to(controller="/case_overview")
+ # if ti is None:
+ # redirect_to(controller="/case_overview")
- # If we edit page_1 we better update the infofield because the names
- # may have been edited
- if ti.name == "page-0":
- try:
- case_session.last_name = request.params.get("name")
- case_session.first_name = request.params.get("vorname")
- case_session.first_meeting = request.params.get("erstgespraech")
- case_session.knr = request.params.get("fn")
- session.save()
- except KeyError:
- print >> sys.stderr, "Error! Could not update Infofield"
+ # # If we edit page_1 we better update the infofield because the names
+ # # may have been edited
+ # if ti.name == "page-0":
+ # try:
+ # case_session.last_name = request.params.get("name")
+ # case_session.first_name = request.params.get("vorname")
+ # case_session.first_meeting = request.params.get("erstgespraech")
+ # case_session.knr = request.params.get("fn")
+ # session.save()
+ # except KeyError:
+ # print >> sys.stderr, "Error! Could not update Infofield"
- # Get old formerrors, save data and store new formdata
- old_errors = case_session.getFormErrors()
- ds_id = request.params["ds"]
- new_errors, page = self.__save(
- ti.name,
- request.params.dict_of_lists(),
- old_errors,
- ds_id)
+ # # Get old formerrors, save data and store new formdata
+ # old_errors = case_session.getFormErrors()
+ # ds_id = request.params["ds"]
+ # new_errors, page = self.__save(
+ # ti.name,
+ # request.params.dict_of_lists(),
+ # old_errors,
+ # ds_id)
- if new_errors:
- c.status_msg = h.status_message("Eingabedaten fehlerhaft! Daten wurden nicht gespeichert.")
- else:
- c.status_msg = h.status_message(u'Daten erfolgreich gespeichert. Bitte beachten Sie die <a href="/case/showhelp/datenschutz_veraenderte_daten" target="_blank">Hinweise zur Datenschutz.</a>')
+ # if new_errors:
+ # c.status_msg = h.status_message("Eingabedaten fehlerhaft! Daten wurden nicht gespeichert.")
+ # else:
+ # c.status_msg = h.status_message(u'Daten erfolgreich gespeichert. Bitte beachten Sie die <a href="/case/showhelp/datenschutz_veraenderte_daten" target="_blank">Hinweise zur Datenschutz.</a>')
- case_session.setFormErrors(new_errors)
- session.save()
+ # case_session.setFormErrors(new_errors)
+ # session.save()
- # Only proceed to next page if the page does not contain errors
- if request.params.get('__formular_next') \
- and not h.hasErrorsOnPage(case_session.page_id):
- nti = ti.nextKey()
- if not nti is None:
- ti = nti
- ti.unfold()
- return self.edit(ds_id, ti.key)
+ # # Only proceed to next page if the page does not contain errors
+ # if request.params.get('__formular_next') \
+ # and not h.hasErrorsOnPage(case_session.page_id):
+ # nti = ti.nextKey()
+ # if not nti is None:
+ # ti = nti
+ # ti.unfold()
+ # return self.edit(ds_id, ti.key)
- def __save(self, pageName, params, old_errors, ds_id):
- # fetch dataset if valid
- document = g.formedTree
- page = document.getPageStore(pageName, int(ds_id))
- page.setId(ds_id)
- result = page.save(params, old_errors, document)
- return result, page
+ #def __save(self, pageName, params, old_errors, ds_id):
+ # # fetch dataset if valid
+ # document = g.formedTree
+ # page = document.getPageStore(pageName, int(ds_id))
+ # page.setId(ds_id)
+ # result = page.save(params, old_errors, document)
+ # return result, page
@checkRole('cm_ka')
def importCase(self):
Modified: wasko/trunk/waskaweb/lib/navigation.py
===================================================================
--- wasko/trunk/waskaweb/lib/navigation.py 2009-07-28 09:10:14 UTC (rev 552)
+++ wasko/trunk/waskaweb/lib/navigation.py 2009-07-28 12:41:28 UTC (rev 553)
@@ -53,11 +53,14 @@
log = logging.getLogger(__name__)
def get_navigation(id, openfolders=None):
+ print "n1"
factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ print "n2"
instance_tree = factory.loadInstanceTreeByIdentifier(
id,
session.get('uncommited_fields'))
navigation = NavigationTree(instance_tree, openfolders)
+ print "n3"
return navigation
Modified: wasko/trunk/waskaweb/model/case.py
===================================================================
--- wasko/trunk/waskaweb/model/case.py 2009-07-28 09:10:14 UTC (rev 552)
+++ wasko/trunk/waskaweb/model/case.py 2009-07-28 12:41:28 UTC (rev 553)
@@ -51,6 +51,11 @@
from waskaweb.model.repeatgroup import AidList, CREATE_RG_BILDEN_DS,CREATE_RG_LEBEN_DS, CREATE_RG_QUALI_DS, CREATE_RG_BERUF_DS
from waskaweb.model.statement import PrivacyStatement, AidPlanStatement, DiscretionStatement
from waskaweb.model.document import listDocuments
+from waskaweb.lib.db import PostgresDBInterface
+from formed.instance.backends.postgres import DBFactory as InstanceFactory
+from formed.instance.tree import SetDataException, RepeatInstanceContainerNode
+from formed.meta.data import RepeatNode
+from waskaweb.controllers.formularpage import convert2dic
from waskaweb.model.phase_transition import phase_description
from waskaweb.model.phases_factory import RequiredFields
@@ -59,6 +64,37 @@
from os import tmpnam, unlink
+def get_field_identifier(id, name, it=None, idx=0):
+ '''Will return the identifier of a field. If the field in in a rg the
+ identifier of the first occourance will be returned on default.'''
+ # Map generic fieldnames to specific fieldnames
+ # get name of the field
+ nc = g.formedTree.findByName(name)
+ if not nc: return None
+
+ # is the field within a rg. if so get name
+ parent = nc.getParent()
+ rg = None
+ while parent:
+ if isinstance(parent, RepeatNode):
+ rg = parent
+ break
+ parent = parent.getParent()
+
+ if not rg:
+ return "%s:%d" % (name, id)
+
+ # get instance of the rg
+ rgc = it.getItem("%s:%d" % (rg.getName(), id))
+ if not rgc: return None
+ rgs = rgc.getChildren()
+ if not rgs:
+ pass
+ #rg = rgc.createInstance()
+ else:
+ rg = rgs[idx]
+ return '%s:%s:%s' % (name, rg.getInternalIdentifier(), id)
+
def save_getone(params, k, v):
try:
return params.getone(k)
@@ -137,7 +173,7 @@
CREATE_CASE_SQL = """SELECT create_master_ds(%(uuid)s)"""
UPDATE_CASE_ON_CREATE_SQL = """UPDATE master_tbl_view set name = %(name)s, vorname = %(vorname)s, mitarb_vv = %(gvorname)s, mitarb_vn = %(gname)s, einwilligung = %(einwilligung)s, addresse_strassenr_1 = %(strassenr)s, addresse_strasse_1 = %(strasse)s, addresse_plz_1 = %(plz)s, addresse_ort_1 = %(ort)s WHERE id = %(id)s"""
-INIT_CASE_SQL= """UPDATE page_0_view SET ks = %(ka_name)s, fkz = %(fkz)s, mitarb_zv = %(vorname)s, mitarb_zn = %(nachname)s WHERE id = %(id)s"""
+INIT_CASE_SQL= """UPDATE master_tbl_view SET ks = %(ka_name)s, fkz = %(fkz)s, mitarb_zv = %(vorname)s, mitarb_zn = %(nachname)s WHERE id = %(id)s"""
CREATE_RG_KOMPETENZ_DS = """SELECT create_rg_kompetenz_ds(%(id)s, %(uuid)s)"""
@@ -430,54 +466,45 @@
# XXX: This a workaround the RGs
# self._createDependencies(id, uuid)
except:
+ print "Fehler"
traceback.print_exc(file=sys.stderr)
return None
if init == True:
try:
self._initNewCase(id)
+ print "5"
except StandardError, err:
print "Error on initialising the case: %s" % err
raise
case = Case()
case.id = id
+ print "6"
return case
def _updateMasterOnCreate(self, id, data):
- conn, cur = None, None
+ factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ instance_tree = factory.loadInstanceTreeByIdentifier(
+ id,
+ session.get('uncommited_fields'))
try:
- user = session['USER_AUTHORIZED']
- #if user.standin:
- # group = UserGroupFactory().load(user.standin)
- # gname = group.name
- # gvorname = 'Gruppe'
- #else:
- # gname = None
- # gvorname = None
- gname = None
- gvorname = None
- agency = Agency()
- statement = data.get('statement_signed') and 1 or -1
+ form_result = convert2dic(data)
+ instance_tree.setData(form_result)
+ session['uncommitted_fields'] = instance_tree.commit()
+ session.save()
+ except SetDataException, err:
+ # Do nothing than setting the status message. In the future the
+ # exception can be used to fill out the form again with htmlfill,
+ # which will clean up the renderer code a lot! But this is for the
+ # future
+ #error_status(_('Error while saving data'))
+ pass
+ except:
+ print traceback.print_exc()
+ #error_status(_('Error while saving data'))
+ raise # Saving failed with unknown reason! Raise exception ->
+ # should result in a bugreport dialog if enabled.
- fields = {
- 'strasse': data.get('strasse'),
- 'strassenr': data.get('strassenr'),
- 'plz': data.get('plz'),
- 'ort': data.get('wohnort'),
- 'name': data.get('name_1'),
- 'vorname': data.get('vorname_1'),
- 'gname': gname,
- 'gvorname': gvorname,
- 'einwilligung': statement,
- 'id': id
- }
- conn = db.getConnection()
- cur = conn.cursor()
- cur.execute(UPDATE_CASE_ON_CREATE_SQL, fields)
- conn.commit()
- finally:
- db.recycleConnection(conn, cur)
-
def _initNewCase(self, id):
conn, cur = None, None
try:
@@ -493,9 +520,13 @@
conn = db.getConnection()
cur = conn.cursor()
cur.execute(INIT_CASE_SQL, fields)
+ print "1"
conn.commit()
+ print "2"
finally:
+ print "3"
db.recycleConnection(conn, cur)
+ print "4"
def _createDependencies(self, id, uuid=None):
con, cur = None, None
@@ -722,56 +753,82 @@
return self.statement
def _loadFromDB(self, id):
+ result = {}
try:
- result = None
- conn, c = None, None
- try:
- conn = db.getConnection()
- c = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- fields = {'id': id}
- c.execute(LOAD_CASE_DIGEST_SQL, fields)
- result = c.fetchone()
- finally:
- db.recycleConnection(conn, c)
+ factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ it = factory.loadInstanceTreeByIdentifier(id)
+ fields = [
+ 'name',
+ 'vorname',
+ 'fn',
+ 'addresse_strasse',
+ 'addresse_strassenr',
+ 'addresse_plz',
+ 'addresse_ort',
+ 'addresse_vorwahl',
+ 'addresse_telefonnummer',
+ 'addresse_weiteretelefonnummern',
+ 'addresse_email',
+ 'einverstaendniserklaerung',
+ 'mutter_vn',
+ 'mutter_n',
+ 'mutter_vorwahl',
+ 'mutter_telefonnummer',
+ 'mutter_email',
+ 'vater_vn',
+ 'vater_n',
+ 'vater_vorwahl',
+ 'vater_telefonnummer',
+ 'vater_email'
+ ]
- self.last_name = unicode(str(result.get('name_1', '')), 'utf-8')
- self.first_name = unicode(str(result.get('vorname_1', '')), 'utf-8')
- self.knr = unicode(str(result.get('kundennummer')), 'utf-8')
- self.plz = unicode(str(result.get('plz', '')), 'utf-8')
- self.street = unicode(str(result.get('strasse', '')), 'utf-8')
- self.streetnr = unicode(str(result.get('strassenr', '')), 'utf-8')
- self.city = unicode(str(result.get('wohnort', '')), 'utf-8')
- self.telephone_1 = unicode(str(result.get('vorwahl', '')), 'utf-8')
- self.telephone_2 = unicode(str(result.get('telefon_1', '')), 'utf-8')
- self.telephone_3 = unicode(str(result.get('vorwahl_2', '')), 'utf-8')
- self.telephone_4 = unicode(str(result.get('telefon_2', '')), 'utf-8')
- self.mobiletel = unicode(str(result.get('mobiltelefon', '')), 'utf-8')
- self.telephone_more = F.NA(unicode(str(result.get('telefon_sonstige', '')), 'utf-8')).replace('\n', '<br>')
+ for name in fields:
+ fid = get_field_identifier(id, name, it)
+ print fid
+ if not fid: continue
+ item = it.getItem(fid)
+ if not item: continue
+ value = item.getValue()
+ if not value: continue
+ result[name] = value
+ except:
+ traceback.print_exc(file=sys.stderr)
- self.email = unicode(str(result.get('email', '')), 'utf-8')
- self.age = result.get('alter') and "%.0f" % result.get('alter') or "0"
- self.statement = (result.get('einverstaendniserklaerung') >= 0)
+ self.last_name = unicode(str(result.get('name', '')), 'utf-8')
+ self.first_name = unicode(str(result.get('vorname', '')), 'utf-8')
+ self.knr = unicode(str(result.get('fn')), 'utf-8')
+ self.plz = unicode(str(result.get('addresse_plz', '')), 'utf-8')
+ self.street = unicode(str(result.get('addresse_strasse', '')), 'utf-8')
+ self.streetnr = unicode(str(result.get('addresse_strassenr', '')), 'utf-8')
+ self.city = unicode(str(result.get('addresse_ort', '')), 'utf-8')
+ self.telephone_1 = unicode(str(result.get('addresse_vorwahl', '')), 'utf-8')
+ self.telephone_2 = unicode(str(result.get('addresse_telefonnummer', '')), 'utf-8')
+ self.telephone_3 = ""
+ self.telephone_4 = ""
+ self.telephone_more = F.NA(unicode(str(result.get('addresse_weiteretelefonnummern', '')), 'utf-8')).replace('\n', '<br>')
- # Parents of the kids
- self.mother_first_name = unicode(str(result.get('mutter_vn', '')), 'utf-8')
- self.mother_last_name = unicode(str(result.get('mutter_n', '')), 'utf-8')
- self.mother_telephone_1 = unicode(str(result.get('mutter_vorwahl1_1', '')), 'utf-8')
- self.mother_telephone_2 = unicode(str(result.get('mutter_telefonnummer1_1', '')), 'utf-8')
- self.mother_telephone_3 = unicode(str(result.get('mutter_vorwahl2_1', '')), 'utf-8')
- self.mother_telephone_4 = unicode(str(result.get('mutter_telefonnummer2_1', '')), 'utf-8')
- self.mother_email = unicode(str(result.get('mutter_email_1', '')), 'utf-8')
+ self.email = unicode(str(result.get('addresse_email', '')), 'utf-8')
+ #self.age = result.get('alter') and "%.0f" % result.get('alter') or "0"
+ self.statement = (result.get('einverstaendniserklaerung') >= 0)
- self.father_first_name = unicode(str(result.get('vater_vn', '')), 'utf-8')
- self.father_last_name = unicode(str(result.get('vater_n', '')), 'utf-8')
- self.father_telephone_1 = unicode(str(result.get('vater_vorwahl1_1', '')), 'utf-8')
- self.father_telephone_2 = unicode(str(result.get('vater_telefonnummer1_1', '')), 'utf-8')
- self.father_telephone_3 = unicode(str(result.get('vater_vorwahl2_1', '')), 'utf-8')
- self.father_telephone_4 = unicode(str(result.get('vater_telefonnummer2_1', '')), 'utf-8')
- self.father_email = unicode(str(result.get('vater_email_1', '')), 'utf-8')
+ # Parents of the kids
+ self.mother_first_name = unicode(str(result.get('mutter_vn', '')), 'utf-8')
+ self.mother_last_name = unicode(str(result.get('mutter_n', '')), 'utf-8')
+ self.mother_telephone_1 = unicode(str(result.get('mutter_vorwahl', '')), 'utf-8')
+ self.mother_telephone_2 = unicode(str(result.get('mutter_telefonnummer', '')), 'utf-8')
+ self.mother_telephone_3 = unicode(str(result.get('mutter_vorwahl', '')), 'utf-8')
+ self.mother_telephone_4 = unicode(str(result.get('mutter_telefonnummer', '')), 'utf-8')
+ self.mother_email = unicode(str(result.get('mutter_email', '')), 'utf-8')
- except:
- traceback.print_exc(file=sys.stderr)
+ self.father_first_name = unicode(str(result.get('vater_vn', '')), 'utf-8')
+ self.father_last_name = unicode(str(result.get('vater_n', '')), 'utf-8')
+ self.father_telephone_1 = unicode(str(result.get('vater_vorwahl', '')), 'utf-8')
+ self.father_telephone_2 = unicode(str(result.get('vater_telefonnummer', '')), 'utf-8')
+ self.father_telephone_3 = unicode(str(result.get('vater_vorwahl', '')), 'utf-8')
+ self.father_telephone_4 = unicode(str(result.get('vater_telefonnummer', '')), 'utf-8')
+ self.father_email = unicode(str(result.get('vater_email', '')), 'utf-8')
+
class SessionCase:
'''This class holds all needed information for the currently selected case'''
def __init__(self, id=None):
Modified: wasko/trunk/waskaweb/templates/casemanagement/digest_body.mako
===================================================================
--- wasko/trunk/waskaweb/templates/casemanagement/digest_body.mako 2009-07-28 09:10:14 UTC (rev 552)
+++ wasko/trunk/waskaweb/templates/casemanagement/digest_body.mako 2009-07-28 12:41:28 UTC (rev 553)
@@ -95,17 +95,13 @@
<td class="hl">${c.digest.city | F.NA, h}</td>
</tr>
<tr>
- <td class="label">${_('cm_digest_tbl_label_telephone')} 1</td>
+ <td class="label">${_('cm_digest_tbl_label_telephone')}</td>
<td class="">(${c.digest.telephone_1 | F.NA, h}) ${c.digest.telephone_2 | F.NA, h}</td>
</tr>
<tr>
- <td class="label hl">${_('cm_digest_tbl_label_telephone')} 2</td>
- <td class="hl">(${c.digest.telephone_3| F.NA, h}) ${c.digest.telephone_4| F.NA, h}</td>
+ <td class="label hl">${_('cm_digest_tbl_label_telephone_more')}</td>
+ <td class="hl">${c.digest.telephone_more | }</td>
</tr>
- <tr>
- <td class="label">${_('cm_digest_tbl_label_telephone_more')}</td>
- <td class="">${c.digest.telephone_more | }</td>
- </tr>
</table>
</td>
</tr>
@@ -125,25 +121,21 @@
<td class="label">${_('cm_digest_tbl_label_firstname')}</td>
<td class="">${c.digest.mother_first_name | F.NA, h}</td>
</tr>
- <tr>
- <td class="label hl">${_('cm_digest_tbl_label_email')}</td>
- % if c.digest.mother_email != "None":
- <td class="hl"><a href="mailto:${c.digest.mother_email | F.NA, h}">${c.digest.mother_email | F.NA, h}</a></td>
- % else:
- <td class="hl">${c.digest.mother_email | F.NA, h}</td>
- % endif
- </tr>
</table>
</td>
<td>
<table class="digest_table_right">
<tr>
- <td class="label hl">${_('cm_digest_tbl_label_telephone')} 1</td>
+ <td class="label hl">${_('cm_digest_tbl_label_telephone')}</td>
<td class="hl">(${c.digest.mother_telephone_1 | F.NA, h}) ${c.digest.mother_telephone_2| F.NA, h}</td>
</tr>
<tr>
- <td class="label">${_('cm_digest_tbl_label_telephone')} 2</td>
- <td class="">(${c.digest.mother_telephone_3 | F.NA, h}) ${c.digest.mother_telephone_4 | F.NA, h}</td>
+ <td class="label">${_('cm_digest_tbl_label_email')}</td>
+ % if c.digest.mother_email != "None":
+ <td class=""><a href="mailto:${c.digest.mother_email | F.NA, h}">${c.digest.mother_email | F.NA, h}</a></td>
+ % else:
+ <td class="">${c.digest.mother_email | F.NA, h}</td>
+ % endif
</tr>
<tr>
<td colspan="2"> </td>
@@ -165,25 +157,21 @@
<td class="label">${_('cm_digest_tbl_label_firstname')}</td>
<td class="">${c.digest.father_first_name | F.NA, h}</td>
</tr>
- <tr>
- <td class="label hl">${_('cm_digest_tbl_label_email')}</td>
- % if c.digest.father_email != "None":
- <td class="hl"><a href="mailto:${c.digest.father_email | F.NA, h}">${c.digest.father_email | F.NA, h}</a></td>
- % else:
- <td class="hl">${c.digest.father_email | F.NA, h}</td>
- % endif
- </tr>
</table>
</td>
<td>
<table class="digest_table_right">
<tr>
- <td class="label hl">${_('Telefon')} 1</td>
+ <td class="label hl">${_('Telefon')}</td>
<td class="hl">(${c.digest.father_telephone_1 | F.NA, h}) ${c.digest.father_telephone_2 | F.NA, h}</td>
</tr>
<tr>
- <td class="label">${_('Telefon')} 2</td>
- <td class="">(${c.digest.father_telephone_3 | F.NA, h}) ${c.digest.father_telephone_4| F.NA, h}</td>
+ <td class="label">${_('cm_digest_tbl_label_email')}</td>
+ % if c.digest.father_email != "None":
+ <td class=""><a href="mailto:${c.digest.father_email | F.NA, h}">${c.digest.father_email | F.NA, h}</a></td>
+ % else:
+ <td class="">${c.digest.father_email | F.NA, h}</td>
+ % endif
</tr>
<tr>
<td colspan="2"> </td>
More information about the Mpuls-commits
mailing list