[Mpuls-commits] r747 - in wasko/branches/2.0/waskaweb: controllers lib public/styles

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Jan 12 16:15:26 CET 2010


Author: torsten
Date: 2010-01-12 16:15:20 +0100 (Tue, 12 Jan 2010)
New Revision: 747

Modified:
   wasko/branches/2.0/waskaweb/controllers/formularpage.py
   wasko/branches/2.0/waskaweb/lib/renderer_new.py
   wasko/branches/2.0/waskaweb/public/styles/all.css
   wasko/branches/2.0/waskaweb/public/styles/color3.css
Log:
Added last changes


Modified: wasko/branches/2.0/waskaweb/controllers/formularpage.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/formularpage.py	2010-01-11 16:25:12 UTC (rev 746)
+++ wasko/branches/2.0/waskaweb/controllers/formularpage.py	2010-01-12 15:15:20 UTC (rev 747)
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 import logging
 import traceback
 import formencode
@@ -18,6 +20,36 @@
 
 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:
@@ -32,16 +64,20 @@
         session['case'].id, 
         session.get('uncommited_fields'))
     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 = "Fehler" 
+            c.formularerrors = u"Fehler" 
             renderer      = ViewRenderer(instance_tree, page,session.get('render_mode', 'ro')=='ro')
-        #errorrenderer = ErrorRenderer(page.getErrors(), page.getWarnings()) 
-        #log.debug('select: errorrenderer ok: %s' % errorrenderer)
-        #c.formularerrors = errorrenderer.render(page) 
+        errorrenderer = ErrorRenderer(errors, warnings) 
+        c.formularerrors = errorrenderer.render(page) 
         try:
             mark_folderopen(session['navigation.tree'].getTreeItem(id)) 
             if session['navigation.tree'].getTreeItem(id).nextKey():
@@ -54,8 +90,17 @@
         session['case'].setPageId(c.page_id)
         session['navigation.selectedpage'] = id
         session.save()
-    return render('/formularpage/content.mako')
 
+    # 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)
+
 class FormularpageController(BaseController):
 
 
@@ -67,7 +112,7 @@
 
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
     def select(self, id):
-        c.formular = unicode(get_rendered_page(id), 'utf-8')
+        c.formular = get_rendered_page(id)
         return render('/formularpage/formular.mako')
 
     @checkRole(('cm_ka'))
@@ -88,7 +133,11 @@
     @checkRole(('cm_ka'))
     def undo(self, id):
         try:
-            pass # remove id from errors in session
+            unc = session.get('uncommited_fields')
+            if unc: 
+                del unc[id]
+                session['uncommited_fields'] = unc
+                session.save()
         except:
             pass
         return self.select(session['navigation.selectedpage'])
@@ -103,7 +152,7 @@
         try:
             form_result = convert2dic(request.params)
             instance_tree.setData(form_result)
-            session['uncommitted_fields'] = instance_tree.commit()
+            session['uncommited_fields'] = instance_tree.commit()
             session.save()
             #ok_status(_('Successfully saved data'))
             # show next page after saving?
@@ -116,7 +165,8 @@
             # which will clean up the renderer code a lot! But this is for the
             # future
             #error_status(_('Error while saving data'))
-            pass
+            session['uncommited_fields'] = instance_tree.commit()
+            session.save()
         except:
             log.error(traceback.print_exc())
             #error_status(_('Error while saving data'))

Modified: wasko/branches/2.0/waskaweb/lib/renderer_new.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/renderer_new.py	2010-01-11 16:25:12 UTC (rev 746)
+++ wasko/branches/2.0/waskaweb/lib/renderer_new.py	2010-01-12 15:15:20 UTC (rev 747)
@@ -217,18 +217,20 @@
         log.debug('Annotations: %s' % meta.getAnnotations(['help', 'requiered', 'evaluation']))
         if meta.hasHelp():
             log.debug('Found help')
-            out.append('<a href="/annotations/help/%s" target="_blank"><img src="/images/icons/formular/help.png"></a>' % meta.getName())
+            out.append('<a href="/annotations/help/%s" target="_blank"><img src="/images/icons/formular/help.png" alt="help"></a>' % meta.getName())
         if meta.hasRequired():
-            out.append('<a href="/annotations/required/%s" target="_blank"><img src="/images/icons/formular/required.png"></a>' % meta.getName())
+            out.append('<a href="/annotations/required/%s" target="_blank"><img src="/images/icons/formular/required.png" alt="required"></a>' % meta.getName())
         if meta.hasEvaluation():
-            out.append('<a href="/annotations/evaluation/%s" target="_blank"><img src="/images/icons/formular/evaluation.png"></a>' % meta.getName())
+            out.append('<a href="/annotations/evaluation/%s" target="_blank"><img src="/images/icons/formular/evaluation.png" alt="evaluation"></a>' % meta.getName())
         return "\n".join(out)
 
     def _renderErrors(self, node):
         meta = self._getMeta(node)
         out = []
-        if node.hasErrors():
-            out.append('<span class="error">%s</span>' % node.getError())
+        error = '<form:error name="%s" format="">' % node.getIdentifier()
+        if node.hasErrors() or True:
+            #out.append('<span class="error">%s</span>' % node.getErrors())
+            out.append('<span class="error">%s</span>' % error)
         return "\n".join(out)
 
     def _renderDummyGroup(self, node):
@@ -464,7 +466,7 @@
         value = node.getValue()
         disabled = self.ro_mode and "disabled" or ""
         #checked = self.stateStack[-1] == value and "checked" or ""
-        print "mvalue: %s value: %s" % (mvalue, value)
+        #print "mvalue: %s value: %s" % (mvalue, value)
         checked = mvalue == value and "checked" or ""
         out = []
         out.append('<input type="checkbox" id="%s" name="%s" value="%s" %s %s %s %s>' 
@@ -530,7 +532,7 @@
         selected    = ""
         out         = ""
 
-        print "render %s" % name
+        #print "render %s" % name
         
         try:
             toSelect = self.stateStack[-1]
@@ -772,64 +774,151 @@
         self.warnings    = warnings
 
     def render(self, page):
-        meta = self._getMeta(page)
+        meta = page.getMeta()
         page_name = meta.getName()
+        tree = page.getInstanceTree()
 
         #errors_list = [kv for kv in self.error_items.iteritems() if kv[1].page == page_name]
-        errors_list = [kv for kv in self.error_items.iteritems()]
+        #errors_list = [kv for kv in self.error_items.iteritems()]
         #order = dict([(w.getName(), idx) for idx, w in enumerate(page.allWidgets())])
 
         out = []
 
-        if errors_list:
+        if self.error_items:
             out.append('<div class="widget dialog">')
-            out.append('<h1><img src="/images/icons/alert.png">%s</h1>' % _('Formular errors'))
+            out.append('<h1><img src="/images/alert.png">%s</h1>' % _('Formular errors'))
             out.append('<ol>')
 
-            #errors_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
 
-            for k, v in errors_list:
-                out.append(u'<li><a href="/formularpage/undo/%s">' % k)
-                out.append(u'<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"' % _('Restore last valid value'))
+            for k, v in self.error_items.iteritems():
+                element = tree.getFormEd().findByName(k.split(':')[0])
+                #print element
+                description = element.getDescription()
+                out.append('<li><a href="/formularpage/undo/%s">' % k)
+                out.append('<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"/>' % _('Restore last valid value'))
                 out.append(
-                    u'</a>'
-                    u'<a class="error" href="#f_%s">%s: %s</a></li>'% (k, v.name, u", ".join(v.messages)))
+                    '</a>'
+                    '<a class="error" href="#f_%s">%s: %s</a></li>'% (k, description, v))
 
             out.append('</ol>')
             out.append('</div>')
 
         if self.warnings:
-            # hash by warning message
-            warns = {}
-            warnings_list = self.warnings.items()
-            #warnings_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
+            out.append('<div class="widget dialog">')
+            out.append('<h1><img src="/images/info.png">%s</h1>' % _('Formular warnings'))
+            out.append('<ol>')
 
-            for k, v in warnings_list:
-                msg = u", ".join(v[1])
-                items = warns.setdefault(msg, [])
-                items.append((k, v[0].getDescription()))
+            for k, v in self.warnings.iteritems():
+                element = tree.getFormEd().findByName(k.split(':')[0])
+                #print element
+                description = element.getDescription()
+                out.append('<li><a href="/formularpage/undo/%s">' % k)
+                out.append('<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"/>' % _('Restore last valid value'))
+                out.append(
+                    '</a>'
+                    '<a class="error" href="#f_%s">%s: %s</a></li>'% (k, description, v))
+            out.append('</ol>')
+            out.append('</div>')
 
-                out.append('<div class="widget dialog">')
-                out.append('<h1><img src="/images/icons/info.png">%s</h1>' % _('Formular warnings'))
-                out.append('<ol>')
+        #if self.warnings:
+        #    # hash by warning message
+        #    warns = {}
+        #    warnings_list = self.warnings.items()
+        #    #warnings_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
 
-            counter = (len(self.warnings) > 5) and 1 or None
+        #    for k, v in warnings_list:
+        #        msg = u", ".join(v[1])
+        #        items = warns.setdefault(msg, [])
+        #        items.append((k, v[0].getDescription()))
 
