[web2py] SQL query to web2py code

2016-06-09 Thread 'Annet' via web2py-users
I have the following SQL query (in Postgresql):


SELECT ntw_edge.outid, ntw_edge.inid, ntw_edge.label, alias_edge.inid, 
alias_edge.outid, alias_edge.label
FROM ntw_edge
LEFT OUTER JOIN ntw_edge AS alias_edge
ON ntw_edge.inid=alias_edge.outid
WHERE ntw_edge.outid=1147;


In web2py I have:

def retrieve_edge():
alias_edge = db.ntw_edge.with_alias('alias_edge')
rows = 
db(db.ntw_edge.outID==1147).select(left=db.ntw_edge.on(db.ntw_edge.inID==alias_edge.outID))
return dict(rows=rows)


The SQL query returns the right records:

1147549registered1147549registered
1147  1149registered

The web2py query returns only 1 record:

1147549registered1147549registered


Why doesn't the web2py query return the correct result?


Kind regards,

Annet

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


Re: [web2py] SQL query to web2py code

2016-06-09 Thread Massimiliano
Try to print the sql generated from web2py:

print db(db.ntw_edge.outID==1147)._select(left=db.ntw_edge.on(db.
ntw_edge.inID==alias_edge.outID))

On Thu, Jun 9, 2016 at 10:10 AM, 'Annet' via web2py-users <
web2py@googlegroups.com> wrote:

> I have the following SQL query (in Postgresql):
>
>
> SELECT ntw_edge.outid, ntw_edge.inid, ntw_edge.label, alias_edge.inid,
> alias_edge.outid, alias_edge.label
> FROM ntw_edge
> LEFT OUTER JOIN ntw_edge AS alias_edge
> ON ntw_edge.inid=alias_edge.outid
> WHERE ntw_edge.outid=1147;
>
>
> In web2py I have:
>
> def retrieve_edge():
> alias_edge = db.ntw_edge.with_alias('alias_edge')
> rows =
> db(db.ntw_edge.outID==1147).select(left=db.ntw_edge.on(db.ntw_edge.inID==alias_edge.outID))
> return dict(rows=rows)
>
>
> The SQL query returns the right records:
>
> 1147549registered1147549registered
> 1147  1149registered
>
> The web2py query returns only 1 record:
>
> 1147549registered1147549registered
>
>
> Why doesn't the web2py query return the correct result?
>
>
> Kind regards,
>
> Annet
>
> --
> 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.
>



-- 
Massimiliano

-- 
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] Querying data using admin

2016-06-09 Thread António Ramos
hello
how can i, via admin query a table using in the input box more than 1 field
to query?

