[web2py] Re: How can I run a command once at launch?

2019-09-04 Thread 'Francis Windram' via web2py-users
Wonderful, thanks Dave! This is probably the correct approach for me to 
take.

And that is a fair point, I think for the most part I organised it like 
that to prevent drift (though I do know of the preventdrift argument to 
schedule_task()) and ensure that the task always queued for 2200 the next 
day.

That said, looking at the problem with fresh eyes it does seem to be a 
simpler and more sensible option just to use the built-in rescheduling 
function.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/7f727cf5-c854-48e6-bcc4-a175184e9a66%40googlegroups.com.


[web2py] How can I run a command once at launch?

2019-09-02 Thread 'Francis Windram' via web2py-users
Hi All,

Seems like a simple question here but I am struggling with finding an 
elegant solution.

I have a scheduler running with one task that runs at around 2200 every 
night, then queues the next run at 2200 the next day. However I am at a 
loss on how to trigger off the first run (aside from a one-off script to 
schedule the first run)

Adding a piece of code in the model which checks whether an eod_run job is 
in the scheduler table and schedules one if not seems like it adds a lot of 
overhead, considering the models are run very regularly.
Assuming that all things work properly, once the scheduler runs one job, it 
should just queue the next one, but I'm not sure if that persists over 
server shutdowns.

Do you have any suggestions? I could drop down and use a cron job on the 
server itself, or using the cron functionality in web2py, but that feels 
like stepping backwards when we have a perfectly functional scheduler 
already enabled.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/155e91c6-bb4b-4957-a148-383f7b29f603%40googlegroups.com.


[web2py] Re: How can I return a report to the user in the view?

2019-04-29 Thread 'Francis Windram' via web2py-users
Brilliant, thank you! The pre tags worked exactly as required.

-- 
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: Inconsistent file upload behaviour

2019-03-27 Thread 'Francis Windram' via web2py-users
Just to add to this, I've done some further testing and can confirm a few 
more bits about the inconsistency.

Firstly the behaviour is not browser-specific, occurring in both firefox 
and chrome.

Secondly it seems to fail always when running web2py normally. When running 
in the debugger in pycharm it *sometimes* works, and sometimes fails in 
precisely the same manner. I am somewhat at my wits end.

My only thoughts are either a caching issue or a race condition, but I 
can't see any immediate reason for either of these. Even when starting with 
a fresh session we seem to see this behaviour...

On Tuesday, 26 March 2019 11:50:06 UTC, Francis Windram wrote:
>
> Hi All,
>
> I'm having a very very weird problem with some upload processing I'm 
> performing in web2py.
> Firstly for context here is the code I am using:
>
> Controller:
> def validate_test():
> form = SQLFORM.factory(
> Field('csvfile', 'upload'), table_name="dataset_upload")
> if form.validate():
> logger.info("form validating")
> candidate_file = request.vars.csvfile.file.read()
> logger.info("{}".format(candidate_file))
> elif form.process().accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
> return dict(form=form)
>
>
> And the View:
> {{extend 'layout.html'}}
>
>  class="jumbotron">
> 
> {{=form}}
> 
>
> This is essentially as simple as it can be. The user should upload a csv 
> file, and I wish to run a suite of validators on that csv file before 
> returning to the user whether the validation was passed or where it failed 
> and on what.
>
> Now this is the first step, just checking that the form csv is readable by 
> the server. And here is where I hit the problem:
> Sometimes I get out (as expected) the contents of the csv file from logger
> .info("{}".format(candidate_file))
> Most of the time I just get out a blank string, even with the same input 
> file!
>
> I feel like I'm going mad, doing the same thing twice and getting 
> different results. It smells to me like caching or race conditions but I 
> just have no idea what really is going on or why this might be happening.
>
> Do you have any ideas?
>
> Thanks!
>
> P.S. also more generally is this a good way to perform validation on a csv 
> file without any database IO? I want users to be able to check whether 
> their file fits the canonical format prior to actually attempting to commit 
> it to the database?
> It would be nice to be able to use the Web2Py validators to do this 
> validation, but I don't really want to start creating temporary staging 
> tables to perform this validation prior to upload, especially as I have a 
> multi-table structure which the data will be going in to, but it comes in 
> as a flat csv.
>

-- 
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] Inconsistent file upload behaviour

2019-03-26 Thread 'Francis Windram' via web2py-users
Hi All,

I'm having a very very weird problem with some upload processing I'm 
performing in web2py.
Firstly for context here is the code I am using:

Controller:
def validate_test():
form = SQLFORM.factory(
Field('csvfile', 'upload'), table_name="dataset_upload")
if form.validate():
logger.info("form validating")
candidate_file = request.vars.csvfile.file.read()
logger.info("{}".format(candidate_file))
elif form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)


And the View:
{{extend 'layout.html'}}



{{=form}}


This is essentially as simple as it can be. The user should upload a csv 
file, and I wish to run a suite of validators on that csv file before 
returning to the user whether the validation was passed or where it failed 
and on what.

