[web2py] Re: Retrieving values from appconfig.ini to a view

2018-10-30 Thread 黄祥
pls try in views/layout.html (untested)
{{=appconf.take("app.version") }}

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: Mongodb Error

2018-10-30 Thread 黄祥
from the error traceback seems like a problem with a connection to mongodb, 
wrong password or username, pls ensure the authentication to mongodb 
connection is correct

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: Retrieving values from appconfig.ini to a view

2018-10-30 Thread Dave S


On Tuesday, October 30, 2018 at 7:41:09 AM UTC-7, Francis Windram wrote:
>
> Good Evening,
>
> I'm a relative newby to web2py, but with a few years of Python under my 
> belt and old knowledge of HTML (from the pre-HTML5 days).
>
> When I deploy a new release, part of the procedure is to update the 
> version line in appconfig.ini, e.g.:
>
> [app] 
> appname = Webapp
> version = 1.0.0 
>
> to
>
> [app] 
> appname = Webapp
> version = 1.0.1 
>
>
>
> Now this all works fine, but I want to display this as part of the footer 
> in a form akin to:
>
> Webapp v1.0.1, Copyright © 2018
>
> This footer is currently generated in (the default) layout.html as follows:
>
> 
>   
> {{=T('Copyright')}}  
> {{=request.now.year}}
>  
> {{=T('Powered by')}}
> http://www.web2py.com/;>web2py
>   
>   
> 
>
>
> I know that in a controller you can access the appconfig args using code 
> along the lines of:
>
> from gluon.contrib.appconfig import AppConfig
>
> appconf = AppConfig(reload=False)
> print(appconf.take("app.version"))
>
>
> However, I have no idea how to do a similar call to the appconfig 
> variables from a view.
> Any ideas? Do I need a controller to serve this information to the view? 
> And if so, in what controller file would that controller reside?
>
> Many thanks,
> Francis
>

Views are assembled on the server (except for things like jQuery), and have 
a "this piece is python" syntax which you can see in the footer example  
{{=T('Copyright')}} // Apply T() to the string 'Copyright' and insert here
{{=request.now.year}}  // insert here the value of request.now.year

-- 
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: STYLE() function has been changed in 2.17.2

2018-10-30 Thread Dave S


On Tuesday, October 30, 2018 at 12:49:48 PM UTC-7, A3 wrote:
>
>  Python version 2.7.6 
>

The reason I ask is because the "bytes expected" message makes me think 
this is a corner of the Py3 adaptation that might not have been tested much.

/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: Multiprocessing and Web2py Scheduler

2018-10-30 Thread Dave S


On Tuesday, October 30, 2018 at 7:41:09 AM UTC-7, Daniel R. wrote:
>
> Hello,
>
> I've been working on an application in Web2py for a while now and, for the 
> most part, I've been able to find answers to my questions online. However, 
> I am having trouble now trying to figure out if I can use Python 
> multiprocessing along with the Scheduler in Web2py in the way that I need 
> to do so.
>
> Essentially, I have an application that, upon some specified user input, 
> the application needs to run one or more resource-intensive calculations 
> (which can take upwards of an hour to complete). That being said, all the 
> calculations need to run in the background and the results need to be 
> reported back to the user. To deal with running the calculations in the 
> background, I have decided that I will use the Web2py built-in scheduler 
> and to deal with the resource-intensive aspect of the problem I am using 
> the Python multiprocessing Pool class so that the application can take 
> advantage of the multiple cores in the server that the application will be 
> running on.
>
> Starting the calculations using the Scheduler and multiprocessing has been 
> fairly painless. However, I lock a bunch of UI stuff so that the user can't 
> make changes while the tests are running, and, since the tests take so 
> long, another requirement is that the user has the ability to cancel all 
> the calculations (if they've made a mistake or have changed their mind 
> about waiting more time for the calculations to complete). The problem that 
> I'm having is that I cannot figure out how to use Web2py to cancel these 
> tests.
>
> I understand that to end a task is not complicated, and that to terminate 
> the worker processes using the Python multiprocessing module all I need to 
> do is call Pool.terminate(). The reason I'm having trouble doing this is 
> that I can't find any way to persistently store these Pool instances to 
> access them from another request.
>
> I have been considering that a potential solution may be using cache.ram, 
> if that will allow me to store a dictionary of these Pool instances. 
> However, I am open to any other potential solutions, like if there's 
> another way to get back to the correct Pool instance, if there's another 
> way to create a persistent global (like a Queue) that I can use to 
> communicate with the workers, or any other potential solutions.
>
> If I seem to have any misunderstandings or if I need to clarify anything 
> more please let me know.
>


