[web2py] Re: Call functions from other applications without network requests

2017-01-12 Thread Brendan Barnwell
On Saturday, January 7, 2017 at 11:07:36 AM UTC-8, Anthony wrote:
>
> On Saturday, January 7, 2017 at 1:57:36 PM UTC-5, Brendan Barnwell wrote:
>>
>> The shared functionality involves DB access, so as far as I can tell it 
>> cannot be abstracted into modules that would then be imported with a normal 
>> import.
>>
>
> You can use the DAL from modules as well. As Niphlod suggested, you can 
> also use the scheduler to schedule and run a task in the context of another 
> app, though that might not be as fast as you'd like, as even setting 
> immediate=True, it could take up to "heartbeat" seconds for the worker to 
> pick up and execute the task, and then you have to check for the results.
>
>
I can use the DAL, but can I use the "db" object defined in my models 
file?  Or do you mean I could use the DAL if I rewrote my other app to use 
a "model-less" approach where the models were defined in some other manner?

-- 
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] add_button to go to the previous page

2017-01-12 Thread Dave S
On Thursday, January 12, 2017 at 11:50:16 AM UTC-8, Dave S wrote:
>
>
>
> On Thursday, January 12, 2017 at 11:36:32 AM UTC-8, Andrea Fae' wrote:
>>
>> request.env.http_referer contains all URL starting with http://..., I 
>> need the last part after /. Thank you
>>
>
> Python has the urlparse functions.  Indeed, web2py uses that stuff.
> 
>
>
>

Note that the REFERRER might not exist if the user has directly entered the 
URL.

 

> /dps
>

-d
 

>  
>
>>
>> Il giorno giovedì 12 gennaio 2017 18:45:58 UTC+1, Gaurav Vichare ha 
>> scritto:
>>>
>>> request.env.http_referer contains link to the referrer page, i. e. 
>>> previous page!
>>>
>>> On Thursday, January 12, 2017 at 7:55:26 PM UTC+5:30, Andrea Fae' wrote:

 I don't know what is the previous page because this page can come from 
 different pages...this is the problem...I want to reference the previous 
 page... thank you

 Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
 scritto:
>
> example:
>
> form.add_button("Annulla",URL('default','index'))
>
> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :
>
>> with this:
>>
>> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>>
>> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>>
>>> I have this situation
>>> form = crud.update(db.pc, pc, onaccept=crud.archive, 
>>> deletable=False, next='lista_pc')
>>> form.add_button("Annulla",URL('lista_pc'))
>>> 
>>> I want that button "annulla" go in the previus page, not in the 
>>> 'lista_pc'.
>>> How to do?
>>> thank you
>>>
>>> -- 
>>> 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] Re: import csv that can update some existing data in existing table

2017-01-12 Thread 黄祥
nice trick gael

thanks and best regards,
stifan

-- 
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: import csv that can update some existing data in existing table

2017-01-12 Thread Gael Princivalle
Hi Stifan.

I do it like that, for example for a table called cm1:
import os
from cStringIO import StringIO

#Original table
db.define_table('cm1',
Field('code', type='integer'),
Field('title_en', type='string'),
Field('title_it', type='string'))

#Table for update - Useful for not changing id's, and also if in your table 
you've some referenced fields.
db.define_table('cm1_for_update',
Field('code', type='integer'),
Field('title_en', type='string'),
Field('title_it', type='string')).

