[web2py] Getting web2py to reload module files for each return view
Hi, Working with a team building a reasonably complex webapp for an investment management system, and I'm trying to learn something of the system too. I have a module that updates data from a file (simulating an FTP drop). Once the module has been loaded the first time, it doesn't update for either changes in code or in the underlying data no matter how often I refresh the page. Is there a particular way to force web2py to reload any files each time a page is refreshed? Am I doing something completely wrong? Thanks The code is as follows: module: *dataxl.py* from gluon import * import csv import json import os from xlrd import open_workbook as lox def mydata(): filepath = os.join(current.request.folder, 'static', 'sample-data', \ '20-10-2014_sample-data-for-designer.xls') oldbook = lox(filepath) names = oldbook.sheet_names() workbook = {} for name in names: worksheet = [] oldsheet = ws.sheet_by_name(name) nrows = oldsheet.nrows ncols = oldsheet.ncols colnames = [ oldsheet.cell(0,i).value for i in range(ncols) ] rownames = [ oldsheet.cell(i,0).value for i in range(nrows) ] for nrow in xrange(1,nrows): worksheet.append({colnames[ncol]: oldsheet.cell(nrow,ncol).value \ for ncol in xrange(ncols)}) workbook[name] = worksheet return workbook controller: *performance.py* import dataxl wsheet = dataxl.mydata() attr = wsheet[ 'Performance_Attr' ] @auth.requires_login() def perf_multi_asset(): clientId = set(i[ 'client' ] for i in attr.values()) portId = [ 'All' ] portId.append(j for j in set(i[0] for i in attr.items() \ if i[ 1 ][ 'Attribution Level' ] == 0 \ or i[ 1 ][ 'Attribution Level' ] == 1)) perform = SQLFORM.factory( Field('client', 'string'),requires=IS_IN_SET(clientId)), Field('portfolio', 'string'),requires=IS_IN_SET(portId)), Field('start_date', 'date'), Field('end_date', 'date') ).process() if perform.vars.portfolio == 'All': data = {i[ 0 ]:i[ 1 ] for i in attr.items() if i[ 1 ][ 'client' ] == perform.vars.client} else: data = {i[ 0 ]:i[ 1 ] for i in attr.items() if i[ 1 ][ 'client' ] == perform.vars.client \ and i[ 0 ] == perform.vars.portfolio} return locals() and view: *performance/perf_multi_asset.html* {{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals ())}} {{extend 'layout.html'}} {{=STYLE(XML(".generic-widget,#no_table_start_date,#no_table_end_date {width:100px}"))}} {{=perform.custom.begin}} Client Name: {{=perform.custom.widget.client}} Portfolio ID: {{=perform.custom.widget.portfolio}} Start Date: {{=perform.custom.widget.start_date}} End Date: {{=perform.custom.widget.end_date}} {{=perform.custom.submit}} {{=perform.custom.end}} {{=BEAUTIFY(XML(data))}} -- 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: Getting web2py to reload module files for each return view
Thanks Massimo. Perfect. On Saturday, 25 October 2014 07:52:03 UTC+8, Massimo Di Pierro wrote: > > Normally modules are not reloaded because they are cached by python. > web2py can bypass this, depending on where the modules are located. If you > kwwp in your modules in the web2py app/modules folder then you can do in > your models/db.py > > DEBUG=True > from gluon.custom_import import track_changes; track_changes(DEBUG) > > This will reload your modules when they change/ > > > > On Friday, 24 October 2014 03:33:33 UTC-5, tahnoon pasha wrote: >> >> Hi, >> >> Working with a team building a reasonably complex webapp for an >> investment management system, and I'm trying to learn something of the >> system too. >> >> I have a module that updates data from a file (simulating an FTP drop). >> Once the module has been loaded the first time, it doesn't update for >> either changes in code or in the underlying data no matter how often I >> refresh the page. >> >> Is there a particular way to force web2py to reload any files each time a >> page is refreshed? Am I doing something completely wrong? >> >> Thanks >> >> The code is as follows: >> >> module: *dataxl.py* >> >> from gluon import * >> import csv >> import json >> import os >> from xlrd import open_workbook as lox >> >> >> >> >> def mydata(): >> filepath = os.join(current.request.folder, 'static', 'sample-data', \ >>'20-10-2014_sample-data-for-designer.xls') >> oldbook = lox(filepath) >> names = oldbook.sheet_names() >> workbook = {} >> for name in names: >> worksheet = [] >> oldsheet = ws.sheet_by_name(name) >> nrows = oldsheet.nrows >> ncols = oldsheet.ncols >> colnames = [ oldsheet.cell(0,i).value for i in range(ncols) ] >> rownames = [ oldsheet.cell(i,0).value for i in range(nrows) ] >> for nrow in xrange(1,nrows): >> worksheet.append({colnames[ncol]: oldsheet.cell(nrow,ncol).value >> \ >> for ncol in xrange(ncols)}) >> workbook[name] = worksheet >> return workbook >> >> controller: *performance.py* >> >> import dataxl >> >> >> wsheet = dataxl.mydata() >> >> attr = wsheet[ 'Performance_Attr' ] >> >> @auth.requires_login() >> def perf_multi_asset(): >> >> clientId = set(i[ 'client' ] for i in attr.values()) >> portId = [ 'All' ] >> portId.append(j for j in set(i[0] for i in attr.items() \ >> if i[ 1 ][ 'Attribution Level' ] == 0 \ >> or i[ 1 ][ 'Attribution Level' ] == 1)) >> >> perform = SQLFORM.factory( >> Field('client', 'string'),requires=IS_IN_SET(clientId)), >> Field('portfolio', 'string'),requires=IS_IN_SET(portId)), >> Field('start_date', 'date'), >> Field('end_date', 'date') >> ).process() >> >> if perform.vars.portfolio == 'All': >> data = {i[ 0 ]:i[ 1 ] for i in attr.items() if i[ 1 ][ 'client' ] >> == perform.vars.client} >> else: >> data = {i[ 0 ]:i[ 1 ] for i in attr.items() if i[ 1 ][ 'client' ] >> == perform.vars.client \ >> and i[ 0 ] == perform.vars.portfolio} >> >> return locals() >> >> and view: *performance/perf_multi_asset.html* >> >> {{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals >> ())}} >> {{extend 'layout.html'}} >> >> {{=STYLE(XML(".generic-widget,#no_table_start_date,#no_table_end_date >> {width:100px}"))}} >> >> >> {{=perform.custom.begin}} >> >> >> Client Name: >> {{=perform.custom.widget.client}} >> >> >> >> Portfolio ID: >> {{=perform.custom.widget.portfolio}} >> >> >> >> Start Date: >> {{=perform.custom.widget.start_date}} >> >> >> >> End Date: >> {{=perform.custom.widget.end_date}} >> >> >> >> >> {{=perform.custom.submit}} >> >> >> {{=perform.custom.end}} >> >> >> >> {{=BEAUTIFY(XML(data))}} >> >> -- 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] Getting a form field to return var on select
Hi, I saw a discussion begin on this subject on Stackoverflow but can't find the continuation here. I have a case where I need to use the input in one form field (eg portfolio) to filter options of the IS_IN_SET constraint for a subsequent form field (eg sector/industry). I'm pretty new to web2py and jquery. How would I go about implementing this? 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] Including a label inside a form field
I have a series of form elements as follows form = SQLFORM.factory ( Field ('client', requires=IS_IN_SET (['Client','Rhubarb','Custard','Bogies']), default='Client'), Field ('portfolio', requires=IS_IN_SET (['US Equity','Multi Asset ETF','Portfolio']), default='Portfolio'), Field ('benchmark', requires=IS_IN_SET (['S&P 500','Custom Policy','Benchmark']), default='Benchmark'), Field ('methodology', requires=IS_IN_SET (['Brinson-Fachler', 'Regression','Method']), default='Method'), Field('level1', requires=IS_IN_SET(['Sector','Industry','Asset Class', 'Level 1']), default='Level 1'), Field('level2', requires=IS_IN_SET(['Sector','Industry','Asset Class', 'Level 2']), default='Level 2'), Field ('start_date', 'date', default="Start Date"), Field ('end_date', 'date', default="End Date") ).process () I have a slightly fumble fingered approach to set a label inside each form field instead of as a label above or alongside as shown in the code, by setting the label as a default. The page this input form will be used for is a busy one and space is at a premium. Is there a more elegant way to put form labels into the form field that won't fail on the dates inputs? As a side question, the approach above displays the default inside the widget for Method, Level 1 and Level 2, but not for client, portfolio and benchmark. Is there something wrong with my code that would cause that? 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] How to reuse a form in webpy
Hi I'm trying to reuse a form to de-clutter my code. The idea was to create a form class using a SQLFORM.factory with all the validation rules set up and then use it for each view in the module. class form (): ''' USAGE: thisform = form(([clients],defaultc),([portfolios],defaultp),) ''' import datetime def __init__ (self, cset, pset, bset, l1set, l2set): form = SQLFORM.factory (Field ("client", requires=IS_IN_SET (cset [0]), default=cset [1]), Field ("portfolio", requires=IS_IN_SET (pset [0]), default=pset [1]), Field ("benchmark", requires=IS_IN_SET (bset [0]), default=bset [1]), Field ("startdate", "datetime", default=datetime.datetime (2013, 1, 11, 0, 0, 0)), Field ("enddate", "datetime", default=datetime.datetime (2013, 3, 30, 0, 0, 0)), Field ("level1", requires=IS_IN_SET (l1set [0]), default=l1set [1]), Field ("level2", requires=IS_IN_SET (l2set [0])), default=l2set [1]) def accepted (self, form): startdate = enddate = client = portfolio = benchmark = level1 = level1 = [] if form.process().accepted: client = form.vars.client portfolio = form.vars.portfolio benchmark = form.vars.benchmark startdate = form.vars.startdate enddate = form.vars.enddate level1 = form.vars.level1 level2 = form.vars.level2 if startdate: startdate = datetime.datetime.strftime (startdate, "%Y-%m-%d %H:%M:%S") if enddate: enddate = datetime.datetime.strftime (enddate, "%Y-%m-%d %H:%M:%S") return dict (client=client, portfolio=portfolio, benchmark=benchmark, startdate=startdate, enddate=enddate, level1=level1, level2=level2) that failed completely with an `AttributeError: form has no attribute process` so I tried defining a method instead with the code below: def form(): form = SQLFORM.factory(Field('Client'), Field('Portfolio')) return form def sandbox(): f2= [] f1 = form().process() if f1.process().accepted: f2 = "rhubarb" return dict(f2=f2) and the view `{{=f2}}` returns `[]` without ever displaying a form Would anyone have any thoughts on how to acomplish this? 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: IMPORTANT - WEB2PY CONSULTING
As a user of web2py consultants, can I please just add what a great idea it is to do this. On Monday, 16 February 2015 06:21:36 UTC+8, Massimo Di Pierro wrote: > > We need to update the list of companies that provide web2py consulting. > This list is obsolete: > > http://web2py.com/init/default/support > > Some links are broke. Most pages do not even mention web2py. Some of them > have a design that is simply not acceptable for a web development company. > > That list will be eliminated. IF YOU WANT TO BE LISTED please update your > page to have a decent design and MENTION WEB2PY on the main site. Then > respond to this thread by providing an updated link and the country were > you incorporated. If you have a self-employed individual list your country > of residence. > > -- 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.