[web2py] Re: How to limit access to administrative interface?

2017-01-08 Thread Sepehr Mohamadi
I got it myself!
I should disable admin interface at all on a production server! And make 
another local web2py just in case:

http://web2py.com/books/default/chapter/29/13/deployment-recipes?search=administrative+interface#Securing-sessions-and-admin


On Sunday, January 8, 2017 at 9:37:03 AM UTC+3:30, Sepehr Mohamadi wrote:
>
> Hi every body!
>
> I wonder how to limit access to administrative interface?
> I read a lot how to grant access control to users in a project,
> But found no document about how to limit access to administrative 
> interface?
>
> Can I limit it to special IPs?
> Can I add 2FA?
> Can I add Captcha?
> ...
>

-- 
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] Self-hosted web analytics solutions for Web2py

2017-01-08 Thread Joe
Thanks for the link Richard,

I just copied everything and tried it but I am getting this error: 
OperationalError: no such table: usage_statistics

I think I am missing a step.

Can you please advise.

Thanks.

Cheers,

Joe





On Friday, January 6, 2017 at 11:12:36 PM UTC+8, Richard wrote:
>
> You can look on the side of piwik : https://piwik.org/
>
> If you only want to log your users activity and don't need that much of 
> analytic you can have look at this slice : 
>
>
> http://www.web2pyslices.com/slice/show/1618/basic-usage-statistics-log-what-your-users-do
>
> But it has a drawback which is that it makes an insert each time users 
> make request... Plus you don't have any analytics, graph, you have to forge 
> your own query to trend your data.
>
> Here there was discussion about improving this contrib by making it less 
> database intensive : 
> https://groups.google.com/d/msg/web2py/659_7_hDiks/947KRwtQDssJ
>
> good luck
>
> Richard
>
>
>
> On Fri, Jan 6, 2017 at 8:12 AM, Joe > 
> wrote:
>
>> I am interested in using a self-hosted web analytics solutions on 
>> Pythonanywhere for my Web2py apps.
>> I asked this question on the Pythonanywhere forum, they suggested to ask 
>> here.
>> Can anyone suggest the best solution for this and let me know the easiest 
>> way to install it on the server? 
>> Thanks.
>> Cheers,
>> Joe
>>
>> -- 
>> 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: Rest Json

2017-01-08 Thread PK


On Saturday, January 7, 2017 at 9:45:15 PM UTC, 黄祥 wrote:
>
> pls try :
> ### Change user with email if username is disabled
> ### Check patterns in 
> http://127.0.0.1:8000/application/controller/api/patterns.json
>
> ## curl
> # GET
> curl -X GET --user user:password -i 
> http://127.0.0.1:8000/application/controller/api/books.json
> # POST
> curl -X POST --user user:password -i -d "name=name0&website=website0" 
> http://127.0.0.1:8000/application/controller/api/books.json
> # PUT
> curl -X PUT --user user:password -i -d "name=name1&website=website1" 
> http://127.0.0.1:8000/application/controller/api/books/2.json
> # DELETE
> curl -X DELETE --user user:password -i 
> http://127.0.0.1:8000/application/controller/api/books/2.json
>
> ## Python using requests
> import requests
> from requests.auth import HTTPBasicAuth 
> payload_0 = {"name": "name0", "website": "website0"}
> payload_1 = {"name": "name1", "website": "website1"}
> auth = HTTPBasicAuth('user', 'password')
> # GET
> r = requests.get("
> http://127.0.0.1:8000/application/controller/api/bank.json";, auth = 
> auth).json()
> print r
> # POST
> r = requests.post("
> http://127.0.0.1:8000/application/controller/api/bank.json";, data = 
> payload_0, auth = auth)
> # PUT
> r = requests.put("
> http://127.0.0.1:8000/application/controller/api/bank/2.json";, data = 
> payload_1, auth = auth)
> # DELETE
> r = requests.delete("
> http://127.0.0.1:8000/application/controller/api/bank/2.json";, auth = 
> auth)
>
> best regards,
> stifan
>

Thank.it helps me a lots. i worked Python. it work well.
But My Front End is Android  and i want to know how auth user and password 
login work in restapi .
how should i send data to server .

-- 
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] response.flash or session.flash with dict instead of string???

2017-01-08 Thread António Ramos
hello i´m using toastr as a replacement form the web2py flash html.

For toastr i need the message and the type of message ,info error success.

My question is if is it safe and possible to set

response.flash=dict(type="error",mesg="test message")

