[web2py] Re: autodelete image computed field
Any success on getting the computed thumbnail image to autodelete? I'm having trouble with this too, where an update of a new thumbnail will not delete the old file. On Saturday, April 28, 2012 5:06:25 PM UTC-7, ctrlSoft wrote: hi i have a resize function wich creates image thumbanils... def THUMB(image, nx=120, ny=120): from PIL import Image import os try: img = Image.open(request.folder + 'static/img_folder/' + image) img.thumbnail((nx,ny), Image.ANTIALIAS) root,ext = os.path.splitext(image) thumb='%s_thumb%s' %(root, ext) img.save(request.folder + 'static/img_folder/' + thumb) return thumb except: return None and this : db.define_table(news, Field('image', 'upload', requires=IS_EMPTY_OR(IS_IMAGE()), uploadfolder=request.folder+'static/img_folder', autodelete=True), Field('image_thumb', 'upload', compute=lambda r: THUMB(r['image']), autodelete=True), Field(title,label=T('Title'),requires=IS_NOT_EMPTY()), Field(content ,type='text',label=T('Content'),requires=IS_NOT_EMPTY())) the problem is when i delete a row, image(big image) is deleteing from disk but the image_thumb stil remains on disk. any solutions are welcome :), thx ___ Alex --
Re: [web2py] Re: REF: Modal Window: Automatically close and update parent window:
Oke gr8!!! will give it a shot!!! thanx you guys, so much to learn!! wb2py rocks!! On 11/8/12, Paolo Caruccio paolo.carucci...@gmail.com wrote: a possible solution (skeleton code so please check for errors and omissions): # controllers def companies(): return dict() def add_company(): form = SQLFORM(db.company, formstyle='bootstrap') if form.process().accepted: session.flash = 'form accepted' redirect(URL('add_company', vars={'success':'ok'})) elif form.errors: response.flash = 'form has errors' else: pass return dict(form=form) # view = companies.html {{extend 'layout.html'} !-- Button to trigger modal -- a href=#myModal class=btn data-toggle=modalLaunch modal/a !-- Modal -- div id=myModal class=modal hide fade div class=modal-header button type=button class=close data-dismiss=modal×/button nbsp; /div div class=modal-body {{=LOAD('default', add_company.load', ajax=True, ajax_trap=True)}} /div div class=modal-footernbsp;/div /div script type=text/javascript jQuery('#myModal').on('hidden', function () { // ajax call to refresh data grid }) /script # view = add_company.load {{=form}} script type=text/javascript jQuery(document).ready(function(){ var res = '{{=request.vars.success}}' if (res != 'None') { jQuery('#myModal').modal('hide'); }; }); /script Il giorno giovedì 8 novembre 2012 16:52:46 UTC+1, software.ted ha scritto: Hi, How do I auto close a JS Bootstrap modal window that has simple form and then update a grid on the calling main page??? I am using Bootstrap modal window. Model: db.define_table('department', Field('name')) db.define_table('office', Field('name'), Field('department', db.department)) Controller: def add_department(): form=SQLFORM(db.department) if ..: ... else: ... return dict(form=form) def add_office(): form = SQLFORM(db.office) if ...: ... else: add_department.load: {{=form}} add_office.load: {{=form}} What I want in the view is to be able to add a company using a bootstrap modal window after clicking on save close the modal window and update a grid with a new company added in the same window. Also I when i add office modal window, in the dropbox i want to see the just added company without refreshing the main winnow but using ajax. Any ideas pointer...thanx in advance... enalapril + nifedipin + pediatric benlin Teddy L. /~ -- -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ --
[web2py] Re: Optimized way to use web2py Scheduler
ehm, missing something here: worker(s) do(es) auto-assignments of tasks. there's no web2py involved in assigning task to a particular worker. Said that, I'd run one worker if there are no requisites like I need function1 and function2 to run concurrently, in which case, start 2 workers, they'll split the jobs. On Friday, November 9, 2012 7:59:04 AM UTC+1, Amit wrote: Hi, I have more than 10 functions which has to be executed by Scheduler and each task has assigned different time ( for e.g...one has to execute on every 15 minutes, other one has to executes on every 24 hrs etc... ) to execute, so in my CustomScheduler.py module : I wiil have 10 different statements like below: db.scheduler_task.validate_and_insert( function_name='func1', args='[]', repeats = 0, # run indefinately period = 3600, # every 1h timeout = 120, # should take less than 120 seconds ) db.scheduler_task.validate_and_insert( function_name='func2', args='[]', repeats = 0, # run indefinately period = 900, # every 15 min timeout = 120, # should take less than 120 seconds ) My doubt is what will be the better optimized approach to assign those 10 tasks to Scheduler: 1. Create only one worker using *web2py -K appname* command for all tasks, which will further takes care of running all tasks at designated time OR 2. Create 10 different workers means execute above command 10 times and then web2py takes care of assigning the task to each worker. which will be the best optimized way to use web2py scheduler? Regards, Amit --
[web2py] REF: Tabs and FORMSQL.Grid focus
HI, I have tabs and in one one of them I have a SQLFORM.grid displayed. But when i hit say view or search the grid, the default tabs is displayed. Is there a way of making SQLFORM.grid make ajax calls instead of refreshing whole page...or is there another way i can ensure my grid refreshes the same tab on which is is displayed...here is my code: Control: def index(): response.subtitle = Human Resource and Administration db.department.id.readable = False headers = {'db.department.name': 'Department Name','db.department.description': 'Description'} default_sort_order=[db.department.name] form = SQLFORM.grid(db.department, headers=headers, orderby=default_sort_order, create=False, deletable=False, editable=False, maxtextlength=64, paginate=25) return dict(form=form) Views - index.html: {{extend 'layout.html'}} div class=tabbable !-- Only required for left/right tabs -- ul class=nav nav-tabs li class=activea href=#tab1 data-toggle=tabSection 1/a/li lia href=#tab2 data-toggle=tabSection 2/a/li li class=dropdown a class=dropdown-toggle data-toggle=dropdown href=# Meta Data /a ul class=dropdown-menu lia href=#tab3 id=department tabindex=-1 data-toggle=tabManage Departments/a/li lia href=#tab3 id=office tabindex=-1 data-toggle=tabManage Office Titles/a/li li class=divider/li lia href=#tab3 tabindex=-1 data-toggle=tabManage List/a/li /ul /li /ul div class=tab-content div class=tab-pane active id=tab1 pI'm in Section 1./p /div div class=tab-pane id=tab2 pHowdy, I'm in Section 2./p /div div class=tab-pane id=tab3 div id=department_form{{include 'administration/test.html'}}/div /div /div /div script jQuery('#department_form').hide(); jQuery('#department').click(function(){ jQuery('#department_form').show('fade'); }); /script View: test.html !--Navigation Bar-- div class=navbar div class=navbar-inner a class=brand href=#Manage Department Data/a ul class=nav li class=activea href=#Add New/a/li lia href=#Edit/a/li li class=divider-vertical/li /ul form class=navbar-form pull-left input type=text class=span2 placeholder=search button type=submit class=btnSearch/button /form /div /div !--Nav End -- !--Grid-- {{=form}} -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ --
[web2py] Re: how i can write a web2py code nto javascript
Do you mean that you want the code to appear on the webpage? Save your code into a file in the static folder, and include in your views file using response.files: {{response.files.append(URL('static','js_folder/your_file.js'))}} On Wednesday, November 7, 2012 5:39:36 PM UTC+8, Ali Alroomi wrote: hello plz i need help i need t write web2py code into javascript ike the following my code plz any help with the this: $.fn.fancybox = function(options) { $(this).data('fancybox', $.extend({}, options)); $(this).unbind('click.fb').bind('click.fb', function(e) { e.preventDefault(); if (busy) return; busy = true; $(this).blur(); selectedArray= []; selectedIndex= 0; {{for i in db().select(db.Project.ALL):}} var rel = $(this).attr('rel') || ''; var message = {{=i.CategoryID}}; var url = ?pro= + escape(message); if (!rel || rel == '' || rel === 'nofollow') { selectedArray.push(this); } else { selectedArray= $(a[rel= + rel + ], area[rel= + rel + ]); selectedIndex= selectedArray.index( this ); /*window.open(url, _self);*/ history.replaceState({}, Title, url); } fancybox_start(); return false; }); return this; }; --
Re: [web2py] Re: Optimized way to use web2py Scheduler
Thanks Niphold for your informative response so If i understood correctly, in my case , I don't need to start 10 different workers as all these 10 tasks will have different time period to run hence one worker will be sufficient to perform the required tasks and in any case, suppose I have to run more than one tasks at the same time period then I should go to the approach of starting more than one workers. Thanks, Amit On Fri, Nov 9, 2012 at 3:16 PM, Niphlod niph...@gmail.com wrote: ehm, missing something here: worker(s) do(es) auto-assignments of tasks. there's no web2py involved in assigning task to a particular worker. Said that, I'd run one worker if there are no requisites like I need function1 and function2 to run concurrently, in which case, start 2 workers, they'll split the jobs. On Friday, November 9, 2012 7:59:04 AM UTC+1, Amit wrote: Hi, I have more than 10 functions which has to be executed by Scheduler and each task has assigned different time ( for e.g...one has to execute on every 15 minutes, other one has to executes on every 24 hrs etc... ) to execute, so in my CustomScheduler.py module : I wiil have 10 different statements like below: db.scheduler_task.validate_**and_insert( function_name='func1', args='[]', repeats = 0, # run indefinately period = 3600, # every 1h timeout = 120, # should take less than 120 seconds ) db.scheduler_task.validate_**and_insert( function_name='func2', args='[]', repeats = 0, # run indefinately period = 900, # every 15 min timeout = 120, # should take less than 120 seconds ) My doubt is what will be the better optimized approach to assign those 10 tasks to Scheduler: 1. Create only one worker using *web2py -K appname* command for all tasks, which will further takes care of running all tasks at designated time OR 2. Create 10 different workers means execute above command 10 times and then web2py takes care of assigning the task to each worker. which will be the best optimized way to use web2py scheduler? Regards, Amit -- --
Re: [web2py] Re: Optimized way to use web2py Scheduler
yep. The only limit to having a single scheduler for all your tasks is that it's allowed to have only one running task in a single point in time. NB: no task is discarded at all, only the concurrency is avoided, e.g.: if you have five tasks scheduled for 9.00 AM you'll get all your five tasks executed but they will be serialized one after another, so, let's say, the fifth one will be started on 9.05AM . If you have, e.g. two tasks that need to run every 5 minutes and each one takes 5 minutes to finish, one scheduler will not be able to perform all the iterations you need, so you need to start 2 of them. --
Re: [web2py] Re: Optimized way to use web2py Scheduler
How to start 2 or more workers? Em sexta-feira, 9 de novembro de 2012 11h47min31s UTC, Niphlod escreveu: yep. The only limit to having a single scheduler for all your tasks is that it's allowed to have only one running task in a single point in time. NB: no task is discarded at all, only the concurrency is avoided, e.g.: if you have five tasks scheduled for 9.00 AM you'll get all your five tasks executed but they will be serialized one after another, so, let's say, the fifth one will be started on 9.05AM . If you have, e.g. two tasks that need to run every 5 minutes and each one takes 5 minutes to finish, one scheduler will not be able to perform all the iterations you need, so you need to start 2 of them. --
[web2py] Salting tables with legacy data, when to turn on record versioning?
I am migrating data from a legacy PHP/MySQL app to Web2py/Postgres. The new app will have record versioning for archival purposes. Should I migrate the data with record versioning turned on, or should I wait and turn it on after the completing the migration? Thanks, Cliff Kachinske --
Re: [web2py] Re: Optimized way to use web2py Scheduler
one worker web2py.py -K yourapp two workers: two shells of the above one, or just web2py.py -K yourapp,yourapp --
[web2py] OperationalError: database is locked
Greetings... I may have a problem with my database (sqlite) locking. Traceback (most recent call last): File /home/web2py/src/web2py/gluon/scheduler.py, line 218, in executor result = dumps(_function(*args,**vars)) File applications/ircmessage/models/tasks.py, line 57, in send_unsent_messages for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): File /home/web2py/src/web2py/gluon/dal.py, line 8787, in select return adapter.select(self.query,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 2127, in select return super(SQLiteAdapter, self).select(query, fields, attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1615, in select return self._select_aux(sql,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1580, in _select_aux self.execute(sql) File /home/web2py/src/web2py/gluon/dal.py, line 1693, in execute return self.log_execute(*a, **b) File /home/web2py/src/web2py/gluon/dal.py, line 1687, in log_execute ret = self.cursor.execute(*a, **b) OperationalError: database is locked I have a scheduler every minute that get's records (messages) out of the DB with a status of unsent. The messages then get posted to an IRC channel and updated to sent to they are not included the next time the scheduler runs the script. This seems to work just fine. It's when I inject a new message (which by default has a message status set to unsent) via a bash script. The message inserts fine but my script that posts it to the IRC channel doesn't not post anything but simply updates it's status to sent without actually sending it. By sending it I mean post a message over sockets. Here is my model for sending unsent messages: for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): message_id = row.id message_message = row.message message_uid = row.uid #socket connection already opened earlier in the script s.send(PRIVMSG %s :%s - %s\r\n % (channel, message_uid, message_message)) print message %s has been sent % message_id ## Only seems to print message when a delay is here. time.sleep(5) ## Set message record to sent and update modified field modified_stamp = strftime(%Y-%m-%d %H:%M:%S) db.messages[message_id] = dict(status='sent', modified=modified_stamp) db.commit() Inserting a message via jsonrpc (shown) and cURL (not shown): @service.jsonrpc def savemessage(message, uid): db.messages.insert(message=message, uid=uid) db.commit() message = {status:saved} return message Should I simply switch to a postgresql or mysql database to prevent this locking? Thanks for any help/advice in advance --
[web2py] Re: OperationalError: database is locked
if you can, use a separate db for the scheduler. SQLite doesn't handle well concurrent writes (with default operational capabilities), so having the scheduler operating on the same database of your insertion of messages can lead to locks. Just do db = DAL('whatever.db') db2 = DAL('whatever_scheduler.db') db.define_table('messages', .) from gluon.scheduler import Scheduler mysched = Scheduler(db2) and to queue tasks you can then use db2.scheduler_tasks.validate_and_insert() or, with the new API mysched.queue_task(***) On Friday, November 9, 2012 3:56:59 PM UTC+1, Mike Anson wrote: Greetings... I may have a problem with my database (sqlite) locking. Traceback (most recent call last): File /home/web2py/src/web2py/gluon/scheduler.py, line 218, in executor result = dumps(_function(*args,**vars)) File applications/ircmessage/models/tasks.py, line 57, in send_unsent_messages for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): File /home/web2py/src/web2py/gluon/dal.py, line 8787, in select return adapter.select(self.query,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 2127, in select return super(SQLiteAdapter, self).select(query, fields, attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1615, in select return self._select_aux(sql,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1580, in _select_aux self.execute(sql) File /home/web2py/src/web2py/gluon/dal.py, line 1693, in execute return self.log_execute(*a, **b) File /home/web2py/src/web2py/gluon/dal.py, line 1687, in log_execute ret = self.cursor.execute(*a, **b) OperationalError: database is locked I have a scheduler every minute that get's records (messages) out of the DB with a status of unsent. The messages then get posted to an IRC channel and updated to sent to they are not included the next time the scheduler runs the script. This seems to work just fine. It's when I inject a new message (which by default has a message status set to unsent) via a bash script. The message inserts fine but my script that posts it to the IRC channel doesn't not post anything but simply updates it's status to sent without actually sending it. By sending it I mean post a message over sockets. Here is my model for sending unsent messages: for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): message_id = row.id message_message = row.message message_uid = row.uid #socket connection already opened earlier in the script s.send(PRIVMSG %s :%s - %s\r\n % (channel, message_uid, message_message)) print message %s has been sent % message_id ## Only seems to print message when a delay is here. time.sleep(5) ## Set message record to sent and update modified field modified_stamp = strftime(%Y-%m-%d %H:%M:%S) db.messages[message_id] = dict(status='sent', modified=modified_stamp) db.commit() Inserting a message via jsonrpc (shown) and cURL (not shown): @service.jsonrpc def savemessage(message, uid): db.messages.insert(message=message, uid=uid) db.commit() message = {status:saved} return message Should I simply switch to a postgresql or mysql database to prevent this locking? Thanks for any help/advice in advance --
Re: [web2py] OperationalError: database is locked
what version of sqlite ? import sqlite3 print sqlite3.sqlite_version for sqlite =3.7 you can do db.executesql('PRAGMA journal_mode=WAL') to enable wal ( http://www.sqlite.org/draft/wal.html ) and I am sure that you will not get this error anymore, I remember I had something like that some times ago and that worked --
Re: [web2py] OperationalError: database is locked
PS: it is enough to execute that only once db.executesql('PRAGMA journal_mode=WAL') then you can remove it --
[web2py] Re: OperationalError: database is locked
Thank you again Niphlod. That seems like a sensible way for me to separate the two out. I'll give that a try. On Friday, 9 November 2012 10:31:04 UTC-5, Niphlod wrote: if you can, use a separate db for the scheduler. SQLite doesn't handle well concurrent writes (with default operational capabilities), so having the scheduler operating on the same database of your insertion of messages can lead to locks. Just do db = DAL('whatever.db') db2 = DAL('whatever_scheduler.db') db.define_table('messages', .) from gluon.scheduler import Scheduler mysched = Scheduler(db2) and to queue tasks you can then use db2.scheduler_tasks.validate_and_insert() or, with the new API mysched.queue_task(***) On Friday, November 9, 2012 3:56:59 PM UTC+1, Mike Anson wrote: Greetings... I may have a problem with my database (sqlite) locking. Traceback (most recent call last): File /home/web2py/src/web2py/gluon/scheduler.py, line 218, in executor result = dumps(_function(*args,**vars)) File applications/ircmessage/models/tasks.py, line 57, in send_unsent_messages for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): File /home/web2py/src/web2py/gluon/dal.py, line 8787, in select return adapter.select(self.query,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 2127, in select return super(SQLiteAdapter, self).select(query, fields, attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1615, in select return self._select_aux(sql,fields,attributes) File /home/web2py/src/web2py/gluon/dal.py, line 1580, in _select_aux self.execute(sql) File /home/web2py/src/web2py/gluon/dal.py, line 1693, in execute return self.log_execute(*a, **b) File /home/web2py/src/web2py/gluon/dal.py, line 1687, in log_execute ret = self.cursor.execute(*a, **b) OperationalError: database is locked I have a scheduler every minute that get's records (messages) out of the DB with a status of unsent. The messages then get posted to an IRC channel and updated to sent to they are not included the next time the scheduler runs the script. This seems to work just fine. It's when I inject a new message (which by default has a message status set to unsent) via a bash script. The message inserts fine but my script that posts it to the IRC channel doesn't not post anything but simply updates it's status to sent without actually sending it. By sending it I mean post a message over sockets. Here is my model for sending unsent messages: for row in db(db.messages.status=='unsent').select(db.messages.id, db.messages.message, db.messages.uid): message_id = row.id message_message = row.message message_uid = row.uid #socket connection already opened earlier in the script s.send(PRIVMSG %s :%s - %s\r\n % (channel, message_uid, message_message)) print message %s has been sent % message_id ## Only seems to print message when a delay is here. time.sleep(5) ## Set message record to sent and update modified field modified_stamp = strftime(%Y-%m-%d %H:%M:%S) db.messages[message_id] = dict(status='sent', modified=modified_stamp) db.commit() Inserting a message via jsonrpc (shown) and cURL (not shown): @service.jsonrpc def savemessage(message, uid): db.messages.insert(message=message, uid=uid) db.commit() message = {status:saved} return message Should I simply switch to a postgresql or mysql database to prevent this locking? Thanks for any help/advice in advance --
Re: [web2py] OperationalError: database is locked
I really appreciate your input Vasile. I will round back on to your advice should Niphlod's advice of separating the scheduler DB and my messaging DB not help me out here. On Friday, 9 November 2012 10:33:01 UTC-5, Vasile Ermicioi wrote: PS: it is enough to execute that only once db.executesql('PRAGMA journal_mode=WAL') then you can remove it --
[web2py] Re: What can cause unable to install application?
Hello Luca, where do you teach? Look into gluon/admin.py app_install. There is a try...except. Try replace except Exception: if did_mkdir: rmtree(path) return False with except Exception: import traceback print traceback.format_exc() if did_mkdir: rmtree(path) return False Also if you open a ticket about this, I will make sure better errors are reported via admin. I have apps that allows students to upload projects w2p and bulk install them, bulk register and test them. Need polishing. Remind me in a couple of weeks and I will be happy to share them. Massimo On Friday, 9 November 2012 00:08:32 UTC-6, Luca wrote: I am using web2py to teach a class on web development, and sometimes the students submit .w2p packages as assignments that cannot be loaded. When I or the TAs try to load them, we get the unable to install application message. What can cause this message? The packages open without problem when I tar xfvz them, so it's not clear to me what the problem is. Many thanks! --
[web2py] Re: gitpython module error
It is not a requirement. It is an experimental feature for now. We cannot include it because has binary dependences. When we'll support hg, we'll include it since it has no binary dependencies. On Friday, 9 November 2012 01:19:23 UTC-6, Luc Chase wrote: When trying to install a package from github I get an error saying that I need to have the gitpython module. But when I execute the following it seems it is already there... sudo pip install gitpython Password: Requirement already satisfied (use --upgrade to upgrade): gitpython in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/GitPython-0.3.2.RC1-py2.7.egg Requirement already satisfied (use --upgrade to upgrade): gitdb=0.5.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gitdb-0.5.4-py2.7-macosx-10.5-intel.egg (from gitpython) Requirement already satisfied (use --upgrade to upgrade): async=0.6.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/async-0.6.1-py2.7-macosx-10.5-intel.egg (from gitdb=0.5.1-gitpython) Requirement already satisfied (use --upgrade to upgrade): smmap=0.8.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smmap-0.8.2-py2.7.egg (from gitdb=0.5.1-gitpython) Cleaning up... So what do I need to do to ensure it is available to Web2py ? By the way... gitpython is a requirement of web2py so how come it isn't included? It also can't be used as a tag in this group? --
Re: [web2py] Re: Help with db query
Assuming that request.args contains the right values, this should work: category = request.args[1].replace('_', ' ') query = (db.Supplements.Category == category) ((db.Supplements.Users == request.args[0]) | (db.Supplements.Users == Both)) records = db(query).select() Notes: - contains does not work as it's intended only for fields defined as list types, - the alternative is to use belongs as Niphlod suggested yesterday. --
[web2py] Capturing field changes with _after_update and smartgrid
I'm missing something. I have a table where I want to react to changes to a particular field. I'm trying to use the _after_update callback check for this. However, using this it appears to me that I am only seeing the data values after the update. I can't see what they were before the update so I don't know which fields we actually updated. Is there a 'bef'ore' buffer available that I'm missing? I'm trying to capture changes made using a smartgrid. Any tips would be appreciated. -Jim --
[web2py] Re: Capturing field changes with _after_update and smartgrid
Why not just use before_update? On Friday, November 9, 2012 10:53:21 AM UTC-7, Jim S wrote: I'm missing something. I have a table where I want to react to changes to a particular field. I'm trying to use the _after_update callback check for this. However, using this it appears to me that I am only seeing the data values after the update. I can't see what they were before the update so I don't know which fields we actually updated. Is there a 'bef'ore' buffer available that I'm missing? I'm trying to capture changes made using a smartgrid. Any tips would be appreciated. -Jim --
[web2py] Re: Capturing field changes with _after_update and smartgrid
Because the update may fail. -Jim On Friday, November 9, 2012 12:20:18 PM UTC-6, Derek wrote: Why not just use before_update? On Friday, November 9, 2012 10:53:21 AM UTC-7, Jim S wrote: I'm missing something. I have a table where I want to react to changes to a particular field. I'm trying to use the _after_update callback check for this. However, using this it appears to me that I am only seeing the data values after the update. I can't see what they were before the update so I don't know which fields we actually updated. Is there a 'bef'ore' buffer available that I'm missing? I'm trying to capture changes made using a smartgrid. Any tips would be appreciated. -Jim --
[web2py] Re: What can cause unable to install application?
Massimo, I teach at UCSC; here is the class web page: https://sites.google.com/a/ucsc.edu/luca/classes/cmps-183-hypermedia-and-the-web/cmps-183-fall-2012 Thank you for the help; I will do this next time a student package does not load properly! Luca On Friday, November 9, 2012 8:18:21 AM UTC-8, Massimo Di Pierro wrote: Hello Luca, where do you teach? Look into gluon/admin.py app_install. There is a try...except. Try replace except Exception: if did_mkdir: rmtree(path) return False with except Exception: import traceback print traceback.format_exc() if did_mkdir: rmtree(path) return False Also if you open a ticket about this, I will make sure better errors are reported via admin. I have apps that allows students to upload projects w2p and bulk install them, bulk register and test them. Need polishing. Remind me in a couple of weeks and I will be happy to share them. Massimo On Friday, 9 November 2012 00:08:32 UTC-6, Luca wrote: I am using web2py to teach a class on web development, and sometimes the students submit .w2p packages as assignments that cannot be loaded. When I or the TAs try to load them, we get the unable to install application message. What can cause this message? The packages open without problem when I tar xfvz them, so it's not clear to me what the problem is. Many thanks! --
[web2py] Re: how i can write a web2py code nto javascript
No, he's trying to use a web2py function within the javascript, or have web2py write javascript instead of html. I'm not sure it can do that. On Friday, November 9, 2012 3:37:10 AM UTC-7, lyn2py wrote: Do you mean that you want the code to appear on the webpage? Save your code into a file in the static folder, and include in your views file using response.files: {{response.files.append(URL('static','js_folder/your_file.js'))}} On Wednesday, November 7, 2012 5:39:36 PM UTC+8, Ali Alroomi wrote: hello plz i need help i need t write web2py code into javascript ike the following my code plz any help with the this: $.fn.fancybox = function(options) { $(this).data('fancybox', $.extend({}, options)); $(this).unbind('click.fb').bind('click.fb', function(e) { e.preventDefault(); if (busy) return; busy = true; $(this).blur(); selectedArray= []; selectedIndex= 0; {{for i in db().select(db.Project.ALL):}} var rel = $(this).attr('rel') || ''; var message = {{=i.CategoryID}}; var url = ?pro= + escape(message); if (!rel || rel == '' || rel === 'nofollow') { selectedArray.push(this); } else { selectedArray= $(a[rel= + rel + ], area[rel= + rel + ]); selectedIndex= selectedArray.index( this ); /*window.open(url, _self);*/ history.replaceState({}, Title, url); } fancybox_start(); return false; }); return this; }; --
[web2py] Re: Capturing field changes with _after_update and smartgrid
Use before_update to store the current data in the session, then the after_update would have access to it. On Friday, November 9, 2012 11:55:36 AM UTC-7, Jim S wrote: Because the update may fail. -Jim On Friday, November 9, 2012 12:20:18 PM UTC-6, Derek wrote: Why not just use before_update? On Friday, November 9, 2012 10:53:21 AM UTC-7, Jim S wrote: I'm missing something. I have a table where I want to react to changes to a particular field. I'm trying to use the _after_update callback check for this. However, using this it appears to me that I am only seeing the data values after the update. I can't see what they were before the update so I don't know which fields we actually updated. Is there a 'bef'ore' buffer available that I'm missing? I'm trying to capture changes made using a smartgrid. Any tips would be appreciated. -Jim --
[web2py] Re: Optimized way to use web2py Scheduler
cron On Thursday, November 8, 2012 10:59:04 PM UTC-8, Amit wrote: Hi, I have more than 10 functions which has to be executed by Scheduler and each task has assigned different time ( for e.g...one has to execute on every 15 minutes, other one has to executes on every 24 hrs etc... ) to execute, so in my CustomScheduler.py module : I wiil have 10 different statements like below: db.scheduler_task.validate_and_insert( function_name='func1', args='[]', repeats = 0, # run indefinately period = 3600, # every 1h timeout = 120, # should take less than 120 seconds ) db.scheduler_task.validate_and_insert( function_name='func2', args='[]', repeats = 0, # run indefinately period = 900, # every 15 min timeout = 120, # should take less than 120 seconds ) My doubt is what will be the better optimized approach to assign those 10 tasks to Scheduler: 1. Create only one worker using *web2py -K appname* command for all tasks, which will further takes care of running all tasks at designated time OR 2. Create 10 different workers means execute above command 10 times and then web2py takes care of assigning the task to each worker. which will be the best optimized way to use web2py scheduler? Regards, Amit --
[web2py] Re: How many error tickets does a typical newbie handle?
Are you saying your app used to work but now it doesn't? I don't understand your problem exactly. On Tuesday, November 6, 2012 5:34:40 PM UTC-8, Bill Thayer wrote: Didn't have ANY problems with this line of work in 2 years of deployment. So your post does help with migration errors but... I have 81 tickets today mostly related to lambda taking [1|2] arguments but only [0|1] given. This leads to all sorts of variations leading to errors because sometimes '%(something)s' works and other times you just need r.something or simply lambda val: function(val). Much of my errors today were dealing with validators, looks like lambda functions and validators I had last week are not working now. Just when I figured my data tables were ready I have to go through each one line by line and rewrite validators lambda functions (and requires= and default= etc) I've already removed most of my referenced fields. Hope you guys plan on having a web2py boot camp very soon. There have been probably 74 or more posts made in this Google group in the last week so I can't think that I'm alone. I've read most of the code, all of the book and epidocs and most of the posts here and on stackoverflow. I bought the application developement cookbook, tried the slices. Kept my versions up to date etc... Still, I am probably going to get fired divorced for this project being so late after all the hours I put on it. -Bill --
[web2py] Re: sym link for an application - is it possible?
Symlinks should work fine. The symlink should be to the app's directory on your hard drive. On Tuesday, November 6, 2012 12:40:37 AM UTC-8, dederocks wrote: I'd like to have an application folder on dropbox, so I've replaced the application folder with a link on the folder in dropbox -- but it doesn't work. The problem is not dropbox related I think -- it's more an issue of the shortcut link in windows. Any workaround? --
[web2py] DAL and Pivot Tables
(I already post this question, but it was deleted in few seconds and no reason was mentioned. I try to repost it, removing formatting and external links... If something is wrong, please inform me :) I have defined this model: db.define_table('fruits_in_shop', Field('shop_name'), Field('species'), Field('number','integer')) With this kind of record inside: fruits_in_shop.id fruits_in_shop.shop_name fruits_in_shop.species fruits_in_shop.number 1 Mark's shop apple 32 2 Mark's shop pear 22 3 John's Market banana 22 4 John's Market apple 36 I'm looking for a way to show the result as a pivot table: Shop applepear banana Mark's shop 32 220 John's Market 32 0 22 I often used a mysql trick to get this result, but there is a way to get this result using DAL? Otherwise I suppose to perform sequential queries and store the results in a dictionary. (fruits-select distict fruit from table; for fruit in fruits: column-select * from table where fruit=fruit;) In this case, there is a (easy) way to convert that dictionary into a gluon.sql.Rows object? Should I use its __init__ method? --
[web2py] Routing help with url helper
Hi, i am having the basic routing where i omitted the application name in url. Below is the content of my routes.py default_application = 'init' default_controller = 'default' default_function = 'index' routes_in = ( ( '/$c/$f' , '/init/$c/$f' ), ( '/$c/$f/$anything' , '/init/$c/$f/$anything' ) ) routes_out = [(x, y) for (y, x) in routes_in] But when i generate a url via URL helper {{=URL(f='temp.json', hmac_key=, user_signature=True)}} This will generate a URL with application name which means that application name will be treated as controller and I will get a HTTP 404. So either i create my URL manually, but then i wouldn't be able to use digitally signed url or I should modify the routes.py which I am not able to figure out without dropping the URL routing. Also, I tried putting a=None and a='' in URL helper, still application name is appending. Thank you, Ashu --
[web2py] web2py appliance not working
Can some one tell if the eStore example appliance is working for you? https://github.com/mdipierro/web2py-appliances/tree/master/EStoreExample In web2py 2.1.1 the products don't get listed, I get an invalid SQL error. --
[web2py] Pivot tables using DAL?
Dear All, I have defined this model: db.define_table('fruits_in_shop', Field('shop_name'), Field('species'), Field('number','integer')) With this kind of record inside: fruits_in_shop.idhttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.id fruits_in_shop.shop_namehttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.shop_name fruits_in_shop.specieshttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.species fruits_in_shop.numberhttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.number 1 http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/1Mark's shopapple322http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/2Mark's shoppear223http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/3John's Marketbanana224http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/4John's Marketapple36 I'm looking for a way to show the result as a pivot table: *Shop applepear banana* Mark's shop 32 220 John's* *Market 32 0 22 I often used a mysql trick to get this result (similar to this one: http://www.artfulsoftware.com/infotree/queries.php#78), but there is a way to get this result using DAL? Otherwise I suppose to perform sequential queries and store the results in a dictionary. (fruits-select distict fruit from table; for fruit in fruits: column-select * from table where fruit=fruit;) In this case, there is a (easy) way to convert that dictionary into a gluon.sql.Rows object? Should I use its __init__ method? Any help would be apprecciated :) --
[web2py] Something I have been working on ...
https://github.com/mdipierro/mdpcl This is not web2py related but it is python related. The JS part could find applications in web2py apps. --
Re: [web2py] Re: Capturing field changes with _after_update and smartgrid
I thought of that too, but for some reason it appears to be a fragile solution in my mind. Should I be putting more faith in the stack? Is this something that is commonly done? -Jim On Fri, Nov 9, 2012 at 1:39 PM, Derek sp1d...@gmail.com wrote: Use before_update to store the current data in the session, then the after_update would have access to it. On Friday, November 9, 2012 11:55:36 AM UTC-7, Jim S wrote: Because the update may fail. -Jim On Friday, November 9, 2012 12:20:18 PM UTC-6, Derek wrote: Why not just use before_update? On Friday, November 9, 2012 10:53:21 AM UTC-7, Jim S wrote: I'm missing something. I have a table where I want to react to changes to a particular field. I'm trying to use the _after_update callback check for this. However, using this it appears to me that I am only seeing the data values after the update. I can't see what they were before the update so I don't know which fields we actually updated. Is there a 'bef'ore' buffer available that I'm missing? I'm trying to capture changes made using a smartgrid. Any tips would be appreciated. -Jim -- --
Re: [web2py] Re: Capturing field changes with _after_update and smartgrid
simple scientific thoughts. It's like databases triggers. Db triggers apply to the onupdate event, i.e. they let you use a set of just updated fields AND the fields that are going to be updated. Web2py has to intercept the update before or after, because databases (the python dbapi in general) don't expose that functionality. I rely on database triggers most of the times (as soon as I have access to the underlying database), but that's just because for simple things I'm faster on coding database triggers than python functions. However, with after_update, you can't scientific-ly know the values the rows had before the update, because the update has already happened. The stack works (I have in production several apps relying on web2py's triggers). After all, all your db(something).update() pass to the same function that applies - conditionally - the triggers. PS: if the update fails, then the trigger fails too if you don't do a db.commit() in the trigger itself. All web2py's operations are handled in transactions, so it's safe. Moreover, all the before_* triggers have the feature that if that function call returns True the update is not done kinda of an additional validation (I use that in business logics, e.g., you can't delete the default mapping for a particular product category) --
Re: [web2py] Re: Capturing field changes with _after_update and smartgrid
Thanks Niphlid, I was going to ask about the db.commit issue before but forgot. I'm going to give the _before_update callback a try and see how well that works for me. Thanks for all the responses, I truly appreciate it. -Jim On Fri, Nov 9, 2012 at 3:32 PM, Niphlod niph...@gmail.com wrote: simple scientific thoughts. It's like databases triggers. Db triggers apply to the onupdate event, i.e. they let you use a set of just updated fields AND the fields that are going to be updated. Web2py has to intercept the update before or after, because databases (the python dbapi in general) don't expose that functionality. I rely on database triggers most of the times (as soon as I have access to the underlying database), but that's just because for simple things I'm faster on coding database triggers than python functions. However, with after_update, you can't scientific-ly know the values the rows had before the update, because the update has already happened. The stack works (I have in production several apps relying on web2py's triggers). After all, all your db(something).update() pass to the same function that applies - conditionally - the triggers. PS: if the update fails, then the trigger fails too if you don't do a db.commit() in the trigger itself. All web2py's operations are handled in transactions, so it's safe. Moreover, all the before_* triggers have the feature that if that function call returns True the update is not done kinda of an additional validation (I use that in business logics, e.g., you can't delete the default mapping for a particular product category) -- --
Re: [web2py] Re: Capturing field changes with _after_update and smartgrid
Just reporting back. The _before_update is working perfectly for me. -Jim On Fri, Nov 9, 2012 at 3:45 PM, Jim Steil ato.st...@gmail.com wrote: Thanks Niphlid, I was going to ask about the db.commit issue before but forgot. I'm going to give the _before_update callback a try and see how well that works for me. Thanks for all the responses, I truly appreciate it. -Jim On Fri, Nov 9, 2012 at 3:32 PM, Niphlod niph...@gmail.com wrote: simple scientific thoughts. It's like databases triggers. Db triggers apply to the onupdate event, i.e. they let you use a set of just updated fields AND the fields that are going to be updated. Web2py has to intercept the update before or after, because databases (the python dbapi in general) don't expose that functionality. I rely on database triggers most of the times (as soon as I have access to the underlying database), but that's just because for simple things I'm faster on coding database triggers than python functions. However, with after_update, you can't scientific-ly know the values the rows had before the update, because the update has already happened. The stack works (I have in production several apps relying on web2py's triggers). After all, all your db(something).update() pass to the same function that applies - conditionally - the triggers. PS: if the update fails, then the trigger fails too if you don't do a db.commit() in the trigger itself. All web2py's operations are handled in transactions, so it's safe. Moreover, all the before_* triggers have the feature that if that function call returns True the update is not done kinda of an additional validation (I use that in business logics, e.g., you can't delete the default mapping for a particular product category) -- --
Re: [web2py] Re: Capturing field changes with _after_update and smartgrid
Cool, I might have suggested using versioning if all you are trying to do is to track changes. On Friday, November 9, 2012 3:38:28 PM UTC-7, Jim S wrote: Just reporting back. The _before_update is working perfectly for me. -Jim On Fri, Nov 9, 2012 at 3:45 PM, Jim Steil ato@gmail.com javascript: wrote: Thanks Niphlid, I was going to ask about the db.commit issue before but forgot. I'm going to give the _before_update callback a try and see how well that works for me. Thanks for all the responses, I truly appreciate it. -Jim On Fri, Nov 9, 2012 at 3:32 PM, Niphlod nip...@gmail.com javascript:wrote: simple scientific thoughts. It's like databases triggers. Db triggers apply to the onupdate event, i.e. they let you use a set of just updated fields AND the fields that are going to be updated. Web2py has to intercept the update before or after, because databases (the python dbapi in general) don't expose that functionality. I rely on database triggers most of the times (as soon as I have access to the underlying database), but that's just because for simple things I'm faster on coding database triggers than python functions. However, with after_update, you can't scientific-ly know the values the rows had before the update, because the update has already happened. The stack works (I have in production several apps relying on web2py's triggers). After all, all your db(something).update() pass to the same function that applies - conditionally - the triggers. PS: if the update fails, then the trigger fails too if you don't do a db.commit() in the trigger itself. All web2py's operations are handled in transactions, so it's safe. Moreover, all the before_* triggers have the feature that if that function call returns True the update is not done kinda of an additional validation (I use that in business logics, e.g., you can't delete the default mapping for a particular product category) -- --
[web2py] Re: DAL and Pivot Tables
try using groupby and sum http://web2py.com/books/default/chapter/29/06#sum,-avg,-min,-max-and-len On Friday, November 9, 2012 1:10:40 PM UTC-7, Rocco wrote: (I already post this question, but it was deleted in few seconds and no reason was mentioned. I try to repost it, removing formatting and external links... If something is wrong, please inform me :) I have defined this model: db.define_table('fruits_in_shop', Field('shop_name'), Field('species'), Field('number','integer')) With this kind of record inside: fruits_in_shop.id fruits_in_shop.shop_name fruits_in_shop.species fruits_in_shop.number 1 Mark's shop apple 32 2 Mark's shop pear 22 3 John's Market banana 22 4 John's Market apple 36 I'm looking for a way to show the result as a pivot table: Shop applepear banana Mark's shop 32 220 John's Market 32 0 22 I often used a mysql trick to get this result, but there is a way to get this result using DAL? Otherwise I suppose to perform sequential queries and store the results in a dictionary. (fruits-select distict fruit from table; for fruit in fruits: column-select * from table where fruit=fruit;) In this case, there is a (easy) way to convert that dictionary into a gluon.sql.Rows object? Should I use its __init__ method? --
[web2py] Re: calendar display
Please reply to this as soon as possible.Thank you in advance On Sunday, November 4, 2012 8:03:20 AM UTC+5:30, dantuluri jaganadha raju wrote: Hi, I want to display the calendar that will display when we click on some field(appropriate) of a form .One thing is that I will not click on field.,what I mean is that ,it should appear as soon as I entered that page and should have same functions(dynamic) that is in normal calendar that displays in web2py.Moreover I am NOT USING EXTENDED LAYOUT.HTML and using new layout. please reply as soon as possible what changes I have to make. Thank you in advance ... Raju. --
[web2py] Images not laoded
Hello All, The images of my home page didn't load if I try to access it with the following URLs: localhost:8000/ localhost:8000/mm/ but loaded fine with: localhost:8000/mm/default/ or localhost:8000/mm/default/index/ the name of my application being, of course, mm and my home page is displayed by default/index. In the console of Firebug I've got the following error message for each images of the home page (when I try to access it by / or /mm) : NetworkError: 404 NOT FOUND - http://127.0.0.1:8000/static/images/image.jpg;. My folder image is under: ~/web2py/applications/mm/static/images. It is a problem if I want to set deafult_application = mm (in routes.py)... Could you help me understand that situation? Thanks. --
[web2py] Re: Images not laoded
Are you doing images like this? IMG(_src=URL('static','logo.png'), _alt=My Logo) or img src=URL('static','logo.png') alt=My Logo On Friday, November 9, 2012 7:20:03 PM UTC-8, Julien Courteau wrote: Hello All, The images of my home page didn't load if I try to access it with the following URLs: localhost:8000/ localhost:8000/mm/ but loaded fine with: localhost:8000/mm/default/ or localhost:8000/mm/default/index/ the name of my application being, of course, mm and my home page is displayed by default/index. In the console of Firebug I've got the following error message for each images of the home page (when I try to access it by / or /mm) : NetworkError: 404 NOT FOUND - http://127.0.0.1:8000/static/images/image.jpg;. My folder image is under: ~/web2py/applications/mm/static/images. It is a problem if I want to set deafult_application = mm (in routes.py)... Could you help me understand that situation? Thanks. --
[web2py] Ref: SQLFORM.grid question
Hi, How does one achieve clicking a row SQLFORM.grid and the details open in a modal window form, save changes to fields then modal window closes and the grid is refreshed with changes. Whr can I find comprehensive documentation on the SQLFORM.grid. Teddy L --