[web2py] Re: https and stripe

2016-10-26 Thread Jaimee S
interesting, so what you're saying is that once i deploy to python anywhere 
ill no longer have any problems with setting up Nginx. Great! Will the 
payment part of my website still be accessible, just not trusted, without 
an ssl certificate? 

On Wednesday, October 26, 2016 at 1:56:04 AM UTC-5, Anthony wrote:
>
>
> scripts/setup-web2py-nginx-uwsgi-on-centos.sh
>> scripts/setup-web2py-nginx-uwsgi-ubuntu.sh'''
>>
>> Does this mean that once I complete these steps then I'll have 
>> successfully deployed to nginx and that I'm able to access the website from 
>> online?
>>
>
> Yes, though you will need to take additional steps for access via a domain 
> name rather than just the IP address of your server (i.e., you need to 
> register a domain name and configure the nameservers so it points to your 
> domain). Also, the web2py scripts set up a self-signed certificate, which 
> is fine for development use or your personal access to admin, but it will 
> generate browser warnings for regular users, so you will want a certificate 
> from a certificate authority for production purposes.
>  
>
>> Here is some information that I found online just now:
>> '''
>> PythonAnywhere is an online Integrated Development Environment (IDE) and 
>> Web hosting service based on the Python programming language. '''
>>
>> '''Nginx can be deployed to serve dynamic HTTP content on the network 
>> using FastCGI, SCGI handlers for scripts, WSGI application servers or 
>> Phusion Passenger modules, and it can serve as a software load 
>> balancer.[9]'''
>>
>> Based off of the links you sent on nginx, I'm assuming that i'll need to 
>> switch from developing my site on my localhost to the nginx software. Why? 
>>
>
> localhost refers to the location of the server (your local machine), not 
> the software you use to serve HTTP requests. You can run Nginx on your 
> localhost if you want.
>
> In development, you might be using the web2py built-in Rocket server. This 
> server is a fairly basic web server written in Python -- it is not 
> recommended for production, as there are much faster (and likely more 
> reliable/stable) options, such as Nginx+uWSGI.
>  
>
>> I get a feeling that nginx provides some sort of encryption. An 
>> encryption that pythonanywhere doesn't. Am I wrong? Am I comparing apples 
>> and oranges because they aren't similar?
>>
>
> No, nothing to do with encryption.
>  
>
>> Ultimately, I plan on releasing my website when it's almost finished and 
>> tampering with it while it's live kind of like Kanye wests album release. 
>> Python anywhere seems to provide me with that ability. Will I need to 
>> switch my app from localhost to nginx an then deploy to pythonanywhere?
>>
>
> If you deploy to Pythonanywhere, they actually take care of setting up the 
> web server for you (that's part of the value of their service -- they make 
> deployment simple by handling the server administration). In fact, 
> Pythonanywhere will serve your app via Nginx+uWSGI (but you don't have to 
> bother with it at all).
>
> 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.


Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-26 Thread António Ramos
but there were no record to update. it should have created a record.
as i said i created a rruid field in an existing table and the first time i
run the update_or_insert the rruid field of all the records were empty.

Anyway i solved without update_or_insert...

2016-10-26 5:23 GMT+01:00 Anthony :

> On Tuesday, October 25, 2016 at 5:12:39 PM UTC-4, Ramos wrote:
>>
>> Yes i added a new field to an existing table.
>> So all of them became empty in that field.
>> i then executed
>> than i have another app that calls a controller in this app and passes
>> some data in request.vars
>> the controller in this app then does this
>> id=db.empresa.update_or_insert(db.empresa.ruuid==request.var
>> s.ruuid,empresa=entity,tipo='tr',ruuid=request.vars.uuid)
>> and strangely when none of the rows still have that extra field written,
>> it updates the first one with the lower id.
>> I deleted that row and tried again. Again the next id was updated.
>>
>
> .update_or_insert is for updated a *single* record -- if multiple records
> match your query, it will only find and update the first one.
>
> 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.
>

-- 
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: Web2py tool : Send emails to multiple user on schedule basis

2016-10-26 Thread Dave S


On Tuesday, August 16, 2016 at 11:00:11 AM UTC-7, Dave S wrote:
>
>
>
> On Tuesday, August 16, 2016 at 4:58:11 AM UTC-7, madhu nomula wrote:
>>
>> Thank you. 
>> I moved the code to Model. But could you please share me steps that 
>> how to schedule(trigger) it send emails. 
>>
>>
> I thought my suggested code was pretty clear.  sched_tasks() sets up the 
> task to run every day.  The task then checks to see if it needs to send 
> mail to everybody or just to the slow responders.
>
> If you want to schedule the task to run just twice a month, then you 
> change the "86400" to (approximately) 1209600.  I say "approximately" 
> because that value if for "every two weeks".  To do the 1st and 16th, you 
> need to figure out how much time there is from "now" to the 1st or 16th.  
> You'd use a standard Python datetime.timedelta to figure that out.  
>

As I figured out more recently (like in an answer I posted a few hours 
ago), you don't really need a time delta, you just need to figure out if 
the next run is "this month" or "next month' (1-12, not 0-11), and use 
next_run_time.
 

> You can make sched_tasks() start just the first run, and have the task 
> itself schedule itself (actually, another task instance running the same 
> code); in that case, the call to scheduler.queue_task() will set repeats=0.
>
> Please read 
>  http://web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler>
> for details about the scheduler.
>
>
/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: order by the greater of 2 fields

2016-10-26 Thread Anthony Smith


On Wednesday, 26 October 2016 15:25:35 UTC+11, Anthony wrote:
>
> Hi all, 
>> This gets the results using sql but only able to do one or the other is 
>> the controller in web2py
>> select * from animalTask order by 
>> GREATEST(COALESCE(withhold_until_date,0),COALESCE(esi_withhold_until_date,0))
>>  
>> DESC 
>>
>
> What do you mean by "one or the other" -- what is "the other"?
>
> Anthony
>

I meant it would only order by 1 field not the other,but the sql works fine.
just implementing it now  

I will work on it 

cheers

-- 
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] Migrate integer field to string type

2016-10-26 Thread Richard Vézina
Yes is you do it within the shell you better commit every 100 records
depending of the size of the record, but since it just a single column and
integer you can commit even every 500-1000 records I guess without issue...

To do so you can use this snippet :

for i, r in enumerate(db.select()):
db.table.insert(something)
if i % 100 == 0:
db.commit()



On Tue, Oct 25, 2016 at 2:20 PM, Dave S  wrote:

>
>
> On Tuesday, October 25, 2016 at 8:08:28 AM UTC-7, Ian W. Scott wrote:
>>
>> Okay, that's what I was afraid of. Thanks.
>>
>> Ian
>>
>> On Tuesday, October 25, 2016 at 10:06:19 AM UTC-4, Richard wrote:
>>>
>>> You can't just change the field type, you have to create another column
>>> of string type then insert your data from a select of the other column into
>>> it then delete the old useless column... You need to transform the integer
>>> into text at the insert step...
>>>
>>> Richard
>>>
>>
> I would try using a csv export/import.  If it's a large table, I can see
> some pain, but it should be simple in python, awk, or even sed to toss in
> quotes in the right column.
>
> /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.
>

-- 
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: tasks hierarchy

2016-10-26 Thread Pierre
yes i am aware of the scheduler new deps feature
this would require to know every single task id to build the parent 
children relation
I don't know what's in the queue, tasks are queued in arbitrary order and 
the queue evolves constantly so i can't scan single task ids

alltogether the scheduler does a pretty good job

I encounter this only once :

*2016-10-25 14:55:28,137 - web2py.scheduler.hp533#4326 - ERROR - Error 
coordinating TICKER  *

is this some kind of fatal error ?


-- 
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: Deployment question

2016-10-26 Thread Richard Vézina
Version of soft are not so differents so config may still be used without
changes, but this should be double check... For instance, for me, config
had change significantly since 12.04 related to systemd... Nginx not much
but uwsgi has change. It may wise to check for deprecated uwsgi parameter
flag, depending if you use the web2py deployment script or not as the
script is up to date for 16.04.

:)

Richard

On Tue, Oct 25, 2016 at 2:56 PM, Jim S  wrote:

> mcm - thanks for that.
>
> On Tuesday, October 25, 2016 at 12:23:27 PM UTC-5, mcm wrote:
>>
>> One clarification ... better performance is mostly due to the fact that
>> the python GIL is not getting in the way
>>
>> 2016-10-25 19:20 GMT+02:00 Michele Comitini :
>>
>>> > Regarding switching uwsgi to fork-only - should I expect a performance
>>> hit?
>>>
>>> Unless you are very low on RAM you should expect better performance.
>>> Linux fork is a clone call  that uses fully fledged copy-on-write strategy.
>>> Uwsgi forks are long running processes so forking overhead has little
>>> impact. Forks happen late in the request handling chain so memory across
>>> processes diverges little even on long periods.
>>>
>>>  Keep an eye on RSS usage of processes (use top or htop) if you see a
>>> memory runaway over time, uwsgi will take care of it killing the faulty
>>> long running process.  Memory runaway happening too frequently could be
>>> an indication that there is something wrong with your code or some module
>>> you use not releasing some large in memory structure.
>>>
>>>
>>>
>>> 2016-10-25 18:09 GMT+02:00 Jim S :
>>>
 Richard

 Just checked my versions and my old systems that work have:

 uwsgi 2.0.10
 nginx 1.4.6
 web2py 2.14.6

 New system that needs altered uwsgi config

 uwsgi 2.0.14
 nginx 1.10.0
 web2py 2.14.6

 My uwsgi configs are identical except for the commented out 'limit-as =
 512' line.  Nginx configs are identical.


 Regarding switching uwsgi to fork-only - should I expect a performance
 hit?  Any other gotchas I should consider?

 I'm not too concerned as my pages that use pandas have been working
 just fine for almost 6 months now.  But, can never be too careful...

 Really appreciate all the input.

 -Jim



 On Tuesday, October 25, 2016 at 9:50:36 AM UTC-5, Richard wrote:
>
> Jim which web server are we talking now? Nginx? I think you should
> copy/paste configuration so we can have look, I can compare to mine... 
> Just
> the relevant part would suffice...
>
> About threading notice of pandas it says holding lock in case of
> multiple dataframe copy, but Jim report he can't even import pandas as
> pd... So I don't think it the root cause of his issue... But it good to
> know I wasn't aware of that...
>
> Some good read about uwsgi relate to threading :
>
> http://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html (search
> for thread)
>
> http://uwsgi-docs.readthedocs.io/en/latest/articles/Serializ
> ingAccept.html (I notice I have thunder-lock = true in my
> emperor.ini)
>
> I would compare our nginx/uwsgi conf to see if there is not some diff
> that could explained your issue... I am also curious to know if I could
> have threading issue with pandas in my app...
>
> Richard
>
>
>
> On Tue, Oct 25, 2016 at 8:32 AM, Jim Steil  wrote:
>
>> Massimo / Michele
>>
>> Thanks for the input.  I don't know anything about fork only mode.
>> Looks like I have some reading to do.  Thanks again for the input.
>>
>> -Jim
>>
>>
>> On Tue, Oct 25, 2016 at 4:02 AM, Michele Comitini <
>> michele@gmail.com> wrote:
>>
>>> @Jim as per Massimo input, did you check that your uwsgi
>>> configuration is in fork mode only, no threading?  That could be one
>>> possible cause.
>>>
>>> Try also gunicorn instead of uwsgi http://gunicorn.org/
>>>
>>> 2016-10-25 7:19 GMT+02:00 Massimo Di Pierro :
>>>
 Rocket is a multithreaded server and pandas is not thread safe (
 http://pandas.pydata.org/pandas-docs/stable/gotchas.html) be very
 careful with it.


 On Tuesday, 16 August 2016 13:19:42 UTC-5, Dave S wrote:
>
>
>
> On Tuesday, August 16, 2016 at 8:50:51 AM UTC-7, Jim S wrote:
>>
>> Hi
>>
>> I currently have my app deployed using Ubuntu 14.04 / nginx /
>> uwsgi.  I have a couple of servers load-balanced behind a haproxy 
>> server.
>> I'm running ssl on the haproxy system and talking http to web2y 
>> through
>> nginx/uwsgi.
>>
>> Now, I'm trying to upgrade ubuntu to 16.04 and an having issues
>> with pandas (used in my web2py app) through the nginx/uwsgi stack.  
>>

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-26 Thread Anthony
On Wednesday, October 26, 2016 at 4:07:45 AM UTC-4, Ramos wrote:
>
> but there were no record to update. it should have created a record.
> as i said i created a rruid field in an existing table and the first time 
> i run the update_or_insert the rruid field of all the records were empty.
>

Here's the code for update_or_insert:

def update_or_insert(self, _key=DEFAULT, **values):
if _key is DEFAULT:
record = self(**values)
elif isinstance(_key, dict):
record = self(**_key)
else:
record = self(_key)
if record:
record.update_record(**values)
newid = None
else:
newid = self.insert(**values)
return newid

It's hard to say what's going wrong in your case without knowing more about 
the rest of the code and data. Perhaps request.vars.ruuid is None and 
therefore matching all the records.

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.


Re: [web2py] Re: Deployment question

2016-10-26 Thread Jim Steil
The config I'm using is the one that comes from the web2py installer for
ubuntu/nginx/uwsgi in the scripts directory.  So, if that were the case, I
think more people would be seeing it too.

-Jim

On Wed, Oct 26, 2016 at 9:06 AM, Richard Vézina  wrote:

> Version of soft are not so differents so config may still be used without
> changes, but this should be double check... For instance, for me, config
> had change significantly since 12.04 related to systemd... Nginx not much
> but uwsgi has change. It may wise to check for deprecated uwsgi parameter
> flag, depending if you use the web2py deployment script or not as the
> script is up to date for 16.04.
>
> :)
>
> Richard
>
> On Tue, Oct 25, 2016 at 2:56 PM, Jim S  wrote:
>
>> mcm - thanks for that.
>>
>> On Tuesday, October 25, 2016 at 12:23:27 PM UTC-5, mcm wrote:
>>>
>>> One clarification ... better performance is mostly due to the fact that
>>> the python GIL is not getting in the way
>>>
>>> 2016-10-25 19:20 GMT+02:00 Michele Comitini :
>>>
 > Regarding switching uwsgi to fork-only - should I expect a
 performance hit?

 Unless you are very low on RAM you should expect better performance.
 Linux fork is a clone call  that uses fully fledged copy-on-write strategy.
 Uwsgi forks are long running processes so forking overhead has little
 impact. Forks happen late in the request handling chain so memory across
 processes diverges little even on long periods.

  Keep an eye on RSS usage of processes (use top or htop) if you see a
 memory runaway over time, uwsgi will take care of it killing the faulty
 long running process.  Memory runaway happening too frequently could
 be an indication that there is something wrong with your code or some
 module you use not releasing some large in memory structure.



 2016-10-25 18:09 GMT+02:00 Jim S :

> Richard
>
> Just checked my versions and my old systems that work have:
>
> uwsgi 2.0.10
> nginx 1.4.6
> web2py 2.14.6
>
> New system that needs altered uwsgi config
>
> uwsgi 2.0.14
> nginx 1.10.0
> web2py 2.14.6
>
> My uwsgi configs are identical except for the commented out 'limit-as
> = 512' line.  Nginx configs are identical.
>
>
> Regarding switching uwsgi to fork-only - should I expect a performance
> hit?  Any other gotchas I should consider?
>
> I'm not too concerned as my pages that use pandas have been working
> just fine for almost 6 months now.  But, can never be too careful...
>
> Really appreciate all the input.
>
> -Jim
>
>
>
> On Tuesday, October 25, 2016 at 9:50:36 AM UTC-5, Richard wrote:
>>
>> Jim which web server are we talking now? Nginx? I think you should
>> copy/paste configuration so we can have look, I can compare to mine... 
>> Just
>> the relevant part would suffice...
>>
>> About threading notice of pandas it says holding lock in case of
>> multiple dataframe copy, but Jim report he can't even import pandas as
>> pd... So I don't think it the root cause of his issue... But it good to
>> know I wasn't aware of that...
>>
>> Some good read about uwsgi relate to threading :
>>
>> http://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html (search
>> for thread)
>>
>> http://uwsgi-docs.readthedocs.io/en/latest/articles/Serializ
>> ingAccept.html (I notice I have thunder-lock = true in my
>> emperor.ini)
>>
>> I would compare our nginx/uwsgi conf to see if there is not some diff
>> that could explained your issue... I am also curious to know if I could
>> have threading issue with pandas in my app...
>>
>> Richard
>>
>>
>>
>> On Tue, Oct 25, 2016 at 8:32 AM, Jim Steil  wrote:
>>
>>> Massimo / Michele
>>>
>>> Thanks for the input.  I don't know anything about fork only mode.
>>> Looks like I have some reading to do.  Thanks again for the input.
>>>
>>> -Jim
>>>
>>>
>>> On Tue, Oct 25, 2016 at 4:02 AM, Michele Comitini <
>>> michele@gmail.com> wrote:
>>>
 @Jim as per Massimo input, did you check that your uwsgi
 configuration is in fork mode only, no threading?  That could be one
 possible cause.

 Try also gunicorn instead of uwsgi http://gunicorn.org/

 2016-10-25 7:19 GMT+02:00 Massimo Di Pierro 
 :

> Rocket is a multithreaded server and pandas is not thread safe (
> http://pandas.pydata.org/pandas-docs/stable/gotchas.html) be very
> careful with it.
>
>
> On Tuesday, 16 August 2016 13:19:42 UTC-5, Dave S wrote:
>>
>>
>>
>> On Tuesday, August 16, 2016 at 8:50:51 AM UTC-7, Jim S wrote:
>>>
>>> Hi
>>>
>>> I currently have my app deployed using Ubu

[web2py] Re: https and stripe

2016-10-26 Thread Anthony
On Wednesday, October 26, 2016 at 3:08:41 AM UTC-4, Jaimee S wrote:
>
> interesting, so what you're saying is that once i deploy to python 
> anywhere ill no longer have any problems with setting up Nginx. Great! Will 
> the payment part of my website still be accessible, just not trusted, 
> without an ssl certificate?
>

Correct -- though the browser will make it very daunting for any user to 
get to any HTTPS page on your site, so it's not a realistic option for 
production. For example, here is what Chrome shows:
 



To proceed, the user actually has to click the "Advanced" link and then 
follow another link (which is labeled "unsafe").

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: SQLFORM grid search : Get ids of filtered records

2016-10-26 Thread Anthony
Note, the "searchable" argument can be a custom callable -- so, you can 
create a custom function that first calls the default internal query 
builder to get the query that filters the records, then run the update 
using that query, and then simply return the query for use by the grid. 
Here is an example:

def index():
grid_query = db.person.id > 0
selectable=[('Set Selected True', selected_true_callback),
('Set All True', all_true_callback)]
if 'keywords' in request.get_vars:
selectable.append(('Set Filtered True', lambda r: None))

def update_filtered(sfields, keywords):
search_query = SQLFORM.build_query(sfields, keywords)
if 'submit_2' in request.post_vars:
db(grid_query & search_query).update(myboolean=True)
return search_query

grid = SQLFORM.grid(grid_query, user_signature=False, selectable=
selectable,
searchable=update_filtered)
return dict(grid=grid)

In the above, "selectable" is a list of tuples defining two or three 
buttons corresponding to updating selected, all, or (optionally) filtered 
records. The grid will name each button "submit_0", "submit_1", and 
"submit_2", respectively. Whenever a search request comes in, the grid will 
call update_filtered (passing in the search fields and keywords). This 
function first simply calls the built-in query builder, just as the grid 
normally would, generating a DAL query for the search. The code determines 
if the "Set Filtered True" button was clicked by checking for "submit_2" in 
request.post_vars. In that case, it defines the filtered set of records by 
applying the main query for the grid in addition to the search query, and 
then updates that set of records (note, if your first argument to 
SQLFORM.grid is just a table rather than a query, you can skip the 
grid_query part of the code). Finally, it returns the search query for the 
grid to use as usual.

Note, in "selectable", the callback function for "Set Filtered True" is 
simply a do-nothing lambda function, as there won't actually be any 
selected records in this case -- we're just using "selectable" as a 
convenient way to add an additional submit button to the grid.

Anthony

On Tuesday, October 25, 2016 at 2:35:00 AM UTC-4, Madhavi wrote:
>
> Hi,
>
> I am new to web2py and am working on application with a SQLFORM grid with 
> the search feature along with selectable option. I added extra buttons to 
> my grid to set a boolean value for selected records using selectable 
> feature, and added another button to set a boolean value for all the 
> records in the table. Now, I also want to add a button the set this value 
> for only filtered records using the search feature. Is there a way using 
> which I can refer to the ids of only those records which are filtered 
> through the search widget to perform this manipulation only on those 
> records? To explain better, I have the below buttons in place:
>
> 1. Set true for all selected records
> 2. Set true for all records
>
> I also want to add an option to:
>
> 3. Set true for filtered records (filtered records refer to the ones 
> displayed on performing the search in the grid).
>
> Please let me know if this is possible,
>
> Thanks a ton,
>
> Madhavi
>

-- 
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: https and stripe

2016-10-26 Thread Jaimee S
OK, that warning would definitely cost me customers. I'll get right on that ssl 
right away. Thanks for the big tips!

-- 
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] Setting up nginx to enable CORS for a specific function?

2016-10-26 Thread Spokes
This isn't necessarily a web2py-specific question, but perhaps there's a 
web2py-specific solution that's preferable to other solutions, so I thought 
I'd ask it here.

I have some HTML code and javascript, which I'd like to be able to paste 
into any website, and which should access an API endpoint on a web2py 
server. The web2py application is running on an nginx server.

The javascript portion of the client code snippet is as follows: 


$(document).on("click", "button", function(e){
...
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://myurl.com/api/action/";); 
   
xhr.setRequestHeader("Content-Type", 
"application/json");
var jsonStr = JSON.stringify({
   Header:{Procedure:"..."},
   Body: { ... }
});
xhr.send(jsonStr);
});


When the button that triggers the above action is clicked, the following 
error is generated (in Chrome):

XMLHttpRequest cannot load https://myurl.com/api/action. Response to 
preflight request doesn't pass access control check: No 
'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://127.0.0.1:8000' is therefore not allowed access.

As I understand it, this issue can be resolved by enabling CORS in the 
nginx settings . However, I'd 
like to limit the modification to that one API function, which corresponds 
to the application/controller/function combo, "[MyApplication]/api/action". 
I'd appreciate recommendations on how to do this within the context of 
web2py running on nginx. Alternatively, is there a modification to the 
client javascript code (I'd like to keep the code small, so any 
modification would have to not exceed a couple of lines) that would remedy 
the problem? 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.


Re: [web2py] Setting up nginx to enable CORS for a specific function?

2016-10-26 Thread Michele Comitini
You can do that easily in web2py...

Below is a sample of a decorator that allows any origin.
Change it to fit your needs.

You can use in a controller like:

@cors_allow
def action():
   .
   .
   .
   return dict(...)

--

def cors_origin():
origin = request.env.http_origin
headers = {}
headers['Access-Control-Allow-Origin'] = origin

headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS, POST, HEAD,
PUT'
headers['Access-Control-Allow-Headers'] =
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept'
headers['Access-Control-Allow-Credentials'] = 'true';
response.headers.update(headers)

if request.env.request_method == 'OPTIONS':
headers['Content-Type'] = None
raise HTTP(200, '', **headers)


def cors_allow(action):

def f(*args, **kwargs):
cors_origin()
return action(*args, **kwargs)

f.__doc__ = action.__doc__
f.__name__ = action.__name__
f.__dict__.update(action.__dict__)

return f


2016-10-26 20:19 GMT+02:00 Spokes :

> This isn't necessarily a web2py-specific question, but perhaps there's a
> web2py-specific solution that's preferable to other solutions, so I thought
> I'd ask it here.
>
> I have some HTML code and javascript, which I'd like to be able to paste
> into any website, and which should access an API endpoint on a web2py
> server. The web2py application is running on an nginx server.
>
> The javascript portion of the client code snippet is as follows:
>
> 
> $(document).on("click", "button", function(e){
> ...
> var xhr = new XMLHttpRequest();
> xhr.open("POST", "https://myurl.com/api/action/";);
>
> xhr.setRequestHeader("Content-Type",
> "application/json");
> var jsonStr = JSON.stringify({
>Header:{Procedure:"..."},
>Body: { ... }
> });
> xhr.send(jsonStr);
> });
> 
>
> When the button that triggers the above action is clicked, the following
> error is generated (in Chrome):
>
> XMLHttpRequest cannot load https://myurl.com/api/action. Response to
> preflight request doesn't pass access control check: No
> 'Access-Control-Allow-Origin' header is present on the requested resource.
> Origin 'http://127.0.0.1:8000' is therefore not allowed access.
>
> As I understand it, this issue can be resolved by enabling CORS in the
> nginx settings . However, I'd
> like to limit the modification to that one API function, which corresponds
> to the application/controller/function combo,
> "[MyApplication]/api/action". I'd appreciate recommendations on how to do
> this within the context of web2py running on nginx. Alternatively, is there
> a modification to the client javascript code (I'd like to keep the code
> small, so any modification would have to not exceed a couple of lines) that
> would remedy the problem? 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.
>

-- 
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] Select query returns value with type

2016-10-26 Thread xgp . latino
Hi all,

Got this query: 

for row in db().select( db.X.YY.year(), distinct=True, 
orderby=db.X.YY.year(), ):
 ayears.append(  row[ db.X.YY.year() ] )
 count = db( db.X.YY.year() == row( db.X.YY.year() ) 
).count()


Don't know why all rows return the values with an L at the end of the of 
it: [2015L, 6249L, 2016L, 9632L] 
This doesnt happend when its html print.


Any ideas?


Regards,


-- 
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 query returns value with type

2016-10-26 Thread Anthony
The DAL parses all integer values into Python *long* integers 
.
 
The representation of long integers includes a trailing "L", but the "L" is 
not included when converting to a string:

>>> mylongint = long(5)
>>> repr(mylongint)
5L

>>> str(mylongint)
5

Anthony

On Thursday, October 27, 2016 at 12:53:06 AM UTC-4, xgp.lat...@gmail.com 
wrote:
>
> Hi all,
>
> Got this query: 
>
> for row in db().select( db.X.YY.year(), distinct=True, 
> orderby=db.X.YY.year(), ):
>  ayears.append(  row[ db.X.YY.year() ] )
>  count = db( db.X.YY.year() == row( db.X.YY.year() ) 
> ).count()
>
>
> Don't know why all rows return the values with an L at the end of the of 
> it: [2015L, 6249L, 2016L, 9632L] 
> This doesnt happend when its html print.
>
>
> Any ideas?
>
>
> Regards,
>
>
>

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