I would have looked at keeping it all in the Scheduler, but I admit that I 
haven't delved deeply into the multiprocessing aspects of the Scheduler, 
since I rarely need more than 1 worker at a time.  Perhaps worker 1 can 
schedule worker 2 for you, etc.

I can tell you that the controller that schedules your first worker knows 
the task number for that worker, and report it to the user to be used in 
the cancel URL.  If you try the cascade of workers technique, then worker 1 
would know the task number for worker 2, and can log that somehow for the 
cancel controller.  The crudest way of logging would be to print it ... 
stdout for a worker is collected into task_run table, but you could also 
put it in an ordinary db table (which I suppose isn't really different from 
your thought of cache.ram).

I think there was also a few posts a while ago about doing a progress bar 
on the client based on worker status.  Oh, it was actually in the book, 
using a special string fed to print() and available in task_run, so 
monitoring has an example.
http://web2py.com/books/default/chapter/29/04/the-core#Reporting-progress-percentages>
(I don't have any additional examples of this; I do fire-and-leave, with 
the result sent via email.)

/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: STYLE() function has been changed in 2.17.2

2018-10-30 Thread A3
 Python version 2.7.6 

Op dinsdag 30 oktober 2018 20:28:53 UTC+1 schreef Dave S:
>
>
>
> On Tuesday, October 30, 2018 at 4:15:49 AM UTC-7, A3 wrote:
>>
>> I recently upgraded to 2.17.2 and now I noticed that some of my apps 
>> functions don't work anymore.
>> in the past I used e.g.: STYLE(XML('body {color: white}')) 
>> this caused an error: (Expected bytes)
>>
>> after removing XML() you can use STYLE('body {color: white}')
>> but it gives the following output: 
>> 
>>
>> Is this an intended change or a bug?
>>
>>
> What version of Python are you running on?
>
> /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: STYLE() function has been changed in 2.17.2

2018-10-30 Thread Dave S


On Tuesday, October 30, 2018 at 4:15:49 AM UTC-7, A3 wrote:
>
> I recently upgraded to 2.17.2 and now I noticed that some of my apps 
> functions don't work anymore.
> in the past I used e.g.: STYLE(XML('body {color: white}')) 
> this caused an error: (Expected bytes)
>
> after removing XML() you can use STYLE('body {color: white}')
> but it gives the following output: 
> 
>
> Is this an intended change or a bug?
>
>
What version of Python are you running on?

/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] Multiprocessing and Web2py Scheduler

2018-10-30 Thread Daniel R.
Hello,

I've been working on an application in Web2py for a while now and, for the 
most part, I've been able to find answers to my questions online. However, 
I am having trouble now trying to figure out if I can use Python 
multiprocessing along with the Scheduler in Web2py in the way that I need 
to do so.

Essentially, I have an application that, upon some specified user input, 
the application needs to run one or more resource-intensive calculations 
(which can take upwards of an hour to complete). That being said, all the 
calculations need to run in the background and the results need to be 
reported back to the user. To deal with running the calculations in the 
background, I have decided that I will use the Web2py built-in scheduler 
and to deal with the resource-intensive aspect of the problem I am using 
the Python multiprocessing Pool class so that the application can take 
advantage of the multiple cores in the server that the application will be 
running on.

