pep8ized a taddle bit sqlhtml.py
This commit is contained in:
1 parent
5da5d510a0
commit
46c4b1af27
1 file changed
+29
-28
+29
-28
@@ -173,7 +173,7 @@ class StringWidget(FormWidget):
|
|||||||
|
|
||||||
default = dict(
|
default = dict(
|
||||||
_type='text',
|
_type='text',
|
||||||
value=(not value is None and str(value)) or '',
|
value=(value is not None and str(value)) or '',
|
||||||
)
|
)
|
||||||
attr = cls._attributes(field, default, **attributes)
|
attr = cls._attributes(field, default, **attributes)
|
||||||
|
|
||||||
@@ -685,7 +685,7 @@ class AutocompleteWidget(object):
|
|||||||
def __call__(self, field, value, **attributes):
|
def __call__(self, field, value, **attributes):
|
||||||
default = dict(
|
default = dict(
|
||||||
_type='text',
|
_type='text',
|
||||||
value=(not value is None and str(value)) or '',
|
value=(value is not None and str(value)) or '',
|
||||||
)
|
)
|
||||||
attr = StringWidget._attributes(field, default, **attributes)
|
attr = StringWidget._attributes(field, default, **attributes)
|
||||||
div_id = self.keyword + '_div'
|
div_id = self.keyword + '_div'
|
||||||
@@ -1016,7 +1016,7 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
def assert_status(self, status, request_vars):
|
def assert_status(self, status, request_vars):
|
||||||
if not status and self.record and self.errors:
|
if not status and self.record and self.errors:
|
||||||
### if there are errors in update mode
|
# if there are errors in update mode
|
||||||
# and some errors refers to an already uploaded file
|
# and some errors refers to an already uploaded file
|
||||||
# delete error if
|
# delete error if
|
||||||
# - user not trying to upload a new file
|
# - user not trying to upload a new file
|
||||||
@@ -1144,7 +1144,7 @@ class SQLFORM(FORM):
|
|||||||
comment = ''
|
comment = ''
|
||||||
self.custom.comment[fieldname] = comment
|
self.custom.comment[fieldname] = comment
|
||||||
|
|
||||||
if not labels is None and fieldname in labels:
|
if labels is not None and fieldname in labels:
|
||||||
label = labels[fieldname]
|
label = labels[fieldname]
|
||||||
else:
|
else:
|
||||||
label = field.label
|
label = field.label
|
||||||
@@ -1251,7 +1251,7 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
xfields.append((row_id, label, inp, comment))
|
xfields.append((row_id, label, inp, comment))
|
||||||
self.custom.dspval[fieldname] = dspval if (dspval is not None) else nbsp
|
self.custom.dspval[fieldname] = dspval if (dspval is not None) else nbsp
|
||||||
self.custom.inpval[fieldname] = inpval if not inpval is None else ''
|
self.custom.inpval[fieldname] = inpval if inpval is not None else ''
|
||||||
self.custom.widget[fieldname] = inp
|
self.custom.widget[fieldname] = inp
|
||||||
|
|
||||||
# if a record is provided and found, as is linkto
|
# if a record is provided and found, as is linkto
|
||||||
@@ -1266,7 +1266,7 @@ class SQLFORM(FORM):
|
|||||||
query = urllib.quote(
|
query = urllib.quote(
|
||||||
'%s.%s==%s' % (db, rfld, record[self.id_field_name]))
|
'%s.%s==%s' % (db, rfld, record[self.id_field_name]))
|
||||||
lname = olname = '%s.%s' % (rfld.tablename, rfld.name)
|
lname = olname = '%s.%s' % (rfld.tablename, rfld.name)
|
||||||
if ofields and not olname in ofields:
|
if ofields and olname not in ofields:
|
||||||
continue
|
continue
|
||||||
if labels and lname in labels:
|
if labels and lname in labels:
|
||||||
lname = labels[lname]
|
lname = labels[lname]
|
||||||
@@ -1331,7 +1331,6 @@ class SQLFORM(FORM):
|
|||||||
table = self.createform(xfields)
|
table = self.createform(xfields)
|
||||||
self.components = [table]
|
self.components = [table]
|
||||||
|
|
||||||
|
|
||||||
def createform(self, xfields):
|
def createform(self, xfields):
|
||||||
formstyle = self.formstyle
|
formstyle = self.formstyle
|
||||||
if isinstance(formstyle, basestring):
|
if isinstance(formstyle, basestring):
|
||||||
@@ -1487,7 +1486,7 @@ class SQLFORM(FORM):
|
|||||||
field = (self.table[fieldname]
|
field = (self.table[fieldname]
|
||||||
if fieldname in self.table.fields
|
if fieldname in self.table.fields
|
||||||
else self.extra_fields[fieldname])
|
else self.extra_fields[fieldname])
|
||||||
### this is a workaround! widgets should always have default not None!
|
# this is a workaround! widgets should always have default not None!
|
||||||
if not field.widget and field.type.startswith('list:') and \
|
if not field.widget and field.type.startswith('list:') and \
|
||||||
not OptionsWidget.has_options(field):
|
not OptionsWidget.has_options(field):
|
||||||
field.widget = self.widgets.list.widget
|
field.widget = self.widgets.list.widget
|
||||||
@@ -1533,12 +1532,12 @@ class SQLFORM(FORM):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
for fieldname in self.fields:
|
for fieldname in self.fields:
|
||||||
if not fieldname in self.table.fields:
|
if fieldname not in self.table.fields:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not self.ignore_rw and not self.table[fieldname].writable:
|
if not self.ignore_rw and not self.table[fieldname].writable:
|
||||||
### this happens because FORM has no knowledge of writable
|
# this happens because FORM has no knowledge of writable
|
||||||
### and thinks that a missing boolean field is a None
|
# and thinks that a missing boolean field is a None
|
||||||
if self.table[fieldname].type == 'boolean' and \
|
if self.table[fieldname].type == 'boolean' and \
|
||||||
self.vars.get(fieldname, True) is None:
|
self.vars.get(fieldname, True) is None:
|
||||||
del self.vars[fieldname]
|
del self.vars[fieldname]
|
||||||
@@ -1583,7 +1582,7 @@ class SQLFORM(FORM):
|
|||||||
elif hasattr(f, 'file'):
|
elif hasattr(f, 'file'):
|
||||||
(source_file, original_filename) = (f.file, f.filename)
|
(source_file, original_filename) = (f.file, f.filename)
|
||||||
elif isinstance(f, (str, unicode)):
|
elif isinstance(f, (str, unicode)):
|
||||||
### do not know why this happens, it should not
|
# do not know why this happens, it should not
|
||||||
(source_file, original_filename) = \
|
(source_file, original_filename) = \
|
||||||
(cStringIO.StringIO(f), 'file.txt')
|
(cStringIO.StringIO(f), 'file.txt')
|
||||||
else:
|
else:
|
||||||
@@ -1615,7 +1614,7 @@ class SQLFORM(FORM):
|
|||||||
fields[fieldname] = [safe_int(
|
fields[fieldname] = [safe_int(
|
||||||
x) for x in (value and [value] or [])]
|
x) for x in (value and [value] or [])]
|
||||||
elif field.type == 'integer':
|
elif field.type == 'integer':
|
||||||
if not value is None:
|
if value is not None:
|
||||||
fields[fieldname] = safe_int(value)
|
fields[fieldname] = safe_int(value)
|
||||||
elif field.type.startswith('reference'):
|
elif field.type.startswith('reference'):
|
||||||
## Avoid "constraint violation" exception when you have a
|
## Avoid "constraint violation" exception when you have a
|
||||||
@@ -1633,12 +1632,12 @@ class SQLFORM(FORM):
|
|||||||
else:
|
else:
|
||||||
fields[fieldname] = safe_int(value)
|
fields[fieldname] = safe_int(value)
|
||||||
elif field.type == 'double':
|
elif field.type == 'double':
|
||||||
if not value is None:
|
if value is not None:
|
||||||
fields[fieldname] = safe_float(value)
|
fields[fieldname] = safe_float(value)
|
||||||
|
|
||||||
for fieldname in self.vars:
|
for fieldname in self.vars:
|
||||||
if fieldname != 'id' and fieldname in self.table.fields\
|
if fieldname != 'id' and fieldname in self.table.fields\
|
||||||
and not fieldname in fields and not fieldname\
|
and fieldname not in fields and not fieldname\
|
||||||
in request_vars:
|
in request_vars:
|
||||||
fields[fieldname] = self.vars[fieldname]
|
fields[fieldname] = self.vars[fieldname]
|
||||||
|
|
||||||
@@ -1650,7 +1649,7 @@ class SQLFORM(FORM):
|
|||||||
# this should never happen but seems to happen to some
|
# this should never happen but seems to happen to some
|
||||||
del fields['delete_this_record']
|
del fields['delete_this_record']
|
||||||
for field in self.table:
|
for field in self.table:
|
||||||
if not field.name in fields and field.writable is False \
|
if field.name not in fields and field.writable is False \
|
||||||
and field.update is None and field.compute is None:
|
and field.update is None and field.compute is None:
|
||||||
if record_id and self.record:
|
if record_id and self.record:
|
||||||
fields[field.name] = self.record[field.name]
|
fields[field.name] = self.record[field.name]
|
||||||
@@ -1745,7 +1744,7 @@ class SQLFORM(FORM):
|
|||||||
keywords = keywords[0]
|
keywords = keywords[0]
|
||||||
request.vars.keywords = keywords
|
request.vars.keywords = keywords
|
||||||
key = keywords.strip()
|
key = keywords.strip()
|
||||||
if key and not ' ' in key and not '"' in key and not "'" in key:
|
if key and ' ' not in key and not '"' in key and not "'" in key:
|
||||||
SEARCHABLE_TYPES = ('string', 'text', 'list:string')
|
SEARCHABLE_TYPES = ('string', 'text', 'list:string')
|
||||||
parts = [field.contains(
|
parts = [field.contains(
|
||||||
key) for field in fields if field.type in SEARCHABLE_TYPES]
|
key) for field in fields if field.type in SEARCHABLE_TYPES]
|
||||||
@@ -1807,9 +1806,12 @@ class SQLFORM(FORM):
|
|||||||
ftype = field.type.type.split(' ')[0]
|
ftype = field.type.type.split(' ')[0]
|
||||||
else:
|
else:
|
||||||
ftype = field.type.split(' ')[0]
|
ftype = field.type.split(' ')[0]
|
||||||
if ftype.startswith('decimal'): ftype = 'double'
|
if ftype.startswith('decimal'):
|
||||||
elif ftype == 'bigint': ftype = 'integer'
|
ftype = 'double'
|
||||||
elif ftype.startswith('big-'): ftype = ftype[4:]
|
elif ftype == 'bigint':
|
||||||
|
ftype = 'integer'
|
||||||
|
elif ftype.startswith('big-'):
|
||||||
|
ftype = ftype[4:]
|
||||||
# end
|
# end
|
||||||
options = search_options.get(ftype, None)
|
options = search_options.get(ftype, None)
|
||||||
if options:
|
if options:
|
||||||
@@ -2289,7 +2291,7 @@ class SQLFORM(FORM):
|
|||||||
tsv_with_hidden_cols=
|
tsv_with_hidden_cols=
|
||||||
(ExporterTSV, 'TSV (Spreadsheets, hidden cols)', T('Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow')),
|
(ExporterTSV, 'TSV (Spreadsheets, hidden cols)', T('Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow')),
|
||||||
tsv=(ExporterTSV, 'TSV (Spreadsheets)', T('Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.')))
|
tsv=(ExporterTSV, 'TSV (Spreadsheets)', T('Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.')))
|
||||||
if not exportclasses is None:
|
if exportclasses is not None:
|
||||||
"""
|
"""
|
||||||
remember: allow to set exportclasses=dict(csv=False, csv_with_hidden_cols=False) to disable the csv format
|
remember: allow to set exportclasses=dict(csv=False, csv_with_hidden_cols=False) to disable the csv format
|
||||||
"""
|
"""
|
||||||
@@ -2394,8 +2396,8 @@ class SQLFORM(FORM):
|
|||||||
spanel_id = '%s_query_fields' % prefix
|
spanel_id = '%s_query_fields' % prefix
|
||||||
sfields_id = '%s_query_panel' % prefix
|
sfields_id = '%s_query_panel' % prefix
|
||||||
skeywords_id = '%s_keywords' % prefix
|
skeywords_id = '%s_keywords' % prefix
|
||||||
## hidden fields to presever keywords in url after the submit
|
# hidden fields to presever keywords in url after the submit
|
||||||
hidden_fields = [INPUT(_type='hidden', _value=value, _name=key) for key, value in request.get_vars.items() if key not in ['keywords', 'page']]
|
hidden_fields = [INPUT(_type='hidden', _value=v, _name=k) for k, v in request.get_vars.items() if k not in ['keywords', 'page']]
|
||||||
search_widget = lambda sfield, url: CAT(FORM(
|
search_widget = lambda sfield, url: CAT(FORM(
|
||||||
INPUT(_name='keywords', _value=keywords,
|
INPUT(_name='keywords', _value=keywords,
|
||||||
_id=skeywords_id, _class='form-control',
|
_id=skeywords_id, _class='form-control',
|
||||||
@@ -2740,7 +2742,7 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
if htmltable.process(formname=formname).accepted:
|
if htmltable.process(formname=formname).accepted:
|
||||||
htmltable.vars.records = htmltable.vars.records or []
|
htmltable.vars.records = htmltable.vars.records or []
|
||||||
htmltable.vars.records = htmltable.vars.records if type(htmltable.vars.records) == list else [htmltable.vars.records]
|
htmltable.vars.records = htmltable.vars.records if isinstance(htmltable.vars.records, list) else [htmltable.vars.records]
|
||||||
records = [int(r) for r in htmltable.vars.records]
|
records = [int(r) for r in htmltable.vars.records]
|
||||||
if not callable(selectable):
|
if not callable(selectable):
|
||||||
for i, submit_info in enumerate(selectable):
|
for i, submit_info in enumerate(selectable):
|
||||||
@@ -2932,7 +2934,6 @@ class SQLFORM(FORM):
|
|||||||
if isinstance(linked_tables, dict):
|
if isinstance(linked_tables, dict):
|
||||||
linked_tables = linked_tables.get(table._tablename, [])
|
linked_tables = linked_tables.get(table._tablename, [])
|
||||||
|
|
||||||
opts = [OPTION(T('References')+':', _value='')]
|
|
||||||
linked = []
|
linked = []
|
||||||
if linked_tables:
|
if linked_tables:
|
||||||
for item in linked_tables:
|
for item in linked_tables:
|
||||||
@@ -3122,7 +3123,7 @@ class SQLTABLE(TABLE):
|
|||||||
else:
|
else:
|
||||||
_class = 'w2p_odd odd'
|
_class = 'w2p_odd odd'
|
||||||
|
|
||||||
if not selectid is None: # new implement
|
if selectid is not None: # new implement
|
||||||
if record.get('id') == selectid:
|
if record.get('id') == selectid:
|
||||||
_class += ' rowselected'
|
_class += ' rowselected'
|
||||||
|
|
||||||
@@ -3204,7 +3205,7 @@ class SQLTABLE(TABLE):
|
|||||||
if isinstance(headers[colname], dict):
|
if isinstance(headers[colname], dict):
|
||||||
if isinstance(headers[colname]['truncate'], int):
|
if isinstance(headers[colname]['truncate'], int):
|
||||||
truncate_by = headers[colname]['truncate']
|
truncate_by = headers[colname]['truncate']
|
||||||
if not truncate_by is None:
|
if truncate_by is not None:
|
||||||
r = truncate_string(r, truncate_by)
|
r = truncate_string(r, truncate_by)
|
||||||
attrcol = dict() # new implement dict
|
attrcol = dict() # new implement dict
|
||||||
if headers != {}:
|
if headers != {}:
|
||||||
@@ -3302,7 +3303,7 @@ class ExportClass(object):
|
|||||||
value = record[t][f]
|
value = record[t][f]
|
||||||
else:
|
else:
|
||||||
value = record[f]
|
value = record[f]
|
||||||
if field.type == 'blob' and not value is None:
|
if field.type == 'blob' and value is not None:
|
||||||
value = ''
|
value = ''
|
||||||
elif field.represent:
|
elif field.represent:
|
||||||
value = field.represent(value, record)
|
value = field.represent(value, record)
|
||||||
|
|||||||
Reference in new issue
Block a user