-            for k, v in warns.iteritems():
-                out.append(u'<li>')
-                links = []
-                if counter:
-                    for item in v:
-                        links.append(u'<a href="#f_%s" title=%s>%d</a>' % (
-                            item[0], quoteattr(item[1]), counter))
-                        counter += 1
-                else:
-                    for item in v:
-                        links.append(u'<a href="#f_%s">%s</a>' % item)
+        #        out.append('<div class="widget dialog">')
+        #        out.append('<h1><img src="/images/icons/info.png">%s</h1>' % _('Formular warnings'))
+        #        out.append('<ol>')
 
-                out.append(u"%s: %s</li>" % (k, u", ".join(links)))
+        #    counter = (len(self.warnings) > 5) and 1 or None
 
-            out.append(u'</ul></div>')
-        return u"".join(out)
+        #    for k, v in warns.iteritems():
+        #        out.append(u'<li>')
+        #        links = []
+        #        if counter:
+        #            for item in v:
+        #                links.append(u'<a href="#f_%s" title=%s>%d</a>' % (
+        #                    item[0], quoteattr(item[1]), counter))
+        #                counter += 1
+        #        else:
+        #            for item in v:
+        #                links.append(u'<a href="#f_%s">%s</a>' % item)
 
+        #        out.append(u"%s: %s</li>" % (k, u", ".join(links)))
+
+        #    out.append(u'</ul></div>')
+        return "".join(out)
+
+# class ErrorRenderer(object):
+#     
+#     def __init__(self, error_items, warnings):
+#         self.error_items = error_items
+#         self.warnings    = warnings
+# 
+#     def render(self, page):
+#         meta = self._getMeta(page)
+#         page_name = meta.getName()
+# 
+#         #errors_list = [kv for kv in self.error_items.iteritems() if kv[1].page == page_name]
+#         errors_list = [kv for kv in self.error_items.iteritems()]
+#         #order = dict([(w.getName(), idx) for idx, w in enumerate(page.allWidgets())])
+# 
+#         out = []
+# 
+#         if errors_list:
+#             out.append('<div class="widget dialog">')
+#             out.append('<h1><img src="/images/icons/alert.png">%s</h1>' % _('Formular errors'))
+#             out.append('<ol>')
+# 
+#             #errors_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
+# 
+#             for k, v in errors_list:
+#                 out.append(u'<li><a href="/formularpage/undo/%s">' % k)
+#                 out.append(u'<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"' % _('Restore last valid value'))
+#                 out.append(
+#                     u'</a>'
+#                     u'<a class="error" href="#f_%s">%s: %s</a></li>'% (k, v.name, u", ".join(v.messages)))
+# 
+#             out.append('</ol>')
+#             out.append('</div>')
+# 
+#         if self.warnings:
+#             # hash by warning message
+#             warns = {}
+#             warnings_list = self.warnings.items()
+#             #warnings_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
+# 
+#             for k, v in warnings_list:
+#                 msg = u", ".join(v[1])
+#                 items = warns.setdefault(msg, [])
+#                 items.append((k, v[0].getDescription()))
+# 
+#                 out.append('<div class="widget dialog">')
+#                 out.append('<h1><img src="/images/icons/info.png">%s</h1>' % _('Formular warnings'))
+#                 out.append('<ol>')
+# 
+#             counter = (len(self.warnings) > 5) and 1 or None
+# 
+#             for k, v in warns.iteritems():
+#                 out.append(u'<li>')
+#                 links = []
+#                 if counter:
+#                     for item in v:
+#                         links.append(u'<a href="#f_%s" title=%s>%d</a>' % (
+#                             item[0], quoteattr(item[1]), counter))
+#                         counter += 1
+#                 else:
+#                     for item in v:
+#                         links.append(u'<a href="#f_%s">%s</a>' % item)
+# 
+#                 out.append(u"%s: %s</li>" % (k, u", ".join(links)))
+# 
+#             out.append(u'</ul></div>')
+#         return u"".join(out)
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8:

Modified: wasko/branches/2.0/waskaweb/public/styles/all.css
===================================================================
--- wasko/branches/2.0/waskaweb/public/styles/all.css	2010-01-11 16:25:12 UTC (rev 746)
+++ wasko/branches/2.0/waskaweb/public/styles/all.css	2010-01-12 15:15:20 UTC (rev 747)
@@ -256,6 +256,7 @@
 	font-weight: bold;
 	font-size: 0.7em;
 	margin: 0;
+	color: #000;
 }
 
 .formularpage p.readonly{

Modified: wasko/branches/2.0/waskaweb/public/styles/color3.css
===================================================================
--- wasko/branches/2.0/waskaweb/public/styles/color3.css	2010-01-11 16:25:12 UTC (rev 746)
+++ wasko/branches/2.0/waskaweb/public/styles/color3.css	2010-01-12 15:15:20 UTC (rev 747)
@@ -35,6 +35,10 @@
 
 li tt { text-decoration: none; }
 
+.error {
+	color: #a5103b;
+}
+
 /*------------------*/
 /* 2.	Header      */
 /*------------------*/



More information about the Mpuls-commits mailing list