[Mpuls-commits] r2028 - wasko/branches/2.0/jmdweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Mar 19 09:40:03 CET 2010
Author: torsten
Date: 2010-03-19 09:40:02 +0100 (Fri, 19 Mar 2010)
New Revision: 2028
Modified:
wasko/branches/2.0/jmdweb/model/case.py
Log:
* jmdweb/model/case.py (Case.setEditor): Only define jmdspecific
behavior, like setting editor name in formular. (Case.getEditor):
Deleted. Defined in mpulsweb now.
Modified: wasko/branches/2.0/jmdweb/model/case.py
===================================================================
--- wasko/branches/2.0/jmdweb/model/case.py 2010-03-19 07:53:15 UTC (rev 2027)
+++ wasko/branches/2.0/jmdweb/model/case.py 2010-03-19 08:40:02 UTC (rev 2028)
@@ -1,187 +1,186 @@
# -*- coding: utf-8 -*-
#
-# Copyright 2007, 2008, 2010 Intevation GmbH, Germany, <info at intevation.de>
+# copyright 2007, 2008, 2010 intevation gmbh, germany, <info at intevation.de>
#
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
-# Web-Anwendungs-Server fuer Kompetenzagenturen).
+# this file is part of mpuls waska (computer-based case files -
+# web-anwendungs-server fuer kompetenzagenturen).
#
-# mpuls WASKA is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
+# mpuls waska is free software: you can redistribute it and/or modify it under
+# the terms of the gnu affero general public license as published by the
+# free software foundation, either version 3 of the license, or (at your
# option) any later version.
#
-# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
-# License for more details.
+# mpuls waska is distributed in the hope that it will be useful, but without
+# any warranty; without even the implied warranty of merchantability or
+# fitness for a particular purpose. see the gnu affero general public
+# license for more details.
#
-# You should have received a copy of the GNU Affero General Public
-# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
+# you should have received a copy of the gnu affero general public
+# license along with mpuls waska. if not, see <http://www.gnu.org/licenses/>.
#
-# mpuls WASKA has been developed on behalf of the
-# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
-# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
-# European Social Fund resources.
-# Authors:
-# Torsten Irländer <torsten.irlaender at intevation.de>
+# mpuls waska has been developed on behalf of the
+# projekttraeger im deutschen zentrum fuer luft- und raumfahrt e.v. (pt-dlr)
+# within the programme kompetenzagenturen (durchfuehrungsphase) funded by
+# the bundesministerium fuer familie, senioren, frauen und jugend and
+# european social fund resources.
+# authors:
+# torsten irländer <torsten.irlaender at intevation.de>
#
import sys
from datetime import date, datetime
import traceback
import codecs
-import cStringIO as StringIO
-from sets import Set
+import cstringio as stringio
+from sets import set
import logging
import psycopg2.extras
from pylons.i18n import _
-from formed.meta import UNKNOWN_DATE
+from formed.meta import unknown_date
from mpulsweb.lib.base import session, g
from mpulsweb.lib.db import db
-from mpulsweb.model.user import UserObject
-from mpulsweb.model.agencysettings import Agency
-from mpulsweb.model.document import listDocuments
-from mpulsweb.model.case import MpulsCase, MpulsCaseFactory, MpulsCaseOverview, \
- MpulsCaseBundle, MpulsCaseStandin
+from mpulsweb.model.user import userobject
+from mpulsweb.model.agencysettings import agency
+from mpulsweb.model.document import listdocuments
+from mpulsweb.model.case import mpulscase, mpulscasefactory, mpulscaseoverview, \
+ mpulscasebundle, mpulscasestandin
-#from jmdweb.lib.csv import exportAsCSV
-#from jmdweb.lib.excel import exportAsXLS
-#from jmdweb.lib.xmlexport import exportAsXML
+#from jmdweb.lib.csv import exportascsv
+#from jmdweb.lib.excel import exportasxls
+#from jmdweb.lib.xmlexport import exportasxml
-from jmdweb.model.statement import PrivacyStatement, DiscretionStatement
+from jmdweb.model.statement import privacystatement, discretionstatement
from jmdweb.model.phase_transition import phase_description, phase_end, \
- CM_START, CLEAR_START, CLEAR_ENDE
-from jmdweb.model.phases_factory import RequiredFields
+ cm_start, clear_start, clear_ende
+from jmdweb.model.phases_factory import requiredfields
-log = logging.getLogger(__name__)
+log = logging.getlogger(__name__)
def save_getone(params, k, v):
try:
return params.getone(k)
- except KeyError:
+ except keyerror:
return v
-# SQL STATEMENTS
-LOAD_CASESTATE_SQL = """
-SELECT
+# sql statements
+load_casestate_sql = """
+select
s.id,
s.status,
s.zugriff,
- getLastCaseAppointment(m.id) AS letzer_termin,
- m.phase AS phase
-FROM ka_status_tbl_view s JOIN master_tbl_view m ON m.id = s.master_id
-WHERE s.master_id = %(id)s
+ getlastcaseappointment(m.id) as letzer_termin,
+ m.phase as phase
+from ka_status_tbl_view s join master_tbl_view m on m.id = s.master_id
+where s.master_id = %(id)s
"""
-SET_CASESTATE_SQL = """
-UPDATE ka_status_tbl_view
- SET status = %(status)s
- WHERE id = %(id)s"""
+set_casestate_sql = """
+update ka_status_tbl_view
+ set status = %(status)s
+ where id = %(id)s"""
-SET_CASEPHASE_SQL = """
- UPDATE master_tbl_view
- SET phase = %(phase)s
- WHERE id IN (SELECT master_id FROM ka_status_tbl_view WHERE id = %(id)s)"""
+set_casephase_sql = """
+ update master_tbl_view
+ set phase = %(phase)s
+ where id in (select master_id from ka_status_tbl_view where id = %(id)s)"""
-INIT_CASE_SQL = """
-UPDATE master_tbl_view
-SET
+init_case_sql = """
+update master_tbl_view
+set
mitarbeiter_vorname = %(vorname)s,
mitarbeiter_name = %(nachname)s
-WHERE id = %(id)s"""
+where id = %(id)s"""
-SET_EDITOR_SQL = """SELECT set_case_editor(%(userid)s, %(caseid)s)"""
-SET_EDITOR_NAME_SQL = """
-SELECT set_case_editor_name(%(firstname)s, %(lastname)s, %(caseid)s)"""
+set_editor_name_sql = """
+select set_case_editor_name(%(firstname)s, %(lastname)s, %(caseid)s)"""
-ANONYMIZE_CASE = """SELECT anonymize_case_wrapper(%(id)s)"""
+anonymize_case = """select anonymize_case_wrapper(%(id)s)"""
-class CaseBundle(MpulsCaseBundle):
+class casebundle(mpulscasebundle):
- def exportAsCSV(self, case_parts=None, anonymize=False):
- con, cur = None, None
- f = StringIO.StringIO()
- Writer = codecs.getwriter('latin-1')
- out = Writer(f, errors='replace')
+ def exportascsv(self, case_parts=none, anonymize=false):
+ con, cur = none, none
+ f = stringio.stringio()
+ writer = codecs.getwriter('latin-1')
+ out = writer(f, errors='replace')
try:
- con = db.getConnection()
+ con = db.getconnection()
cur = con.cursor()
- exportAsCSV(cur, out, self.listDatasetIds(), case_parts, anonymize)
+ exportascsv(cur, out, self.listdatasetids(), case_parts, anonymize)
out.flush()
bytes = out.getvalue()
out.close()
return bytes
finally:
- db.recycleConnection(con, cur)
+ db.recycleconnection(con, cur)
- def exportAsXML(self, case_parts=None, anonymize=False):
- con, cur = None, None
- f = StringIO.StringIO()
- Writer = codecs.getwriter('utf-8')
- out = Writer(f, errors='replace')
+ def exportasxml(self, case_parts=none, anonymize=false):
+ con, cur = none, none
+ f = stringio.stringio()
+ writer = codecs.getwriter('utf-8')
+ out = writer(f, errors='replace')
try:
- con = db.getConnection()
- cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
- exportAsXML(cur, out, self.listDatasetIds(), case_parts, anonymize)
+ con = db.getconnection()
+ cur = con.cursor(cursor_factory=psycopg2.extras.dictcursor)
+ exportasxml(cur, out, self.listdatasetids(), case_parts, anonymize)
out.flush()
bytes = out.getvalue()
out.close()
return bytes
finally:
- db.recycleConnection(con, cur)
+ db.recycleconnection(con, cur)
- def exportAsXLS(self, case_parts=None, anonymize=False):
- con, cur = None, None
+ def exportasxls(self, case_parts=none, anonymize=false):
+ con, cur = none, none
try:
- con = db.getConnection()
+ con = db.getconnection()
cur = con.cursor()
- return exportAsXLS(cur, self.listDatasetIds(), case_parts,
+ return exportasxls(cur, self.listdatasetids(), case_parts,
anonymize)
finally:
- db.recycleConnection(con, cur)
+ db.recycleconnection(con, cur)
-class CaseOverview(MpulsCaseOverview):
+class caseoverview(mpulscaseoverview):
pass
-class CaseFactory(MpulsCaseFactory):
+class casefactory(mpulscasefactory):
- def _initNewCase(self, id):
- conn, cur = None, None
+ def _initnewcase(self, id):
+ conn, cur = none, none
try:
- user = session['USER_AUTHORIZED']
- agency = Agency()
+ user = session['user_authorized']
+ agency = agency()
fields = {
'vorname': user.first_name,
'nachname': user.last_name,
'id': int(id)
}
- conn = db.getConnection()
+ conn = db.getconnection()
cur = conn.cursor()
- cur.execute(INIT_CASE_SQL, fields)
+ cur.execute(init_case_sql, fields)
conn.commit()
finally:
- db.recycleConnection(conn, cur)
+ db.recycleconnection(conn, cur)
-class SessionCase:
+class sessioncase:
- """This class holds all needed information for the currently selected case
+ """this class holds all needed information for the currently selected case
"""
- def __init__(self, id=None, page_id=None, state=None,
- privacy_statement=False, **kw):
- if id is None:
- self.id = None
+ def __init__(self, id=none, page_id=none, state=none,
+ privacy_statement=false, **kw):
+ if id is none:
+ self.id = none
else:
self.id = int(id)
@@ -195,105 +194,102 @@
def _session_fields(self):
return g.case_factory.get_session_fields()
- def getState(self):
+ def getstate(self):
return self.state
- def setPageId(self, id):
+ def setpageid(self, id):
self.page_id = id
- def getPageId(self):
+ def getpageid(self):
return self.page_id
- def hasPrivacyStatement(self):
+ def hasprivacystatement(self):
return self.privacy_statement
- def setData(self, params):
+ def setdata(self, params):
for field in self._session_fields():
setattr(self, field.alias,
field.convert(save_getone(params, field.name,
field.default)))
- def toFormData(self):
+ def toformdata(self):
data = {}
for field in self._session_fields():
data[field.name] = getattr(self, field.alias)
return data
- def isYoungerThan(self, mydate):
- """Return True if case was active relative to mydate.
+ def isyoungerthan(self, mydate):
+ """return true if case was active relative to mydate.
- Case either started or finished after mdate, or no end date set.
+ case either started or finished after mdate, or no end date set.
"""
y, m, d = mydate.split('-')
if self.first_meeting:
if self.first_meeting > date(int(y), int(m), int(d)):
- return True
+ return true
elif self.cm_end and (self.cm_end <= date(int(y), int(m), int(d))
- and self.cm_end != UNKNOWN_DATE):
- return False
+ and self.cm_end != unknown_date):
+ return false
else:
- return True
- return True
+ return true
+ return true
-class Case(MpulsCase):
+class case(mpulscase):
- def __init__(self, id=None, preset=None, state_id=None, state_status=None,
- state_access=None):
- MpulsCase.__init__(self, id=id, preset=preset)
+ def __init__(self, id=none, preset=none, state_id=none, state_status=none,
+ state_access=none):
+ mpulscase.__init__(self, id=id, preset=preset)
self.init_state(state_id, state_status, state_access)
- self.standin = None
- self.digest = None
+ self.standin = none
+ self.digest = none
self.documents = []
self.appointments = []
- self.privacy_statement = None
- self.discretion_statement = None
+ self.privacy_statement = none
+ self.discretion_statement = none
def init_state(self, state_id, status, access):
- self.state = State(state_id, self.id, status, access)
+ self.state = state(state_id, self.id, status, access)
- def getState(self):
+ def getstate(self):
return self.state
- def setState(self, value):
- self.state.setState(value)
+ def setstate(self, value):
+ self.state.setstate(value)
- def getSessionCase(self):
- """Return a SessionCase object initialized from the current case"""
+ def getsessioncase(self):
+ """return a sessioncase object initialized from the current case"""
fields = dict()
for field in self.get_session_fields():
- # FIXME: Ideally we would use
- # self.get_value(field.name) to get the value. We use
+ # fixme: ideally we would use
+ # self.get_value(field.name) to get the value. we use
# getattr instead because this compatibility layer
- # translates None values into strings which some code
- # (e.g. buildInfofield in
+ # translates none values into strings which some code
+ # (e.g. buildinfofield in
# templates/casemanagement/main.mako) relies on.
fields[field.alias] = getattr(self, field.alias)
- signed = self.getPrivacyStatement().isSigned()
- return SessionCase(self.id, state=self.state,
+ signed = self.getprivacystatement().issigned()
+ return sessioncase(self.id, state=self.state,
privacy_statement=signed,
**fields)
- def getEditor(self):
- """Returns the editor of the case"""
- return UserObject(self.editor)
-
- def setEditor(self, userid):
- """sets the editor of the case to the given userid"""
+ def seteditor(self, userid):
+ """Sets the name of the editor in formular of the case. First call
+ setEditor function in baseclass to transfer the case to the new user.
+ After that set the name."""
+ MpulsCase.setEditor(self, userid)
con, curr = None, None
user = UserObject(userid)
- fields1 = {'caseid': self.id, 'userid': userid}
- fields2 = {'caseid': self.id, 'firstname': user.first_name,
+ fields = {'caseid': self.id, 'firstname': user.first_name,
'lastname': user.last_name}
+ con = db.getConnection()
+ cur = con.cursor()
try:
- con = db.getConnection()
- cur = con.cursor()
- try:
- cur.execute(SET_EDITOR_SQL, fields1)
- cur.execute(SET_EDITOR_NAME_SQL, fields2)
- except:
- con.rollback()
+ cur.execute(SET_EDITOR_NAME_SQL, fields)
con.commit()
+ except Exception, e:
+ log.debug(e)
+ con.rollback()
finally:
db.recycleConnection(con, cur)
return self.editor
More information about the Mpuls-commits
mailing list