[web2py] Re: Grid without consulting database

2015-09-22 Thread Anthony

>
> 1. Create a Table object with appropriate fields and set migrate=False 
> (This creates a dummy table) 
> 2. Convert row values into a list of tuples
> 3. Use db._adapter.parse to create a DAL Rows object using the dummy table:
>
> t_rows = db._adapter.parse(rows, fields=[f for f in db.dummy_table], 
> colnames=db.dummy_table.fields)
>
>
> 4. Create a SQLFORM.grid in controller and then replace the rows with your 
> rows object using the DOM parser.
>
> grid = SQLFORM.grid(db.dummy_table)
> table = grid.element('.web2py_table')
> table[0] = t_rows
>
>
I'm not sure this will be a fruitful approach. The code above won't quite 
work as is, as table[0] is supposed to be a TABLE html helper object, with 
a very specific structure and format, but the above code attempts to 
replace it with a DAL Rows object. This approach will also break 
pagination, searching, sorting, and downloading. So, without the HTML table 
or any of the other grid features, you really get nothing out of using the 
grid in this way.

If you have a set of records in JSON format, you're much better off using a 
solution such as Datatables  (or even just manually 
building an HTML table via a loop in a web2py template).

Anthony

-- 
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: Grid without consulting database

2015-09-22 Thread Anthony
The web2py grid provides functionality specific to working with database 
tables defined via the DAL, such as pagination, sorting, searching, field 
representation, virtual fields, and CRUD operations on records. When 
dealing with data from third party API's or from other formats (e.g., CSV 
files), some of those features are irrelevant (e.g., the CRUD 
functionality), and others would be difficult to implement in a general way 
due to the diversity of APIs and data formats (and would still require you 
to write your own data processing code and/or do a lot of configuration in 
order to interface with the grid's API). Because there are already good 
general purpose data grids that meet this need (such as Datatables 
), there would be little benefit to a 
web2py-specific grid that is divorced from web2py-specific models.

Anthony

On Tuesday, September 22, 2015 at 3:31:55 AM UTC-4, Gary Cowell wrote:
>
> The need to represent data from web services inside a web2py app must be a 
> fairly common requirement, I think. I certainly need(ed) to for a project.
>
> I used a sqlite mem db for each page (I was calling Amazon AWS through 
> boto, get lists of stuff, etc.). I did three things to represent my data.
>
> Firstly, I called some aws APIs and store the result in dicts and lists in 
> session.
>
> Secondly, I used sqlite mem db DAL object , iterated inserts to these from 
> the dicts/lists , and built sqlform.grid from these.
>
> Thirdly, I used sqlform factory with IS_IN_SET for my lists and dicts in 
> session, so I could provide drop down lists of AWS responses in forms.
>
> This was a small, but useful app, which was used by no more than about 6 
> people, so it worked well. Don't know how well this will scale with the 
> sqlite mem db (probably not well).
>
> I'd love a component that would populate grids and lists from arbitrary 
> data, such as from boto or indeed any other web service call.
>
> On Thursday, 10 September 2015 22:42:30 UTC+1, Luis Valladares wrote:
>>
>> Hello! I'm trying to use SQLFORM.grid (or something like this) to my 
>> website, but this page doesnt have a database because it consumes all the 
>> data form a service, so i ask the service for the list of records in a 
>> table and i recieve it in json format and transform to dictionary.
>>
>> What i want to do is use this dictionary to create a grid (Like the 
>> SQLFORM.grid) but the grid doesnt work if i dont specify a query, there is 
>> a way to create a grid without query and instead with a dictionary?
>>
>> Thanks for any help you can give!
>>
>

-- 
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: Grid without consulting database

2015-09-22 Thread pjryan126
 Good point. I guess it depends on how many features are needed. My own 
experience is that using the DOM parser to modify grid parts like the 
buttons gets it pretty far along -- obviously, a lot would be missing, but 
there is so much useful stuff even with a very basic version of the grid 
(i.e., search bar not included).

On Tuesday, September 22, 2015 at 3:22:00 PM UTC-4, Anthony wrote:
>
> 1. Create a Table object with appropriate fields and set migrate=False 
>> (This creates a dummy table) 
>> 2. Convert row values into a list of tuples
>> 3. Use db._adapter.parse to create a DAL Rows object using the dummy 
>> table:
>>
>> t_rows = db._adapter.parse(rows, fields=[f for f in db.dummy_table], 
>> colnames=db.dummy_table.fields)
>>
>>
>> 4. Create a SQLFORM.grid in controller and then replace the rows with 
>> your rows object using the DOM parser.
>>
>> grid = SQLFORM.grid(db.dummy_table)
>> table = grid.element('.web2py_table')
>> table[0] = t_rows
>>
>>
> I'm not sure this will be a fruitful approach. The code above won't quite 
> work as is, as table[0] is supposed to be a TABLE html helper object, with 
> a very specific structure and format, but the above code attempts to 
> replace it with a DAL Rows object (which will ultimately get rendered as a 
> SQLTABLE, which is not quite the same as the grid HTML table). This 
> approach will also break pagination, searching, sorting, and downloading. 
> So, without the standard grid HTML table or any of the other grid features, 
> you really get very little out of using the grid in this way.
>
> Instead, you could do steps 1-3 above, and then replace step 4 with:
>
> grid = SQLTABLE(t_rows)
>
> However, it would probably be easier to just write some code to directly 
> build an HTML table from the original JSON data rather than bothering with 
> steps 1-3. This would also allow for more flexibility in specifying the 
> HTML structure of the table.
>
> Even better, just use an existing data grid solution, such as Datatables 
> , which can consume JSON data directly.
>
> Anthony
>

-- 
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: Grid without consulting database

2015-09-22 Thread Anthony
The problem is that with this method, you don't get a grid at all, you get a 
SQLTABLE, so there is literally no "useful stuff" coming from SQLFORM.grid.

Anthony

-- 
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: Grid without consulting database

2015-09-22 Thread Gary Cowell
The need to represent data from web services inside a web2py app must be a 
fairly common requirement, I think. I certainly need(ed) to for a project.

I used a sqlite mem db for each page (I was calling Amazon AWS through 
boto, get lists of stuff, etc.). I did three things to represent my data.

Firstly, I called some aws APIs and store the result in dicts and lists in 
session.

Secondly, I used sqlite mem db DAL object , iterated inserts to these from 
the dicts/lists , and built sqlform.grid from these.

Thirdly, I used sqlform factory with IS_IN_SET for my lists and dicts in 
session, so I could provide drop down lists of AWS responses in forms.

This was a small, but useful app, which was used by no more than about 6 
people, so it worked well. Don't know how well this will scale with the 
sqlite mem db (probably not well).

I'd love a component that would populate grids and lists from arbitrary 
data, such as from boto or indeed any other web service call.

On Thursday, 10 September 2015 22:42:30 UTC+1, Luis Valladares wrote:
>
> Hello! I'm trying to use SQLFORM.grid (or something like this) to my 
> website, but this page doesnt have a database because it consumes all the 
> data form a service, so i ask the service for the list of records in a 
> table and i recieve it in json format and transform to dictionary.
>
> What i want to do is use this dictionary to create a grid (Like the 
> SQLFORM.grid) but the grid doesnt work if i dont specify a query, there is 
> a way to create a grid without query and instead with a dictionary?
>
> Thanks for any help you can give!
>

-- 
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: Grid without consulting database

2015-09-20 Thread Luis Valladares
Sorry for the late response! i will test this ASAP

El viernes, 11 de septiembre de 2015, 13:48:56 (UTC-4:30), pjryan126 
escribió:
>
> I haven't tested any of this -- I would need a little time to put 
> something together, but I would attack the problem like this:
>
> 1. Create a Table object with appropriate fields and set migrate=False 
> (This creates a dummy table) 
> 2. Convert row values into a list of tuples
> 3. Use db._adapter.parse to create a DAL Rows object using the dummy table:
>
> t_rows = db._adapter.parse(rows, fields=[f for f in db.dummy_table], 
> colnames=db.dummy_table.fields)
>
>
> 4. Create a SQLFORM.grid in controller and then replace the rows with your 
> rows object using the DOM parser.
>
> grid = SQLFORM.grid(db.dummy_table)
> table = grid.element('.web2py_table')
> table[0] = t_rows
>
>
> On Thursday, September 10, 2015 at 6:50:49 PM UTC-4, Luis Valladares wrote:
>>
>> Well, that sounds like a big mess of db i/o, i think it will be better to 
>> use javascript. Maybe this can be put in a "wish list" for future 
>> development in web2py?
>>
>> Thanks for your help!
>>
>> El jueves, 10 de septiembre de 2015, 18:03:01 (UTC-4:30), Leonel Câmara 
>> escribió:
>>>
>>> Well there is, but, it's not pretty. You could create a DAL instance 
>>> using sqlite mem, then you put everything you get from the service there, 
>>> then you send a query in that DAL instance to the grid.  
>>>   
>>> Frankly, this is not a good idea and you'll probably run into problems, 
>>> you're better off using one of the many javascript grid options.
>>>
>>> Here are some options:
>>>
>>> http://handsontable.com/
>>> https://github.com/tonytomov/jqGrid/tree/master
>>> http://datatables.net/
>>>
>>> Or really just make it yourself it's really easy with stuff like 
>>> ractivejs or similar.
>>>  
>>>
>>

-- 
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: Grid without consulting database

2015-09-11 Thread pjryan126
I haven't tested any of this -- I would need a little time to put something 
together, but I would attack the problem like this:

1. Create a Table object with appropriate fields and set migrate=False 
(This creates a dummy table) 
2. Convert row values into a list of tuples
3. Use db._adapter.parse to create a DAL Rows object using the dummy table:

t_rows = db._adapter.parse(rows, fields=[f for f in db.dummy_table], 
colnames=db.dummy_table.fields)


4. Create a SQLFORM.grid in controller and then replace the rows with your 
rows object using the DOM parser.

grid = SQLFORM.grid(db.dummy_table)
table = grid.element('.web2py_table')
table[0] = t_rows


On Thursday, September 10, 2015 at 6:50:49 PM UTC-4, Luis Valladares wrote:
>
> Well, that sounds like a big mess of db i/o, i think it will be better to 
> use javascript. Maybe this can be put in a "wish list" for future 
> development in web2py?
>
> Thanks for your help!
>
> El jueves, 10 de septiembre de 2015, 18:03:01 (UTC-4:30), Leonel Câmara 
> escribió:
>>
>> Well there is, but, it's not pretty. You could create a DAL instance 
>> using sqlite mem, then you put everything you get from the service there, 
>> then you send a query in that DAL instance to the grid.  
>>   
>> Frankly, this is not a good idea and you'll probably run into problems, 
>> you're better off using one of the many javascript grid options.
>>
>> Here are some options:
>>
>> http://handsontable.com/
>> https://github.com/tonytomov/jqGrid/tree/master
>> http://datatables.net/
>>
>> Or really just make it yourself it's really easy with stuff like 
>> ractivejs or similar.
>>
>

-- 
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: Grid without consulting database

2015-09-10 Thread Leonel Câmara
Well there is, but, it's not pretty. You could create a DAL instance using 
sqlite mem, then you put everything you get from the service there, then 
you send a query in that DAL instance to the grid.  
  
Frankly, this is not a good idea and you'll probably run into problems, 
you're better off using one of the many javascript grid options.

Here are some options:

http://handsontable.com/
https://github.com/tonytomov/jqGrid/tree/master
http://datatables.net/

Or really just make it yourself it's really easy with stuff like ractivejs 
or similar.

-- 
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: Grid without consulting database

2015-09-10 Thread Luis Valladares
Well, that sounds like a big mess of db i/o, i think it will be better to 
use javascript. Maybe this can be put in a "wish list" for future 
development in web2py?

Thanks for your help!

El jueves, 10 de septiembre de 2015, 18:03:01 (UTC-4:30), Leonel Câmara 
escribió:
>
> Well there is, but, it's not pretty. You could create a DAL instance using 
> sqlite mem, then you put everything you get from the service there, then 
> you send a query in that DAL instance to the grid.  
>   
> Frankly, this is not a good idea and you'll probably run into problems, 
> you're better off using one of the many javascript grid options.
>
> Here are some options:
>
> http://handsontable.com/
> https://github.com/tonytomov/jqGrid/tree/master
> http://datatables.net/
>
> Or really just make it yourself it's really easy with stuff like ractivejs 
> or similar.
>

-- 
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.