i tried
db.amostras.n==203027 & db.amostras.estante1=="_E_000"  - >error
db.amostras.n==203027 and db.amostras.estante1=="_E_000" -> no error but
seems to search only the second field (db.amostras.estante1=="_E_000)

how can i query based on 2 fields?

Regards
António

-- 
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: migrate uwsgi + nginx --> twisted

2016-06-09 Thread Niphlod
are you talking about web2py ? web2py isn't really leveraging twisted 
features. Not sure if it'll sports better performances than uwsgi+nginx. 
that being said, nginx should still sit on top, proxying to the twisted 
process. 
Twisted has extensive docs on how to start it as a service, such 
as http://twistedmatrix.com/documents/13.2.0/core/howto/systemd.html

On Wednesday, June 8, 2016 at 11:41:32 PM UTC+2, Mark Graves wrote:
>
> Hey everyone,
>
> I am migrating an app from uwsgi + nginx to twisted.
>
> I've read the docs and can get it started on my local machine.
>
> Now, I'm putting it on a separate box.
>
> Does anyone have a service startup script that they would mind sharing?
>
> Otherwise, any recommendations for further reading?
>
> -Mark
>

-- 
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: SELECT without duplicates for a specific field

2016-06-09 Thread tim . nyborg
Looks like you want a subquery.  You'll need to decide which of the items 
to choose when you have a given category_code.
Say you want the first item with a given category code:

sub_query = db()._select(db.products.id.min(), 
groupby=db.products.category_code)
results = db(db.products.id.belongs(sub_query).select()

On Wednesday, 8 June 2016 15:10:33 UTC+1, Gael Princivalle wrote:

> Hello.
>
> Is there a way to select some rows without duplicates for a specific field 
> ?
>
> MODEL:
> db.define_table('products'):
> Field('code', type='string'),
> Field('category_code', type='integer'))
>
> ROWS:
> code / category_code
> A1125 / 3
> C2214 / 2
> D235 / 3
> Z886 / 1
>
> I would like to make a select that give this result:
> code / category_code
> A1125 / 3
> C2214 / 2
> Z886 / 1
>
> Someone have an idea ?
>
> Thanks.
>
>
>

-- 
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: Querying data using admin

2016-06-09 Thread Anthony
Same rules as usual apply -- you need parentheses:

(db.amostras.n==203027) & (db.amostras.estante1=="_E_000")

Anthony

On Thursday, June 9, 2016 at 5:29:39 AM UTC-4, Ramos wrote:
>
> hello 
> how can i, via admin query a table using in the input box more than 1 
> field to query?
>
> i tried
> db.amostras.n==203027 & db.amostras.estante1=="_E_000"  - >error
> db.amostras.n==203027 and db.amostras.estante1=="_E_000" -> no error but 
> seems to search only the second field (db.amostras.estante1=="_E_000)
>
> how can i query based on 2 fields?
>
> Regards
> António
>
>

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


Re: [web2py] Re: Querying data using admin

2016-06-09 Thread António Ramos
Oops
Thank you Anthony

António
2016-06-09 14:39 GMT+01:00 Anthony :

> (db.amostras.n==203027) & (db.amostras.estante1=="_E_000")

-- 
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: Querying data using admin

2016-06-09 Thread isi_jca
Hello!!!

Try using Parenthesis, for example:

(db.tventa.id >= 3)  &  (db.tventa.id <= 7)


Result Set
tventa.id 

tventa.fecha 

tventa.vendedor 

tventa.monto 

3  2016-05-04 
Pedro 900.00
4  2016-05-05 
Andrés 1050.00
5  2016-06-08 
Pepe 123.31
6  2016-06-09 
Pepe 52.36
7  2016-06-10 
Maria 12.36
Regards.

El jueves, 9 de junio de 2016, 6:29:39 (UTC-3), Ramos escribió:
>
> hello 
> how can i, via admin query a table using in the input box more than 1 
> field to query?
>
> i tried
> db.amostras.n==203027 & db.amostras.estante1=="_E_000"  - >error
> db.amostras.n==203027 and db.amostras.estante1=="_E_000" -> no error but 
> seems to search only the second field (db.amostras.estante1=="_E_000)
>
> how can i query based on 2 fields?
>
> Regards
> António
>
>

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


Re: [web2py] Re: Querying data using admin

2016-06-09 Thread António Ramos
Yes it works now.

Too bad that i cannot only return some of the columns. It would be perfect
because i have many columns and i have to scroll to the right a lot.

2016-06-09 14:55 GMT+01:00 isi_jca :

> Hello!!!
>
> Try using Parenthesis, for example:
>
> (db.tventa.id >= 3)  &  (db.tventa.id <= 7)
>
>
> Result Set
> tventa.id
> 
> tventa.fecha
> 
> tventa.vendedor
> 
> tventa.monto
> 
> 3  2016-05-04
> Pedro 900.00
> 4  2016-05-05
> Andrés 1050.00
> 5  2016-06-08
> Pepe 123.31
> 6  2016-06-09
> Pepe 52.36
> 7  2016-06-10
> Maria 12.36
> Regards.
>
>
> El jueves, 9 de junio de 2016, 6:29:39 (UTC-3), Ramos escribió:
>>
>> hello
>> how can i, via admin query a table using in the input box more than 1
>> field to query?
>>
>> i tried
>> db.amostras.n==203027 & db.amostras.estante1=="_E_000"  - >error
>> db.amostras.n==203027 and db.amostras.estante1=="_E_000" -> no error but
>> seems to search only the second field (db.amostras.estante1=="_E_000)
>>
>> how can i query based on 2 fields?
>>
>> Regards
>> António
>>
>> --
> 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.
>

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


Re: [web2py] Re: Querying data using admin

2016-06-09 Thread isi_jca
Ramos:

Other posibility is create a form using grid and then choose columns you 
want to show, for example:

def query_venta():
query = (db.tventa.id >= 3)  &  (db.tventa.id <= 7)

columns = [db.tventa.fecha, db.tventa.monto]]
grid=SQLFORM.grid(query,field_id = db.tventa.id,fields=columns)


query_venta.html

{{=grid}}


Regards

El jueves, 9 de junio de 2016, 12:08:39 (UTC-3), Ramos escribió:
>
> Yes it works now.
>
> Too bad that i cannot only return some of the columns. It would be perfect 
> because i have many columns and i have to scroll to the right a lot.
>
> 2016-06-09 14:55 GMT+01:00 isi_jca >:
>
>> Hello!!!
>>
>> Try using Parenthesis, for example:
>>
>> (db.tventa.id >= 3)  &  (db.tventa.id <= 7)
>>
>>
>> Result Set
>> tventa.id 
>> 
>> tventa.fecha 
>> 
>> tventa.vendedor 
>> 
>> tventa.monto 
>> 
>> 3  2016-05-04 
>> Pedro 900.00
>> 4  2016-05-05 
>> Andrés 1050.00
>> 5  2016-06-08 
>> Pepe 123.31
>> 6  2016-06-09 
>> Pepe 52.36
>> 7  2016-06-10 
>> Maria 12.36
>> Regards.
>>
>>
>> El jueves, 9 de junio de 2016, 6:29:39 (UTC-3), Ramos escribió:
>>>
>>> hello 
>>> how can i, via admin query a table using in the input box more than 1 
>>> field to query?
>>>
>>> i tried
>>> db.amostras.n==203027 & db.amostras.estante1=="_E_000"  - >error
>>> db.amostras.n==203027 and db.amostras.estante1=="_E_000" -> no error but 
>>> seems to search only the second field (db.amostras.estante1=="_E_000)
>>>
>>> how can i query based on 2 fields?
>>>
>>> Regards
>>> António
>>>
>>> -- 
>> 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+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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] Problems using @cache.action(valid_statuses=[200])

2016-06-09 Thread Lisandro
I'm having trouble to avoid caching pages that returned anything else than 
HTTP 200.

Consider the following simple example:

@cache.action(time_expire=300, cache_model=cache.redis, session=False, vars=
False, public=True, valid_statuses=[200])
def index():
raise HTTP(503)

When I hit the URL the first time, I can see in deed a 503 response status 
(I checked headers with Chrome Inspector), and there is nothing cached (I 
checked redis stored keys).
But the second time I hit the URL, the server returns an HTTP 200 with an 
empty body, and it keeps returning HTTP 200 for the 5 minutes 
(time_expire=300).
After that time, I hit the URL again, and I can see the HTTP 500. 

What am I missing?

-- 
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 format JSON data?

2016-06-09 Thread Alex Glaros
how to add json_list to the return line at bottom of function?  I need 
locals too, for use in the view

return locals(json.dumps(json_list)))  ??

-- 
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] resilient background process

2016-06-09 Thread Pierre
Hi

I have no experience with task queues and am thinking to adapt my code from 
both the web2py example of homemade task queues at:

http://web2py.com/books/default/chapter/29/08/emails-and-sms?search=Sending+messages+using+a+background+task#Sending-messages-using-a-background-task

and pythonanywhere longRunningTasks script at:

https://help.pythonanywhere.com/pages/LongRunningTasks/

this page tells the programmer to make sure his code is *resilient to being 
terminated unexpectedly*: what is that mean ? For instance can this code 
extracted from the w2p book be considered resilient :


BOOK EXTRACT:

First, in a model file within our application, we set up a database model 
to store our email queue:

1

2

3

4

5

db.define_table('queue',

Field('status'),

Field('email'),

Field('subject'),

Field('message'))

>From a controller, we can then enqueue messages to be sent by:

1

2

3

4

db.queue.insert(status='pending',

email='y...@example.com',

subject='test',

message='test')

Next, we need a background processing script that reads the queue and sends 
the emails:

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

12

13

## in file /app/private/*mail_queue.py*

import time

while True:

rows =
db(db.queue.status=='pending').select()

for row in rows:

if mail.send(to=row.email,

subject=row.subject,

message=row.message):

row.update_record(status='sent')

else:

   
row.update_record(status='failed')

db.commit()

time.sleep(60) # check every minute


I didn't investigate too much so far but I might adapt the pythonanywhere 
script to trigger something derived from *mail_queue.py* via python 
*subprocess* module. would this be an orthodox/resilient  way to proceed 
with scheduled tasks ?  

https://docs.python.org/2/library/subprocess.html

-- 
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: Problems using @cache.action(valid_statuses=[200])

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 9:13:51 AM UTC-7, Lisandro wrote:
>
> I'm having trouble to avoid caching pages that returned anything else than 
> HTTP 200.
>
> Consider the following simple example:
>
> @cache.action(time_expire=300, cache_model=cache.redis, session=False, 
> vars=False, public=True, valid_statuses=[200])
> def index():
> raise HTTP(503)
>
> When I hit the URL the first time, I can see in deed a 503 response status 
> (I checked headers with Chrome Inspector), and there is nothing cached (I 
> checked redis stored keys).
> But the second time I hit the URL, the server returns an HTTP 200 with an 
> empty body, and it keeps returning HTTP 200 for the 5 minutes 
> (time_expire=300).
> After that time, I hit the URL again, and I can see the HTTP 500. 
>
> What am I missing?
>
>

-- 
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 handle dynamic forms?

2016-06-09 Thread desta
Hello everyone,

My current task is to create a form where fields can be added/removed. Is 
it possible to handle such forms with web2py?

Thanks.

-- 
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 format JSON data?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 9:35:07 AM UTC-7, Alex Glaros wrote:
>
> how to add json_list to the return line at bottom of function?  I need 
> locals too, for use in the view
>
> return locals(json.dumps(json_list)))  ??
>