def update_cm1():
form = SQLFORM.factory(Field('csvfile','upload',uploadfield=False))
form.process()
if form.accepted:
csvtxt = request.vars.csvfile.file.read()
#SET FILE FOR IMPORT - It's possible that you've to change some 
data in your csv file before import
#Replacing decimal separator ',' by '.'
csvtxt = csvtxt.replace(',', '.')
#Replacing field separator ';' by ','
csvtxt = csvtxt.replace(';', ',')
#Replacing field names
csvtxt = csvtxt.replace('Codice_N,Descrizione_Breve,Descr_Inglese',
'cm1.code,cm1.title_it,cm1.title_en')
db(db.cm1_for_update.id > 0).delete() #Cancel all records of 
cm1_for_update table
db.cm1_for_update.import_from_csv_file(StringIO(csvtxt)) #Import 
CSV file in cm1_for_update table
cm1s_for_update = db().select(db.cm1_for_update.ALL)
for cm1_for_update in cm1s_for_update:
n_rows = db(db.cm1.code == cm1_for_update.code).count() #Verify 
how many records are already in the cm1 table
if n_rows == 1: #Update
db(db.cm1.code == cm1_for_update.code).update(
title_en = cm1_for_update.title_en,
title_it = cm1_for_update.title_it)
elif n_rows == 0: #Insert
db.cm1.insert(
code=cm1_for_update.code,
title_en = cm1_for_update.title_en,
title_it = cm1_for_update.title_it)
elif n_rows > 1:
message=('Error, there are duplicated rows.')
break

Il giorno giovedì 12 gennaio 2017 16:46:35 UTC+1, 黄祥 ha scritto:
>
> imagine table with thousands data
> e.g.
> name quantity price 
> product a 10 1 
> product b 15 11000 
>
> and every several months (5 or 6 months) the supplier send the update of 
> the product price
> is it possible to import csv that can update some existing data (*not 
> insert new data*) in existing table?
> e.g.
> TABLE product
> name,price
> product a,11000
> product b,12000
>
> END
>
> thanks and best regards,
> stifan
>

-- 
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] add_button to go to the previous page

2017-01-12 Thread Gael Princivalle
I use this solution, not so 'beautiful' but it works.

In the layout I save the current URL like this:
{{current_url = URL(args=request.args, vars=request.get_vars)}}
I do it in the layout like that I'm sure to always doing it.

After that you can add where you need it in a link this current_url as a 
var, for using it for turning back to the previous page.

Il giorno giovedì 12 gennaio 2017 20:36:32 UTC+1, Andrea Fae' ha scritto:
>
> request.env.http_referer contains all URL starting with http://..., I need 
> the last part after /. Thank you
>
> Il giorno giovedì 12 gennaio 2017 18:45:58 UTC+1, Gaurav Vichare ha 
> scritto:
>>
>> request.env.http_referer contains link to the referrer page, i. e. 
>> previous page!
>>
>> On Thursday, January 12, 2017 at 7:55:26 PM UTC+5:30, Andrea Fae' wrote:
>>>
>>> I don't know what is the previous page because this page can come from 
>>> different pages...this is the problem...I want to reference the previous 
>>> page... thank you
>>>
>>> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
>>> scritto:

 example:

 form.add_button("Annulla",URL('default','index'))

 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :

> with this:
>
> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>
> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>
>> I have this situation
>> form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False, 
>> next='lista_pc')
>> form.add_button("Annulla",URL('lista_pc'))
>> 
>> I want that button "annulla" go in the previus page, not in the 
>> 'lista_pc'.
>> How to do?
>> thank you
>>
>> -- 
>> 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] Re: model define_table select

2017-01-12 Thread Pierre Corbeil
Good day Luca/Massimo,
Can you show me the final code ..i'am trying to do exactly that. 
(unsure of what you have done exactly in db.py)
Thanks

