Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
href = linkto(r, 'table', tablename)
except TypeError:
href = '%s/%s/%s' % (linkto, tablename, r_old)
r = A(r, _href=href)
elif isinstance(field.type, str) and field.type.startswith('reference'):
if linkto:
ref = field.type[10:]
try:
href = linkto(r, 'reference', ref)
except TypeError:
href = '%s/%s/%s' % (linkto, ref, r_old)
if ref.find('.') >= 0:
tref,fref = ref.split('.')
if hasattr(sqlrows.db[tref],'_primarykey'):
href = '%s/%s?%s' % (linkto, tref, urllib.urlencode({fref:r}))
r = A(represent(field,r,record), _href=str(href))
elif field.represent:
r = represent(field,r,record)
elif linkto and hasattr(field._table,'_primarykey') and fieldname in field._table._primarykey:
# have to test this with multi-key tables
key = urllib.urlencode(dict( [ \
((tablename in record \
and isinstance(record, Row) \
and isinstance(record[tablename], Row)) and
(k, record[tablename][k])) or (k, record[k]) \
for k in field._table._primarykey ] ))
r = A(r, _href='%s/%s?%s' % (linkto, tablename, key))
elif isinstance(field.type, str) and field.type.startswith('list:'):
r = represent(field,r or [],record)
elif field.represent:
r = represent(field,r,record)
elif field.type == 'blob' and r:
and isinstance(record,Row) \
and isinstance(record[tablename],Row):
r = record[tablename][fieldname]
elif fieldname in record:
r = record[fieldname]
else:
raise SyntaxError, 'something wrong in Rows object'
r_old = r
if not field:
pass
elif linkto and field.type == 'id':
try:
href = linkto(r, 'table', tablename)
except TypeError:
href = '%s/%s/%s' % (linkto, tablename, r_old)
r = A(r, _href=href)
elif field.type.startswith('reference'):
if linkto:
ref = field.type[10:]
try:
href = linkto(r, 'reference', ref)
except TypeError:
href = '%s/%s/%s' % (linkto, ref, r_old)
if ref.find('.') >= 0:
tref,fref = ref.split('.')
if hasattr(sqlrows.db[tref],'_primarykey'):
href = '%s/%s?%s' % (linkto, tref, urllib.urlencode({fref:r}))
r = A(represent(field,r,record), _href=str(href))
elif field.represent:
r = represent(field,r,record)
elif linkto and hasattr(field._table,'_primarykey') and fieldname in field._table._primarykey:
# have to test this with multi-key tables
key = urllib.urlencode(dict( [ \
((tablename in record \
and isinstance(record, Row) \
and isinstance(record[tablename], Row)) and
(k, record[tablename][k])) or (k, record[k]) \
for k in field._table._primarykey ] ))
r = A(r, _href='%s/%s?%s' % (linkto, tablename, key))
elif field.type.startswith('list:'):
r = represent(field,r or [],record)
elif field.represent:
r = represent(field,r,record)
elif field.type == 'blob' and r:
r = 'DATA'
elif field.type == 'upload':
if upload and r:
r = A('file', _href='%s/%s' % (upload, r))
elif r:
r = 'file'
else:
r = ''
elif field.type in ['string','text']:
r = str(field.formatter(r))
if headers!={}: #new implement dict
if isinstance(headers[colname],dict):
if isinstance(headers[colname]['truncate'], int):
r = truncate_string(r, headers[colname]['truncate'])
elif not truncate is None:
r = truncate_string(r, truncate)
attrcol = dict()#new implement dict
if headers!={}:
if isinstance(headers[colname],dict):
colclass=headers[colname]['class']
def gridbutton(buttonclass='buttonadd',buttontext='Add',
buttonurl=url(args=[]),callback=None,delete=None,trap=True):
if showbuttontext:
if callback:
return A(SPAN(_class=ui.get(buttonclass)),
SPAN(T(buttontext),_title=buttontext,
_class=ui.get('buttontext')),
callback=callback,delete=delete,
_class=trap_class(ui.get('button'),trap))
else:
return A(SPAN(_class=ui.get(buttonclass)),
SPAN(T(buttontext),_title=buttontext,
_class=ui.get('buttontext')),
_href=buttonurl,
_class=trap_class(ui.get('button'),trap))
else:
if callback:
return A(SPAN(_class=ui.get(buttonclass)),
callback=callback,delete=delete,
_title=buttontext,
_class=trap_class(ui.get('buttontext'),trap))
callback=callback,delete=delete,
_class=trap_class(ui.get('button'),trap))
else:
return A(SPAN(_class=ui.get(buttonclass)),
SPAN(T(buttontext),_title=buttontext,
_class=ui.get('buttontext')),
_href=buttonurl,
_class=trap_class(ui.get('button'),trap))
else:
if callback:
return A(SPAN(_class=ui.get(buttonclass)),
callback=callback,delete=delete,
_title=buttontext,
_class=trap_class(ui.get('buttontext'),trap))
else:
return A(SPAN(_class=ui.get(buttonclass)),
_href=buttonurl,_title=buttontext,
_class=trap_class(ui.get('buttontext'),trap))
dbset = db(query)
)
attr = UploadWidget._attributes(field, default, **attributes)
inp = INPUT(**attr)
if download_url and value:
url = download_url + '/' + value
(br, image) = ('', '')
if UploadWidget.is_image(value):
br = BR()
image = IMG(_src = url, _width = UploadWidget.DEFAULT_WIDTH)
requires = attr["requires"]
if requires == [] or isinstance(requires, IS_EMPTY_OR):
inp = DIV(inp, '[',
A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
'|',
INPUT(_type='checkbox',
_name=field.name + UploadWidget.ID_DELETE_SUFFIX),
UploadWidget.DELETE_FILE,
']', br, image)
else:
inp = DIV(inp, '[',
A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
']', br, image)
return inp
key = urllib.urlencode(dict( [ \
((tablename in record \
and isinstance(record, Row) \
and isinstance(record[tablename], Row)) and
(k, record[tablename][k])) or (k, record[k]) \
for k in field._table._primarykey ] ))
r = A(r, _href='%s/%s?%s' % (linkto, tablename, key))
elif field.type.startswith('list:'):
r = field.represent(r or [])
elif field.represent:
r = field.represent(r)
elif field.type == 'blob' and r:
r = 'DATA'
elif field.type == 'upload':
if upload and r:
r = A('file', _href='%s/%s' % (upload, r))
elif r:
r = 'file'
else:
r = ''
elif field.type in ['string','text']:
r = str(field.formatter(r))
ur = unicode(r, 'utf8')
if truncate!=None and len(ur) > truncate:
r = ur[:truncate - 3].encode('utf8') + '...'
row.append(TD(r))
tbody.append(TR(_class=_class, *row))
components.append(TBODY(*tbody))
if selectable:
head.append(TH(_class=ui.get('default','')))
for field in fields:
if columns and not str(field) in columns: continue
if not field.readable: continue
key = str(field)
header = headers.get(str(field),
hasattr(field,'label') and field.label or key)
if sortable:
if key == order:
key, marker = '~'+order, sorter_icons[0]
elif key == order[1:]:
marker = sorter_icons[1]
else:
marker = ''
header = A(header,marker,_href=url(vars=dict(
keywords=request.vars.keywords or '',
order=key)),_class=trap_class())
head.append(TH(header, _class=ui.get('default','')))
if links and links_in_grid:
for link in links:
if isinstance(link,dict):
head.append(TH(link['header'], _class=ui.get('default','')))
# Include extra column for buttons if needed.
include_buttons_column = (details or editable or deletable or
(links and links_in_grid and
not all([isinstance(link, dict) for link in links])))
if include_buttons_column:
head.append(TH(_class=ui.get('default','')))
def self_link(name,p):
d = dict(page=p+1)
if order: d['order']=order
if request.vars.keywords: d['keywords']=request.vars.keywords
return A(name,_href=url(vars=d),_class=trap_class())
NPAGES = 5 # window is 2*NPAGES
image = IMG(_src = url, _width = cls.DEFAULT_WIDTH)
requires = attr["requires"]
if requires == [] or isinstance(requires, IS_EMPTY_OR):
inp = DIV(inp, '[',
A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
'|',
INPUT(_type='checkbox',
_name=field.name + cls.ID_DELETE_SUFFIX,
_id=field.name + cls.ID_DELETE_SUFFIX),
LABEL(cls.DELETE_FILE,
_for=field.name + cls.ID_DELETE_SUFFIX),
']', br, image)
else:
inp = DIV(inp, '[',
A(cls.GENERIC_DESCRIPTION, _href = url),
']', br, image)
return inp