json_list isn't automatically in locals?  You haven't declared it global 
somewhere, have you?

/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] Re: Problems using @cache.action(valid_statuses=[200])

2016-06-09 Thread Anthony
Looks like a bug in the Redis cache implementation. cache.action first 
saves the output to the cache, and later if it is determined that the HTTP 
status is not valid, it then attempts to delete the output from the cache 
via cache_model(cache_key, None) 
. 
Passing None as the second argument to one of the cache models is supposed 
to delete the key, but this does not work with Redis -- see 
https://github.com/web2py/web2py/blob/R-2.14.6/gluon/contrib/redis_cache.py#L152.
 
In the Redis cache client, setting the f argument to None only deletes the 
key if the object wasn't found in the cache or has expired. We should 
probably change the Redis cache to match the behavior of the other cache 
models.

Anthony

On Thursday, June 9, 2016 at 12:13:51 PM UTC-4, Lisandro wrote:
>
> I'm having trouble to avoid caching pages that returned anything else than 
> HTTP 200.
>
> Consider the following simple example:
>
> @cache.action(time_expire=300, cache_model=cache.redis, session=False, 
> vars=False, public=True, valid_statuses=[200])
> def index():
> raise HTTP(503)
>
> When I hit the URL the first time, I can see in deed a 503 response status 
> (I checked headers with Chrome Inspector), and there is nothing cached (I 
> checked redis stored keys).
> But the second time I hit the URL, the server returns an HTTP 200 with an 
> empty body, and it keeps returning HTTP 200 for the 5 minutes 
> (time_expire=300).
> After that time, I hit the URL again, and I can see the HTTP 500. 
>
> What am I missing?
>
>

