Re: [web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-15 Thread Ivan Matveev
The patch is in the text of this message:

patch to make Rows.setvirtualfields work with SQLTABLE

http://groups.google.com/group/web2py/browse_thread/thread/826a37f56c26d689/210036457d278cdc?lnk=gstq=patch+to+make+Rows.setvirtualfields+work+with+SQLTABLE#210036457d278cdc

or e-mailing patched sqlhtml.py to you is the right way?


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-15 Thread Martin.Mulone
If it's for small things you can use:

http://groups.google.com/group/web2py/browse_thread/thread/1a1d52d29611564d/3ef8ca27ecfcea58?lnk=gstq=table+div#3ef8ca27ecfcea58



On Nov 9, 2:36 pm, villas villa...@gmail.com wrote:
 I want to customize the result of SQLTABLE so that it can make me a
 nice table without lines and lines of code in my view file.  To
 achieve that,  I need for example to:

 1) Add columns to hold icons and links and extra stuff.
 2) Customize the rows, e.g.  links which depend on content,  different
 icons etc

 After giving it some thought,  I think I should leave SQLTABLE alone
 and concentrate on 'improving' the rows object so that it contains
 everything I want before passing it to SQLTABLE.

 To do 1) I can simply add a column to the rows object. How can I best
 do that?
 To do 2) I could iterate the rows object and make changes.

 Or  maybe there is another way.
 I appreciate that if I want to style the HTML table,  I'll have to
 write my code in the form (which I am trying to avoid).

 Thanks,
 -D


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-15 Thread villas
@Martin - I like that!

I think the ability to add rows and columns in an obvious way is
something that has been missing.  SQLTABLE needs this feature for
quick 'views'.

However, for DB rows, I think Mr Freeze's Webgrid might be the right
vehicle for further development mainly because we really need the
pagination and set-up options.

I like the idea of using jqGrid,  but it just seems a bit too
complex.  We need things which 'just work' as part of the framework.

Thanks,
-D


On Nov 15, 1:23 pm, Martin.Mulone mulone.mar...@gmail.com wrote:
 If it's for small things you can use:

 http://groups.google.com/group/web2py/browse_thread/thread/1a1d52d296...

 On Nov 9, 2:36 pm, villas villa...@gmail.com wrote:

  I want to customize the result of SQLTABLE so that it can make me a
  nice table without lines and lines of code in my view file.  To
  achieve that,  I need for example to:

  1) Add columns to hold icons and links and extra stuff.
  2) Customize the rows, e.g.  links which depend on content,  different
  icons etc

  After giving it some thought,  I think I should leave SQLTABLE alone
  and concentrate on 'improving' the rows object so that it contains
  everything I want before passing it to SQLTABLE.

  To do 1) I can simply add a column to the rows object. How can I best
  do that?
  To do 2) I could iterate the rows object and make changes.

  Or  maybe there is another way.
  I appreciate that if I want to style the HTML table,  I'll have to
  write my code in the form (which I am trying to avoid).

  Thanks,
  -D




