pep8ized a taddle bit sqlhtml.py
This commit is contained in:
+68
-67
@@ -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)
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ class RadioWidget(OptionsWidget):
|
|||||||
if mods:
|
if mods:
|
||||||
rows += 1
|
rows += 1
|
||||||
|
|
||||||
#widget style
|
# widget style
|
||||||
wrappers = dict(
|
wrappers = dict(
|
||||||
table=(TABLE, TR, TD),
|
table=(TABLE, TR, TD),
|
||||||
ul=(DIV, UL, LI),
|
ul=(DIV, UL, LI),
|
||||||
@@ -440,7 +440,7 @@ class CheckboxesWidget(OptionsWidget):
|
|||||||
if mods:
|
if mods:
|
||||||
rows += 1
|
rows += 1
|
||||||
|
|
||||||
#widget style
|
# widget style
|
||||||
wrappers = dict(
|
wrappers = dict(
|
||||||
table=(TABLE, TR, TD),
|
table=(TABLE, TR, TD),
|
||||||
ul=(DIV, UL, LI),
|
ul=(DIV, UL, LI),
|
||||||
@@ -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'
|
||||||
@@ -859,7 +859,7 @@ def formstyle_bootstrap3_stacked(form, fields):
|
|||||||
controls.add_class('form-control')
|
controls.add_class('form-control')
|
||||||
|
|
||||||
elif isinstance(controls, SPAN):
|
elif isinstance(controls, SPAN):
|
||||||
_controls = P(controls.components)
|
_controls = P(controls.components)
|
||||||
|
|
||||||
if isinstance(label, LABEL):
|
if isinstance(label, LABEL):
|
||||||
label['_class'] = 'control-label'
|
label['_class'] = 'control-label'
|
||||||
@@ -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]
|
||||||
@@ -1282,7 +1282,7 @@ class SQLFORM(FORM):
|
|||||||
# when deletable, add delete? checkbox
|
# when deletable, add delete? checkbox
|
||||||
self.custom.delete = self.custom.deletable = ''
|
self.custom.delete = self.custom.deletable = ''
|
||||||
if record and deletable:
|
if record and deletable:
|
||||||
#add secondary css class for cascade delete warning
|
# add secondary css class for cascade delete warning
|
||||||
css = 'delete'
|
css = 'delete'
|
||||||
for f in self.table.fields:
|
for f in self.table.fields:
|
||||||
on_del = self.table[f].ondelete
|
on_del = self.table[f].ondelete
|
||||||
@@ -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,12 +1582,12 @@ 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:
|
||||||
# this should never happen, why does it happen?
|
# this should never happen, why does it happen?
|
||||||
#print 'f=',repr(f)
|
# print 'f=',repr(f)
|
||||||
continue
|
continue
|
||||||
newfilename = field.store(source_file, original_filename,
|
newfilename = field.store(source_file, original_filename,
|
||||||
field.uploadfolder)
|
field.uploadfolder)
|
||||||
@@ -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]
|
||||||
@@ -1775,11 +1774,11 @@ class SQLFORM(FORM):
|
|||||||
prefix='w2p'
|
prefix='w2p'
|
||||||
):
|
):
|
||||||
T = current.T
|
T = current.T
|
||||||
panel_id='%s_query_panel' % prefix
|
panel_id = '%s_query_panel' % prefix
|
||||||
fields_id='%s_query_fields' % prefix
|
fields_id = '%s_query_fields' % prefix
|
||||||
keywords_id='%s_keywords' % prefix
|
keywords_id = '%s_keywords' % prefix
|
||||||
field_id='%s_field' % prefix
|
field_id = '%s_field' % prefix
|
||||||
value_id='%s_value' % prefix
|
value_id = '%s_value' % prefix
|
||||||
search_options = search_options or {
|
search_options = search_options or {
|
||||||
'string': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
'string': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
||||||
'text': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
'text': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
||||||
@@ -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:
|
||||||
@@ -1872,7 +1874,7 @@ class SQLFORM(FORM):
|
|||||||
criteria.insert(0, SELECT(
|
criteria.insert(0, SELECT(
|
||||||
_id=fields_id,
|
_id=fields_id,
|
||||||
_onchange="jQuery('.w2p_query_row').hide();jQuery('#%s_'+jQuery('#%s').val().replace('.','-')).show();" % (field_id, fields_id),
|
_onchange="jQuery('.w2p_query_row').hide();jQuery('#%s_'+jQuery('#%s').val().replace('.','-')).show();" % (field_id, fields_id),
|
||||||
_style='float:left',_class='form-control',
|
_style='float:left', _class='form-control',
|
||||||
*selectfields))
|
*selectfields))
|
||||||
|
|
||||||
fadd = SCRIPT("""
|
fadd = SCRIPT("""
|
||||||
@@ -2034,7 +2036,7 @@ class SQLFORM(FORM):
|
|||||||
elif left:
|
elif left:
|
||||||
c = 'count(*)'
|
c = 'count(*)'
|
||||||
nrows = dbset.select(c, left=left, cacheable=True, cache=cache_count).first()[c]
|
nrows = dbset.select(c, left=left, cacheable=True, cache=cache_count).first()[c]
|
||||||
elif dbset._db._adapter.dbengine=='google:datastore':
|
elif dbset._db._adapter.dbengine == 'google:datastore':
|
||||||
#if we don't set a limit, this can timeout for a large table
|
#if we don't set a limit, this can timeout for a large table
|
||||||
nrows = dbset.db._adapter.count(dbset.query, limit=1000)
|
nrows = dbset.db._adapter.count(dbset.query, limit=1000)
|
||||||
else:
|
else:
|
||||||
@@ -2076,7 +2078,7 @@ class SQLFORM(FORM):
|
|||||||
'/'.join(str(a) for a in args) == '/'.join(request.args) or
|
'/'.join(str(a) for a in args) == '/'.join(request.args) or
|
||||||
URL.verify(request, user_signature=user_signature,
|
URL.verify(request, user_signature=user_signature,
|
||||||
hash_vars=False) or
|
hash_vars=False) or
|
||||||
(request.args(len(args))=='view' and not logged)):
|
(request.args(len(args)) == 'view' and not logged)):
|
||||||
session.flash = T('not authorized')
|
session.flash = T('not authorized')
|
||||||
redirect(referrer)
|
redirect(referrer)
|
||||||
|
|
||||||
@@ -2112,7 +2114,7 @@ class SQLFORM(FORM):
|
|||||||
tablenames += db._adapter.tables(join)
|
tablenames += db._adapter.tables(join)
|
||||||
tables = [db[tablename] for tablename in tablenames]
|
tables = [db[tablename] for tablename in tablenames]
|
||||||
if fields:
|
if fields:
|
||||||
#add missing tablename to virtual fields
|
# add missing tablename to virtual fields
|
||||||
for table in tables:
|
for table in tables:
|
||||||
for k, f in table.iteritems():
|
for k, f in table.iteritems():
|
||||||
if isinstance(f, Field.Virtual):
|
if isinstance(f, Field.Virtual):
|
||||||
@@ -2136,10 +2138,10 @@ class SQLFORM(FORM):
|
|||||||
if groupby is None:
|
if groupby is None:
|
||||||
field_id = tables[0]._id
|
field_id = tables[0]._id
|
||||||
elif groupby and isinstance(groupby, Field):
|
elif groupby and isinstance(groupby, Field):
|
||||||
#take the field passed as groupby
|
# take the field passed as groupby
|
||||||
field_id = groupby
|
field_id = groupby
|
||||||
elif groupby and isinstance(groupby, Expression):
|
elif groupby and isinstance(groupby, Expression):
|
||||||
#take the first groupby field
|
# take the first groupby field
|
||||||
field_id = groupby.first
|
field_id = groupby.first
|
||||||
while not(isinstance(field_id, Field)):
|
while not(isinstance(field_id, Field)):
|
||||||
# Navigate to the first Field of the expression
|
# Navigate to the first Field of the expression
|
||||||
@@ -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
|
||||||
"""
|
"""
|
||||||
@@ -2314,7 +2316,7 @@ class SQLFORM(FORM):
|
|||||||
# expcolumns = [] start with the visible columns, which
|
# expcolumns = [] start with the visible columns, which
|
||||||
# includes visible virtual fields
|
# includes visible virtual fields
|
||||||
selectable_columns = []
|
selectable_columns = []
|
||||||
#like expcolumns but excluding virtual
|
# like expcolumns but excluding virtual
|
||||||
for table in tables:
|
for table in tables:
|
||||||
for field in table:
|
for field in table:
|
||||||
if field.readable and field.tablename in tablenames:
|
if field.readable and field.tablename in tablenames:
|
||||||
@@ -2322,20 +2324,20 @@ class SQLFORM(FORM):
|
|||||||
expcolumns.append(str(field))
|
expcolumns.append(str(field))
|
||||||
if not(isinstance(field, Field.Virtual)):
|
if not(isinstance(field, Field.Virtual)):
|
||||||
selectable_columns.append(str(field))
|
selectable_columns.append(str(field))
|
||||||
#look for virtual fields not displayed (and virtual method
|
# look for virtual fields not displayed (and virtual method
|
||||||
#fields to be added here?)
|
# fields to be added here?)
|
||||||
for (field_name, field) in table.iteritems():
|
for (field_name, field) in table.iteritems():
|
||||||
if isinstance(field, Field.Virtual) and not str(field) in expcolumns:
|
if isinstance(field, Field.Virtual) and not str(field) in expcolumns:
|
||||||
expcolumns.append(str(field))
|
expcolumns.append(str(field))
|
||||||
|
|
||||||
if export_type in exportManager and exportManager[export_type]:
|
if export_type in exportManager and exportManager[export_type]:
|
||||||
if keywords:
|
if keywords:
|
||||||
try:
|
try:
|
||||||
#the query should be constructed using searchable
|
# the query should be constructed using searchable
|
||||||
#fields but not virtual fields
|
# fields but not virtual fields
|
||||||
sfields = reduce(lambda a, b: a + b,
|
sfields = reduce(lambda a, b: a + b,
|
||||||
[[f for f in t if f.readable and not isinstance(f, Field.Virtual)] for t in tables])
|
[[f for f in t if f.readable and not isinstance(f, Field.Virtual)] for t in tables])
|
||||||
#use custom_query using searchable
|
# use custom_query using searchable
|
||||||
if callable(searchable):
|
if callable(searchable):
|
||||||
dbset = dbset(searchable(sfields, keywords))
|
dbset = dbset(searchable(sfields, keywords))
|
||||||
else:
|
else:
|
||||||
@@ -2394,11 +2396,11 @@ 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',
|
||||||
_onfocus="jQuery('#%s').change();jQuery('#%s').slideDown();" % (spanel_id, sfields_id) if advanced_search else ''
|
_onfocus="jQuery('#%s').change();jQuery('#%s').slideDown();" % (spanel_id, sfields_id) if advanced_search else ''
|
||||||
),
|
),
|
||||||
INPUT(_type='submit', _value=T('Search'), _class="btn btn-default"),
|
INPUT(_type='submit', _value=T('Search'), _class="btn btn-default"),
|
||||||
@@ -2446,7 +2448,7 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
ordermatch, marker = orderby, ''
|
ordermatch, marker = orderby, ''
|
||||||
if orderby:
|
if orderby:
|
||||||
#if orderby is a single column, remember to put the marker
|
# if orderby is a single column, remember to put the marker
|
||||||
if isinstance(orderby, Expression):
|
if isinstance(orderby, Expression):
|
||||||
if orderby.first and not orderby.second:
|
if orderby.first and not orderby.second:
|
||||||
ordermatch, marker = orderby.first, '~'
|
ordermatch, marker = orderby.first, '~'
|
||||||
@@ -2503,7 +2505,7 @@ class SQLFORM(FORM):
|
|||||||
head = TR(*headcols, **dict(_class=ui.get('header')))
|
head = TR(*headcols, **dict(_class=ui.get('header')))
|
||||||
|
|
||||||
cursor = True
|
cursor = True
|
||||||
#figure out what page we are one to setup the limitby
|
# figure out what page we are one to setup the limitby
|
||||||
if paginate and dbset._db._adapter.dbengine == 'google:datastore':
|
if paginate and dbset._db._adapter.dbengine == 'google:datastore':
|
||||||
cursor = request.vars.cursor or True
|
cursor = request.vars.cursor or True
|
||||||
limitby = (0, paginate)
|
limitby = (0, paginate)
|
||||||
@@ -2552,14 +2554,14 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
paginator = UL()
|
paginator = UL()
|
||||||
if paginate and dbset._db._adapter.dbengine == 'google:datastore':
|
if paginate and dbset._db._adapter.dbengine == 'google:datastore':
|
||||||
#this means we may have a large table with an unknown number of rows.
|
# this means we may have a large table with an unknown number of rows.
|
||||||
try:
|
try:
|
||||||
page = int(request.vars.page or 1)-1
|
page = int(request.vars.page or 1) - 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
page = 0
|
page = 0
|
||||||
paginator.append(LI('page %s' % (page+1)))
|
paginator.append(LI('page %s' % (page + 1)))
|
||||||
if next_cursor:
|
if next_cursor:
|
||||||
d = dict(page=page+2, cursor=next_cursor)
|
d = dict(page=page + 2, cursor=next_cursor)
|
||||||
if order:
|
if order:
|
||||||
d['order'] = order
|
d['order'] = order
|
||||||
# see issue 1980, also at the top of the definition
|
# see issue 1980, also at the top of the definition
|
||||||
@@ -2718,8 +2720,8 @@ class SQLFORM(FORM):
|
|||||||
_style='width:100%;overflow-x:auto;-ms-overflow-x:scroll')
|
_style='width:100%;overflow-x:auto;-ms-overflow-x:scroll')
|
||||||
if selectable:
|
if selectable:
|
||||||
if not callable(selectable):
|
if not callable(selectable):
|
||||||
#now expect that selectable and related parameters are
|
# now expect that selectable and related parameters are
|
||||||
#iterator (list, tuple, etc)
|
# iterator (list, tuple, etc)
|
||||||
inputs = []
|
inputs = []
|
||||||
for i, submit_info in enumerate(selectable):
|
for i, submit_info in enumerate(selectable):
|
||||||
submit_text = submit_info[0]
|
submit_text = submit_info[0]
|
||||||
@@ -2733,14 +2735,14 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
if formstyle == 'bootstrap':
|
if formstyle == 'bootstrap':
|
||||||
# add space between buttons
|
# add space between buttons
|
||||||
#inputs = sum([[inp, ' '] for inp in inputs], [])[:-1]
|
# inputs = sum([[inp, ' '] for inp in inputs], [])[:-1]
|
||||||
htmltable = FORM(htmltable, DIV(_class='form-actions', *inputs))
|
htmltable = FORM(htmltable, DIV(_class='form-actions', *inputs))
|
||||||
else:
|
else:
|
||||||
htmltable = FORM(htmltable, *inputs)
|
htmltable = FORM(htmltable, *inputs)
|
||||||
|
|
||||||
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):
|
||||||
@@ -2761,7 +2763,7 @@ class SQLFORM(FORM):
|
|||||||
continue
|
continue
|
||||||
if hasattr(v, "__getitem__"):
|
if hasattr(v, "__getitem__"):
|
||||||
label = v[1]
|
label = v[1]
|
||||||
title = v[2] if len(v)>2 else label
|
title = v[2] if len(v) > 2 else label
|
||||||
else:
|
else:
|
||||||
label = title = k
|
label = title = k
|
||||||
link = url2(vars=dict(
|
link = url2(vars=dict(
|
||||||
@@ -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:
|
||||||
@@ -3064,12 +3065,12 @@ class SQLTABLE(TABLE):
|
|||||||
if headers == 'fieldname:capitalize':
|
if headers == 'fieldname:capitalize':
|
||||||
headers = {}
|
headers = {}
|
||||||
for c in columns:
|
for c in columns:
|
||||||
tfmatch=REGEX_TABLE_DOT_FIELD.match(c)
|
tfmatch = REGEX_TABLE_DOT_FIELD.match(c)
|
||||||
if tfmatch:
|
if tfmatch:
|
||||||
(t, f) = REGEX_TABLE_DOT_FIELD.match(c).groups()
|
(t, f) = REGEX_TABLE_DOT_FIELD.match(c).groups()
|
||||||
headers[t + '.' + f] = f.replace('_', ' ').title()
|
headers[t + '.' + f] = f.replace('_', ' ').title()
|
||||||
else:
|
else:
|
||||||
headers[c]=c
|
headers[c] = c
|
||||||
elif headers == 'labels':
|
elif headers == 'labels':
|
||||||
headers = {}
|
headers = {}
|
||||||
for c in columns:
|
for c in columns:
|
||||||
@@ -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)
|
||||||
@@ -3353,7 +3354,7 @@ class ExporterTSV(ExportClass):
|
|||||||
|
|
||||||
|
|
||||||
class ExporterCSV(ExportClass):
|
class ExporterCSV(ExportClass):
|
||||||
#CSV, represent == True
|
# CSV, represent == True
|
||||||
label = 'CSV'
|
label = 'CSV'
|
||||||
file_ext = "csv"
|
file_ext = "csv"
|
||||||
content_type = "text/csv"
|
content_type = "text/csv"
|
||||||
@@ -3361,7 +3362,7 @@ class ExporterCSV(ExportClass):
|
|||||||
def __init__(self, rows):
|
def __init__(self, rows):
|
||||||
ExportClass.__init__(self, rows)
|
ExportClass.__init__(self, rows)
|
||||||
|
|
||||||
def export(self): #export CSV with rows.represent
|
def export(self): # export CSV with rows.represent
|
||||||
if self.rows:
|
if self.rows:
|
||||||
s = cStringIO.StringIO()
|
s = cStringIO.StringIO()
|
||||||
self.rows.export_to_csv_file(s, represent=True)
|
self.rows.export_to_csv_file(s, represent=True)
|
||||||
@@ -3371,7 +3372,7 @@ class ExporterCSV(ExportClass):
|
|||||||
|
|
||||||
|
|
||||||
class ExporterCSV_hidden(ExportClass):
|
class ExporterCSV_hidden(ExportClass):
|
||||||
#pure csv, no represent.
|
# pure csv, no represent.
|
||||||
label = 'CSV'
|
label = 'CSV'
|
||||||
file_ext = "csv"
|
file_ext = "csv"
|
||||||
content_type = "text/csv"
|
content_type = "text/csv"
|
||||||
|
|||||||
Reference in New Issue
Block a user