-- 
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: Problems using @cache.action(valid_statuses=[200])

2016-06-09 Thread Anthony
On Thursday, June 9, 2016 at 2:46:27 PM UTC-4, Dave S wrote:
>
>
> As a WAG (I dunno the cache manipulators), your "valid_statuses" is 
> setting the status to be returned when the page is served from cache.
>

No, he's using valid_statuses correctly -- the output is cached only when 
the status matches one of those in the valid_statuses list. Actually, it is 
unnecessary to list 200, because by default, only statuses beginning with 
1, 2, or 3 are considered valid.

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: how to format JSON data?

2016-06-09 Thread Alex Glaros
yes json_list automatically appears in locals but at one point putting it 
in return(json.dumps(json_list)) was the only way I could see that the 
escape slashes were added. 

okay, so no more javascript errors now

but am still curious how to phrase syntax for putting it in return clause 
along with locals. If my question makes sense, please let me know.

-- 
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: resilient background process

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 11:32:51 AM UTC-7, Pierre wrote:
>
> [...]
> and pythonanywhere longRunningTasks script at:
>
> https://help.pythonanywhere.com/pages/LongRunningTasks/
>
> this page tells the programmer to make sure his code is *resilient to 
> being terminated unexpectedly*: what is that mean ? For instance can this 
> code extracted from the w2p book be considered resilient :
>
>
At first pass, I'd think that you'd want to make sure that when a process 
gets zapped, you want to be careful which data you lose, and that probably 
has to do with how you handle locks and tmp files.

I won't comment on the task queuing because I use the scheduler, which 
turns out to be quite easy.  In my case, the message is generated in as 
well as mailed by  the scheduled task.  Note that Massimo has a more recent 
example in his "new free toys" post of Jan 26
https://groups.google.com/d/msg/web2py/CWUs9UuU5VQ/zn-88rfgDQAJ>

/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] Re: Problems using @cache.action(valid_statuses=[200])

2016-06-09 Thread Anthony
Just submitted an issue: https://github.com/web2py/web2py/issues/1355

On Thursday, June 9, 2016 at 2:55:52 PM UTC-4, Anthony wrote:
>
> Looks like a bug in the Redis cache implementation. cache.action first 
> saves the output to the cache, and later if it is determined that the HTTP 
> status is not valid, it then attempts to delete the output from the cache 
> via cache_model(cache_key, None) 
> . 
> Passing None as the second argument to one of the cache models is supposed 
> to delete the key, but this does not work with Redis -- see 
> https://github.com/web2py/web2py/blob/R-2.14.6/gluon/contrib/redis_cache.py#L152.
>  
> In the Redis cache client, setting the f argument to None only deletes the 
> key if the object wasn't found in the cache or has expired. We should 
> probably change the Redis cache to match the behavior of the other cache 
> models.
>
> Anthony
>
> On Thursday, June 9, 2016 at 12:13:51 PM UTC-4, Lisandro wrote:
>>
>> I'm having trouble to avoid caching pages that returned anything else 
>> than HTTP 200.
>>
>> Consider the following simple example:
>>
>> @cache.action(time_expire=300, cache_model=cache.redis, session=False, 
>> vars=False, public=True, valid_statuses=[200])
>> def index():
>> raise HTTP(503)
>>
>> When I hit the URL the first time, I can see in deed a 503 response 
>> status (I checked headers with Chrome Inspector), and there is nothing 
>> cached (I checked redis stored keys).
>> But the second time I hit the URL, the server returns an HTTP 200 with an 
>> empty body, and it keeps returning HTTP 200 for the 5 minutes 
>> (time_expire=300).
>> After that time, I hit the URL again, and I can see the HTTP 500. 
>>
>> What am I missing?
>>
>>

-- 
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 format JSON data?

2016-06-09 Thread Anthony
On Thursday, June 9, 2016 at 3:02:16 PM UTC-4, Alex Glaros wrote:
>
> but am still curious how to phrase syntax for putting it in return clause 
> along with locals. If my question makes sense, please let me know.
>

That doesn't make sense because locals() is a dictionary of all of the 
local variables, so it already includes json_list, which is a local 
variable. You can always return a custom dictionary including only the 
particular values you need to return rather than all local variables (which 
is what you should be doing anyway), but that won't change anything 
regarding your use of json_list in the view.

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: How to handle dynamic forms?

