Repository: web2py/web2py

Issue:
show_if is not compatible with recent pydal
With recent pydal refactory introduced by @gi0baro cond.op.**name** is in lower case, while before was in upper case. See https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L109

This breaks any app using show_if since a `RuntimeError("Not Implemented Error")` exception is raised.



Discussion:
@ilvalle thank you for the catch. I was not aware of that function. Will fix it asap.


Resolving patch:
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -110,19 +110,19 @@ def show_if(cond):
     if not cond:
         return None
     base = "%s_%s" % (cond.first.tablename, cond.first.name)
-    if ((cond.op.__name__ == 'EQ' and cond.second is True) or
-            (cond.op.__name__ == 'NE' and cond.second is False)):
+    if ((cond.op.__name__ == 'eq' and cond.second is True) or
+            (cond.op.__name__ == 'ne' and cond.second is False)):
         return base, ":checked"
-    if ((cond.op.__name__ == 'EQ' and cond.second is False) or
-            (cond.op.__name__ == 'NE' and cond.second is True)):
+    if ((cond.op.__name__ == 'eq' and cond.second is False) or
+            (cond.op.__name__ == 'ne' and cond.second is True)):
         return base, ":not(:checked)"
-    if cond.op.__name__ == 'EQ':
+    if cond.op.__name__ == 'eq':
         return base, "[value='%s']" % cond.second
-    if cond.op.__name__ == 'NE':
+    if cond.op.__name__ == 'ne':
         return base, "[value!='%s']" % cond.second
-    if cond.op.__name__ == 'CONTAINS':
+    if cond.op.__name__ == 'contains':
         return base, "[value~='%s']" % cond.second
-    if cond.op.__name__ == 'BELONGS':
+    if cond.op.__name__ == 'belongs':
         if isinstance(cond.second, set):
             cond.second = list(cond.second)
         if isinstance(cond.second, (list, tuple)):
@@ -1528,7 +1528,7 @@ def accepts(
             hideerror=hideerror,
             **kwargs
         )
-        
+
         self.deleted = request_vars.get(self.FIELDNAME_REQUEST_DELETE, False)
 
         self.custom.end = CAT(self.hidden_fields(), self.custom.end)
@@ -1897,24 +1897,24 @@ def search_menu(fields,
                 else:
                     field_type = field.type
 
-                operators = SELECT(*[OPTION(T(option), _value=option) for option in options], 
+                operators = SELECT(*[OPTION(T(option), _value=option) for option in options],
                                     _class='form-control')
                 _id = "%s_%s" % (value_id, name)
                 if field_type in ['boolean', 'double', 'time', 'integer']:
                     widget_ = SQLFORM.widgets[field_type]
-                    value_input = widget_.widget(field, field.default, _id=_id, 
+                    value_input = widget_.widget(field, field.default, _id=_id,
                                                  _class=widget_._class + ' form-control')
                 elif field_type == 'date':
                     iso_format = {'_data-w2p_date_format': '%Y-%m-%d'}
                     widget_ = SQLFORM.widgets.date
-                    value_input = widget_.widget(field, field.default, _id=_id, 
-                                                 _class=widget_._class + ' form-control', 
+                    value_input = widget_.widget(field, field.default, _id=_id,
+                                                 _class=widget_._class + ' form-control',
                                                  **iso_format)
                 elif field_type == 'datetime':
                     iso_format = {'_data-w2p_datetime_format': '%Y-%m-%d %H:%M:%S'}
                     widget_ = SQLFORM.widgets.datetime
-                    value_input = widget_.widget(field, field.default, _id=_id, 
-                                                 _class=widget_._class + ' form-control', 
+                    value_input = widget_.widget(field, field.default, _id=_id,
+                                                 _class=widget_._class + ' form-control',
                                                  **iso_format)
                 elif hasattr(field.requires, 'options'):
                     value_input = SELECT(
@@ -1928,7 +1928,7 @@ def search_menu(fields,
                       field_type.startswith('list:reference ')):
                     widget_ = SQLFORM.widgets.integer
                     value_input = widget_.widget(
-                        field, field.default, _id=_id, 
+                        field, field.default, _id=_id,
                         _class=widget_._class + ' form-control')
                 else:
                     value_input = INPUT(
@@ -2044,7 +2044,7 @@ def grid(query,
              use_cursor=False):
 
         formstyle = formstyle or current.response.formstyle
-        if isinstance(query, Set): 
+        if isinstance(query, Set):
             query = query.query
 
         # jQuery UI ThemeRoller classes (empty if ui is disabled)
@@ -3043,7 +3043,7 @@ def format(table, row):
             query = query & constraints[table._tablename]
         if isinstance(links, dict):
             links = links.get(table._tablename, [])
-        for key in ('fields', 'field_id', 'left', 'headers', 'orderby', 'groupby', 'searchable', 
+        for key in ('fields', 'field_id', 'left', 'headers', 'orderby', 'groupby', 'searchable',
                     'sortable', 'paginate', 'deletable', 'editable', 'details', 'selectable',
                     'create', 'csv', 'links', 'links_in_grid', 'upload', 'maxtextlengths',
                     'maxtextlength', 'onvalidation', 'onfailure', 'oncreate', 'onupdate',


Test patch: