[Mpuls-commits] r2111 - wasko/branches/2.0/jmdweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Mar 24 15:35:10 CET 2010
Author: torsten
Date: 2010-03-24 15:35:09 +0100 (Wed, 24 Mar 2010)
New Revision: 2111
Modified:
wasko/branches/2.0/jmdweb/model/case.py
Log:
* jmdweb/model/case.py (State): Inherited from MpulsCaseState.
Modified: wasko/branches/2.0/jmdweb/model/case.py
===================================================================
--- wasko/branches/2.0/jmdweb/model/case.py 2010-03-24 14:34:12 UTC (rev 2110)
+++ wasko/branches/2.0/jmdweb/model/case.py 2010-03-24 14:35:09 UTC (rev 2111)
@@ -45,7 +45,7 @@
from mpulsweb.model.phase import PhaseFactory
from mpulsweb.model.agencysettings import Agency
from mpulsweb.model.case import MpulsCase, MpulsCaseFactory, MpulsCaseOverview, \
- MpulsCaseBundle
+ MpulsCaseBundle, MpulsCaseState
from jmdweb.model.statement import PrivacyStatement, DiscretionStatement
@@ -58,27 +58,6 @@
return v
# 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
-"""
-
-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)"""
-
INIT_CASE_SQL = """
UPDATE master_tbl_view
SET
@@ -307,148 +286,7 @@
return True
return True
+class State(MpulsCaseState):
+ pass
-class State(object):
-
- """This class store the state and the last accesstime of the case.
- Possible states are:
- * Open (1)
- * Closes (2)
- * outstanding deletion (3)
- * outstanding anonymision (4)
- * anonymised (5)
- """
-
- def __init__(self, id=None, master_id=None, state=None, access=None):
- self.id = id
- self.master_id = master_id
- self.state = state
- self.access = access
- self.phase = None
- self._last_date = None
-
- if self.master_id is not None and self.id is None:
- self._load()
-
- def getLastDateFromDB(self):
- if self._last_date:
- return self._last_date
- else:
- # Reload all the data. As fetching the last appointment
- # for the case is the most expensive part of the operation getting
- # some more values does not hurt.
- self._load()
- return self._last_date
-
- last_date = property(getLastDateFromDB)
-
- def setData(self, id, master_id, state, access):
- self.master_id = master_id
- self.id = id
- self.state = state
- self.access = access
-
- def _load(self):
- conn, cur = None, None
- try:
- conn = db.getConnection()
- cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- cur.execute(LOAD_CASESTATE_SQL, {'id': self.master_id})
- result = cur.fetchone()
- self.id = result.get('id')
- self.state = result.get('status')
- self.access = result.get('zugriff')
- self._last_date = result.get('letzer_termin')
- self.phase = result.get('phase')
- except:
- log.exception('Failed loading State')
- raise
- finally:
- db.recycleConnection(conn, cur)
-
- def getStateLabel(self):
- state_labels = {'1': _('case_state_label_open'),
- '2': _('case_state_label_open'),
- '3': _('case_state_label_outstanding_delete'),
- '4': _('case_state_label_outstanding_anon'),
- '5': _('case_state_label_anon'),
- }
- return state_labels.get(str(self.state))
-
- def isCmFinished(self):
- return self.phase in g.mpuls_config.get('phases', 'finished')
-
- def getState(self):
- return self.state
-
- def setState(self, value):
- conn, cur = None, None
- try:
- try:
- conn = db.getConnection()
- cur = conn.cursor()
- fields = {'status': value, 'id': self.id}
- cur.execute(SET_CASESTATE_SQL, fields)
- conn.commit()
- self.state = value
- finally:
- db.recycleConnection(conn, cur)
- return True
- except:
- traceback.print_exc(file=sys.stderr)
- return False
-
- def getPhase(self):
- return self.phase
-
- def setPhase(self, phase):
- conn, cur = None, None
- try:
- try:
- conn = db.getConnection()
- cur = conn.cursor()
- fields = {'phase': phase, 'id': self.id}
- cur.execute(SET_CASEPHASE_SQL, fields)
- conn.commit()
- self.phase = phase
- finally:
- db.recycleConnection(conn, cur)
- return True
- except:
- traceback.print_exc(file=sys.stderr)
- return False
-
- def getPhaseDescription(self):
- desc = []
- phases = PhaseFactory().load(self.master_id)
- phase = phases.get_current_phase()
- desc.append(g.mpuls_config.get('phases', 'description')[0].get(phase.phase))
- if phase.is_active():
- desc.append(_('Running'))
- else:
- desc.append(_('Finished'))
- return " ".join(desc)
-
- def getAccessTime(self):
- return self.access
-
- def getLastDate(self):
- """Returns the last occuring date from appointments, aids, or
- the last accesstime
- """
- return self.last_date
-
- def getMaxSavetime(self):
- return Agency().getMaxSavetime()
-
- def daysToMaxSavetime(self):
- maxage = self.getMaxSavetime()
- if self.isCmFinished():
- age = datetime.now() - self.getAccessTime()
- else:
- age = datetime.now() - self.getLastDate()
- if int(maxage) != 0:
- return int(maxage) - age.days
- return None
-
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Mpuls-commits
mailing list