2016-06-09 Thread Anthony
There is no built-in functionality for this case, but I don't see why you 
couldn't do something like that. I suppose the details would depend on 
whether you are persisting inputs to the database and what the data model 
looks like. As for the UI, that would probably be handled via Javascript 
and is beyond the scope of web2py.

Anthony

On Thursday, June 9, 2016 at 2:47:43 PM UTC-4, desta wrote:
>
> Hello everyone,
>
> My current task is to create a form where fields can be added/removed. Is 
> it possible to handle such forms with web2py?
>
> Thanks.
>

-- 
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 handle dynamic forms?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>
> Hello everyone,
>
> My current task is to create a form where fields can be added/removed. Is 
> it possible to handle such forms with web2py?
>
> Thanks.
>

I am not sure I understand what you want to do.

Is it

a) have a database table that doesn't change its layout, but you want to 
present different sets of columns at different times?
b) have a database table that doesn't change its layout, but you want to 
hide or unhide columns as the user views the data?
c) something else?

a) is not difficult, if you use the SQLFORM and its relatives ... there are 
settings for hiding fields.
b) is a little more difficult; you may have to choose to reload the page, 
use ajax requests to reload the form, or use javascript to hide columns 
yourself.

http://web2py.com/books/default/chapter/29/07/forms-and-validators>

Good luck!

/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] Re: how to format JSON data?

2016-06-09 Thread Alex Glaros
sorry, I meant what is syntax to return a custom dictionary including only 
the particular values I need to return with the json.dumps phrase?

Is it something like (userID=userID, json.dumps(json_list), 
userLastName=userLastName)  ?

-- 
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 format JSON data?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 12:31:36 PM UTC-7, Alex Glaros wrote:
>
> sorry, I meant what is syntax to return a custom dictionary including only 
> the particular values I need to return with the json.dumps phrase?
>
> Is it something like (userID=userID, json.dumps(json_list), 
> userLastName=userLastName)  ?
>

Closer ... but you need to specify a key for each item. 
return dict(userID=userID, json_list=json.dumps(json_list), userLastName=
userLastName)


/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] Re: How to handle dynamic forms?

2016-06-09 Thread desta
Well, I am really not sure how to implement this on database-side either, 
so any feedback from you, more experienced people, would be very 
insightful. 

Here is an example form of what I mean:

A form that a user can enter books they like. So there is a title field 
that accepts the name of the book. Also there is a button 'Add more books' 
that will create an additional text field for the user to enter an 
additional book title. The amount of books a user can add is unconstrained, 
therefore, one user may add only 1 book and other user can add 100 books.

I don't see how it is possible to store such information in a table in a 
conventional way. One way I am thinking to implement this, is to create a 
JSON string that contains all the information of the form and just enter 
that into the table. What do you think about this method?

Thanks again.

On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:
>
>
>
> On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>>
>> Hello everyone,
>>
>> My current task is to create a form where fields can be added/removed. Is 
>> it possible to handle such forms with web2py?
>>
>> Thanks.
>>
>
> I am not sure I understand what you want to do.
>
> Is it
>
> a) have a database table that doesn't change its layout, but you want to 
> present different sets of columns at different times?
> b) have a database table that doesn't change its layout, but you want to 
> hide or unhide columns as the user views the data?
> c) something else?
>
> a) is not difficult, if you use the SQLFORM and its relatives ... there 
> are settings for hiding fields.
> b) is a little more difficult; you may have to choose to reload the page, 
> use ajax requests to reload the form, or use javascript to hide columns 
> yourself.
>
> http://web2py.com/books/default/chapter/29/07/forms-and-validators>
>
> Good luck!
>
> /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] Re: How to handle dynamic forms?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 1:19:35 PM UTC-7, desta wrote:
>
> Well, I am really not sure how to implement this on database-side either, 
> so any feedback from you, more experienced people, would be very 
> insightful. 
>
> Here is an example form of what I mean:
>
> A form that a user can enter books they like. So there is a title field 
> that accepts the name of the book. Also there is a button 'Add more books' 
> that will create an additional text field for the user to enter an 
> additional book title. The amount of books a user can add is unconstrained, 
> therefore, one user may add only 1 book and other user can add 100 books.
>
> I don't see how it is possible to store such information in a table in a 
> conventional way. One way I am thinking to implement this, is to create a 
> JSON string that contains all the information of the form and just enter 
> that into the table. What do you think about this method?
>
> Thanks again.
>


An additional book would be in additional row in a table.

-
|author  |   title  |
-
| Henry X| The Importance of Y  |
-
| Dorothy D  | Information Warfare and Security |
-
| Peter D| An Exploration of Writing|
-
| Phoebe S   | Birding on Borrowed Time |
-
   | add more  |
   -