Le lundi 28 mars 2016 05:51:33 UTC-4, lucas a écrit :
>
> yes massimo,
>
> that almost worked.  as suggested, i first changed it under the db.py 
> model and then set the request.vars.state_id to the state_id variable just 
> before creating and assigning the SQLFORM under the controller module.  it 
> threw back an empty set of counties.  so i thought maybe request isn't 
> reaching that deep into the db.py module.  so i changed the request.vars 
> into session, like session.state_id = state_id, and also under db.py and 
> that worked great.
>
> i am always amazed of how fast and efficiently i can get things done using 
> web2py.  it really is a wonder and wonderful.
>
> thanx massimo.  lucas
>
> On Sunday, March 27, 2016 at 11:17:19 AM UTC-4, Massimo Di Pierro wrote:
>>
>> Correction. replace
>>
>> IS_IN_DB(db_region(*db_region.post.state_id==db_region.county.state_id*)
>>
>> with
>>
>> IS_IN_DB(db_region(*db_region.county.state_id == **request.vars.state_id*
>> )
>>
>

-- 
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] add_button to go to the previous page

2017-01-12 Thread Dave S


On Thursday, January 12, 2017 at 11:36:32 AM UTC-8, Andrea Fae' wrote:
>
> request.env.http_referer contains all URL starting with http://..., I need 
> the last part after /. Thank you
>

Python has the urlparse functions.  Indeed, web2py uses that stuff.



/dps
 

>
> Il giorno giovedì 12 gennaio 2017 18:45:58 UTC+1, Gaurav Vichare ha 
> scritto:
>>
>> request.env.http_referer contains link to the referrer page, i. e. 
>> previous page!
>>
>> On Thursday, January 12, 2017 at 7:55:26 PM UTC+5:30, Andrea Fae' wrote:
>>>
>>> I don't know what is the previous page because this page can come from 
>>> different pages...this is the problem...I want to reference the previous 
>>> page... thank you
>>>
>>> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
>>> scritto:

 example:

 form.add_button("Annulla",URL('default','index'))

 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :

> with this:
>
> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>
> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>
>> I have this situation
>> form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False, 
>> next='lista_pc')
>> form.add_button("Annulla",URL('lista_pc'))
>> 
>> I want that button "annulla" go in the previus page, not in the 
>> 'lista_pc'.
>> How to do?
>> thank you
>>
>> -- 
>> 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] Re: Order of form.vars not same as they appear in form

2017-01-12 Thread Anthony
form.vars is a dict-like object, so not guaranteed to return keys in any 
particular order. If the form is based on a db table, you can iterate 
through db.table._fields. The form object also includes the list of field 
names in form.fields.

Anthony

On Thursday, January 12, 2017 at 1:37:03 PM UTC-5, Rahul Priyadarsi wrote:
>
> Currently I see that the order in which the fields appear in form is not 
> same when i iterate through form.vars
> I am using SQLFORM.
>
> So how do I get the form.vars so that they appear in same order as they do 
> on the form?
>

-- 
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] add_button to go to the previous page

2017-01-12 Thread Andrea Fae'
request.env.http_referer contains all URL starting with http://..., I need 
the last part after /. Thank you

Il giorno giovedì 12 gennaio 2017 18:45:58 UTC+1, Gaurav Vichare ha scritto:
>
> request.env.http_referer contains link to the referrer page, i. e. 
> previous page!
>
> On Thursday, January 12, 2017 at 7:55:26 PM UTC+5:30, Andrea Fae' wrote:
>>
>> I don't know what is the previous page because this page can come from 
>> different pages...this is the problem...I want to reference the previous 
>> page... thank you
>>
>> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
>> scritto:
>>>
>>> example:
>>>
>>> form.add_button("Annulla",URL('default','index'))
>>>
>>> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :
>>>
 with this:

 form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))

 2017-01-10 8:44 GMT-02:00 Andrea Fae' :

> I have this situation
> form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False, 
> next='lista_pc')
> form.add_button("Annulla",URL('lista_pc'))
> 
> I want that button "annulla" go in the previus page, not in the 
> 'lista_pc'.
> How to do?
> thank you
>
> -- 
> 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] Re: DAL _before_update callback

2017-01-12 Thread Dave S
On Thursday, January 12, 2017 at 7:53:05 AM UTC-8, lyn2py wrote:
>
> Well... after taking time out to write the entire story... my mistake.
>

The first step in code reviews is publishing the code   :-)  Does a lot to 
clarify the mind!

 Glad you found the issue and got it sorted, and thanks for reporting back.

/dps


