[Mpuls-commits] r1210 - in wasko/branches/2.0: . waskaweb/controllers waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Feb 3 11:24:09 CET 2010
Author: bh
Date: 2010-02-03 11:24:03 +0100 (Wed, 03 Feb 2010)
New Revision: 1210
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/controllers/case.py
wasko/branches/2.0/waskaweb/controllers/statement.py
wasko/branches/2.0/waskaweb/model/case.py
wasko/branches/2.0/waskaweb/model/statement.py
Log:
Rework the Statement interface. The Statement are now
instantiated with case and agency objects and use those to fill
out the statement templates when the actual statement text is
actually needed. This avoids unncessary loading of case data just
check whether a statement has been signed.
* waskaweb/model/statement.py (Statement.__init__): Use case and
agency as parameters instead of the case id.
(Statement._substitute, Statement._fetchData)
(Statement.getContent): Removed.
(Statement.fillout): Doesn't take any parameters anymore. The
case and agency needed are now instance variables. This base
class method raises NotImplementedError and has to be overwritten
in derived classes.
(DiscretionStatement.fillout, PrivacyStatement.fillout): Rework to
do all the actual work and adapt to case and agency being instance
variables.
(DiscretionStatement.__init__, PrivacyStatement.__init__):
Removed. The base class __init__ already does what we need
(DiscretionStatement._substitute, PrivacyStatement._substitute):
Removed.
(PrivacyStatement.sign, PrivacyStatement.keepUndefined)
(PrivacyStatement.decline): The case id from the case object, not
the case_id instance variable.
* waskaweb/controllers/case.py (CaseController.newAction): dapt to
new Statement interface
* waskaweb/controllers/statement.py
(StatementController.printPrivacyStatement)
(StatementController.printDiscretionStatement): Adapt to new
Statement interface
* waskaweb/model/case.py (Case.getPrivacyStatement)
(Case.getDiscretionStatement): Adapt to new Statement interface
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-02-03 10:05:38 UTC (rev 1209)
+++ wasko/branches/2.0/ChangeLog 2010-02-03 10:24:03 UTC (rev 1210)
@@ -1,3 +1,41 @@
+2010-02-03 Bernhard Herzog <bh at intevation.de>
+
+ Rework the Statement interface. The Statement are now
+ instantiated with case and agency objects and use those to fill
+ out the statement templates when the actual statement text is
+ actually needed. This avoids unncessary loading of case data just
+ check whether a statement has been signed.
+
+ * waskaweb/model/statement.py (Statement.__init__): Use case and
+ agency as parameters instead of the case id.
+ (Statement._substitute, Statement._fetchData)
+ (Statement.getContent): Removed.
+ (Statement.fillout): Doesn't take any parameters anymore. The
+ case and agency needed are now instance variables. This base
+ class method raises NotImplementedError and has to be overwritten
+ in derived classes.
+ (DiscretionStatement.fillout, PrivacyStatement.fillout): Rework to
+ do all the actual work and adapt to case and agency being instance
+ variables.
+ (DiscretionStatement.__init__, PrivacyStatement.__init__):
+ Removed. The base class __init__ already does what we need
+ (DiscretionStatement._substitute, PrivacyStatement._substitute):
+ Removed.
+ (PrivacyStatement.sign, PrivacyStatement.keepUndefined)
+ (PrivacyStatement.decline): The case id from the case object, not
+ the case_id instance variable.
+
+ * waskaweb/controllers/case.py (CaseController.newAction): dapt to
+ new Statement interface
+
+ * waskaweb/controllers/statement.py
+ (StatementController.printPrivacyStatement)
+ (StatementController.printDiscretionStatement): Adapt to new
+ Statement interface
+
+ * waskaweb/model/case.py (Case.getPrivacyStatement)
+ (Case.getDiscretionStatement): Adapt to new Statement interface
+
2010-02-03 Torsten Irländer <torsten.irlaender at intevation.de>
* waskaweb/controllers/case.py (CaseController.digest): Removed
Modified: wasko/branches/2.0/waskaweb/controllers/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/case.py 2010-02-03 10:05:38 UTC (rev 1209)
+++ wasko/branches/2.0/waskaweb/controllers/case.py 2010-02-03 10:24:03 UTC (rev 1210)
@@ -327,9 +327,8 @@
# Do we want to print the statement?
if request.params.has_key('print'):
c.print_version = 1
- statement = PrivacyStatement()
- agency = Agency()
- c.content = statement.fillout(session_case, agency)
+ statement = PrivacyStatement(session_case, Agency())
+ c.content = statement.fillout()
return render('statement/default_statement.mako')
# Or do we want to store the new case?
Modified: wasko/branches/2.0/waskaweb/controllers/statement.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/statement.py 2010-02-03 10:05:38 UTC (rev 1209)
+++ wasko/branches/2.0/waskaweb/controllers/statement.py 2010-02-03 10:24:03 UTC (rev 1210)
@@ -97,7 +97,7 @@
id = self._checkInt(id)
case = self._loadCase(id)
statement = case.getPrivacyStatement()
- c.content = statement.getContent()
+ c.content = statement.fillout()
return render('statement/default_statement.mako')
@checkRole('cm_ka')
@@ -105,7 +105,7 @@
id = self._checkInt(id)
case = self._loadCase(id)
statement = case.getDiscretionStatement()
- c.content = statement.getContent()
+ c.content = statement.fillout()
return render('statement/default_statement.mako')
@checkRole('cm_ka')
Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py 2010-02-03 10:05:38 UTC (rev 1209)
+++ wasko/branches/2.0/waskaweb/model/case.py 2010-02-03 10:24:03 UTC (rev 1210)
@@ -847,8 +847,7 @@
return self.privacy_statement
try:
# Create privacy_statement
- self.privacy_statement = PrivacyStatement(self.id)
- self.privacy_statement.fillout(self, Agency())
+ self.privacy_statement = PrivacyStatement(self, Agency())
return self.privacy_statement
except:
self.privacy_statement = None
@@ -861,8 +860,7 @@
return self.discretion_statement
try:
# Create discretion_statement
- self.discretion_statement = DiscretionStatement(self.id)
- self.discretion_statement.fillout(self, Agency())
+ self.discretion_statement = DiscretionStatement(self, Agency())
return self.discretion_statement
except:
self.discretion_statement = None
Modified: wasko/branches/2.0/waskaweb/model/statement.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/statement.py 2010-02-03 10:05:38 UTC (rev 1209)
+++ wasko/branches/2.0/waskaweb/model/statement.py 2010-02-03 10:24:03 UTC (rev 1210)
@@ -43,22 +43,13 @@
class Statement:
- def __init__(self, id=None):
- self.case_id = id
- self.content = ""
+ def __init__(self, case, agency):
+ self.case = case
+ self.agency = agency
- def _substitute(self, client, agency):
- return ''
+ def fillout(self):
+ raise NotImplementedError
- def _fetchData(self):
- pass
-
- def getContent(self):
- return self.content
-
- def fillout (self, client, agency, **kwargs):
- return self._substitute(client, agency)
-
def decline(self):
pass
@@ -74,50 +65,29 @@
class DiscretionStatement(Statement):
- def __init__(self, id=None):
- Statement.__init__(self, id)
-
- def fillout(self, client, agency, **kwargs):
- tmpl = agency.getDiscretionStatement()
- self.template = Template(tmpl)
- self.content = self._substitute(client, agency)
- return self.content
-
- def _substitute(self, client, agency):
- # Substitution dictionary
+ def fillout(self):
s = {
- 'VORNAME' : escape(F.NA(client.first_name)),
- 'NACHNAME': escape(F.NA(client.last_name)),
- 'KA_NAME' : escape(F.NA(agency.getName())),
+ 'VORNAME': escape(F.NA(self.case.first_name)),
+ 'NACHNAME': escape(F.NA(self.case.last_name)),
+ 'KA_NAME': escape(F.NA(self.agency.getName())),
}
- result = self.template.safe_substitute(s)
- return result
+ return Template(self.agency.getDiscretionStatement()).safe_substitute(s)
+
class PrivacyStatement(Statement):
- def __init__(self, id=None):
- Statement.__init__(self, id)
-
- def fillout(self, client, agency, **kwargs):
- tmpl = agency.getPrivacyStatement()
- self.template = Template(tmpl)
- self.content = self._substitute(client, agency)
- return self.content
-
- def _substitute(self, client, agency):
- # Substitution dictionary
+ def fillout(self):
s = {
- 'VORNAME' : escape(F.NA(client.first_name)),
- 'NACHNAME' : escape(F.NA(client.last_name)),
- 'PLZ' : escape(F.NA(client.plz)),
- 'STRASSE' : escape(F.NA(client.street)),
- 'STRASSENR' : escape(F.NA(client.streetnr)),
- 'ORT' : escape(F.NA(client.city)),
- 'KA_NAME' : escape(F.NA(agency.getName())),
- 'KA_SPEICHERDAUER': escape(F.NA(agency.getMaxSavetime()))
+ 'VORNAME': escape(F.NA(self.case.first_name)),
+ 'NACHNAME': escape(F.NA(self.case.last_name)),
+ 'PLZ': escape(F.NA(self.case.plz)),
+ 'STRASSE': escape(F.NA(self.case.street)),
+ 'STRASSENR': escape(F.NA(self.case.streetnr)),
+ 'ORT': escape(F.NA(self.case.city)),
+ 'KA_NAME': escape(F.NA(self.agency.getName())),
+ 'KA_SPEICHERDAUER': escape(F.NA(self.agency.getMaxSavetime()))
}
- result = self.template.safe_substitute(s)
- return result
+ return Template(self.agency.getPrivacyStatement()).safe_substitute(s)
def sign(self):
conn, cur = None, None
@@ -125,7 +95,7 @@
conn = db.getConnection()
cur = conn.cursor()
cur.execute(SET_STATEMENT_FLAG_SQL,
- {'id': self.case_id, 'value': 1})
+ {'id': self.case.id, 'value': 1})
conn.commit()
finally:
db.recycleConnection(conn, cur)
@@ -136,7 +106,7 @@
conn = db.getConnection()
cur = conn.cursor()
cur.execute(SET_STATEMENT_FLAG_SQL,
- {'id': self.case_id, 'value': -1})
+ {'id': self.case.id, 'value': -1})
conn.commit()
finally:
db.recycleConnection(conn, cur)
@@ -147,7 +117,7 @@
conn = db.getConnection()
cur = conn.cursor()
cur.execute(SET_STATEMENT_FLAG_SQL,
- {'id': self.case_id, 'value': 0})
+ {'id': self.case.id, 'value': 0})
conn.commit()
finally:
db.recycleConnection(conn, cur)
@@ -160,7 +130,7 @@
try:
conn = db.getConnection()
cur = conn.cursor()
- cur.execute(GET_STATEMENT_FLAG_SQL, {'id': self.case_id})
+ cur.execute(GET_STATEMENT_FLAG_SQL, {'id': self.case.id})
signed = cur.fetchone()[0]
if signed == 1:
return True
More information about the Mpuls-commits
mailing list