Re: [web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-15 Thread Ivan Matveev
Sorry for posting what I'v already posted, but it looks like my post
on the patch to make SQLTABLE work with Rows object with added virtual
fields was lost.

I think the easiest solution to add a column to select result and view
the result in SQLTABLE wold be something like:

class ExtraFields:
def new_column(self):
if self.some_field_in_select==' something':
return A('some_action_link', _href=URL(
f=some_action_controller_function,
args=[self.id]))
else:
return A('great thing', _href='http://www.web2py.com')

rows=db(db.some_table).select()
rows.setvirtualfields(some_table=ExtraFields())
rows.colnames.append('some_table.new_column')
table=SQLTABLE(rows)

This will give an exception telling that

sqlhtml.py:SQLTABLE.__init__

can't do

field = sqlrows.db[tablename][fieldname]

because there is no 'new_column' in the database.
It wants to get the field from the db model to know how to render it.
This doesn't matter when we add a new field to select result
because the new field shell(and will by a view) be cast to string.

The patch:
change
  sqlhtml.py:SQLTABLE.__init__
field = sqlrows.db[tablename][fieldname]
to
try:
 field = sqlrows.db[tablename][fieldname]
except:
 field = None

change
  sqlhtml.py:SQLTABLE.__init__
   if field.represent:
   r = field.represent(r)
to
  if not field:
  pass
  elif field.represent:
  r = field.represent(r)

---Now we are able to include a new field in SQLTABLE
containing anything(text,  link, image, button, form, whatever)
depending on row contents(in ExtraFields.new_column(self): 'self' is a single
  Row in Rows object returned by select) ,
by adding the field to db().select() result.

---Limitation:
in

rows.colnames.append('some_table.new_column')
rows.setvirtualfields(some_table=ExtraField())

'some_table' shell be a table mentioned in select and present in
the db,
 otherwise
'some_table' will be added as a sub dict to Row objects
and you will not see it in SQLTABLE.


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-14 Thread Ivan Matveev
 I want to customize the result of SQLTABLE so that it can make me a
 nice table without lines and lines of code in my view file.  To
 achieve that,  I need for example to:

 1) Add columns to hold icons and links and extra stuff.
 2) Customize the rows, e.g.  links which depend on content,  different
 icons etc

You can add any column to select result. The result can be passed to
SQLTABLE.
See:
http://groups.google.com/group/web2py/browse_thread/thread/826a37f56c26d689/210036457d278cdc?lnk=gstq=patch+to+make+Rows.setvirtualfields+work+with+SQLTABLE#210036457d278cdc



[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-14 Thread Ivan Matveev
 I want to customize the result of SQLTABLE so that it can make me a
 nice table without lines and lines of code in my view file.  To
 achieve that,  I need for example to:
You can add any column to select result. The result can be passed to
SQLTABLE.
See:
http://groups.google.com/group/web2py/browse_thread/thread/826a37f56c26d689/210036457d278cdc?lnk=gstq=patch+to+make+Rows.setvirtualfields+work+with+SQLTABLE#210036457d278cdc


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-14 Thread villas
Nice one Ivan!  Will the patch be included in Web2py?  I hope Massimo
likes it.

-D

On Nov 15, 12:27 am, Ivan Matveev imatvee...@gmail.com wrote:
  I want to customize the result of SQLTABLE so that it can make me a
  nice table without lines and lines of code in my view file.  To
  achieve that,  I need for example to:

  1) Add columns to hold icons and links and extra stuff.
  2) Customize the rows, e.g.  links which depend on content,  different
  icons etc

 You can add any column to select result. The result can be passed to
 SQLTABLE.
 See:http://groups.google.com/group/web2py/browse_thread/thread/826a37f56c...


Re: [web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-14 Thread Ivan Matveev
  Will the patch be included in Web2py?  I hope Massimo
 likes it.

So do I. Otherwise I will have to patch after every web2py update.


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-14 Thread mdipierro
I am confused. Where is the patch?

On Nov 14, 7:16 pm, Ivan Matveev imatvee...@gmail.com wrote:
   Will the patch be included in Web2py?  I hope Massimo
  likes it.

 So do I. Otherwise I will have to patch after every web2py update.


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-10 Thread villas
The function looks interesting, but I didnt understand how to create
the cols var.

def mytable(rows, cols):
return  TABLE(*[TR(*[TD(row[c]) for c in cols]) for row in rows])

I would be grateful for an example how it might work.

I did have this other idea to include an extra column, but I imagine
that it's not so elegant as above.

rows = db(db.test.id0).select()
extras = list()
for row in rows: extras.append('whatever')

for row,extra in zip(rows,extras):
print TR(TD(row.id),TD(extra))

-D

On Nov 9, 6:33 pm, mdipierro mdipie...@cs.depaul.edu wrote:
 I see two options:

 1) use

     db.table.field.represent = lambda value: DIV(value)

 and give any representation you want to the field value.

 2) If this does not work make your own SQLTABLE helper:

 def mytable(rows, cols):
     return  TABLE(*[TR(*[TD(row[c]) for c in cols]) for row in rows)

 On Nov 9, 11:36 am, villas villa...@gmail.com wrote:

  I want to customize the result of SQLTABLE so that it can make me a
  nice table without lines and lines of code in my view file.  To
  achieve that,  I need for example to:

  1) Add columns to hold icons and links and extra stuff.
  2) Customize the rows, e.g.  links which depend on content,  different
  icons etc

  After giving it some thought,  I think I should leave SQLTABLE alone
  and concentrate on 'improving' the rows object so that it contains
  everything I want before passing it to SQLTABLE.

  To do 1) I can simply add a column to the rows object. How can I best
  do that?
  To do 2) I could iterate the rows object and make changes.

  Or  maybe there is another way.
  I appreciate that if I want to style the HTML table,  I'll have to
  write my code in the form (which I am trying to avoid).

  Thanks,
  -D