> In define_tables > Field, I assigned it (a long time ago) as "string" 
> instead of "integer". So the comparison was switched around, because it was 
> comparing a single digit, e.g. 5, to a double digit number, like 15. It's 
> all fixed per the web2py book when I enforced "int()". Gr. 
>
> On Thursday, January 12, 2017 at 11:35:12 PM UTC+8, lyn2py wrote:
>>
>> Hi guys, I just wanted to confirm this.
>>
>> The web2py book (link = 
>> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update)
>>  
>> says:
>> "The return values of these callback should be None or False. If any of 
>> the _before_* callback returns a True value it will abort the actual 
>> insert/update/delete operation."
>>
>> But my experience differs, I am comparing the value in db ("query set") 
>> and the value I am about to insert ("fields"). 
>> CRITERION: If the "query set" is a smaller value, abort the update 
>> operation.
>> So, per the instruction in the web2py book, I made it like so:
>> db.table._before_update.append(lambda s,f: qs(number)>
>> which means the "query set" is smaller than the "fields", then, it's 
>> TRUE, so, abort update. 
>>
>> But it didn't work until I switched the operator sign to make the 
>> statement FALSE, like so:
>> db.table._before_update.append(lambda s,f: qs(number)>f['number'])
>>
>> which means the "query set" is NOT smaller than the "fields". It would 
>> abort update. 
>>
>> Am I confused about something or does the web2py book need an edit/update?
>>
>> Thank you for reading!
>>
>

-- 
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] Order of form.vars not same as they appear in form

2017-01-12 Thread Rahul Priyadarsi
Currently I see that the order in which the fields appear in form is not 
same when i iterate through form.vars
I am using SQLFORM.

So how do I get the form.vars so that they appear in same order as they do 
on the form?

-- 
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] add_button to go to the previous page

2017-01-12 Thread Gaurav Vichare
request.env.http_referer contains link to the referrer page, i. e. previous 
page!

On Thursday, January 12, 2017 at 7:55:26 PM UTC+5:30, Andrea Fae' wrote:
>
> I don't know what is the previous page because this page can come from 
> different pages...this is the problem...I want to reference the previous 
> page... thank you
>
> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
> scritto:
>>
>> example:
>>
>> form.add_button("Annulla",URL('default','index'))
>>
>> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :
>>
>>> with this:
>>>
>>> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>>>
>>> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>>>
 I have this situation
 form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False, 
 next='lista_pc')
 form.add_button("Annulla",URL('lista_pc'))
 
 I want that button "annulla" go in the previus page, not in the 
 'lista_pc'.
 How to do?
 thank you

 -- 
 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] Issue with web2py load component

2017-01-12 Thread Gaurav Vichare
I have LOAD component in my application. I made changes in web2py/routes.py 
file and made my application default application, 'default' controller and 
'index' function as defaults. Also added function list of default.py 
controller in routes.py to distinguish between args and function 
name(https://groups.google.com/d/msg/web2py/yi5rPK4APKs/rVBg9AiShPUJ). Now 
when I open my app (http://127.0.0.1:8000/  or 
http://127.0.0.1:8000/test/default/index), load component div loads 
complete app in it, and this goes in loop. 

Here is routes.py and minimal code

#routes.py

routers = dict(

# base router
BASE=dict(
default_application='test',
default_controller = 'default',
default_function = 'index',
functions = ['index', 'user', 'download', 'call',
 'test_load'],
),)


--

# default.pydef index():
return dict(message=T('Welcome to web2py!'))
def test_load():
return dict(message=T('This is sample component'))

---

# Views{{extend 
'layout.html'}}{{=message}}{{=LOAD('default','test_load.load',ajax=True)}}

{{=message}}


Screenshot:



Please help me to solve this issue.

Thank You
- Gaurav

-- 
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] add_button to go to the previous page

2017-01-12 Thread Áureo Dias Neto
I do not know if this is the best way to do this, because it is not very
practical if you have several pages ..

2017-01-12 14:14 GMT-02:00 Áureo Dias Neto :