regards

Antonio

-- 
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] Help needed simplifying creation of response.menu 4-tuple

2017-01-08 Thread Terrence Brannon
I attempted to simplify creation of the response.menu list of tuples by the 
following function:


def menu_item(menu_item_text, url, sub_menu=None, ignore=False):
# First element of tuple is the text of the meny item.
retval = list(menu_item_text)

# Second element of the tuple indicates if this menu item is the
# current active one.
retval.append(url == URL())

# Third element is the link to follow when this item is selected.
retval.append(url)

# The fourth item is an optional sub_menu.
if sub_menu:
retval.append(sub_menu)
else:
retval.append([])

retval.append(ignore)

return retval


but when using it like so:

def public_menu():

response.menu += [
menu_item('How it Works', URL('default', 'how_it_works')),
menu_item('Testimonials', URL('default', 'testimonials')),
menu_item('Sign up Now!', URL('default', 'register')),
menu_item('Login'   , URL('default', 'login')),
]

if auth.is_logged_in():
logged_in_menu()
else:
public_menu()


I get the error:

127.0.0.1.2017-01-08.19-46-22.ca7178e4-a2b2-48f7-8463-81d2c8f70f27
 need more than 1 value to unpack Version 
web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

Traceback (most recent call last):
  File 
"/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/restricted.py", line 
227, in restricted
exec ccode in environment
  File 
"/home/schemelab/domains/org/metaperl/web2py/web2py/applications/refbank/views/default/index.html",
 line 59, in 
  File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/globals.py", 
line 430, in write
self.body.write(xmlescape(data))
  File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", line 
131, in xmlescape
return data.xml()
  File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", line 
2580, in xml
return self.serialize(self.data, 0).xml()
  File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", line 
2545, in serialize
li.append(self.serialize(item[3], level + 1))
  File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", line 
2525, in serialize
(name, active, link) = item[:3]
ValueError: need more than 1 value to unpack


-- 
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] response.flash or session.flash with dict instead of string???

2017-01-08 Thread Anthony
Try it and see. ;-)

-- 
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] Installed applications

2017-01-08 Thread new2py
Hi, 

This may be a dumb question, but I have saved/installed apps on my web2py 
account, but when I login from another computer, my apps are no longer 
there ( only when I login from my home computer (which they were created 
on). Is there any way to pull them up outside of my home computer? If I 
take my home computer with me somewhere else will they show up, as well? 

Thanks for your help. 

-- 
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 share a variable between the web users in Web2Py without a database

2017-01-08 Thread Alwyn Pan
I have a Web2Py webapp which is a web interface for a blastn script. Now I 
need to limit the process running simultaneously, my thought is,

When the webapp starts, the way I did is, in default.py:

available_worker = multiprocessing.cpu_count() - 1


def get_workers():
global available_worker
return available_worker


def consume_worker():
global available_worker
available_worker = available_worker - 1


def free_worker():
global available_worker
available_worker = available_worker + 1


def index():
if get_workers() > 0:
consume_worker()
# run a script
free_worker()
print get_workers()


Obviously, it will not work as every time the web loads, it resets the 
available_worker to `multiprocessing.cpu_count() - 1`.

I am just wondering, if there is a way I can share the availabe_worker 
across the web sessions or users. 

So by the time a user A loads the page, the `available_worker` is 2, he 
runs the script. While user A is running the script, a user B loads the 
webapp, and he gets `available_worker` is 1, and he runs the script. While 
A and B are running the script, the a user C comes, he gets 
`available_worker` is 0, so he has to wait until either A or B finishes the 
script before he can run the script.

I am new to programming, a detailed explanation and sample code will be 
much much appreciated. 

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.


Re: [web2py] Self-hosted web analytics solutions for Web2py

2017-01-08 Thread Joe
Thanks for the link Richard,

This is great! I deployed it and it works perfectly.
BTW: what is the best way to include a unique session id for each visit in 
the 'usage_statistics' table?

On Friday, January 6, 2017 at 11:12:36 PM UTC+8, Richard wrote:
>
> You can look on the side of piwik : https://piwik.org/
>
> If you only want to log your users activity and don't need that much of 
> analytic you can have look at this slice : 
>
>
> http://www.web2pyslices.com/slice/show/1618/basic-usage-statistics-log-what-your-users-do
>
> But it has a drawback which is that it makes an insert each time users 
> make request... Plus you don't have any analytics, graph, you have to forge 
> your own query to trend your data.
>
> Here there was discussion about improving this contrib by making it less 
> database intensive : 
> https://groups.google.com/d/msg/web2py/659_7_hDiks/947KRwtQDssJ
>
> good luck
>
> Richard
>
>
>
> On Fri, Jan 6, 2017 at 8:12 AM, Joe > 
> wrote:
>
>> I am interested in using a self-hosted web analytics solutions on 
>> Pythonanywhere for my Web2py apps.
>> I asked this question on the Pythonanywhere forum, they suggested to ask 
>> here.
>> Can anyone suggest the best solution for this and let me know the easiest 
>> way to install it on the server? 
>> Thanks.
>> Cheers,
>> Joe
>>
>> -- 
>> 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] Connecting new table to mysql db on Pythonanywhere

