[Mpuls-commits] r1503 - in wasko/branches/2.0: mpulsweb/controllers waskaweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 11 09:21:24 CET 2010


Author: torsten
Date: 2010-02-11 09:21:24 +0100 (Thu, 11 Feb 2010)
New Revision: 1503

Added:
   wasko/branches/2.0/mpulsweb/controllers/formularpage.py
Removed:
   wasko/branches/2.0/waskaweb/controllers/formularpage.py
Log:
Moved formularpage controller to mpulsbase


Copied: wasko/branches/2.0/mpulsweb/controllers/formularpage.py (from rev 1500, wasko/branches/2.0/waskaweb/controllers/formularpage.py)


Property changes on: wasko/branches/2.0/mpulsweb/controllers/formularpage.py
___________________________________________________________________
Name: svn:mergeinfo
   + 

Deleted: wasko/branches/2.0/waskaweb/controllers/formularpage.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/formularpage.py	2010-02-11 08:20:46 UTC (rev 1502)
+++ wasko/branches/2.0/waskaweb/controllers/formularpage.py	2010-02-11 08:21:24 UTC (rev 1503)
@@ -1,197 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import logging
-import traceback
-
-import formencode
-
-from pylons import request, session, c
-from pylons import g
-from pylons.i18n import _
-
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
-from formed.instance.tree import SetDataException, RepeatInstanceContainerNode
-
-from mpulsweb.lib.security import checkRole
-from mpulsweb.lib.db import  PostgresDBInterface
-from mpulsweb.lib.navigation import  mark_folderopen
-
-from mpulsweb.lib.base import BaseController, render
-from mpulsweb.lib.renderer import ViewRenderer, RepeatGroupRenderer, \
-     ErrorRenderer
-
-
-log = logging.getLogger(__name__)
-
-
-def convertErrorItem2ErrorDic(error_items):
-    if error_items is None:
-        return {}
-    errors = {}
-    print error_items
-    for items in error_items:
-        for e in items:
-            if e.type == 0:
-                errors[e.name] = e.msg
-    return errors
-
-def convertErrorItem2WarningDic(error_items):
-    if error_items is None:
-        return {}
-    errors = {}
-    print error_items
-    for items in error_items:
-        for e in items:
-            if e.type == 1:
-                errors[e.name] = e.msg
-    return errors
-
-def convertErrorItem2ValueDic(error_items):
-    if error_items is None:
-        return {}
-    errors = {}
-    print error_items
-    for items in error_items:
-        for e in items:
-            errors[e.name] = e.bad
-    return errors
-
-
-def convert2dic(params):
-    result = {}
-    for i in params:
-        # libformed
-        if i not in ['save', 'savenext', 'page']:
-            result[i] = params[i]
-    return result
-
-def get_rendered_page(id):
-    factory = InstanceFactory(g.formedTree, PostgresDBInterface())
-    instance_tree = factory.loadInstanceTreeByIdentifier(
-        session['case'].id,
-        session.get('uncommited_fields'))
-
-    log.debug('Getting page "%s"' % id)
-    page = instance_tree.getItem(id)
-
-    errors = convertErrorItem2ErrorDic(page.getErrors())
-    warnings = convertErrorItem2WarningDic(page.getErrors())
-    defaults = convertErrorItem2ValueDic(page.getErrors())
-
-    if page:
-        c.formularheader = "<h1>%s</h1>" % page.getMeta().getDescription()
-        if isinstance(page, RepeatInstanceContainerNode):
-            renderer = RepeatGroupRenderer(instance_tree, page,
-                                           session.get('render_mode',
-                                                       'ro') == 'ro')
-        else:
-            c.formularerrors = u"Fehler"
-            renderer = ViewRenderer(instance_tree, page,
-                                    session.get('render_mode', 'ro') == 'ro')
-        errorrenderer = ErrorRenderer(errors, warnings)
-        c.formularerrors = errorrenderer.render(page)
-        try:
-            mark_folderopen(session['navigation.tree'].getTreeItem(id))
-            if session['navigation.tree'].getTreeItem(id).nextKey():
-                c.formular = renderer.render(showNext=True)
-            else:
-                c.formular = renderer.render(showNext=False)
-        except:
-            print traceback.print_exc()
-        c.page_id = page.getIdentifier()
-        session['case'].setPageId(c.page_id)
-        session['navigation.selectedpage'] = id
-        session.save()
-
-    # Render form and use htmlfill to fillout the form and mark errorfields.
-    form = unicode(render('/formularpage/content.mako'), 'utf-8')
-
-    # Currently values of the fields are set within the renderer.
-    # Htmlfill is used to fill in the error values from the error items.
-    return formencode.htmlfill.render(form, defaults=defaults,
-                                      errors=errors, auto_insert_errors=False,
-                                      force_defaults=False)
-
-
-class FormularpageController(BaseController):
-
-    def index(self):
-        # Return a rendered template
-        # return render('/formularpage.mako')
-        # or, return a response
-        return 'Hello World'
-
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def select(self, id):
-        c.formular = get_rendered_page(id)
-        return render('/formularpage/formular.mako')
-
-    @checkRole(('cm_ka'))
-    def edit(self, id):
-        session['render_mode'] = 'rw'
-        session.save()
-        try:
-            return self.select(id)
-        except:
-            print traceback.print_exc()
-
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def show(self, id):
-        session['render_mode'] = 'ro'
-        session.save()
-        return self.select(id)
-
-    @checkRole(('cm_ka'))
-    def undo(self, id):
-        try:
-            unc = session.get('uncommited_fields')
-            if unc:
-                del unc[id]
-                session['uncommited_fields'] = unc
-                session.save()
-        except:
-            pass
-        return self.select(session['navigation.selectedpage'])
-
-    @checkRole(('cm_ka'))
-    def save(self):
-        factory = InstanceFactory(g.formedTree, PostgresDBInterface())
-        instance_tree = factory.loadInstanceTreeByIdentifier(
-            session['case'].id,
-            session.get('uncommited_fields'))
-        page_id = request.params['page']
-        try:
-            form_result = convert2dic(request.params)
-            instance_tree.setData(form_result)
-            session['uncommited_fields'] = instance_tree.commit()
-            session.save()
-            #ok_status(_('Successfully saved data'))
-            # show next page after saving?
-            if request.params.has_key('savenext'):
-                page_id = session['navigation.tree'].getTreeItem(page_id).nextKey().key
-
-        except SetDataException, err:
-            # Do nothing than setting the status message. In the future the
-            # exception can be used to fill out the form again with htmlfill,
-            # which will clean up the renderer code a lot! But this is for the
-            # future
-            #error_status(_('Error while saving data'))
-            session['uncommited_fields'] = instance_tree.commit()
-            session.save()
-        except:
-            log.error(traceback.print_exc())
-            #error_status(_('Error while saving data'))
-            raise # Saving failed with unknown reason! Raise exception ->
-                  # should result in a bugreport dialog if enabled.
-        return self.select(page_id)
-
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def printout(self, id):
-        c.print_version = 1
-        render_mode = session['render_mode']
-        session['render_mode'] = 'ro'
-        session.save()
-        page = self.select(id)
-        session['render_mode'] = render_mode
-        session.save()
-        return page



More information about the Mpuls-commits mailing list