> > for quick development-shots, i need to execute my untouched(may i > could change "print" to "return") Python scripts(..with loops) in the > Controller. > The output should be renderd direct via http, without long-winded > setting up the view for each function. > Is that possible? >
If I understand you want to return a string directly without being processed by the view. On a controller function, if you return a string (not a dict) it will be rendered as is. Tiago -- On Wed, Feb 24, 2010 at 4:48 PM, AsmanCom <d.as...@web.de> wrote: > Hi, > > for quick development-shots, i need to execute my untouched(may i > could change "print" to "return") Python scripts(..with loops) in the > Controller. > The output should be renderd direct via http, without long-winded > setting up the view for each function. > Is that possible? > > To my next concern.... > > On my actual Project i have simple form field with submit button on my > controller: > form = SQLFORM.factory(Field('update_url', default='http://.domain.org/ > text_file.txt <http://domain.org/%0Atext_file.txt>', > requires=IS_NOT_EMPTY())) > > On Submit the text file should be downloaded to Server indicated by an > Progress Bar on the Page. > Next the file should be inserted to the DB line by line(for loop with > regex) and again indicated by the same Progress Bar ..... > > My Code so far(... relies on clienttools example specifically on > jqueryUI-progressbar and an urllib2 +report_hook snippet i´ve found > somewhere): > _______________________________________________________________________ > def chunk_report(bytes_so_far, chunk_size, total_size): > percent = float(bytes_so_far) / total_size > percent = round(percent*100) > return percent > > > if bytes_so_far >= total_size: > return ('100.0') > > def chunk_read(response, chunk_size=8192, report_hook=None): > total_size = response.info().getheader('Content-Length').strip() > total_size = int(total_size) > bytes_so_far = 0 > > while 1: > chunk = response.read(chunk_size) > bytes_so_far += len(chunk) > > if not chunk: > break > > if report_hook: > report_hook(bytes_so_far, chunk_size, total_size) > > percent = float(bytes_so_far) / total_size > percent = round(percent*100) > return percent #bytes_so_far > > > def url_progress(): > wrapper = DIV(progress,_style="width:400px;") > jqueryui_progress() > form = SQLFORM.factory(Field('update_url', > default='http://.domain.org/text_file.txt', requires=IS_NOT_EMPTY())) > if form.accepts(request.vars, session): > response.flash = "Got it!" > try: > import urllib2 > openurl = urllib2.urlopen(request.vars.update_url) > chunk_read(openurl, report_hook=chunk_report) > except Exception, e: > session.flash = DIV(T('Unable to download from url > because:'),PRE(str(e))) > redirect(URL(r=request)) > event.listen('submit',"form","return confirm('Are you sure?');") # > adds a confirmation to submit > page.ready(jq("update_oui").focus()()) > # return dict(form=form) > return dict(wrapper=wrapper, form=form) > > # jQuery progress bar > progress = DIV(_id="progress") > def jqueryui_progress(): > wrapper = DIV(progress,_style="width:400px;") > page.include("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/ > jquery-ui.min.js<http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/%0Ajquery-ui.min.js>", > download=True) > page.include("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/ > themes/ui-darkness/jquery-ui.css<http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/%0Athemes/ui-darkness/jquery-ui.css>", > download=True) > callback = js.call_function(get_progress) > page.ready(jq(progress).progressbar( dict(value='0') )() ) > page.ready(js.timer(callback,2000)) > return dict(wrapper=wrapper) > > def get_progress(): > return jq(progress).progressbar('option', 'value', > request.now.second)()# > ________________________________________________________________ > > > But now i stuck.... can anyone put me on the right way? > When the Page is loaded, both elemts show up correctly. > When i do the submit: > - The Progressbar freezes(Callback dont work while downloading the > file...) > - The Download works and shows 100% when completed(but the while 1 > loop, which calls the report_hook dont work at all! and i need it to > update the Progress bar... I think?) > > + I need to change the Progressbar callback source when updating DB > after downloading the file... > > Anyone any suggestions? > > Best regards, > > Dieter Asman > > - AsmanCom - > Germany > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.