[Mpuls-commits] r1531 - in wasko/branches/2.0: . waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 12 12:18:31 CET 2010
Author: bh
Date: 2010-02-12 12:18:30 +0100 (Fri, 12 Feb 2010)
New Revision: 1531
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (Field.__init__): New parameter and
instance variable: preload. Indicates all fields to explicitly
load when instantiating a case from its id.
(LOAD_CASE_SQL): Do not hard-wire the
list of fields to retrieve.
(CaseFactory.loadById): Build the list of fields to retrieve with
LOAD_CASE_SQL from the return value of get_preload_fields.
(Case.fields): Set preload for all fields previously hard-wired in
LOAD_CASE_SQL
(Case.get_preload_fields): New method to return the fields to
preload.
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-02-12 09:53:38 UTC (rev 1530)
+++ wasko/branches/2.0/ChangeLog 2010-02-12 11:18:30 UTC (rev 1531)
@@ -1,3 +1,17 @@
+2010-02-12 Bernhard Herzog <bh at intevation.de>
+
+ * waskaweb/model/case.py (Field.__init__): New parameter and
+ instance variable: preload. Indicates all fields to explicitly
+ load when instantiating a case from its id.
+ (LOAD_CASE_SQL): Do not hard-wire the
+ list of fields to retrieve.
+ (CaseFactory.loadById): Build the list of fields to retrieve with
+ LOAD_CASE_SQL from the return value of get_preload_fields.
+ (Case.fields): Set preload for all fields previously hard-wired in
+ LOAD_CASE_SQL
+ (Case.get_preload_fields): New method to return the fields to
+ preload.
+
2010-02-12 Torsten Irländer <torsten.irlaender at intevation.de>
* mpulsweb/lib/renderer.py: Removed some debugging output.
Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py 2010-02-12 09:53:38 UTC (rev 1530)
+++ wasko/branches/2.0/waskaweb/model/case.py 2010-02-12 11:18:30 UTC (rev 1531)
@@ -128,16 +128,7 @@
SET phase = %(phase)s
WHERE id IN (SELECT master_id FROM ka_status_tbl_view WHERE id = %(id)s)"""
-LOAD_CASE_SQL = """
-SELECT
- name,
- vorname,
- bearbeiter_id,
- fn,
- erstgespraech,
- datum_cm_ende
-FROM master_tbl_view WHERE id = %(id)s
-"""
+LOAD_CASE_SQL = """SELECT %(fields)s FROM master_tbl_view WHERE id = %%(id)s"""
DELETE_CASE_SQL = """select delete_master_ds(%(id)s)"""
INIT_CASE_SQL = """
@@ -379,8 +370,10 @@
try:
conn = db.getConnection()
c = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
+ fields = Case.get_preload_fields()
+ query = LOAD_CASE_SQL % dict(fields=", ".join(fields))
fields = {'id': id}
- c.execute(LOAD_CASE_SQL, fields)
+ c.execute(query, fields)
result = c.fetchone()
if not result:
raise LoadCaseNotExistsError("Es konnte keine Fallakte geladen"
@@ -630,6 +623,15 @@
of the master table. search_match and search_retrieve
are completely independent settings.
+ preload -- If true (default false), the field will be loaded from
+ the database explicitly when creating a Case object from
+ an id using CaseFactory.loadById. This flag must be set
+ for all fields from the master table that cannot be
+ loaded using the formed tree, because otherwise the
+ fields won't be available through the case object at all.
+ For other fields it can be an optimization to set this
+ flag.
+
alias -- Additional name under which the attribute can be
accessed directly as an attribute of the case object.
Default is None, which means that the field is not
@@ -649,13 +651,15 @@
def __init__(self, name, digest=False,
search_retrieve=False, search_match=False,
- session=False, alias=None, alias_force_string=True):
+ session=False, preload=False,
+ alias=None, alias_force_string=True):
self.name = name
self.digest = digest
self.search_retrieve = search_retrieve
self.search_match = search_match
self.session = session
+ self.preload = preload
self.alias = alias
self.alias_force_string = alias_force_string
@@ -685,11 +689,14 @@
#
fields = [
Field("name", digest=True, search_retrieve=True, search_match=True,
- alias="last_name", alias_force_string=True, session=True),
+ alias="last_name", alias_force_string=True, session=True,
+ preload=True),
Field("vorname", digest=True, search_retrieve=True, search_match=True,
- alias="first_name", alias_force_string=True, session=True),
+ alias="first_name", alias_force_string=True, session=True,
+ preload=True),
Field("fn", digest=True, search_retrieve=True, search_match=True,
- alias="knr", alias_force_string=True, session=True),
+ alias="knr", alias_force_string=True, session=True,
+ preload=True),
Field("geburtsdatum", digest=True),
Field("addresse_strasse", digest=True,
alias="street", alias_force_string=True, session=True),
@@ -715,10 +722,11 @@
Field("vater_telefonnummer", digest=True),
Field("vater_email", digest=True),
- Field("erstgespraech", alias="first_meeting", session=True),
- Field("datum_cm_ende", alias="cm_end", session=True),
+ Field("erstgespraech", alias="first_meeting", session=True,
+ preload=True),
+ Field("datum_cm_ende", alias="cm_end", session=True, preload=True),
Field("bearbeiter_id", search_retrieve=True,
- alias="editor", session=False),
+ alias="editor", session=False, preload=True),
]
alias_dict = dict((field.alias, field) for field in fields
@@ -758,6 +766,11 @@
return [field.name for field in cls.fields if field.alias is not None]
@classmethod
+ def get_preload_fields(cls):
+ """Return a list with the names of the fields to preload."""
+ return [field.name for field in cls.fields if field.preload]
+
+ @classmethod
def get_session_fields(cls):
"""Return a list describing the fields to store in the session case.
The items of the list are those items of cls.alias whose
More information about the Mpuls-commits
mailing list