Starting the calculations using the Scheduler and multiprocessing has been 
fairly painless. However, I lock a bunch of UI stuff so that the user can't 
make changes while the tests are running, and, since the tests take so 
long, another requirement is that the user has the ability to cancel all 
the calculations (if they've made a mistake or have changed their mind 
about waiting more time for the calculations to complete). The problem that 
I'm having is that I cannot figure out how to use Web2py to cancel these 
tests.

I understand that to end a task is not complicated, and that to terminate 
the worker processes using the Python multiprocessing module all I need to 
do is call Pool.terminate(). The reason I'm having trouble doing this is 
that I can't find any way to persistently store these Pool instances to 
access them from another request.

I have been considering that a potential solution may be using cache.ram, 
if that will allow me to store a dictionary of these Pool instances. 
However, I am open to any other potential solutions, like if there's 
another way to get back to the correct Pool instance, if there's another 
way to create a persistent global (like a Queue) that I can use to 
communicate with the workers, or any other potential solutions.

If I seem to have any misunderstandings or if I need to clarify anything 
more please let me know.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: off topic: pg_dump syntax for pythonanywhere

2018-10-30 Thread Alexandra Lee
Could you post what the correct syntax is please?  It is 2018 and 
pythonanywhere has corrected --username but I am having a problem with 
--file and database. In psql help -file seems to be for the file from which 
to execute not the file to which to write. So I remain confused ! 

On Wednesday, 3 February 2016 02:38:42 UTC+1, Alex Glaros wrote:
>
> got it to work but doesn't seem to match pythonAnywhere documentation: 
> https://help.pythonanywhere.com/pages/RegularPostgresBackups
>
> for example, instead of "--name=" should be "--username=",  and filename has 
> extra error-causing parm ("mydb")
>
> type this in bash console to get Postgres help: psql --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] Re: Auth question

2018-10-30 Thread fjbernal2020
Hi,

I think the easier way is here 
http://web2py.com/books/default/chapter/29/09/access-control

 

> ## after auth = Auth(db)
>
>  
>
db.define_table('workspaces',
>
> Field('workspace', 'string', requires=IS_NOT_EMPTY()))
>
 
>
auth.settings.extra_fields['auth_user']= [
>   Field('workspace', 'reference workspaces', label=T('workspace')]
>
>  
>
db.auth_user.workspace.requires = IS_IN_DB(db, db.workspaces.id, 
'%(workspace)s')
>
>  
I din't try, but I would :)

-- 
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] Creating a CSV backup for the database file in the app

2018-10-30 Thread Francis Windram
You should just be able to use a relative path, i.e.
"./static/dbbackup/backup.csv" rather than
"C:/Users/me/Desktop/web2py/applications/webapp1/static/dbbackup/backup.csv".

("../" would take you to one folder above where you started, and "../../"
would go two folder levels up. )

You may need to set up the folder structure appropriately first.

I hope that's somewhat helpful!

Thanks,
Francis

On Tue, 23 Oct 2018, 19:44 mostwanted,  wrote:

> I have a folder in my desktop that contains a CSV file that backs up
> information everytime something gets saved into the database. What i wanna
> know is how can I instead have this folder and CSV backup file saved in the
> app somewhere so that even if i relocate the application or take it online
> i don't have redefine the folder path or have it missing because the path
> was not defined correctly.
>
> *CONTROLLER SAVING TO THE EXTERNAL CSV FILE:*
> def index():
> form=SQLFORM(db.Customer)
> if form.accepts(request.vars, session):
> customer=db(db.Customer).select(db.Customer.ALL)
> #db.export_to_csv_file(open('C:/Users/me/Desktop/backup/backup.csv',
> 'wb'))
> customer.export_to_csv_file(open(
> 'C:/Folder1/Backup/Client_Bookings_Backup.csv', 'wb'))
> response.flash = T("CLIENT BOOKED")
> elif form.errors:
> response.flash = T("BOOKING FAILED! Please observe the form!")
> return locals()
>
> Regards:
>
> Mostwanted
>
> --
> 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] Retrieving values from appconfig.ini to a view