2017-01-08 Thread Joe
I have a table already defined in my app and it's connected to mysql on 
Pythonanywhere.
I wanted to define an other table in the same app but I am unable to 
connect this new table to db.

In my db.py file I have this:

*if not request.env.web2py_runtime_gae:*
*## if NOT running on Google App Engine use SQLite or other DB*
*db = 
DAL('mysql:myaccount.mysql.pythonanywhere-services.com/myaccount$dbname')*

This works as expected for the table already defined, but when I try to 
define an other table it crashes.
I get this error:

ProgrammingError: ( "Table 'myaccount$dbname.tablename' doesn't exist")


I am probably missing something obvious.

Can anyone advise me on this please?

Thanks.

Cheers,

Joe


-- 
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: Help needed simplifying creation of response.menu 4-tuple

2017-01-08 Thread Dave S


On Sunday, January 8, 2017 at 12:04:07 PM UTC-8, Terrence Brannon wrote:
>
> I attempted to simplify creation of the response.menu list of tuples by 
> the following function:
>
>
> def menu_item(menu_item_text, url, sub_menu=None, ignore=False):
> # First element of tuple is the text of the meny item.
> retval = list(menu_item_text)
>
> # Second element of the tuple indicates if this menu item is the
> # current active one.
> retval.append(url == URL())
>
> # Third element is the link to follow when this item is selected.
> retval.append(url)
>
> # The fourth item is an optional sub_menu.
> if sub_menu:
> retval.append(sub_menu)
> else:
> retval.append([])
>
> retval.append(ignore)
>
> return retval
>
>
> but when using it like so:
>
> def public_menu():
>
> response.menu += [
> menu_item('How it Works', URL('default', 'how_it_works')),
> menu_item('Testimonials', URL('default', 'testimonials')),
> menu_item('Sign up Now!', URL('default', 'register')),
> menu_item('Login'   , URL('default', 'login')),
> ]
>
> if auth.is_logged_in():
> logged_in_menu()
> else:
> public_menu()
>
>
> I get the error:
>
> 127.0.0.1.2017-01-08.19-46-22.ca7178e4-a2b2-48f7-8463-81d2c8f70f27
>  need more than 1 value to unpack
>

I think you have to have something for the 4th value; if there is no 
submenu, try putting None in that spot.


/dps


 

> Version 
> web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
>   File 
> "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/restricted.py", 
> line 227, in restricted
> exec ccode in environment
>   File 
> "/home/schemelab/domains/org/metaperl/web2py/web2py/applications/refbank/views/default/index.html",
>  line 59, in 
>   File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/globals.py", 
> line 430, in write
> self.body.write(xmlescape(data))
>   File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", 
> line 131, in xmlescape
> return data.xml()
>   File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", 
> line 2580, in xml
> return self.serialize(self.data, 0).xml()
>   File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", 
> line 2545, in serialize
> li.append(self.serialize(item[3], level + 1))
>   File "/home/schemelab/domains/org/metaperl/web2py/web2py/gluon/html.py", 
> line 2525, in serialize
> (name, active, link) = item[:3]
> ValueError: need more than 1 value to unpack
>
>
>

-- 
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: Installed applications

2017-01-08 Thread Dave S


On Sunday, January 8, 2017 at 4:50:45 PM UTC-8, new2py wrote:
>
> Hi, 
>
> This may be a dumb question, but I have saved/installed apps on my web2py 
> account, but when I login from another computer, my apps are no longer 
> there ( only when I login from my home computer (which they were created 
> on). Is there any way to pull them up outside of my home computer? If I 
> take my home computer with me somewhere else will they show up, as well? 
>
> Thanks for your help. 
>


What are you using for hosting?

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