> you can take this:
>
> if user is in PageA, and click a button to go to another page, pass the
> name of the actual page as arg, before redirect.. example:
>
> -user is in PageA:
> on the button that redirect to another X page:
>
> form.add_button("Annulla",URL('default','PageX',args='PageA'))
>
>
> when user is on the PageX; you can fetch the arg on URL to back to PageA:
>
> previous_page = request.args(0)
>
> and the button to back to previous page:
>
> form.add_button("Annulla",URL('default',previous_page ))
>
> 2017-01-12 12:25 GMT-02:00 Andrea Fae' :
>
>> I don't know what is the previous page because this page can come from
>> different pages...this is the problem...I want to reference the previous
>> page... thank you
>>
>> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha
>> scritto:
>>>
>>> example:
>>>
>>> form.add_button("Annulla",URL('default','index'))
>>>
>>> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :
>>>
 with this:

 form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))

 2017-01-10 8:44 GMT-02:00 Andrea Fae' :

> I have this situation
> form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False,
> next='lista_pc')
> form.add_button("Annulla",URL('lista_pc'))
>
> I want that button "annulla" go in the previus page, not in the
> 'lista_pc'.
> How to do?
> thank you
>
> --
> 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.
>>
>
>

-- 
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] add_button to go to the previous page

2017-01-12 Thread Áureo Dias Neto
you can take this:

if user is in PageA, and click a button to go to another page, pass the
name of the actual page as arg, before redirect.. example:

-user is in PageA:
on the button that redirect to another X page:

form.add_button("Annulla",URL('default','PageX',args='PageA'))


when user is on the PageX; you can fetch the arg on URL to back to PageA:

previous_page = request.args(0)

and the button to back to previous page:

form.add_button("Annulla",URL('default',previous_page ))

2017-01-12 12:25 GMT-02:00 Andrea Fae' :

> I don't know what is the previous page because this page can come from
> different pages...this is the problem...I want to reference the previous
> page... thank you
>
> Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha
> scritto:
>>
>> example:
>>
>> form.add_button("Annulla",URL('default','index'))
>>
>> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto :
>>
>>> with this:
>>>
>>> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>>>
>>> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>>>
 I have this situation
 form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False,
 next='lista_pc')
 form.add_button("Annulla",URL('lista_pc'))

 I want that button "annulla" go in the previus page, not in the
 'lista_pc'.
 How to do?
 thank you

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

-- 
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: DAL _before_update callback

2017-01-12 Thread lyn2py
Well... after taking time out to write the entire story... my mistake.

In define_tables > Field, I assigned it (a long time ago) as "string" 
instead of "integer". So the comparison was switched around, because it was 
comparing a single digit, e.g. 5, to a double digit number, like 15. It's 
all fixed per the web2py book when I enforced "int()". Gr. 

On Thursday, January 12, 2017 at 11:35:12 PM UTC+8, lyn2py wrote:
>
> Hi guys, I just wanted to confirm this.
>
> The web2py book (link = 
> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update)
>  
> says:
> "The return values of these callback should be None or False. If any of 
> the _before_* callback returns a True value it will abort the actual 
> insert/update/delete operation."
>
> But my experience differs, I am comparing the value in db ("query set") 
> and the value I am about to insert ("fields"). 
> CRITERION: If the "query set" is a smaller value, abort the update 
> operation.
> So, per the instruction in the web2py book, I made it like so:
> db.table._before_update.append(lambda s,f: qs(number)
> which means the "query set" is smaller than the "fields", then, it's TRUE, 
> so, abort update. 
>
> But it didn't work until I switched the operator sign to make the 
> statement FALSE, like so:
> db.table._before_update.append(lambda s,f: qs(number)>f['number'])
>
> which means the "query set" is NOT smaller than the "fields". It would 
> abort update. 
>
> Am I confused about something or does the web2py book need an edit/update?
>
> Thank you for reading!
>

-- 
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] import csv that can update some existing data in existing table

2017-01-12 Thread 黄祥
imagine table with thousands data
e.g.
name quantity price 
product a 10 1 
product b 15 11000 

and every several months (5 or 6 months) the supplier send the update of 
the product price
is it possible to import csv that can update some existing data (*not 
insert new data*) in existing table?
e.g.
TABLE product
name,price
product a,11000
product b,12000