>
> On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:
>>
>>
>>
>> On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>>>
>>> Hello everyone,
>>>
>>> My current task is to create a form where fields can be added/removed. 
>>> Is it possible to handle such forms with web2py?
>>>
>>> Thanks.
>>>
>>
>> I am not sure I understand what you want to do.
>>
>> Is it
>>
>> a) have a database table that doesn't change its layout, but you want to 
>> present different sets of columns at different times?
>> b) have a database table that doesn't change its layout, but you want to 
>> hide or unhide columns as the user views the data?
>> c) something else?
>>
>> a) is not difficult, if you use the SQLFORM and its relatives ... there 
>> are settings for hiding fields.
>> b) is a little more difficult; you may have to choose to reload the page, 
>> use ajax requests to reload the form, or use javascript to hide columns 
>> yourself.
>>
>> http://web2py.com/books/default/chapter/29/07/forms-and-validators>
>>
>> Good luck!
>>
>> /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] Re: How to handle dynamic forms?

2016-06-09 Thread desta
The book part that I mentioned is a part of much larger form, that has more 
dynamic elements. So I was thinking it was a good idea to store the whole 
form into a single table to keep things manageable. If I understand 
correctly you suggest to break up the form on db-side, and create a table 
for each dynamic part of the form (similar to the books example).

On Thursday, June 9, 2016 at 11:35:28 PM UTC+3, Dave S wrote:
>
>
>
> On Thursday, June 9, 2016 at 1:19:35 PM UTC-7, desta wrote:
>>
>> Well, I am really not sure how to implement this on database-side either, 
>> so any feedback from you, more experienced people, would be very 
>> insightful. 
>>
>> Here is an example form of what I mean:
>>
>> A form that a user can enter books they like. So there is a title field 
>> that accepts the name of the book. Also there is a button 'Add more books' 
>> that will create an additional text field for the user to enter an 
>> additional book title. The amount of books a user can add is unconstrained, 
>> therefore, one user may add only 1 book and other user can add 100 books.
>>
>> I don't see how it is possible to store such information in a table in a 
>> conventional way. One way I am thinking to implement this, is to create a 
>> JSON string that contains all the information of the form and just enter 
>> that into the table. What do you think about this method?
>>
>> Thanks again.
>>
>
>
> An additional book would be in additional row in a table.
>
> -
> |author  |   title  |
> -
> | Henry X| The Importance of Y  |
> -
> | Dorothy D  | Information Warfare and Security |
> -
> | Peter D| An Exploration of Writing|
> -
> | Phoebe S   | Birding on Borrowed Time |
> -
>| add more  |
>-
>
>
>>
>> On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:
>>>
>>>
>>>
>>> On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:

 Hello everyone,

 My current task is to create a form where fields can be added/removed. 
 Is it possible to handle such forms with web2py?

 Thanks.

>>>
>>> I am not sure I understand what you want to do.
>>>
>>> Is it
>>>
>>> a) have a database table that doesn't change its layout, but you want to 
>>> present different sets of columns at different times?
>>> b) have a database table that doesn't change its layout, but you want to 
>>> hide or unhide columns as the user views the data?
>>> c) something else?
>>>
>>> a) is not difficult, if you use the SQLFORM and its relatives ... there 
>>> are settings for hiding fields.
>>> b) is a little more difficult; you may have to choose to reload the 
>>> page, use ajax requests to reload the form, or use javascript to hide 
>>> columns yourself.
>>>
>>> http://web2py.com/books/default/chapter/29/07/forms-and-validators>
>>>
>>> Good luck!
>>>
>>> /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] Re: How to handle dynamic forms?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 1:42:29 PM UTC-7, desta wrote:
>
> The book part that I mentioned is a part of much larger form, that has 
> more dynamic elements. So I was thinking it was a good idea to store the 
> whole form into a single table to keep things manageable. If I understand 
> correctly you suggest to break up the form on db-side, and create a table 
> for each dynamic part of the form (similar to the books example).
>
>
You may want to give us a more detailed example, but using a temporary 
table to hold things is certainly one possible solution.

/dps

 

> On Thursday, June 9, 2016 at 11:35:28 PM UTC+3, Dave S wrote:
>>
>>
>>
>> On Thursday, June 9, 2016 at 1:19:35 PM UTC-7, desta wrote:
>>>
>>> Well, I am really not sure how to implement this on database-side 
>>> either, so any feedback from you, more experienced people, would be very 
>>> insightful. 
>>>
>>> Here is an example form of what I mean:
>>>
>>> A form that a user can enter books they like. So there is a title field 
>>> that accepts the name of the book. Also there is a button 'Add more books' 
>>> that will create an additional text field for the user to enter an 
>>> additional book title. The amount of books a user can add is unconstrained, 
>>> therefore, one user may add only 1 book and other user can add 100 books.
>>>
>>> I don't see how it is possible to store such information in a table in a 
>>> conventional way. One way I am thinking to implement this, is to create a 
>>> JSON string that contains all the information of the form and just enter 
>>> that into the table. What do you think about this method?
>>>
>>> Thanks again.
>>>
>>
>>
>> An additional book would be in additional row in a table.
>>
>> -
>> |author  |   title  |
>> -
>> | Henry X| The Importance of Y  |
>> -
>> | Dorothy D  | Information Warfare and Security |
>> -
>> | Peter D| An Exploration of Writing|
>> -
>> | Phoebe S   | Birding on Borrowed Time |
>> -
>>| add more  |
>>-
>>
>>
>>>
>>> On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:



 On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>
