[web2py] Record format and SQLFORM.factory

2015-01-26 Thread César Bustíos Benites
Hello! I have a table called *presupuesto *with a custom *format*:

db.define_table('presupuesto',
Field('jar', db.jar, label='JAR'),
Field('monto', 'decimal(11, 2)', label='Presupuesto inicial', 
requires=IS_NOT_EMPTY(error_message='Ingrese un monto para el 
presupuesto')),
Field('monto_mensual', 'decimal(11, 2)', label='Presupuesto mensual', 
compute=lambda r: Decimal(r.monto)/Decimal('12')),
Field('ano', 'integer', label='Año', 
requires=[IS_NOT_EMPTY(error_message='Ingrese el año'), 
IS_INT_IN_RANGE(1980, 2100, error_message='Año inválido')]),
format=lambda record: '%s %s' % (record.jar.nombre, record.ano)
)

I'm using the following SQLFORM.factory in a view:

@auth.requires_login()
def control_gastos():
form = SQLFORM.factory(
Field('Presupuesto', requires=IS_IN_DB(db, db.presupuesto)),
submit_button='Continuar',
table_name='presupuesto',
)
form.element(_type='submit')['_class'] = 'btn btn-success'
form.element('#presupuesto_Presupuesto')['_class'] = 'form-control'
form.element('#presupuesto_Presupuesto')['_style'] = 'width: 100%'
return dict(form=form)

Somehow, I was expecting that the records shown in the form were formatted 
as define in the table but that's not happening. Am I missing something?



Thanks,
César

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Record format and SQLFORM.factory

2015-01-26 Thread César Bustíos Benites
Hello Niphlod, do I have to do that? I think I'm missing the point with the 
*format* parameter of *define_table*.

On Monday, January 26, 2015 at 3:01:09 PM UTC-5, Niphlod wrote:

 where are you telling to SQLFORM.factory the representation of the record 
 ? 

 On Monday, January 26, 2015 at 5:09:31 PM UTC+1, César Bustíos Benites 
 wrote:

 Hello! I have a table called *presupuesto *with a custom *format*:

 db.define_table('presupuesto',
 Field('jar', db.jar, label='JAR'),
 Field('monto', 'decimal(11, 2)', label='Presupuesto inicial', 
 requires=IS_NOT_EMPTY(error_message='Ingrese un monto para el 
 presupuesto')),
 Field('monto_mensual', 'decimal(11, 2)', label='Presupuesto mensual', 
 compute=lambda r: Decimal(r.monto)/Decimal('12')),
 Field('ano', 'integer', label='Año', requires=[IS_NOT_EMPTY(
 error_message='Ingrese el año'), IS_INT_IN_RANGE(1980, 2100, 
 error_message='Año inválido')]),
 format=lambda record: '%s %s' % (record.jar.nombre, record.ano)
 )


 I'm using the following SQLFORM.factory in a view:

 @auth.requires_login()
 def control_gastos():
 form = SQLFORM.factory(
 Field('Presupuesto', requires=IS_IN_DB(db, db.presupuesto)),
 submit_button='Continuar',
 table_name='presupuesto',
 )
 form.element(_type='submit')['_class'] = 'btn btn-success'
 form.element('#presupuesto_Presupuesto')['_class'] = 'form-control'
 form.element('#presupuesto_Presupuesto')['_style'] = 'width: 100%'
 return dict(form=form)


 Somehow, I was expecting that the records shown in the form were 
 formatted as define in the table but that's not happening. It's only 
 showing IDs:


 https://lh6.googleusercontent.com/-HVtGNOVneTI/VMZm_thtOTI/YFs/YrDCU2mdVLI/s1600/Screenshot%2Bfrom%2B2015-01-26%2B11%3A09%3A18.png

 What am I missing?


 Thanks,
 César



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to add a column to SQLFORM.smartgrid that contains the row count?

2015-01-16 Thread César Bustíos Benites
Dave / Paolo, thank you for your answer. Yes, I'm just using {{=form}} 
inside the view. I have read about the links parameter but I can't find a 
way to add a number to each of the rows using that method. I think I will 
just fall back to rendering the data manually. Is there some kind of loop 
counter while using {{for}} .. {{pass}} in the view:

{{ for row in rows: }}
{{ forloop.counter }} 
{{ .. }}
{{ pass }}




On Thursday, January 15, 2015 at 4:46:59 PM UTC-5, Dave S wrote:



 On Thursday, January 15, 2015 at 11:47:07 AM UTC-8, César Bustíos Benites 
 wrote:

 Hello all, I have a simple SQLFORM.smartgrid using two tables: tramites 
 and tramites_procesos:



 Is your view anything different  from
 {{=form}}

 I would assume, without having actually gotten to smartgrids yet, that a 
 virtual field would be part of the answer.
 URL:
 http://web2py.com/books/default/chapter/29/07/forms-and-validators#Virtual-fields-in-SQLFORM-grid-and-smartgrid
 

 Sorry for the vague answer.

 /dps




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to add a column to SQLFORM.smartgrid that contains the row count?

2015-01-15 Thread César Bustíos Benites
Hello all, I have a simple SQLFORM.smartgrid using two tables: tramites 
and desarrollo_tramites:

https://lh6.googleusercontent.com/-n3RmEWYCkP0/VLgYJVm42TI/YAI/FQU8KmqkrLQ/s1600/tramites.png
This is how the code looks like:

@auth.requires_login()
def consulta_tramite():
user_id = auth.user.id
user_area = auth.user.area
db.tramites.estado.writable = False
db.tramites_procesos.tramite.writable = False
db.tramites_procesos.usuario.default = user_id
db.tramites_procesos.usuario.writable = False
form = SQLFORM.smartgrid(
db.tramites,
linked_tables = ['tramites_procesos'],
divider=' ⇒',
fields=[
db.tramites.id,
db.tramites.tiempo,
db.tramites.documento_generado,
db.tramites_procesos.id,
db.tramites_procesos.tiempo,
db.tramites_procesos.indicacion,
db.tramites_procesos.usuario,
db.tramites_procesos.area_destino,
db.tramites_procesos.usuario_destino,
db.tramites_procesos.comentarios
],
editable=False,
deletable=False,
create=False,
details=False,
exportclasses=dict(xml=False, html=False, json=False, tsv=False, 
tsv_with_hidden_cols=False),
maxtextlength=100,
formstyle='bootstrap'
)


if form.element('.web2py_table table'):
form.element('.web2py_table table')['_class'] = 'table 
table-bordered'
for tr in form.element('.web2py_table table tbody'):
for td in tr.components:
if 'Urgente' in td.components:
td.add_class('warning warning-message')
elif 'Muy Urgente' in td.components:
td.add_class('danger danger-message')
return dict(form=form)

I want to add an extra column at the beginning of the table that shows the 
row count, something like this:

# | Nº trámite | Fecha | ...
===
1 | ...
2 | ...
3 | ...
4 | ...

How can I achieve such thing?

Thank you,
César B.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.