END

thanks and best regards,
stifan

-- 
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] DAL _before_update callback

2017-01-12 Thread lyn2py
Hi guys, I just wanted to confirm this.

The web2py book (link = 
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update)
 
says:
"The return values of these callback should be None or False. If any of the 
_before_* callback returns a True value it will abort the actual 
insert/update/delete operation."

But my experience differs, I am comparing the value in db ("query set") and 
the value I am about to insert ("fields"). 
CRITERION: If the "query set" is a smaller value, abort the update 
operation.
So, per the instruction in the web2py book, I made it like so:
db.table._before_update.append(lambda s,f: qs(number)f['number'])

which means the "query set" is NOT smaller than the "fields". It would 
abort update. 

Am I confused about something or does the web2py book need an edit/update?

Thank you for reading!

-- 
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] Grid search disregards time zone

2017-01-12 Thread icodk
My server is in UTC, my client is in Europe (time zones) .When client 
searches on a date time field the datetime string is sent in local time. 
The grid is showing datetime in local time as it should,using the great 
timezone plugin
(didn't work also before Breksit:-)

-- 
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] Problem with custom widget on edit form

2017-01-12 Thread Carlos Cesar Caballero Díaz
Hi, I am getting a problem with a custom widget 
(https://github.com/daxslab/web2py-typeahead/blob/master/modules/plugin_typeahead/typeahead.py) 
using SQLFORM, everything works fine but with the edit form, when I 
click on submit button the form is not updated with the new value (the 
new value is in db but not in the form), after that, if I refresh the 
form page, then the new value is there.


Any idea of what I might be doing wrong?

Greetings.

--
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] add_button to go to the previous page

2017-01-12 Thread Andrea Fae'
I don't know what is the previous page because this page can come from 
different pages...this is the problem...I want to reference the previous 
page... thank you

Il giorno martedì 10 gennaio 2017 11:48:42 UTC+1, Áureo Dias Neto ha 
scritto:
>
> example:
>
> form.add_button("Annulla",URL('default','index'))
>
> 2017-01-10 8:47 GMT-02:00 Áureo Dias Neto  >:
>
>> with this:
>>
>> form.add_button("Annulla",URL( 'CONTROLLER' , 'FUNCTION_NAME' ))
>>
>> 2017-01-10 8:44 GMT-02:00 Andrea Fae' :
>>
>>> I have this situation
>>> form = crud.update(db.pc, pc, onaccept=crud.archive, deletable=False, 
>>> next='lista_pc')
>>> form.add_button("Annulla",URL('lista_pc'))
>>> 
>>> I want that button "annulla" go in the previus page, not in the 
>>> 'lista_pc'.
>>> How to do?
>>> thank you
>>>
>>> -- 
>>> 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] mixing ldap Active Directory authentication and local authentication

2017-01-12 Thread Andrea Fae'
Hello,
I want to use both local and domain AD authentication.
I did the job but I want to see Profile and change password ONLY for local 
users and not for domain users.
How to do?
Thank you

-- 
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] Are executesql parameters escaped?

2017-01-12 Thread Jorrit
When I use *db.executesql* like so:

birthdays = db.executesql("SELECT * FROM auth_user WHERE  DAYOFYEAR(curdate() 
-2) < dayofyear(dateOfBirth) "
  "AND DAYOFYEAR(curdate()) +7 >= 
dayofyear(dateOfBirth) "
  "AND employeeState_id = {1} AND location_id IN 
(SELECT location_id FROM clusterLocation WHERE cluster_id={0}) ORDER BY 
MONTH(dateOfBirth), "
  "DAY(dateOfBirth);".format(cluster, active_id), 
as_dict=True)


...are the cluster and active_id parameters SQL-escaped? If not what is the 
best way to do this?

-- 
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: Arbitrary args/kwargs with service?

2017-01-12 Thread Anthony
Feel free to open a Github issue, or better yet, send a pull request.