Now this is the first step, just checking that the form csv is readable by 
the server. And here is where I hit the problem:
Sometimes I get out (as expected) the contents of the csv file from logger.
info("{}".format(candidate_file))
Most of the time I just get out a blank string, even with the same input 
file!

I feel like I'm going mad, doing the same thing twice and getting different 
results. It smells to me like caching or race conditions but I just have no 
idea what really is going on or why this might be happening.

Do you have any ideas?

Thanks!

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


[web2py] Re: Selecting from SQLFORM grid generated using a join selects incorrect IDs

2018-11-19 Thread 'Francis Windram' via web2py-users

That works perfectly! Thank you very much

On Monday, 19 November 2018 14:38:55 UTC, Anthony wrote:
>
> With joins, you have to specify the ID field explicitly:
>
> SQLFORM.grid(..., field_id=db.applics1.id)
>
> Anthony
>
> On Monday, November 19, 2018 at 4:48:14 AM UTC-5, Francis Windram wrote:
>>
>> Hi All,
>>
>> I'm hitting an issue with the selectable field in SQLFORM.grid.
>>
>> I have a controller including a grid generated from a join on three 
>> tables as follows:
>>
>> applics_fields = ['first_name', 'last_name', 'email', 'rank', 'nerc_elig'
>> , 'cv', 'coverletter', 'refletter1',
>>   'refletter2']
>> proposals_fields = ['project_title', 'case_partner']
>> pi_fields = ['first_name', 'last_name']
>> fields_to_select = [db.applics1[field] for field in applics_fields] + 
>> \
>>[db.proposals[field] for field in proposals_fields
>> ] + \
>>[db.PIs[field] for field in pi_fields]
>>
>> grid = SQLFORM.grid((db.applics1.project == db.proposals.id) & (db.
>> proposals.PI_name == db.PIs.id),
>> csv=False,
>> deletable=False,
>> create=False,
>> details=False,
>> editable=False,
>> fields=fields_to_select,
>> headers={'PIs.last_name': 'PI Last Name', 
>> 'PIs.first_name': 'PI First Name'},
>> selectable=[('Download Public PDFs', lambda ids: 
>> zip_pdfs(ids, track=1))],
>> paginate=False)
>>
>> This generates the correct grid in the view, however when I select the 
>> records I want to pass to zip_pdfs(), the ids passed to the function are 
>> those of the PI table, not of the applics1 table.
>>
>> Is there a way to specify from which table it pulls the ids to be 
>> selected and passed to zip_pdfs()?
>>
>> 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] Selecting from SQLFORM grid generated using a join selects incorrect IDs

2018-11-19 Thread 'Francis Windram' via web2py-users
Hi All,

I'm hitting an issue with the selectable field in SQLFORM.grid.

I have a controller including a grid generated from a join on three tables 
as follows:

applics_fields = ['first_name', 'last_name', 'email', 'rank', 'nerc_elig', 
'cv', 'coverletter', 'refletter1',
  'refletter2']
proposals_fields = ['project_title', 'case_partner']
pi_fields = ['first_name', 'last_name']
fields_to_select = [db.applics1[field] for field in applics_fields] + \
   [db.proposals[field] for field in proposals_fields] + 
\
   [db.PIs[field] for field in pi_fields]

grid = SQLFORM.grid((db.applics1.project == db.proposals.id) & (db.
proposals.PI_name == db.PIs.id),
csv=False,
deletable=False,
create=False,
details=False,
editable=False,
fields=fields_to_select,
headers={'PIs.last_name': 'PI Last Name', 
'PIs.first_name': 'PI First Name'},
selectable=[('Download Public PDFs', lambda ids: 
zip_pdfs(ids, track=1))],
paginate=False)

This generates the correct grid in the view, however when I select the 
records I want to pass to zip_pdfs(), the ids passed to the function are 
those of the PI table, not of the applics1 table.

Is there a way to specify from which table it pulls the ids to be selected 
and passed to zip_pdfs()?

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

2018-10-31 Thread 'Francis Windram' via web2py-users


On Tuesday, 30 October 2018 20:12:11 UTC, Dave S wrote:
>
>
>
> 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
>
>
> See 
> http://web2py.com/books/default/chapter/29/05/the-views> 
>  ... the '{{ ... }}' construction is introduced right away.
>
> The part I find tricky here is that you need to do an import of AppConfig, 
> or I'd say just try adding this to your footer:
>
> {{ = appconf.take("app.version")}}
>
>
> I can do the import easily enough in the controller, so I've just tested 
> that.  Import AppConfig at the top of the module, and define appconf as 
> in models/db.py.  Then in your controller return statement add 
> ..., app_version = appconf.take("app.version"), 
> and in your footer add 
> {{== app_version}}
> You can do this in whatever controller you want, and the view will then 
> display the version.
>
> Even better, since you probably want all pages to display the version, is 
> just set app_version in your model file (db.py is where I tested it), and 
> it then becomes a global.
>
> /dps
>
>  
Perfect! With the vars defined in db.py, this all works swimmingly! Thank 
you very much

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