example:
b50_periodo_academico.py:
db.define_table('periodo_academico',
Field('carrera',db.carrera),
Field('codigo', 'string', length=16), #
Field('nombre', 'string', length=64, default='Carrera, Nombre del
Periodo'), # odontologia 2013-2014
Field('fecha_ini', 'date'),
Field('fecha_fin', 'date'),
Field('sistema', 'string', length=1, default='1'),
#auditoria
Field('ip', 'string', length=64, default=request.client,
update=request.client, writable=False, readable=False),
Field('fecha', 'date',default=request.now, update=request.now,
writable=False, readable=False),
Field('user_update', db.auth_user, default=id_user, update=id_user,
writable=False, readable=False),
format = '%(nombre)s'
)
# requires
db.periodo_academico.codigo.requires = db.periodo_academico.nombre.requires
= _requires_nombre
db.periodo_academico.sistema.requires = IS_IN_SET(_status, zero=None)
#represent
db.periodo_academico.sistema.represent = lambda v, row: mi_represent(v,
_status)
db_base_config.py:
_status = {
'1':'Cerrado',
'2':'Activo',
'3':'Uso interno',
}
def mi_represent(v, almacen, row=None):
mostrar = None
try:
mostrar = almacen[v]
except:
mostrar = '---'
return mostrar
El viernes, 16 de noviembre de 2012 17:45:23 UTC-4:30, Massimo Di Pierro
escribió:
>
> some where you have a Field(...,represent=something)
>
> and something takes two arguments, not one. Can you show us the model?
>
> On Friday, 16 November 2012 08:51:32 UTC-6, www.diazluis.com wrote:
>>
>> {{
>> import cStringIO
>> stream=cStringIO.StringIO()
>> estudiante_arancel_rows.export_to_csv_file(ofile=stream, represent=True)
>> response.headers['Content-Type']='application/vnd.ms-excel'
>> response.headers['Content-Disposition'] = "attachment; filename=%s" %
>> 'data_sga.csv'
>> response.write(stream.getvalue(), escape=False)
>> }}
>>
>>
>> Traceback (most recent call last):
>> File "/home/diazluis2007/web2py/gluon/restricted.py", line 212, in
>> restricted
>> exec ccode in environment
>> File
>> "/home/diazluis2007/web2py/applications/sga/views/estudiante_arancel/exportar_excel.html",
>>
>> line 3, in <module>
>> stream=cStringIO.StringIO()
>> File "/home/diazluis2007/web2py/gluon/dal.py", line 9249, in
>> export_to_csv_file
>> value = field.represent(value)
>> TypeError: <lambda>() takes exactly 2 arguments (1 given)
>>
>> web2py: 2.2.1
>>
>
--