[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-10 Thread DenesL
If all you need is an extra column have a look at col3 in SQLFORM
http://web2py.com/book/default/chapter/07#SQLFORM


On Nov 10, 5:33 am, villas villa...@gmail.com wrote:
 The function looks interesting, but I didnt understand how to create
 the cols var.

 def mytable(rows, cols):
 return  TABLE(*[TR(*[TD(row[c]) for c in cols]) for row in rows])

 I would be grateful for an example how it might work.

 I did have this other idea to include an extra column, but I imagine
 that it's not so elegant as above.

 rows = db(db.test.id0).select()
 extras = list()
 for row in rows: extras.append('whatever')

 for row,extra in zip(rows,extras):
 print TR(TD(row.id),TD(extra))

 -D

 On Nov 9, 6:33 pm, mdipierro mdipie...@cs.depaul.edu wrote:

  I see two options:

  1) use

  db.table.field.represent = lambda value: DIV(value)

  and give any representation you want to the field value.

  2) If this does not work make your own SQLTABLE helper:

  def mytable(rows, cols):
  return  TABLE(*[TR(*[TD(row[c]) for c in cols]) for row in rows)

  On Nov 9, 11:36 am, villas villa...@gmail.com wrote:

   I want to customize the result of SQLTABLE so that it can make me a
   nice table without lines and lines of code in my view file.  To
   achieve that,  I need for example to:

   1) Add columns to hold icons and links and extra stuff.
   2) Customize the rows, e.g.  links which depend on content,  different
   icons etc

   After giving it some thought,  I think I should leave SQLTABLE alone
   and concentrate on 'improving' the rows object so that it contains
   everything I want before passing it to SQLTABLE.

   To do 1) I can simply add a column to the rows object. How can I best
   do that?
   To do 2) I could iterate the rows object and make changes.

   Or  maybe there is another way.
   I appreciate that if I want to style the HTML table,  I'll have to
   write my code in the form (which I am trying to avoid).

   Thanks,
   -D


[web2py] Re: Manipulate Rows Object and/or SQLTABLE

2010-11-09 Thread mdipierro
I see two options:

1) use

db.table.field.represent = lambda value: DIV(value)

and give any representation you want to the field value.

2) If this does not work make your own SQLTABLE helper:

def mytable(rows, cols):
return  TABLE(*[TR(*[TD(row[c]) for c in cols]) for row in rows)



On Nov 9, 11:36 am, villas villa...@gmail.com wrote:
 I want to customize the result of SQLTABLE so that it can make me a
 nice table without lines and lines of code in my view file.  To
 achieve that,  I need for example to:

 1) Add columns to hold icons and links and extra stuff.
 2) Customize the rows, e.g.  links which depend on content,  different
 icons etc

 After giving it some thought,  I think I should leave SQLTABLE alone
 and concentrate on 'improving' the rows object so that it contains
 everything I want before passing it to SQLTABLE.

 To do 1) I can simply add a column to the rows object. How can I best
 do that?
 To do 2) I could iterate the rows object and make changes.

 Or  maybe there is another way.
 I appreciate that if I want to style the HTML table,  I'll have to
 write my code in the form (which I am trying to avoid).

 Thanks,
 -D