2018-10-30 Thread 'Francis Windram' via web2py-users
Good Evening,

I'm a relative newby to web2py, but with a few years of Python under my 
belt and old knowledge of HTML (from the pre-HTML5 days).

When I deploy a new release, part of the procedure is to update the version 
line in appconfig.ini, e.g.:

[app] 
appname = Webapp
version = 1.0.0 

to

[app] 
appname = Webapp
version = 1.0.1 



Now this all works fine, but I want to display this as part of the footer 
in a form akin to:

Webapp v1.0.1, Copyright © 2018

This footer is currently generated in (the default) layout.html as follows:


  
{{=T('Copyright')}}  
{{=request.now.year}}
 
{{=T('Powered by')}}
http://www.web2py.com/;>web2py
  
  



I know that in a controller you can access the appconfig args using code 
along the lines of:

from gluon.contrib.appconfig import AppConfig

appconf = AppConfig(reload=False)
print(appconf.take("app.version"))


However, I have no idea how to do a similar call to the appconfig variables 
from a view.
Any ideas? Do I need a controller to serve this information to the view? 
And if so, in what controller file would that controller reside?

Many thanks,
Francis

-- 
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] Mongodb Error

2018-10-30 Thread lbjc1978
I'm trying to use MongoDB for the first time. I looked at this 

 link 
as one of the guidance. but ended up with an error.
My code below:

from gluon import current
from pymongo import MongoClient
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
from gluon.custom_import import track_changes
track_changes(True)
db = DAL('mongodb://username:password@localhost/test', pool_size=0)
Post = db.define_table('post',
   Field('author', 'reference auth_user', default=auth.
user_id, writable=False, readable=False),
   Field('comments', 'text', requires=IS_NOT_EMPTY(),
 default ="Hi there it's me", notnull=False),
   auth.signature
   )




Error:

  File "/home/maurice/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
  File "/home/maun/web2py/applications/boyeve/models/db2.py" 
, line 12, in 

db = DAL('mongodb://username:password@localhost/test', pool_size=0)
  File "/usr/local/lib/python2.7/dist-packages/pydal/base.py", line 169, in 
__call__
obj = super(MetaDAL, cls).__call__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pydal/base.py", line 474, in 
__init__
"Failure to connect, tried %d times:\n%s" % (attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pydal/base.py", line 454, in 
__init__
self._adapter = adapter(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/__init__.py", 
line 40, in __call__
obj = super(AdapterMeta, cls).__call__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/base.py", line 
52, in __init__
self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/pydal/helpers/classes.py", line 
184, in _reconnect_and_configure
self._configure_on_first_reconnect()
  File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 
79, in _configure_on_first_reconnect
"serverStatus")['version']
  File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 611, 
in command
read_preference) as (sock_info, slave_ok):
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 
1101, in _socket_for_reads
with self._get_socket(server) as sock_info:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 
1058, in _get_socket
with server.get_socket(self.__all_credentials) as sock_info:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 1006, in 
get_socket
sock_info.check_auth(all_credentials)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 677, in 
check_auth
auth.authenticate(credentials, self)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 563, in 
authenticate
auth_func(credentials, sock_info)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 540, in 
_authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 262, in 
_authenticate_scram
res = sock_info.command(source, cmd)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 579, in 
command
unacknowledged=unacknowledged)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/network.py", line 150, 
in command
parse_write_concern_error=parse_write_concern_error)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 155, 
in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
OperationFailure: Authentication failed.


I need help to solve this

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] STYLE() function has been changed in 2.17.2

2018-10-30 Thread A3
I recently upgraded to 2.17.2 and now I noticed that some of my apps 
functions don't work anymore.
in the past I used e.g.: STYLE(XML('body {color: white}')) 
this caused an error: (Expected bytes)

after removing XML() you can use STYLE('body {color: white}')
but it gives the following output: 


Is this an intended change or a bug?




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