From d7ace92c04e7e72b2f0981bf0c9260a4be7fb10b Mon Sep 17 00:00:00 2001 From: mdipierro Date: Thu, 29 Nov 2012 22:35:20 -0600 Subject: [PATCH] Allow for Field Validators to handle None values, fixed issue 1183, thanks Joe Barnhart --- VERSION | 2 +- applications/admin/static/css/web2py.css | 8 ++++++-- applications/admin/static/js/web2py.js | 2 +- applications/admin/views/shell/index.html | 4 ++-- applications/examples/static/css/web2py.css | 8 ++++++-- applications/examples/static/js/web2py.js | 2 +- applications/welcome/static/css/web2py.css | 4 ++++ applications/welcome/static/js/web2py.js | 2 +- gluon/dal.py | 8 +++++--- 9 files changed, 27 insertions(+), 13 deletions(-) diff --git a/VERSION b/VERSION index 425fe3ef..4a24ded7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.2.1 (2012-11-29 18:20:27) stable +Version 2.2.1 (2012-11-29 22:34:41) stable diff --git a/applications/admin/static/css/web2py.css b/applications/admin/static/css/web2py.css index ac04a0f0..947648ad 100644 --- a/applications/admin/static/css/web2py.css +++ b/applications/admin/static/css/web2py.css @@ -61,7 +61,7 @@ input[type=text],input[type=password],select{width:300px; margin-right:5px} border-top:1px #DEDEDE solid; } .header { - // background:; + /* background:; */ } @@ -115,6 +115,10 @@ div.flash { z-index:2000; } +div.flash #closeflash{color:inherit; float:right;} +.ie-lte7 div.flash +#closeflash{color:expression(this.parentNode.currentStyle['color']);float:none;position:absolute;right:4px;} + div.flash:hover { opacity:0.25; } div.error_wrapper {display:block} @@ -182,7 +186,7 @@ div.error { * will look better with the declarations below * if needed to remove base.css consider keeping these following lines in some css file. */ -// .web2py_table {border:1px solid #ccc} +/* .web2py_table {border:1px solid #ccc} */ .web2py_paginator {} .web2py_grid {width:100%} .web2py_grid table {width:100%} diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 34a50546..8824a79e 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -55,7 +55,7 @@ function web2py_event_handlers() { jQuery(function() { var flash = jQuery('.flash'); flash.hide(); - if(flash.html()) flash.append('×').slideDown(); + if(flash.html()) flash.append('×').slideDown(); web2py_ajax_init(document); web2py_event_handlers(); }); diff --git a/applications/admin/views/shell/index.html b/applications/admin/views/shell/index.html index 028dd424..50c30caf 100644 --- a/applications/admin/views/shell/index.html +++ b/applications/admin/views/shell/index.html @@ -66,7 +66,7 @@
-
+
>>>
@@ -103,7 +103,7 @@ jQuery(document).ready(function(){ if(s.length>1 && s.substr(s.length-1,1)=='\n' && s.substr(s.length-2,1)!=':' && (s.indexOf(':\n ')<0 || s.substr(s.length-2,1)=='\n')) { t.val(''); - jQuery.post("{{=URL(r=request,f='callback',args=app)}}", + jQuery.post("{{=URL('callback',args=app)}}", {statement:s},function(data){o.html(o.html()+data).attr('scrollTop',o.attr('scrollHeight'));}); } else { }; if(event.keyCode==RETURN){ diff --git a/applications/examples/static/css/web2py.css b/applications/examples/static/css/web2py.css index ac04a0f0..947648ad 100644 --- a/applications/examples/static/css/web2py.css +++ b/applications/examples/static/css/web2py.css @@ -61,7 +61,7 @@ input[type=text],input[type=password],select{width:300px; margin-right:5px} border-top:1px #DEDEDE solid; } .header { - // background:; + /* background:; */ } @@ -115,6 +115,10 @@ div.flash { z-index:2000; } +div.flash #closeflash{color:inherit; float:right;} +.ie-lte7 div.flash +#closeflash{color:expression(this.parentNode.currentStyle['color']);float:none;position:absolute;right:4px;} + div.flash:hover { opacity:0.25; } div.error_wrapper {display:block} @@ -182,7 +186,7 @@ div.error { * will look better with the declarations below * if needed to remove base.css consider keeping these following lines in some css file. */ -// .web2py_table {border:1px solid #ccc} +/* .web2py_table {border:1px solid #ccc} */ .web2py_paginator {} .web2py_grid {width:100%} .web2py_grid table {width:100%} diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index 34a50546..8824a79e 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -55,7 +55,7 @@ function web2py_event_handlers() { jQuery(function() { var flash = jQuery('.flash'); flash.hide(); - if(flash.html()) flash.append('×').slideDown(); + if(flash.html()) flash.append('×').slideDown(); web2py_ajax_init(document); web2py_event_handlers(); }); diff --git a/applications/welcome/static/css/web2py.css b/applications/welcome/static/css/web2py.css index 1ad43fd0..947648ad 100644 --- a/applications/welcome/static/css/web2py.css +++ b/applications/welcome/static/css/web2py.css @@ -115,6 +115,10 @@ div.flash { z-index:2000; } +div.flash #closeflash{color:inherit; float:right;} +.ie-lte7 div.flash +#closeflash{color:expression(this.parentNode.currentStyle['color']);float:none;position:absolute;right:4px;} + div.flash:hover { opacity:0.25; } div.error_wrapper {display:block} diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 34a50546..8824a79e 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -55,7 +55,7 @@ function web2py_event_handlers() { jQuery(function() { var flash = jQuery('.flash'); flash.hide(); - if(flash.html()) flash.append('×').slideDown(); + if(flash.html()) flash.append('×').slideDown(); web2py_ajax_init(document); web2py_event_handlers(); }); diff --git a/gluon/dal.py b/gluon/dal.py index dfd0b28f..e74deda5 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -8495,6 +8495,7 @@ class Field(Expression): filter_in = None, filter_out = None, custom_qualifier = None, + map_none = None, ): self._db = self.db = None # both for backward compatibility self.op = None @@ -8535,6 +8536,7 @@ class Field(Expression): self.custom_qualifier = custom_qualifier self.label = label if label!=None else fieldname.replace('_',' ').title() self.requires = requires if requires!=None else [] + self.map_none = map_none def set_attributes(self,*args,**attributes): self.__dict__.update(*args,**attributes) @@ -8666,7 +8668,7 @@ class Field(Expression): def formatter(self, value): requires = self.requires if value is None or not requires: - return value + return value or self.map_none if not isinstance(requires, (list, tuple)): requires = [requires] elif isinstance(requires, tuple): @@ -8681,7 +8683,7 @@ class Field(Expression): def validate(self, value): if not self.requires or self.requires == DEFAULT: - return (value, None) + return ((value if value!=self.map_none else None), None) requires = self.requires if not isinstance(requires, (list, tuple)): requires = [requires] @@ -8689,7 +8691,7 @@ class Field(Expression): (value, error) = validator(value) if error: return (value, error) - return (value, None) + return ((value if value!=self.map_none else None), None) def count(self, distinct=None): return Expression(self.db, self.db._adapter.COUNT, self, distinct, 'integer')