Depending on your use case, another option is to instead decorate the 
call() action in order to pass in extra args (you can strip them out of 
request.args and request.vars before the service method gets called).

Anthony

On Wednesday, January 11, 2017 at 11:01:56 PM UTC-5, Brendan Barnwell wrote:
>
> On Thursday, January 5, 2017 at 7:04:56 AM UTC-8, Anthony wrote:
>>
>> But from the other side of things, I guess the question is, if we can do 
>>> that, is there ever any reason to use the "service" mechanism at all?  Or 
>>> can request.restful do everything service can do, and more?
>>>
>>
>> I suppose their use cases are overlapping. If @request.restful works for 
>> you in this case, then use it. The @service mechanism lets you easily 
>> expose functions for use in remote procedure calls, including via 
>> standardized RPC protocols. The @service decorators also automatically 
>> return the correct response format, whereas @request.restful requires the 
>> use of the generic views (disabled by default) to automatically generate 
>> different response formats (though it will automatically generate JSON if 
>> the request specifies "application/json").
>>
>> Anthony
>>
>
>
> I guess the request.restful approach works better for me at this point.  
> Is there a way to tell web2py to enable generic views only for restful 
> controller functions, and disable them otherwise?
>
> In continuing to explore both approaches, I gained a better understanding 
> of my problem with the service approach, and I want to share it here 
> because I think it is worth thinking about in terms of the design of 
> web2py.  The problem I have with the service approach is that it seems to 
> make impossible to use a decorator to wrap a service controller function in 
> order to add or remove arguments, because the service function will "block" 
> web2py from seeing what arguments the real service function accepts, 
> causing web2py to pass the wrong arguments.
>
> There is a certain Python idiom that goes something like this:
>
> def accept_extra_arg(func):
> def wrapper(extra_arg, *args, **kwargs):
> # maybe do something with extra_arg here
> result = func(*args, **kwargs)
> # maybe do something with extra_arg here
> return result
> return wrapper
>
> @accept_extra_arg
> def foo(x, y):
> return x+y
>
> The idea is that the accept_extra_arg decorator allows you to wrap your 
> function with a handler that accepts an extra argument which the function 
> does not see, but which is used to preprocess the function's arguments 
> and/or postprocess its result.  In the case of web APIs, for instance, this 
> is a natural way to do something like write a series of API functions that 
> require an API key to be used: you can have a @requires_key decorator that 
> wraps functions, allowing the function itself to be "pure" and just 
> concentrate on returning the data, without having to handle the checking of 
> the API key.  There is a related idiom which is the reverse, involving 
> writing a decorator that accepts an argument and returns a decorated 
> function accepting *fewer* arguments that the original, allowing a behavior 
> akin to functools.partial, by which some arguments are specified in advance 
> via the decorator, rather than being passed on each call to the decorated 
> function.
>
> The web2py service mechanism breaks this idiom.  The problem is that 
> because the wrapped function is supposed to be agnostic as to the arguments 
> of the function it wraps, it just accepts *args and **kwargs (in addition 
> to its extra argument).  This means that web2py won't pass it anything.  
> This kind of breaks the RPC idea that calling the function internally 
> should be the same as calling it via the network API: if my function wants 
> to use *args and/or **kwargs, web2py apparently doesn't provide a way for 
> me to use it in a seamless manner for internal vs external calls.
>
> I *think* I have been able to get around this with request.restful, 
> because it passes everything along without trying to match the arguments.  
> But it is somewhat annoying for the case of read-only APIs because of the 
> extra layer of indirection required (returning a function that returns the 
> data, rather than just returning the data).
>
> What I really want is the ability to write an arbitrary function, 
> accepting arbitrary arguments.  I want the ability to wrap that function 
> with decorators that absorb or add arguments as I please.  And then I want 
> to be able to expose that arbitrarily wrapped function as a service 
> endpoint (presumably by wrapping the function with a web2py decorator as 
> the last one).  I don't want any of the decorators nor the original 
> function ever to have to worry about *how* the arguments are being passed 
> (e.g., positionally or by keyword), and I don't want any function in the