> Hello everyone,
>
> My current task is to create a form where fields can be added/removed. 
> Is it possible to handle such forms with web2py?
>
> Thanks.
>

 I am not sure I understand what you want to do.

 Is it

 a) have a database table that doesn't change its layout, but you want 
 to present different sets of columns at different times?
 b) have a database table that doesn't change its layout, but you want 
 to hide or unhide columns as the user views the data?
 c) something else?

 a) is not difficult, if you use the SQLFORM and its relatives ... there 
 are settings for hiding fields.
 b) is a little more difficult; you may have to choose to reload the 
 page, use ajax requests to reload the form, or use javascript to hide 
 columns yourself.

 http://web2py.com/books/default/chapter/29/07/forms-and-validators
 >

 Good luck!

 /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] Re: How to handle dynamic forms?

2016-06-09 Thread desta
Something like this:


* ## Personal Details ##
* Name:_
* Surname: _
* 
* Mobile phone: _
* 
* ## Book part ##
* Book title: _
* 
*  
* 
* 
* Do you like movies? Yes/No
* (if yes then show the ##movie part##, else skip)
* 
* ## Movie part ##
* Movie title: 
* 
*  
* 
* Do you prefer cars or bikes?
* (if car then show ## cars parts ## else show ## bikes part ##)
* 
* ## Car part ##
* Car model: __
* Upload image: 
*   
* 
*   
* 
* ## Bike part ##
* Bike model: __
* Upload image: 
*   
* 
*   


Thanks.

On Thursday, June 9, 2016 at 11:47:03 PM UTC+3, Dave S wrote:
>
>
>
> On Thursday, June 9, 2016 at 1:42:29 PM UTC-7, desta wrote:
>>
>> The book part that I mentioned is a part of much larger form, that has 
>> more dynamic elements. So I was thinking it was a good idea to store the 
>> whole form into a single table to keep things manageable. If I understand 
>> correctly you suggest to break up the form on db-side, and create a table 
>> for each dynamic part of the form (similar to the books example).
>>
>>
> You may want to give us a more detailed example, but using a temporary 
> table to hold things is certainly one possible solution.
>
> /dps
>
>  
>
>> On Thursday, June 9, 2016 at 11:35:28 PM UTC+3, Dave S wrote:
>>>
>>>
>>>
>>> On Thursday, June 9, 2016 at 1:19:35 PM UTC-7, desta wrote:

 Well, I am really not sure how to implement this on database-side 
 either, so any feedback from you, more experienced people, would be very 
 insightful. 

 Here is an example form of what I mean:

 A form that a user can enter books they like. So there is a title field 
 that accepts the name of the book. Also there is a button 'Add more books' 
 that will create an additional text field for the user to enter an 
 additional book title. The amount of books a user can add is 
 unconstrained, 
 therefore, one user may add only 1 book and other user can add 100 books.

 I don't see how it is possible to store such information in a table in 
 a conventional way. One way I am thinking to implement this, is to create 
 a 
 JSON string that contains all the information of the form and just enter 
 that into the table. What do you think about this method?

 Thanks again.

>>>
>>>
>>> An additional book would be in additional row in a table.
>>>
>>> -
>>> |author  |   title  |
>>> -
>>> | Henry X| The Importance of Y  |
>>> -
>>> | Dorothy D  | Information Warfare and Security |
>>> -
>>> | Peter D| An Exploration of Writing|
>>> -
>>> | Phoebe S   | Birding on Borrowed Time |
>>> -
>>>| add more  |
>>>-
>>>
>>>

 On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:
>
>
>
> On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>>
>> Hello everyone,
>>
>> My current task is to create a form where fields can be 
>> added/removed. Is it possible to handle such forms with web2py?
>>
>> Thanks.
>>
>
> I am not sure I understand what you want to do.
>
> Is it
>
> a) have a database table that doesn't change its layout, but you want 
> to present different sets of columns at different times?
> b) have a database table that doesn't change its layout, but you want 
> to hide or unhide columns as the user views the data?
> c) something else?
>
> a) is not difficult, if you use the SQLFORM and its relatives ... 
> there are settings for hiding fields.
> b) is a little more difficult; you may have to choose to reload the 
> page, use ajax requests to reload the form, or use javascript to hide 
> columns yourself.
>
>  http://web2py.com/books/default/chapter/29/07/forms-and-validators>
>
> Good luck!
>
> /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

[web2py] Re: How to handle dynamic forms?

2016-06-09 Thread Dave S


On Thursday, June 9, 2016 at 2:26:32 PM UTC-7, desta wrote:
>
> Something like this:
>
> [details elided]

A profile type of page, eh?  Perhaps Ron C has some ideas.

I would be tempted to use separate forms for each section and use ajax 
calls to transmit the data to the server.  I would pick certain items to be 
in the primary table (such as the personal details), and have separate 
tables for the things with multiple entries (like the books), with a 
reference field back to the primary table.  You'd need to write some 
javascript for things like making the bike form visible instead of the car 
form, and you may want also to write some javascript to submit the 
different forms, either as a result of clicking one OK button or by 
detecting when focus has changed.

