[Mpuls-commits] r5980 - in base/trunk/mpulsweb: controllers lib lib/helper model
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Mon Jun 11 14:46:56 CEST 2012
Author: bricks
Date: 2012-06-11 14:46:56 +0200 (Mon, 11 Jun 2012)
New Revision: 5980
Modified:
base/trunk/mpulsweb/controllers/formularpage.py
base/trunk/mpulsweb/lib/helper/case.py
base/trunk/mpulsweb/lib/navigation.py
base/trunk/mpulsweb/model/case.py
base/trunk/mpulsweb/model/meta.py
base/trunk/mpulsweb/model/phase.py
Log:
Use the new get_instance_factory method from Globals object
Use the new get_instance_factory method from Globals object
instead of creating an own InstanceFactory at several places.
With this change it has become possible to override the instance
tree in a mpuls application.
Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/controllers/formularpage.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -6,14 +6,12 @@
from pylons.controllers.util import abort, redirect
from pylons.i18n.translation import get_lang
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
from formed.instance.tree import SetDataException, RepeatInstanceContainerNode
from formed.renderer.html import apply_hidden_booleans, RepeatGroupRenderer, \
ErrorRenderer, TreeFormData
from mpulsweb.lib.translation import _
from mpulsweb.lib.security import checkRole
-from mpulsweb.lib.db import PostgresDBInterface
from mpulsweb.lib.navigation import mark_folderopen, get_navigation
from mpulsweb.lib.base import BaseController, render, session
from mpulsweb.lib.helpers import literal, url
@@ -51,7 +49,7 @@
printrenderer=ViewPrintRenderer,
errorrenderer=ErrorRenderer):
if instance_tree is None:
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
instance_tree = factory.loadInstanceTreeByIdentifier(
session['case'].id,
session.get('uncommited_fields'))
@@ -133,7 +131,7 @@
def get_rendered_page(self, id, instance_tree=None):
if instance_tree is None:
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
instance_tree = factory.loadInstanceTreeByIdentifier(
session['case'].id,
session.get('uncommited_fields'))
Modified: base/trunk/mpulsweb/lib/helper/case.py
===================================================================
--- base/trunk/mpulsweb/lib/helper/case.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/lib/helper/case.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import logging
from formed.instance.tree import InstanceLeaf
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
from formed.meta.data import DateLeaf
from mpulsweb.lib.base import g
from mpulsweb.lib.translation import _
-from mpulsweb.lib.db import PostgresDBInterface, db
+from mpulsweb.lib.db import db
from mpulsweb.lib.helpers import format_date, format_number
log = logging.getLogger(__name__)
@@ -21,7 +20,7 @@
def copy_field(src_id=None, src_field=None, dst_id=None, dst_field=None):
data = {}
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
sit = factory.loadInstanceTreeByIdentifier(src_id)
dit = factory.loadInstanceTreeByIdentifier(dst_id)
item = sit.getItem("%s:%s" % (src_field, src_id))
@@ -36,7 +35,7 @@
def copy_instance_tree(it, fields=None):
'''Does a full copy of a given instance tree. If fields is not None, the only fields will be copied whoch are define in fields. This is done by deleting the values after copying."'''
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
new_it = factory.copy_instance_tree(it, fields)
return new_it
Modified: base/trunk/mpulsweb/lib/navigation.py
===================================================================
--- base/trunk/mpulsweb/lib/navigation.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/lib/navigation.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -36,11 +36,9 @@
from formed.meta.data import PageNode, Leaf, RadioNode, Node
from formed.instance.tree import InstanceNode, RepeatInstanceContainerNode, \
RepeatInstanceNode, IDENTIFIER_SEPARATOR
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
from formed.renderer.html import TreeFormData
from mpulsweb.lib.translation import _
-from mpulsweb.lib.db import PostgresDBInterface
import mpulsweb.lib.helpers
# normally we would import session from mpulsweb.lib.base, but to avoid
@@ -72,7 +70,7 @@
def get_navigation(id, openfolders=None):
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
instance_tree = factory.loadInstanceTreeByIdentifier(id,
session.get('uncommited_fields'))
navigation = NavigationTree(instance_tree, openfolders)
Modified: base/trunk/mpulsweb/model/case.py
===================================================================
--- base/trunk/mpulsweb/model/case.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/model/case.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -36,11 +36,9 @@
import psycopg2.extras
from pylons import config
-from mpulsweb.lib.translation import _
from formed.meta.data import RepeatNode, DateLeaf, IntLeaf, TextLeaf,\
ChoiceNode, RadioNode, RuleLeaf
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
from formed.instance.backends.xmlimport import XMLImportException
from formed.instance.backends.dbxmlimport import DBXMLImporter
from formed.instance.backends.common import RuleEvalContext
@@ -56,6 +54,7 @@
from mpulsweb.model.document import listDocuments, export_documents, \
get_documents_import_factory, import_documents
from mpulsweb.model.statement import PrivacyStatement
+from mpulsweb.lib.translation import _
from mpulsweb.model.phase import PhaseFactory, StartPhasePart, \
PhaseAnonymizableCheckException, ConsistenceCheckException, PHASEFIELD, PC_MANUAL
from mpulsweb.model.user import UserObject
@@ -430,7 +429,7 @@
return num
def export(self, type='XML', anonym=True, selection=None):
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
num = 0
xmltree = factory.toXML(self.case_list, selection=selection,
@@ -643,10 +642,13 @@
def _load_formed_instance_tree(self):
if self.formed_instance is None:
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = self._get_instance_factory()
self.formed_instance = factory.loadInstanceTreeByIdentifier(
self.id, uncommited=self.uncommitted)
+ def _get_instance_factory(self):
+ return g.get_instance_factory()
+
def get_formed_instance_tree(self):
"""Return the formed instance tree associated with the case object.
The instance tree will be loaded if hasn't been loaded yet.
@@ -1048,7 +1050,7 @@
def copy(self):
"""Copy the case and all its contents into a new case."""
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = self._get_instance_factory()
self._load_formed_instance_tree()
factory.copy_instance_tree(self.formed_instance)
@@ -1303,7 +1305,7 @@
will get initialized with some standard information like the
editor information.
"""
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = self._get_instance_factory()
instance_tree = factory.createNewInstanceTree(uuid)
id = instance_tree.getRootNode().getIdentifier()
Modified: base/trunk/mpulsweb/model/meta.py
===================================================================
--- base/trunk/mpulsweb/model/meta.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/model/meta.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -13,9 +13,7 @@
from pylons import config
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
-
-from mpulsweb.lib.db import PostgresDBInterface, db
+from mpulsweb.lib.db import db
from mpulsweb.lib.translation import _
from mpulsweb.lib.base import g, session
from mpulsweb.lib.security import get_unmapped_db_name
@@ -230,7 +228,7 @@
def get_meta_xml(self):
"""Return the data to transfer to the meta server as an XML string."""
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
xmltree = factory.toXML([self.master_id])
return convert_meta_xml(g.meta_converter,
ElementTree.tostring(xmltree.getroot()))
Modified: base/trunk/mpulsweb/model/phase.py
===================================================================
--- base/trunk/mpulsweb/model/phase.py 2012-06-11 12:44:33 UTC (rev 5979)
+++ base/trunk/mpulsweb/model/phase.py 2012-06-11 12:46:56 UTC (rev 5980)
@@ -6,7 +6,6 @@
from pylons import app_globals as g, tmpl_context as c
from mpulsweb.lib.translation import _
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
from formed.instance.backends.common import RuleEvalContext
from formed.instance.tree import PageInstanceNode
from formed.meta.data import PageNode, RepeatNode
@@ -116,7 +115,7 @@
def load(self, id):
'''Build phaselist from metadata and load current state from instance tree'''
self.build()
- factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ factory = g.get_instance_factory()
it = factory.loadInstanceTreeByIdentifier(id)
for p in self.phases:
start = p.start
More information about the Mpuls-commits
mailing list