That's just off the top of my head, and I'm less of a user-experience guy 
than some of the denizens of this group.

/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] Re: How to handle dynamic forms?

2016-06-09 Thread Anthony
The books and movies could be done easily via list:string fields. However, 
for the cars and bikes, you would need linked tables with child records 
because you need to store both the model and an uploaded image for each.

Anthony

On Thursday, June 9, 2016 at 5:26:32 PM UTC-4, desta wrote:
>
> Something like this:
>
> 
> * ## Personal Details ##
> * Name:_
> * Surname: _
> * 
> * Mobile phone: _
> * 
> * ## Book part ##
> * Book title: _
> * 
> *  
> * 
> * 
> * Do you like movies? Yes/No
> * (if yes then show the ##movie part##, else skip)
> * 
> * ## Movie part ##
> * Movie title: 
> * 
> *  
> * 
> * Do you prefer cars or bikes?
> * (if car then show ## cars parts ## else show ## bikes part ##)
> * 
> * ## Car part ##
> * Car model: __
> * Upload image: 
> *   
> * 
> *   
> * 
> * ## Bike part ##
> * Bike model: __
> * Upload image: 
> *   
> * 
> *   
> 
>
> Thanks.
>
> On Thursday, June 9, 2016 at 11:47:03 PM UTC+3, Dave S wrote:
>>
>>
>>
>> On Thursday, June 9, 2016 at 1:42:29 PM UTC-7, desta wrote:
>>>
>>> The book part that I mentioned is a part of much larger form, that has 
>>> more dynamic elements. So I was thinking it was a good idea to store the 
>>> whole form into a single table to keep things manageable. If I understand 
>>> correctly you suggest to break up the form on db-side, and create a table 
>>> for each dynamic part of the form (similar to the books example).
>>>
>>>
>> You may want to give us a more detailed example, but using a temporary 
>> table to hold things is certainly one possible solution.
>>
>> /dps
>>
>>  
>>
>>> On Thursday, June 9, 2016 at 11:35:28 PM UTC+3, Dave S wrote:



 On Thursday, June 9, 2016 at 1:19:35 PM UTC-7, desta wrote:
>
> Well, I am really not sure how to implement this on database-side 
> either, so any feedback from you, more experienced people, would be very 
> insightful. 
>
> Here is an example form of what I mean:
>
> A form that a user can enter books they like. So there is a title 
> field that accepts the name of the book. Also there is a button 'Add more 
> books' that will create an additional text field for the user to enter an 
> additional book title. The amount of books a user can add is 
> unconstrained, 
> therefore, one user may add only 1 book and other user can add 100 books.
>
> I don't see how it is possible to store such information in a table in 
> a conventional way. One way I am thinking to implement this, is to create 
> a 
> JSON string that contains all the information of the form and just enter 
> that into the table. What do you think about this method?
>
> Thanks again.
>


 An additional book would be in additional row in a table.

 -
 |author  |   title  |
 -
 | Henry X| The Importance of Y  |
 -
 | Dorothy D  | Information Warfare and Security |
 -
 | Peter D| An Exploration of Writing|
 -
 | Phoebe S   | Birding on Borrowed Time |
 -
| add more  |
-


>
> On Thursday, June 9, 2016 at 10:23:58 PM UTC+3, Dave S wrote:
>>
>>
>>
>> On Thursday, June 9, 2016 at 11:47:43 AM UTC-7, desta wrote:
>>>
>>> Hello everyone,
>>>
>>> My current task is to create a form where fields can be 
>>> added/removed. Is it possible to handle such forms with web2py?
>>>
>>> Thanks.
>>>
>>
>> I am not sure I understand what you want to do.
>>
>> Is it
>>
>> a) have a database table that doesn't change its layout, but you want 
>> to present different sets of columns at different times?
>> b) have a database table that doesn't change its layout, but you want 
>> to hide or unhide columns as the user views the data?
>> c) something else?
>>
>> a) is not difficult, if you use the SQLFORM and its relatives ... 
>> there are settings for hiding fields.
>> b) is a little more difficult; you may have to choose to reload the 
>> page, use ajax requests to reload the form, or use javascript to hide 
>> columns yourself.
>>
>> > http:/

Re: [web2py] SQL query to web2py code

2016-06-09 Thread 'Annet' via web2py-users
Hi Massimiliano,

Thanks for your helpful reply.

print db(db.ntw_edge.outID==1147)._select(left=db.ntw_edge.on(db.
> ntw_edge.inID==alias_edge.outID))
>


Web2py generates:

SELECT  alias_edge.outid, alias_edge.inid, alias_edge.label, 
ntw_edge.outid, ntw_edge.inid, ntw_edge.label
FROM ntw_edge AS alias_edge
LEFT JOIN ntw_edge 
ON (ntw_edge.inID = alias_edge.outID)
WHERE (ntw_edge.outID = 1147);


This helped me fgiure out the correct query:

rows = 
db(db.ntw_edge.inID==1147).select(left=alias_edge.on(db.ntw_edge.outID==alias_edge.inID))


Kind regards,

Annet

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