[web2py] Re: Caching downloads
It seems Mariano's story has a happy ending. Congratulations. But on a second thought, can anyone explain why "if you quickly reload pages, they fail" in the very first caching-download version? Caching download can improve speed, can with a side effect of bypassing priviledge check, but no matter what, it shall not cause content fail to load. I remember I once tried @cache(...) but encounter similar problems, then I give up. :-( Nice to pick it up if someone can throw some light. Thanks! Regards, iceberg On May5, 11:39am, Mariano Reingart wrote: > .. after using fast_download (changing headers and using > stream) it runs really quickly! > > (I know, serving through apache would be even faster, but in this case > I prefer portability and a easy configuration) > > You can see how it's running here: > > http://www.pyday.com.ar/rafaela2010/ > > (look at images at the sidebar) > > Thanks so much, > > Mariano > > > > > >> On May 4, 9:04 pm, Mariano Reingart wrote: > >>> I thought so, > > >>> I had to modify mydownload so browsers do client-side caching, > >>> speeding up the web-page load: > > >>> def fast_download(): > >>> # very basic security: > >>> if not request.args(0).startswith("sponsor.logo"): > >>> return download() > >>> # remove/add headers that prevent/favors caching > >>> del response.headers['Cache-Control'] > >>> del response.headers['Pragma'] > >>> del response.headers['Expires'] > >>> filename = os.path.join(request.folder,'uploads',request.args(0)) > >>> response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y > >>> %H:%M:%S +", time.localtime(os.path.getmtime(filename))) > >>> return response.stream(open(filename,'rb')) > > >>> TODO: handle If-Modified-Since (returning 304 if not modified), but as > >>> you said, let the browser do that if so much performance is needed (so > >>> far, fast_download is working fine for me now :-) > > >>> Thanks very much for your help, and please let me know if there is > >>> anything wrong with this approach, > > >>> Best regards, > > >>> Mariano > > >>> On Tue, May 4, 2010 at 10:23 PM, mdipierro > >>> wrote: > >>> > caching downloads does not make sense. This is because the role of > >>> > download is to check permissions to download a file (if they are set). > >>> > if you cache it then you do not check. If you do not need to check do > >>> > not use download. Use > > >>> > def mydownload(): > >>> > return > >>> > response.stream(open(os.path.join(request.folder,'uploads',request.args(0)) > >>> > ,'rb')) > > >>> > or better use the web server to download the uploaded files. > > >>> > On May 4, 6:11 pm, Mariano Reingart wrote: > >>> >> To cache images, I'm trying to do: > > >>> >> @cache(request.env.path_info,60,cache.ram) > >>> >> def download(): return response.download(request,db) > > >>> >> But seems that is not > >>> >> working:http://www.web2py.com.ar/raf10dev/default/index > >>> >> (see images at sidebar, if you quickly reload pages, they fail) > > >>> >> The book says something about response.render, but nothing about > >>> >> download... > >>> >> Anyway, I'm not sure if this is a good use of @cache, are there any > >>> >> other way ? > > >>> >> BTW, why Cache-Control: no?... > > >>> >> Best regards, > > >>> >> Mariano > >>> >> Reingarthttp://www.sistemasagiles.com.arhttp://reingart.blogspot.com
[web2py] Bug and fix about IS_DATE_IN_RANGE()
Hi Massimo, Right now, IS_DATE_IN_RANGE(minimum=foo, maximum=bar) does NOT accept the given minimum nor maximum value. That is not the design intention according to error message. Please get rid off the two equal marks in IS_DATE_IN_RANGE.__call__(). Same applies to IS_DATETIME_IN_RANGE. Thanks. Iceberg
[web2py] Re: Bug and fix about IS_DATE_IN_RANGE()
Thanks for the quick response and fix. But one more comment when talking about doctest. You current doctest cases does not qualified to catch the bug. You need to design cases for critical point. Besides, you need not use "print" in doctest. For example, the current trunk: >>> v = IS_DATE_IN_RANGE(minimum=datetime.date(2008,1,1), \ maximum=datetime.date(2009,12,31), \ format="%m/%d/ %Y",error_message="oops") >>> print v('03/03/2008') (datetime.date(2008, 3, 3), None) I would suggest: >>> v = IS_DATE_IN_RANGE(minimum=datetime.date(2008,1,1), \ maximum=datetime.date(2009,12,31), \ format="%m/%d/ %Y",error_message="oops") >>> v('1/01/2008') (datetime.date(2008, 1, 1), None) Might not be considered as a big deal, although. Just my $0.02 Regards, Iceberg On May8, 7:39am, mdipierro wrote: > Done. I added one test each. we should have more tests in gluon/tests > we have none, only doctests for validators. > > On May 7, 4:26 pm, Jonathan Lundell wrote: > > > > > On May 7, 2010, at 9:30 AM, Iceberg wrote: > > > > Right now, IS_DATE_IN_RANGE(minimum=foo, maximum=bar) does NOT accept > > > the given minimum nor maximum value. That is not the design intention > > > according to error message. Please get rid off the two equal marks in > > > IS_DATE_IN_RANGE.__call__(). > > > > Same applies to IS_DATETIME_IN_RANGE. > > > Anybody who patches this: please add the relevant doctests.
[web2py] How to set multiple primary key?
Hi there, I am fiddling multiple primary keys. Somehow I managed to find following example inside gluon/sql.py db.define_table('account', Field('accnum','integer'), Field('acctype'), Field('accdesc'), primarykey=['accnum','acctype']) But running the example throws: Traceback (most recent call last): .. File "C:\DOWNLOAD\google_appengine\web2py\gluon\sql.py", line 2112, in __init__ raise SyntaxError, 'invalid table "%s" attribute: %s' % (tablename, k) SyntaxError: invalid table "account" attribute: sequence_name What did I do wrong? Iceberg
[web2py] Re: How to set multiple primary key?
I am not dealing with legacy tables, I am just starting a new db and wondering whether I can set multiple primary key, in order to eliminate the chance of duplicated data. For example. db = DAL('sqlite://storage.sqlite') db.define_table('account', Field('given_name'), Field('surname'), Field('phone_number'), primarykey=['given_name','surname']) On May9, 3:23am, DenesL wrote: > Multiple primary keys should work if you are defining legacy tables in > one of the supported DB engines. > Are you using MS SQL, DB2, Ingres or Informix? > Can we see the model? > > On May 8, 5:57 am, Iceberg wrote: > > > > > Hi there, > > > I am fiddling multiple primary keys. Somehow I managed to find > > following example inside gluon/sql.py > > > db.define_table('account', > > Field('accnum','integer'), > > Field('acctype'), > > Field('accdesc'), > > primarykey=['accnum','acctype']) > > > But running the example throws: > > > Traceback (most recent call last): > > .. > > File "C:\DOWNLOAD\google_appengine\web2py\gluon\sql.py", line 2112, > > in __init__ > > raise SyntaxError, 'invalid table "%s" attribute: %s' % > > (tablename, k) > > SyntaxError: invalid table "account" attribute: sequence_name > > > What did I do wrong? > > > Iceberg
[web2py] Re: Calculation error
Is that possibly because the default value of tipvalue is a string '0.15'? Try use float 0.15 instead. -- Iceberg On May9, 11:00am, greenpoise wrote: > Model: > > db.define_table('order', > Field('employee',db.person), > Field('tablenumber'), > Field('ordernumber'), > Field('orderdate','date'), > Field('totalsale', 'decimal(10,2)'), > Field('tipgranted', 'decimal(10,2)',default=None, update=None, > readable=False), > Field('tipvalue','decimal(10,2)',default='0.15'),) > > @auth.requires_login() > def show_orders(): > db.order.tipgranted.compute=lambda r: > r['totalsale']*r['tipvalue'] > form=crud.create(db.order) > > orders=db(db.order.employee==employee.id).select(orderby=db.order.ordernumb > er) > return dict(employee=employee,orders=orders,form=form) > > thanks > > On May 8, 10:54 pm, mdipierro wrote: > > > > > Can you show us the model and the action that triggers this? > > > On May 8, 9:49 pm, greenpoise wrote: > > > > Can someone help me. I am trying to do a simple calculation of fields. > > > Fields are defined as decimal in db.py and here is the calculation: > > > > db.order.tipgranted.compute=lambda r: r['totalsale']*r['tipvalue'] > > > > error: TypeError: can't multiply sequence by non-int of type 'float'
[web2py] Re: How to set multiple primary key?
Thanks for the info. Would you please comment on my following understanding and further questions? 1. Keyed tables are only designed for dealing with legacy tables. Is that true? And how do we define multiple primary keys in a brand new db? Consider the address book scenario in my previous post. 2. Keyed tables are yet to be supported in some other DB engines, but NOT the handy SQLite. Is there any special reason for that? AFAIK SQLite contains native support for multiple primary key. 3. Neither keyword KeyedTable nor primarykey can be found in http://www.web2py.com/book right now. Why? Denes' good work deserves being mentioned as a dedicated section. Thanks in advance. Sincerely, Iceberg On May9, 8:55pm, DenesL wrote: > SQLite is not one of the supported DBs. > Keyed tables are only supported in MS SQL, DB2, Ingres and Informix. > Other DB engines (except SQLite)might be added following section E > inhttp://groups.google.com/group/web2py/msg/c9848792a8999c5f > > On May 8, 2:48 pm, Iceberg wrote: > > > > > I am not dealing with legacy tables, I am just starting a new db and > > wondering whether I can set multiple primary key, in order to > > eliminate the chance of duplicated data. > > > For example. > > > db = DAL('sqlite://storage.sqlite') > > db.define_table('account', > > Field('given_name'), > > Field('surname'), > > Field('phone_number'), > > primarykey=['given_name','surname']) > > > On May9, 3:23am, DenesL wrote: > > > > Multiple primary keys should work if you are defining legacy tables in > > > one of the supported DB engines. > > > Are you using MS SQL, DB2, Ingres or Informix? > > > Can we see the model? > > > > On May 8, 5:57 am, Iceberg wrote: > > > > > Hi there, > > > > > I am fiddling multiple primary keys. Somehow I managed to find > > > > following example inside gluon/sql.py > > > > > db.define_table('account', > > > > Field('accnum','integer'), > > > > Field('acctype'), > > > > Field('accdesc'), > > > > primarykey=['accnum','acctype']) > > > > > But running the example throws: > > > > > Traceback (most recent call last): > > > > .. > > > > File "C:\DOWNLOAD\google_appengine\web2py\gluon\sql.py", line 2112, > > > > in __init__ > > > > raise SyntaxError, 'invalid table "%s" attribute: %s' % > > > > (tablename, k) > > > > SyntaxError: invalid table "account" attribute: sequence_name > > > > > What did I do wrong? > > > > > Iceberg
[web2py] Enhancement to gluon.tools.Mail
Hi pals, gluon.tools.Mail is handy but it doesn't not contain the Date header of a mail. Some email system tend to suspect such email as spam because it is not like usual email client behavior. It is easy to fix. Just add a line after the line begins with "payload['Subject'] = ..." as below: from time import gmtime, strftime payload['Date'] = strftime("%a, %d %b %Y %H:%M:%S +", gmtime()) Besides, document here has some typo ("gluon.tool.Mail") and perhaps outdated (no need for globals() any more). http://web2py.com/book/default/section/5/5?search=mail Regards, Iceberg
[web2py] Re: Catch and replace vars
Model: db.define_table('table_1', Field('field_1'), Field('field_2') ) Controller: def index(): def magic(form): form.vars.field_2 = form.vars.field_1 form = SQLFORM(db.table_1) if form.accepts(request.vars, onvalidation=magic): pass # ok return {'form': form} I did not test it. But it shows you the key of using onvalidation() trick. Regards, Iceberg On May11, 12:08am, AsmanCom wrote: > Hi, > > i want to do a simple task: > > def function_1(): > var_field_1=request.vars.field_1 > if var_field_1: > return var_field_1 > > db.define_table('table_1', > Field('field_1','string' ), > Field('field_2', default=function_1) > ) > > db.table_1.field_1.default='Autogenerated' > db.table_1.field_2.default='Autogenerated' > > I want to catch default vars from field 1 and insert them in field_2 > instead. > Is this possible? > > ###becomes interesting when combined, with IS_IN_DB and the > get_or_create function###
[web2py] Re: User stack or queue
Hi peter, since you are a beginner of web2py even python, why not just come back to learn Python [1] and then web2py [2]? Don't expect to learn their "syntax" on a maillist. Please, cherish your time, as well as others. If, after your syntax learning, you have some design question or puzzles, feel free to come back and lots of people will be glad to help you. By the way, you join this maillist one year ago and sent 100+ posts. Didn't you learn some python and web2py since then? [1] http://docs.python.org/tutorial/ [2] http://www.web2py.com/book On May11, 12:21am, pk wrote: > ok thank you very much, > but i am a beginner of web2py and python. > what i have to do into a controller, what into the view? > how is the syntax? > > peter > > On 10 Mai, 18:17, Vasile Ermicioi wrote: > > > > > here is a sketch: > > > db.define_table('what_to_see', Field('html_code', 'text')) > > db.define_table('what_to_see_queue', Field('user', db.users), > > Field('when_allowed_to_see', 'datetime')) > > > if user_not_in_queue: > > if last_user_allowed_time + 5minutes < time_now: > > when_allowed_to_see = time_now > > else: > > when_allowed_to_see = time_now > > add_user_to_queue_with_his_time > > if when_allowed_to_see > time_now: > > display_refresh_in (when_allowed_to_see - time_now) > > and_a_script_to_refresh_page_after_a_period_of_time > > else: > > display_html_code > > delete_user_from_queue
[web2py] Re: Enhancement to gluon.tools.Mail
It works! :-) On May11, 4:58am, mdipierro wrote: > In trunk, thanks. Please check it. > > On May 10, 3:23 am, Iceberg wrote: > > > > > Hi pals, > > > gluon.tools.Mail is handy but it doesn't not contain the Date header > > of a mail. Some email system tend to suspect such email as spam > > because it is not like usual email client behavior. > > > It is easy to fix. Just add a line after the line begins with > > "payload['Subject'] = ..." as below: > > > from time import gmtime, strftime > > payload['Date'] = strftime("%a, %d %b %Y %H:%M:%S +", > > gmtime()) > > > Besides, document here has some typo ("gluon.tool.Mail") and perhaps > > outdated (no need for globals() any > > more).http://web2py.com/book/default/section/5/5?search=mail > > > Regards, > > Iceberg
[web2py] Re: Catch and replace vars
I must miss the "compute" feature. Now I am picking it up. Would you please confirm whether my understanding is correct? The code: Field('bar', compute=lambda r:r.foo) is an easier equivalent for: def callback(form): form.vars.bar = form.vars.foo form.accepts(..., onvalidation=callback) and it only works before inserting or updating a record into db. On the contrary, rows.setvirtualfields(...), only works when retrieving records from db. (Detail in http://groups.google.com/group/web2py/browse_frm/thread/d93eee8cc2495c8c ) Is it right? Regards, iceberg On May11, 10:23pm, mdipierro wrote: > I think you look for something like > > db.table.field_2.compute=lambda r: request.vars.field_1 > > On May 11, 4:01 am, AsmanCom wrote: > > > > > That would be a great solution, but i´ve to do this in model because i > > am using the awesome JQGrid plugin (app.ebansoftware.net/ > > editable_jqgrid/). > > The dilemma is: > > - I need to do this in the model > > - I can`t get the vars from table.field.default (self-evident) > > - I need a working IS_IN_DB(db,'table.id','table.name') validator and > > label (for the JQGrid plugin) > > - I can´t add an aditional validator (because IS_IN_DB +label don´t > > show up right, when combined with other validators) > > - The form must be visible to the user, so i can´t go with > > table.field.compute > > > So I think to implement this with Field default function is the right > > approach? > > But I need to catch the vars, compute someth. and Insert. > > > Any ideas? > > > On 10 Mai, 19:47, Iceberg wrote: > > > > Model: > > > db.define_table('table_1', > > > Field('field_1'), > > > Field('field_2') > > > ) > > > > Controller: > > > def index(): > > > def magic(form): > > > form.vars.field_2 = form.vars.field_1 > > > form = SQLFORM(db.table_1) > > > if form.accepts(request.vars, onvalidation=magic): > > > pass # ok > > > return {'form': form} > > > > I did not test it. But it shows you the key of using onvalidation() > > > trick. > > > > Regards, > > > Iceberg > > > > On May11, 12:08am, AsmanCom wrote: > > > > > Hi, > > > > > i want to do a simple task: > > > > > def function_1(): > > > > var_field_1=request.vars.field_1 > > > > if var_field_1: > > > > return var_field_1 > > > > > db.define_table('table_1', > > > > Field('field_1','string' ), > > > > Field('field_2', default=function_1) > > > > ) > > > > > db.table_1.field_1.default='Autogenerated' > > > > db.table_1.field_2.default='Autogenerated' > > > > > I want to catch default vars from field 1 and insert them in field_2 > > > > instead. > > > > Is this possible? > > > > > ###becomes interesting when combined, with IS_IN_DB and the > > > > get_or_create function###
[web2py] Delete record without triggering validators?
Hi Massimo, Right now validators are triggered even when a record is successfully being deleted. This can be annoying in case I am deleting old records as below: db.define_table('my_table', Field('today', 'date', requires=IS_DATE_IN_RANGE(minimum=request.now.date()), default = request.now.date(), ) ) What if we drop all the form.errors content before line 923 in gluon/ sqlhtml.py? if requested_delete: .. self.form.errors = {} # to override unnecessary error message return True Or a better way is to do delete before validators are called. Can you do that? Regards, Iceberg
[web2py] Re: Catch and replace vars
Thanks for the tip, but there seems some more subtle difference between form.accepts(..., onvalidation=callback) VS Field('bar', compute=lambda r:r['foo']). The latter will cause that field no longer showts up in SQLFORM, because its default self.fields excludes all compute field. Is there any reason for that? Right now I still have to stick to my form.accepts(..., onvalidation=callback) approach. :-/ Sincerely, Iceberg On May12, 1:30am, mdipierro wrote: > Yes but > > Field('bar', compute=lambda r:r['foo']) > > not > > Field('bar', compute=lambda r:r.foo) > > On May 11, 11:28 am, Iceberg wrote: > > > > > I must miss the "compute" feature. Now I am picking it up. Would you > > please confirm whether my understanding is correct? > > > The code: > > Field('bar', compute=lambda r:r.foo) > > is an easier equivalent for: > > def callback(form): form.vars.bar = form.vars.foo > > form.accepts(..., onvalidation=callback) > > and it only works before inserting or updating a record into db. > > > On the contrary, rows.setvirtualfields(...), only works when > > retrieving records from db. (Detail > > inhttp://groups.google.com/group/web2py/browse_frm/thread/d93eee8cc2495c8c > > ) > > > Is it right? > > > Regards, > > iceberg > > > On May11, 10:23pm, mdipierro wrote: > > > > I think you look for something like > > > > db.table.field_2.compute=lambda r: request.vars.field_1 > > > > On May 11, 4:01 am, AsmanCom wrote: > > > > > That would be a great solution, but i´ve to do this in model because i > > > > am using the awesome JQGrid plugin (app.ebansoftware.net/ > > > > editable_jqgrid/). > > > > The dilemma is: > > > > - I need to do this in the model > > > > - I can`t get the vars from table.field.default (self-evident) > > > > - I need a working IS_IN_DB(db,'table.id','table.name') validator and > > > > label (for the JQGrid plugin) > > > > - I can´t add an aditional validator (because IS_IN_DB +label don´t > > > > show up right, when combined with other validators) > > > > - The form must be visible to the user, so i can´t go with > > > > table.field.compute > > > > > So I think to implement this with Field default function is the right > > > > approach? > > > > But I need to catch the vars, compute someth. and Insert. > > > > > Any ideas? > > > > > On 10 Mai, 19:47, Iceberg wrote: > > > > > > Model: > > > > > db.define_table('table_1', > > > > > Field('field_1'), > > > > > Field('field_2') > > > > > ) > > > > > > Controller: > > > > > def index(): > > > > > def magic(form): > > > > > form.vars.field_2 = form.vars.field_1 > > > > > form = SQLFORM(db.table_1) > > > > > if form.accepts(request.vars, onvalidation=magic): > > > > > pass # ok > > > > > return {'form': form} > > > > > > I did not test it. But it shows you the key of using onvalidation() > > > > > trick. > > > > > > Regards, > > > > > Iceberg > > > > > > On May11, 12:08am, AsmanCom wrote: > > > > > > > Hi, > > > > > > > i want to do a simple task: > > > > > > > def function_1(): > > > > > > var_field_1=request.vars.field_1 > > > > > > if var_field_1: > > > > > > return var_field_1 > > > > > > > db.define_table('table_1', > > > > > > Field('field_1','string' ), > > > > > > Field('field_2', default=function_1) > > > > > > ) > > > > > > > db.table_1.field_1.default='Autogenerated' > > > > > > db.table_1.field_2.default='Autogenerated' > > > > > > > I want to catch default vars from field 1 and insert them in field_2 > > > > > > instead. > > > > > > Is this possible? > > > > > > > ###becomes interesting when combined, with IS_IN_DB and the > > > > > > get_or_create function###
[web2py] Re: Using LOAD from a controller?
def function_A(): return {'something':'blah blah'} def function_B(): return {another_thing} then in function_A.html you can use: {{=something}} {{=LOAD(URL(r=request,f='function_B'),ajax=True)}} On May12, 4:16am, Keith Edmunds wrote: > I was to display a form using Ajax in response to a click on a link on the > page. I have tried putting this in the view: > > New todo > > > with this in the controller: > > def new(): > > return = LOAD('todo','todo_form',ajax=True) > > def todo_form(): > form = SQLFORM(db.tasks,fields=['priority','subject','duedate']) > if form.accepts(request.vars,session): > session.flash = 'record inserted' > redirect(URL(request.application,'default','index')) > return form > > ...but that doesn't work. > > I don't think I've fully understood how LOAD works - can someone point me > in the right direction, please?
[web2py] Re: Using LOAD from a controller?
On a second look, your case seems having no need for LOAD. How about adjust your code like this? New todo On May12, 4:43am, Keith Edmunds wrote: > Sorry, Iceburg, I appreciate your attempt to help, but you've lost me > completely! Can you explain? > > Thanks
[web2py] Re: Catch and replace vars
So if I understand it correctly, the Field(..., compute=...) is only suitable for defining a field which is not supposed to be showed in SQLFORM(), neither supposed to be filled by human. For example, this case can use Field(..., compute=...). db.define_table('circles', Field('radius', 'double'), Field('area', 'double', compute = lambda record: record['radius']**2*3.14), ) And this case should not. (Why? Try.) db.define_table('visitor_booking', Field('adult', 'integer'), Field('kid', 'integer', compute = lambda r: min(r['kid'], r['adult']) ), # each kid must be accompanied by one dedicated adult ) PS: Of course the latter case should have better approach. Here I am just demostrating when and when not to use Field(..., compute=...) Regards, iceberg On May12, 2:22am, Iceberg wrote: > Thanks for the tip, but there seems some more subtle difference > between form.accepts(..., onvalidation=callback) VS Field('bar', > compute=lambda r:r['foo']). > > The latter will cause that field no longer showts up in SQLFORM, > because its default self.fields excludes all compute field. Is there > any reason for that? > > Right now I still have to stick to my form.accepts(..., > onvalidation=callback) approach. :-/ > > Sincerely, > Iceberg > > On May12, 1:30am, mdipierro wrote: > > > > > Yes but > > > Field('bar', compute=lambda r:r['foo']) > > > not > > > Field('bar', compute=lambda r:r.foo) > > > On May 11, 11:28 am, Iceberg wrote: > > > > I must miss the "compute" feature. Now I am picking it up. Would you > > > please confirm whether my understanding is correct? > > > > The code: > > > Field('bar', compute=lambda r:r.foo) > > > is an easier equivalent for: > > > def callback(form): form.vars.bar = form.vars.foo > > > form.accepts(..., onvalidation=callback) > > > and it only works before inserting or updating a record into db. > > > > On the contrary, rows.setvirtualfields(...), only works when > > > retrieving records from db. (Detail > > > inhttp://groups.google.com/group/web2py/browse_frm/thread/d93eee8cc2495c8c > > > ) > > > > Is it right? > > > > Regards, > > > iceberg > > > > On May11, 10:23pm, mdipierro wrote: > > > > > I think you look for something like > > > > > db.table.field_2.compute=lambda r: request.vars.field_1 > > > > > On May 11, 4:01 am, AsmanCom wrote: > > > > > > That would be a great solution, but i´ve to do this in model because i > > > > > am using the awesome JQGrid plugin (app.ebansoftware.net/ > > > > > editable_jqgrid/). > > > > > The dilemma is: > > > > > - I need to do this in the model > > > > > - I can`t get the vars from table.field.default (self-evident) > > > > > - I need a working IS_IN_DB(db,'table.id','table.name') validator and > > > > > label (for the JQGrid plugin) > > > > > - I can´t add an aditional validator (because IS_IN_DB +label don´t > > > > > show up right, when combined with other validators) > > > > > - The form must be visible to the user, so i can´t go with > > > > > table.field.compute > > > > > > So I think to implement this with Field default function is the right > > > > > approach? > > > > > But I need to catch the vars, compute someth. and Insert. > > > > > > Any ideas? > > > > > > On 10 Mai, 19:47, Iceberg wrote: > > > > > > > Model: > > > > > > db.define_table('table_1', > > > > > > Field('field_1'), > > > > > > Field('field_2') > > > > > > ) > > > > > > > Controller: > > > > > > def index(): > > > > > > def magic(form): > > > > > > form.vars.field_2 = form.vars.field_1 > > > > > > form = SQLFORM(db.table_1) > > > > > > if form.accepts(request.vars, onvalidation=magic): > > > > > > pass # ok > > > > > > return {'form': form} > > > > > > > I did not test it. But it shows you the key of using onvalidation() > > > > > > trick. > > > > > > > Regards, > > > > > > Iceberg > > > > > > > On May11, 12:08am, AsmanCom wrote: > > > > > > > > Hi, > > > > > > > > i want to do a simple task: > > > > > > > > def function_1(): > > > > > > > var_field_1=request.vars.field_1 > > > > > > > if var_field_1: > > > > > > > return var_field_1 > > > > > > > > db.define_table('table_1', > > > > > > > Field('field_1','string' ), > > > > > > > Field('field_2', default=function_1) > > > > > > > ) > > > > > > > > db.table_1.field_1.default='Autogenerated' > > > > > > > db.table_1.field_2.default='Autogenerated' > > > > > > > > I want to catch default vars from field 1 and insert them in > > > > > > > field_2 > > > > > > > instead. > > > > > > > Is this possible? > > > > > > > > ###becomes interesting when combined, with IS_IN_DB and the > > > > > > > get_or_create function###
[web2py] Re: Catch and replace vars
As I said at the end of my previous post: "Of course the latter case should have better approach. Here I am just demostrating when and when not to use Field(..., compute=...) " The point here is I wanna figure out the scenario for all those not-so- obvious parameters of Field(...), such as compute, authorize, update, etc. Some answers can be found via google "web2py Field foo", some don't. And so far the official book seems contain no chapter for that. [1] is too simple, and [2] is outdated. [1] http://web2py.com/book/default/section/6/3 [2] http://web2py.com/book/default/docstring/Field On May12, 11:32pm, mdipierro wrote: > Why would you want web2py to auto-compute a field when you have asked > the user for its value? unless you want the computation BEFORE you > prompt the user for a value. But in this case it cannot depend on > other fields because they have not been insrted yet. > > On May 12, 9:30 am, Iceberg wrote: > > > > > So if I understand it correctly, the Field(..., compute=...) is only > > suitable for defining a field which is not supposed to be showed in > > SQLFORM(), neither supposed to be filled by human. > > > For example, this case can use Field(..., compute=...). > > > db.define_table('circles', > > Field('radius', 'double'), > > Field('area', 'double', > > compute = lambda record: record['radius']**2*3.14), > > ) > > > And this case should not. (Why? Try.) > > > db.define_table('visitor_booking', > > Field('adult', 'integer'), > > Field('kid', 'integer', > > compute = lambda r: min(r['kid'], r['adult']) ), > > # each kid must be accompanied by one dedicated adult > > ) > > > PS: Of course the latter case should have better approach. Here I am > > just demostrating when and when not to use Field(..., compute=...) > > > Regards, > > iceberg > > > On May12, 2:22am, Iceberg wrote: > > > > Thanks for the tip, but there seems some more subtle difference > > > between form.accepts(..., onvalidation=callback) VS Field('bar', > > > compute=lambda r:r['foo']). > > > > The latter will cause that field no longer showts up in SQLFORM, > > > because its default self.fields excludes all compute field. Is there > > > any reason for that? > > > > Right now I still have to stick to my form.accepts(..., > > > onvalidation=callback) approach. :-/ > > > > Sincerely, > > > Iceberg > > > > On May12, 1:30am, mdipierro wrote: > > > > > Yes but > > > > > Field('bar', compute=lambda r:r['foo']) > > > > > not > > > > > Field('bar', compute=lambda r:r.foo) > > > > > On May 11, 11:28 am, Iceberg wrote: > > > > > > I must miss the "compute" feature. Now I am picking it up. Would you > > > > > please confirm whether my understanding is correct? > > > > > > The code: > > > > > Field('bar', compute=lambda r:r.foo) > > > > > is an easier equivalent for: > > > > > def callback(form): form.vars.bar = form.vars.foo > > > > > form.accepts(..., onvalidation=callback) > > > > > and it only works before inserting or updating a record into db. > > > > > > On the contrary, rows.setvirtualfields(...), only works when > > > > > retrieving records from db. (Detail > > > > > inhttp://groups.google.com/group/web2py/browse_frm/thread/d93eee8cc2495c8c > > > > > ) > > > > > > Is it right? > > > > > > Regards, > > > > > iceberg
[web2py] Re: When and how to use command line option -f FOLDER?
Hi Massimo, Turns out that the fix [1] is not completed. Most apps work when using "web2py -f another_web2py_folder", but not those contains local_import('my_module', app='my_app'). Should be easy to fix, but I even tried to add following lines at line 706 of gluon/widget.py, yet have no luck. sys.path.append(options.folder) sys.path.append(os.path.join(options.folder,'applications')) What can I do? [1] http://code.google.com/p/web2py/source/detail?r=52c0b092adef8a96f1f18c84e5681d4548acd9ae Regards, Iceberg On Apr8, 2:18pm, mdipierro wrote: > here is how it works now (its was more convoluted before) > > web2py must find gluon folder in path. > it also expects to find applications/ in os.environ['web2py_path'] or > in os.getcwd(). > > -f path sets os.environ['web2py_path'] = path > > Massimo
[web2py] Re: PGP Mail
On May15, 10:39am, Massimo Di Pierro wrote: > Thanks to szimszon we have PGP in Mail (trunk only) > > mail.send( > self, > to, > subject='None', > message='None', > attachments=None, > cc=None, > bcc=None, > reply_to=None, > encoding='utf-8', > cipher_type=None, > sign=True, > sign_passphrase=None, > encrypt=True, > ) > > Please check it. Should > cipher_type=None, > sign=True, > sign_passphrase=None, > encrypt=True, > be set at the send level or at the mail.settings level? Do people tend > to use different passphrases for different emails or the same one? Nice to know that. And I agree those cipher options be set at send() level, because a website might want to send out automatic email FROM different account, say, most normal notice from "donotre...@mydomain.com", but some interview confirmation from "h...@mydomain.com", etc.? But it doesn't harm if mail.settings contains all those cipher options, and then inside send() we code like this: def send(..., cipher_type=None, sign=True, sign_passphrase=None, encrypt=True, ): if not cipher_type: cipher_type = self.settings.cipher_type ...
[web2py] Re: When and how to use command line option -f FOLDER?
On May15, 11:08am, Jonathan Lundell wrote: > On May 14, 2010, at 11:27 AM, Iceberg wrote: > > > Turns out that the fix [1] is not completed. Most apps work when using > > "web2py -f another_web2py_folder", but not those contains > > local_import('my_module', app='my_app'). > > > Should be easy to fix, but I even tried to add following lines at line > > 706 of gluon/widget.py, yet have no luck. > > sys.path.append(options.folder) > > sys.path.append(os.path.join(options.folder,'applications')) > > > What can I do? > > > [1]http://code.google.com/p/web2py/source/detail?r=52c0b092adef8a96f1f18... > > Suggestion. > > path = os.path.normpath(path) > if path not in sys.path: sys.path.insert(0, path) > > Two things: normalizing the path is a good idea, and using insert instead of > append means that the new path will override what's in the old one. Hi Jonathan, thanks for your throwing lights, two at a time. :-) I try os.path.normpath(options.folder) but it is not the case. Because options.folder is already in local platform format. Besides, it seems the built-in import statement tolerates sys.path as ['C:\\foo', '../ bar'] anyway. Mysteriously, using sys.path.insert(...) rather than sys.path.append(...) does help. But I just don't understand. I used to think that the build-in import statement always goes through all folders inside sys.path, one by one, so in theory it does not matter whether a path appears in sys.path earlier or later. (Unless two different version of same name module exist in two different path, but it is not the case this time.) //shrug Any explanation for that, Jonathan? @Massimo, thanks for your latest attempt, but it should be adjusted as below. And please also keep the comment which is valuable also. sys.path.insert(0, path) # somehow it need to be ahead of cwd Thank you two. Regards, Iceberg
[web2py] Re: large sites/application.
Just some thought. What if we could somehow change app1's model into a module, automatically? For example app1/models/__init__.py # Add this And then append this into your app1/models/db.py: __all__ = [ 'what', 'you', 'wanna', 'share' ] # This might not be necessary Havn't tried it. But if it works, we only have two places for model files, as good as django. On May15, 6:51pm, Thadeus Burgess wrote: > Yes, web2py runs fine with 50 models. And this is awesome if your just > dealing with one application > > What gets messy is when you have two applications, which depend on > each others models. > > You end up having to stick the common models in a module, and > importing it, but now you have three places to edit model files, and > this is where django shines in its re-usable app structure.. > > In web2py you have to do > > from common_model import myModel > > in both applications, its complex and stupid. In django its just > > from myapp1 import myModel > > And you start using it, everything is still defined in myapp1, no need > for redefining your models or even sticking them in a third location. > > -- > Thadeus
[web2py] Re: integer range select box
On May15, 11:14pm, Jose wrote: > On 15 mayo, 10:58, Richard wrote: > > > I want the user to select an integer between a certain range (their > > birth year) . IS_INT_IN_RANGE provides the restriction but uses an > > input box - how can I get SQLFORM to use a select box for this integer > > range? > > > Richard > > This helps you? > > .requires = IS_IN_SET([x for x in range(1, 4)], zero=None) > > Jose Why bother the [x for x in ...] ? Just do requires = IS_IN_SET(range(1, 4)) And in case that list is quite large, the alternative is: Field('a_large_number', 'integer', requires = IS_INT_IN_RANGE(minimum=1, maximum=10), comment = 'NOTICE: Input something between 1 and 10') Iceberg
[web2py] Re: nightly built
On Apr17, 1:17pm, mdipierro wrote: > Please check it: > http://web2py.com/examples/static/nightly/web2py_src.zip http://web2py.com/examples/static/nightly/web2py_win.zip http://web2py.com/examples/static/nightly/web2py_osx.zip > > -- Just an idea. Why not put this download links inside http://www.web2py.com/examples/default/download so that people can easier find and try them?
[web2py] Re: When and how to use command line option -f FOLDER?
On May15, 3:46pm, Iceberg wrote: > @Massimo, thanks for your latest attempt, but it should be adjusted as > below. And please also keep the comment which is valuable also. > > sys.path.insert(0, path) # somehow it need to be ahead of cwd > Hi Massimo, the latest 1.78.1 solves the problem, well, almost. Now apps can run, but cron jobs inside those -f another_web2py_folder will not fire. At least line 769 and line 779 in gluon/widget.py should be changed from os.getcwd() to web2py_path. Besides, you might need to double check every os.getcwd() in all source code. For example, line 262 of gluon/newcron.py contains a os.getcwd() too although it would be "just" a misleading log message. Sorry for keep you busy. :-) -- Iceberg
[web2py] Re: web2py 1.78.1 is OUT
About OPTGROUP, here is an example. CHINA={ 'CAN':'Guangzhou', 'SHA':'Shanghai', 'PEK':'Beijing(Peking)',} INTERNATIONAL = { 'SYD':'Sydney', 'BKK':'Bankok', } AIRPORTS = dict(CHINA.items() + INTERNATIONAL.items()) db.define_table('booking', Field('departure', requires=IS_IN_SET(AIRPORTS)), ..., ) # so far, nothing is new. Then... from gluon.sqlhtml import OptionsWidget class GroupOptionsWidget(OptionsWidget): def __init__(self, groups): self.groups = groups def widget(self, field, value, **attributes): attr = OptionsWidget._attributes(field, {'value':value}, **attributes) opts = [OPTION('')] + [ OPTGROUP( # OPTGROUP(...) is available since web2py 1.77.4 _label=group, *[OPTION(v, _value=k) for (k, v) in options.items()]) for group, options in self.groups.items() ] return SELECT(*opts, **attr) db.booking.departure.widget = GroupOptionsWidget({'China':CHINA, 'International':INTERNATIONAL}).widget # That is it. # I know it is not cool that we need to define our own GroupOptionsWidget every time. But if there is enough interest, I guess we can do more to enhance the already-too-complicated IS_IN_SET(...), to support following pattern: Field('departure', IS_IN_SET( {'China':CHINA, 'International':INTERNATIONAL} ) ) I mean, a dict of dicts should automatically trigger a predefined GroupOptionsWidget. Regards, Iceberg On May16, 2:10pm, Jason Brower wrote: > Oh fun. But waht OPTGROUP, and block name/end stuff do? How do I use > it? > Best Regards, > Jason > > > > On Sat, 2010-05-15 at 22:14 -0700, mdipierro wrote: > > Please check it > > > changelog > > - new template system allows {{block name}}{{end}}, thanks Thadeus > > - fixed mime headers in emails, included PGP in emails, thanks Gyuris > > - automatic database retry connect when pooling and lost connections > > - OPTGROUP helper, thanks Iceberg > > - web2py_ajax_trap captures all form submissions, thank you Skiros > > - multicolumn checkwidget and arbitrary chars in multiple is_in_set, > > thanks hy > > - Québécois for welcome, thanks Chris > > - crud.search(), thanks Mr Freeze > > - DAL(...migrate,fake_migrate), thanks Thadeus
[web2py] Re: Display reference fields in read-only form
Not sure. Can't Field(..., writable=False) do the trick? On May17, 5:44pm, Andrew Buchan wrote: > Hi all, > If I have a referenced field where I specify which field in the referenced > table to display, like so: > Field('To_Department', requires = IS_IN_DB(db, db.department.id, > '%(Department_Name)s')), > SQLFORM generates a form with a drop-down box showing me the Department_Name > of the departments, but only if it is an INSERT or UPDATE form. > My question is, how do I get a read-only form to display the Department_Name > instead of the id of the referenced record? > Can't seem to find an example or answer on the web, but there must surely be > an easy way... > Thanks,Andy. > > _http://clk.atdmt.com/UKM/go/19780/direct/01/ > Do you have a story that started on Hotmail? Tell us now
[web2py] Re: Sending Email bug
On May17, 4:55pm, PanosJee wrote: > Hello everyone, > I am trying to send an email (html and txt) but it fails. I tried to > simplify my code in order to test it. > > mail.send(to='panos...@gmail.com',subject='test',message='test') > > But i am getting: > File "/Users/panosjee/Documents/Work/web2py/gluon/tools.py", line 302, > in send > attachment.attach(MIMEText.MIMEText(text,_charset='utf-8')) > File "/Library/Python/2.5/site-packages/email-4.0.2-py2.5.egg/email/ > __init__.py", line 79, in __getattr__ > ImportError: No module named text > > Any clue? ( i ve read the tools.py and the text variable should be > string but web2py i looking for a module ?) Strange. Try to isolate the problem with fewer code. If you can reproduce the problem without gluon/tools.py, you probably find a bug for email lib itself. :)
[web2py] Re: Production releases
Maintaining a 2-4 weeks gap between development release and production release, is certainly a systematic precaution which can earn us some time for bug finding and fixing. However it only works best when a significant amount of volunteers who is willing to update to latest development release quickly and often. >From technical point of view, we still need more doctest, unittest cases to cover as much as possible features. On May18, 12:12pm, mdipierro wrote: > Two weeks seems like an eternity but we will have to do as you say. > > Massimo > > On May 17, 11:09 pm, "mr.freeze" wrote: > > > > > This is where web2py fails to earn its enterprise billing. Here's a > > simple solution: Call the released version the development version and > > promote the development version to the released version after 2-4 > > weeks. > > > On May 17, 10:38 pm, mdipierro wrote: > > > > You raise an excellent point. > > > > So far the only security bug was the one reported a few months ago. > > > 1) Yet we do need a mechanism for reporting this kind of problems. > > > > 2) We also need a team of volunteers committed to check nightly built > > > the week before release. So far very people check the nightly built. > > > > 3) Definitively we need more tests about features in place to avoid > > > that new features break old features. > > > > Bugs in new features are going to happen no matter what but that is > > > not a serious issue. > > > > Massimo > > > > On May 17, 10:00 pm, Kevin Bowling wrote: > > > > > I'm going to take a stab in the dark and venture to say that I'm not > > > > the only one using web2py in a "production" environment (i.e. people > > > > other than me are accessing the app) :-P > > > > > It seems that with many recent releases there are rather embarrassing > > > > bugs. The worst was several months ago when authentication was > > > > completely disabled. > > > > > Can we adopt a strategy to minimize these potential disasters? A > > > > sufficient beta channel would do the trick, and a tightening of what > > > > is acceptable as a release build. > > > > > Also, how about a security channel so we know when an old version is > > > > unsafe and upgrades are mandatory? Is there any statement on this > > > > already? > > > > > Regards, > > > > Kevin
[web2py] Re: expire_sessions.py and cron
I think there is a cleaner way. No need to modify the applications/ admin/cron/expire_sessions.py whenever you add or remove your apps. You just put this line into each of applications/your_app/cron/crontab 10 2 * * * root **applications/admin/cron/expire_sessions.py The point here is that, you only need to invoke the built-in admin/ cron/expire_sessions.py, because it can already work on caller-app's folder. @Massimo: And I just don't see any reason why this line does not go into scaffold app. @Annet: Sorry, but what do you mean "emil"? On May19, 6:39pm, mdipierro wrote: > You can but you can also modify expire_sessions.py > > EXPIRATION_MINUTES=60 > import os, time, stat > for app in ['admin','init','examples','welcome']: # add yours > path=os.path.join(request.folder,'..',app,'sessions') > if not os.path.exists(path): > os.mkdir(path) > now=time.time() > for file in os.listdir(path): > filename=os.path.join(path,file) > t=os.stat(filename)[stat.ST_MTIME] > if os.path.isfile(filename) and now-t>EXPIRATION_MINUTES*60 \ > and file.startswith(('1','2','3','4','5','6','7','8','9')): > os.unlink(filename) > > so that one expire_sessions.py does it for all your apps. > On May 19, 5:21 am, annet wrote: > > > > > Massimo, > > > Emil just tried running the following command on my account: > > > python2.5 /home/fitwise/webapps/customweb2py/web2py/web2py.py -S > > admin -R applications/admin/cron/expire_sessions.py > > > This was successfully executed, and the output was: > > web2py Enterprise Web Framework > > Created by Massimo Di Pierro, Copyright 2007-2010 > > Version 1.76.5 (2010-03-11 15:19:08) > > Database drivers available: SQLite3, MySQL, PostgreSQL > > > I verified that this actually cleaned up my sessions. It did in admin, > > not in init, b2b etc. Would it be possible to copy the > > expire_sessions.py to every single application's cron directory and > > set this command as a cron by editing my crontab (crontab -e): > > > 10 * * * * /usr/local/bin/python2.5 /home/fitwise/webapps/customweb2py/ > > web2py/web2py.py -S init -R applications/init/cron/expire_sessions.py > > > According to Emil: > > > Applications do not really have crontabs. They may have some built-in > > feature which makes them work similar to crontab, but it is a > > completely separate system than your "real" crontab (the one you see > > when you runt 'crontab -l'). > > > By the way, the Web2py installation that I have is running behind > > Apache + mod_wsgi. > > > Kind regards, > > > Annet.
[web2py] Re: Actual situation of web2py compatibility
On May22, 4:33pm, GoldenTiger wrote: > I have found a lot of contradictorius information about Web2Py > compatibility along internet, due to changes in diferent version, I > suposse > > I am trying to installing web2py at Hostgator without sucess , with > Python 2.4.3 > Sometimes Hostgator Support say NO it is not compatible at shared > hosting, another times they say me YES it is compatible > > Anyone could install it at a hostgator ? > > Please I would like to know actual information: > > 1- Is there any stable version supporting Python 2.4 actually? ( May > 22th 2010 ) > > 2- Any extra dependencies necessary? > > 3- About performance on GAE, is it better or equal than shared > hosting ? > > Thanks ! Just for your information, there were more discussion about Hostgator and some other choices here. http://groups.google.com/group/web2py/browse_frm/thread/2b7800cfa079ad5f#
[web2py] Re: hiding email password
On May24, 12:51am, mattynoce wrote: > hi, i have a question about sending emails. i'm running my program on > google app engine, and due to google's rules i need to have an > administrator as the "from" for all my emails. so i created an > account, let's call it "sampleemai...@gmail.com," figuring that would > be the "from" for all my emails for now. > > to send emails, sampleemai...@gmail.com needs to be an administrator > of the application on gae, so i did that. but i'm in a situation where > i'm sharing code with other developers i need to work with but don't > want to give them admin access. > > in db.py, i have the following lines: > mail.settings.sender='sampleemai...@gmail.com' > mail.settings.login='sampleemai...@gmail.com:testPassword' > > but by giving web2py my email password, i'm actually giving other > developers full administrative access to my application on gae. > > i recognize this isn't a web2py "problem," but it's an issue i need to > solve. does anyone have any ideas of how to get around this? > > thanks, > > matt So, in general, you want to share your source code, but not the configuration of one specific deployment. Perhaps you have to put your setting in a separate config file other than the source code. Something like this? mail.setting.sender = open('/home/me/my_sender.ini').read() Or you can read it from a db table, especially when using GAE? Just some thoughts. Regards, Iceberg
[web2py] Re: Production releases
ittest surely can not prevent all problem, but I think we are now doing less than enough, rather than overcooked. Most features are testable but still without test cases. I admit sometimes it can feel boring and time consuming to write test cases, but it is still worthy if you believe test cases should be considered a valuable part of source code and it pays off when doing TDD or recursive test after refactoring. Ok, ok, enough preachment here. :) Locking a release (candidate) for one week before releasing and allow people testing it, is the way python doing. It should work as long as, enough people, even those who would not update his work copy frequently, are willing to response to the call of "Uncle M" saying "I want you to test web2py RC-1.x" :-) http://blogs.gnome.org/dcbw/files/2009/03/unclesam.jpg Let's keep making web2py better! Regards, Iceberg
[web2py] Re: parsehtml
I ran the code and nothing goes wrong, no exception either. By the way, what is the user case of this HTMLParser? Regards, Iceberg On May23, 11:46pm, Massimo Di Pierro wrote: > Anybody interested in helping with this? > > It scrapes an html files and converts into a tree hierarchy of web2py > helpers > > 'xxx' -> DIV('xxx') > > It kind of works but fails at three exceptions described in the file. > > Massimo > > parsehtml.py > 1K查看下载
[web2py] Re: parsehtml
I did not try but I assume the builtin python module HTMLParser already handle at least (1) tags like , not sure about (2) and (3). On May24, 4:32am, mdipierro wrote: > hmmm somehow I did not save comments in the file. > > This does not handle well: > > 1) tags like > 2) attributes that contain > in quotes > 3) attributes that contain escaped quotes > > On May 23, 10:46 am, Massimo Di Pierro > wrote: > > > > > Anybody interested in helping with this? > > > It scrapes an html files and converts into a tree hierarchy of web2py > > helpers > > > 'xxx' -> DIV('xxx') > > > It kind of works but fails at three exceptions described in the file. > > > Massimo > > > parsehtml.py > > 1KViewDownload
[web2py] Re: parsehtml
Hi Massimo, Good to know you finally made it! :-) Albeit not knowing where and when to use this new feature, I came up with an HTML Optimizier such as [1], in a dozen lines of web2py code. [1] http://www.iwebtool.com/html_optimizer [2] Put this inside your controller. def easter(): # This code release in public domain from gluon.html import web2pyHTMLParser form = FORM( TEXTAREA(_name='input'), BR(), INPUT(_type='submit', _value='Optimize!'), ) result = '' if form.accepts(request.vars, keepvalues=True): result = web2pyHTMLParser(form.vars.input).tree return {'':DIV( 'Insert your HTML code to optimize:', form, FIELDSET(PRE(str(result))),)} Well, not exactly an html optimizer, because our version does not strip spaces inside text content. Just for fun. Regards, Iceberg On May25, 4:27am, mdipierro wrote: > Good suggestion. Now you can do > > >>> from gluon.html import web2pyHTMLParser > >>> tree = web2pyHTMLParser('helloworld div>').tree > >>> tree.element(_a='b') > ['_c']=5 > >>> > str(tree) > 'helloworld' > > works great! > > On May 24, 5:11 am, Iceberg wrote: > > > > > I did not try but I assume the builtin python module HTMLParser > > already handle at least (1) tags like , not sure about (2) > > and (3). > > > On May24, 4:32am, mdipierro wrote: > > > > hmmm somehow I did not save comments in the file. > > > > This does not handle well: > > > > 1) tags like > > > 2) attributes that contain > in quotes > > > 3) attributes that contain escaped quotes > > > > On May 23, 10:46 am, Massimo Di Pierro > > > wrote: > > > > > Anybody interested in helping with this? > > > > > It scrapes an html files and converts into a tree hierarchy of web2py > > > > helpers > > > > > 'xxx' -> DIV('xxx') > > > > > It kind of works but fails at three exceptions described in the file. > > > > > Massimo > > > > > parsehtml.py > > > > 1KViewDownload
[web2py] Re: parsehtml
On May26, 12:35am, mdipierro wrote: > I cannot push it until tonight but I have this: > > >>> a=TAG('Headerthis is a test') > >>> print a > > Headerthis is a test>>> a.flatten() > > 'Headerthis is a test'>>> a.flatten(filter=lambda x: re.sub('\s+',' ',x)) > > 'Headerthis is a test'>>> a.flatten(filter=lambda x: re.sub('\s+','-',x)) > > 'Headerthis-is-a-test'>>> a.flatten(render=dict(h1=lambda x: > '#'+x+'\n\n'),filter=lambda x: x.replace(' ','-')) > > '#Header\n\nthis-is-a-test' > > filter is applied to text and render is applier to tags. > so your > > result = web2pyHTMLParser(form.vars.input).tree > > could be written as > > result = TAG(form.vars.input).flatten(filter=lambda x: re.sub('\s > +',' ',x)), render=dict(br=lambda x:'\n',p=lambda x: x+'\n')) > > Can somebody propose better names for "filter" ad "render"? I could > not come up with anything better. > > Massimo > Since render={...} does render html tags into another form, so I think "render" is good name. filter=lambda... is not very good because the python has a reserved keyword "filter" for built-in filter() which acts in different logic. We should avoid conflict and confusing. How about we just use "replace"? I mean .flatten(replace=lambda x:x, render={...}) Regards, Iceberg
[web2py] Re: Delete record without triggering validators?
> On May 11, 1:08 pm,Iceberg wrote: > > > Hi Massimo, > > > Right now validators are triggered even when a record is successfully > > being deleted. This can be annoying in case I am deleting old records > > as below: > > > db.define_table('my_table', > > Field('today', 'date', > > requires=IS_DATE_IN_RANGE(minimum=request.now.date()), > > default = request.now.date(), > > ) > > ) > > > What if we drop all the form.errors content before line 923 in gluon/ > > sqlhtml.py? > > if requested_delete: > > .. > > self.form.errors = {} # to override unnecessary error message > > return True > > > Or a better way is to dodeletebefore validators are called. Can you > > do that? > > > Regards, > >Iceberg On May12, 2:18am, mdipierro wrote: > Good point! Will do. > > Massimo > Any news?
[web2py] Re: flawed architecture creating race condition for database writes
On May27, 11:32pm, Carl wrote: > the flaw is in my architecture not web2py. can you help with a better > approach? Needs to be BigTable-friendly to boot. > > I have two user types: Agents and Candidates > Agents invite Candidates to Parties. > > I keep a Party table recording all such Party invites. > Candidates can be invited to the same Party by several Agents so I > have an Invite table recording which Agents invited which Candidates > to which Parties. > > 1. On a new Party invitation I check if the Candidate has already been > invited by looking in the Party table. > 2. If a party isn't found then I insert into the Party table > 3. I insert the Agent into Invite table has a value pointing to the > appropriate Party row. > > Here's the "race condition"... > > **Between** steps 1 and 2 above another party invite is sent and > checked for pre-existance. it's not found because step 2 by the 1st > agent's run through hasn't yet executed. > > Thus duplicate party invitations are inserted into the database. > > What's the better approach to employ? Here is my attempt. Not a perfect one. db.define_table('Agent', Field('name', unique=True)) db.define_table('Candidate', Field('name', unique=True)) db.define_table('Party', Field('name', unique=True)) db.define_table('Invitation', Field('agent', db.Agent), Field('candidate', db.Candidate), Field('party', db.Party), # Ideally, we should set up two fields, candidate and party, # as combinated primary key in db level. But I don't know how. ) # Then, in controller def invite(): def no_duplicate(form): if db( (db.Invitation.candidate==form.vars.candidate) & (db.Invitation.party==form.vars.party) ).count(): form.errors.candidate = 'Already invited to this party' form = SQLFORM(db.Invitation) if form.accepts( ..., onvalidation=no_duplicate): response.flash = 'ok' # However, theoretically speaking there is still a slim time gap, # maybe 0.2 second, between the onvalidation and the later insertion. return {'':form}
[web2py] Re: flawed architecture creating race condition for database writes
The bullet-proof solution should be setting twin-field primary key in db level, I believe. Hope somebody can show us how to do that in web2py db.define_table(...), if not using db.executesql('set up the primary key blah blah'). On the other hand, in a non-db level, inside web2py, perhaps Massimo will introduce a global ThreadLock so that developers can do: def invite(): with web2py_lock: form = ... if form.accepts(...): ... or maybe a syntactic sugar: @with_lock def invite(): all_the_original_code Wait and see what other may say. On May28, 1:44am, Carl wrote: > thanks Iceberg. > > your approach is pretty much what I have right now. I'm looking for a > bullet-proof approach. > otherwise I'm running code with "fingers crossed two users don't use > the system at the same time" > > and I want to encourage usage :) > > C > > On May 27, 6:09 pm, Iceberg wrote: > > > > > On May27, 11:32pm, Carl wrote: > > > > the flaw is in my architecture not web2py. can you help with a better > > > approach? Needs to be BigTable-friendly to boot. > > > > I have two user types: Agents and Candidates > > > Agents invite Candidates to Parties. > > > > I keep a Party table recording all such Party invites. > > > Candidates can be invited to the same Party by several Agents so I > > > have an Invite table recording which Agents invited which Candidates > > > to which Parties. > > > > 1. On a new Party invitation I check if the Candidate has already been > > > invited by looking in the Party table. > > > 2. If a party isn't found then I insert into the Party table > > > 3. I insert the Agent into Invite table has a value pointing to the > > > appropriate Party row. > > > > Here's the "race condition"... > > > > **Between** steps 1 and 2 above another party invite is sent and > > > checked for pre-existance. it's not found because step 2 by the 1st > > > agent's run through hasn't yet executed. > > > > Thus duplicate party invitations are inserted into the database. > > > > What's the better approach to employ? > > > Here is my attempt. Not a perfect one. > > > db.define_table('Agent', Field('name', unique=True)) > > db.define_table('Candidate', Field('name', unique=True)) > > db.define_table('Party', Field('name', unique=True)) > > db.define_table('Invitation', > > Field('agent', db.Agent), > > Field('candidate', db.Candidate), > > Field('party', db.Party), > > # Ideally, we should set up two fields, candidate and party, > > # as combinated primary key in db level. But I don't know how. > > ) > > > # Then, in controller > > def invite(): > > def no_duplicate(form): > > if db( (db.Invitation.candidate==form.vars.candidate) > > & (db.Invitation.party==form.vars.party) ).count(): > > form.errors.candidate = 'Already invited to this party' > > form = SQLFORM(db.Invitation) > > if form.accepts( ..., onvalidation=no_duplicate): > > response.flash = 'ok' > > # However, theoretically speaking there is still a slim time gap, > > # maybe 0.2 second, between the onvalidation and the later > > insertion. > > return {'':form}
[web2py] Re: Delete record without triggering validators?
> > > On May 11, 1:08 pm,Iceberg wrote: > > > > > Hi Massimo, > > > > > Right now validators are triggered even when a record is successfully > > > > being deleted. This can be annoying in case I am deleting old records > > > > as below: > > > > > db.define_table('my_table', > > > > Field('today', 'date', > > > > requires=IS_DATE_IN_RANGE(minimum=request.now.date()), > > > > default = request.now.date(), > > > > ) > > > > ) > > > > > What if we drop all the form.errors content before line 923 in gluon/ > > > > sqlhtml.py? > > > > if requested_delete: > > > > .. > > > > self.form.errors = {} # to override unnecessary error message > > > > return True > > > > > Or a better way is to do delete before validators are called. Can you > > > > do that? > > > > > Regards, > > > >Iceberg > On May27, 9:13pm, mdipierro wrote: > Posting a possible solution in trunk now. > in gluon/sqlhtml.py replace > > if requested_delete: > > return True > > with > > if requested_delete: > > self.errors.clear() > return True > > let me know if it works for you. > It works as expected. Good. On the other hand, like I said in the first post of this thread (quoted above), a better way is to do delete before validators are called. Right now all the real delete job are performed at line 911, after a potential early exit at line 905, this makes me a little nervous, "will the delete operation be unintentionally bypassed in some certain circumstance?" But after all, so far so good. So you make the decision whether a refactor is needed here.
[web2py] Re: Autoincrement field
I guess the point here is, generally speaking, what is a secure way to make two or more subsequent DAL operations are performed without race condition. Is a kind of lock needed? An example to describe the problem (but not solving it): def index(): with a_lock_to_prevent_concurrent_requests: # but how? latest_data = db(...).select(...) new_data = do_something_with( latest_data ) db.mytable.insert( new_data ) See also: http://groups.google.com/group/web2py/browse_frm/thread/35be6bba0c02eab0# On May28, 5:25am, mdipierro wrote: > What is wrong with the default id field that web2py creates for every > table? > > On May 27, 3:16 pm, matclab wrote: > > > > > Hello, > > I'm finding this message in a thread from February... > > > I thought that autoincremented field would guaranty unicity in the > > table. > > I'm afraid the provided solution would allow two record to have the > > same autonumber field (think about an access from two users at the > > same time). > > I guess the autoincrement should be done on the DAL or database side, > > inside a transaction > > > What do you think about it ? > > > On 19 jan, 21:38, Thadeus Burgess wrote: > > > > max_id= db(db.table.autonumber>1).select(db.table.autonumber, # > > > select all records, and only pull the autonumber column > > > orderby=~db.table.autonumber, # > > > descending sort on the autonumber, (highest first) > > > limitby=(0,1) # limit the query and > > > only select the first record > > > ).first().autonumber # pull the first record > > > from the web2py rows object, and get its autonumber member > > > > db.table.autonumber.default = max_id + 1 # Set the table default as > > > the last autonumber and incremented by one. > > > db.table.autonumber.writable = False > > > > form = crud.create(db.table) > > > > -Thadeus > > > > On Tue, Jan 19, 2010 at 4:32 AM, ceriox wrote: > > > > thanks for the reply but i'm not a good web2py programmer ... i > > > > writing my first real app > > > > you can write the code for my request? (i can't understand the post of > > > > your link) > > > > > -- > > > > 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 > > > > athttp://groups.google.com/group/web2py?hl=en.
[web2py] Re: Dependent drop downs
On May28, 2:38pm, Neveen Adel wrote: > Hello, > > I have > db.define_table('type', > SQLField('name','string',length=2) > SQLField('parent','reference db.type') > ) > > db.define_table('member', > SQLField('name','string'), > SQLField('type',db.type), > SQLField('subtype',db.type), > ) > > I want when select a value of type the drop down of subtype changed > according to selection. > > when am searching on it i found a solution that someone posted it > before > " > $('#tourplan_city').change(function(){ $.ajax( ) } > " > But i don't know what is the " $.ajax( ) " and where i will > write my query that compute result of subtype dropdown? > > Could anyone help me ? > > Thanks in advance > > Neveen web2py book is your friend. :) http://web2py.com/book/default/section/10/3?search=ajax
[web2py] Better record deletion in SQLFORM
Hello Massimo, This proposal tries to address the last point mentioned in [1], quoted below. ".. when deleting a record, form variables should be cleared which is not the case here. In my openion this’s not a good idea in fact, and needs to be fixed because it’s really tempting to see the variables still in the form and makes one clicks the ['submit'] button again to see what would happen and it returns ‘object not found’ error message." An easy idea, which was also suggested in [1], is to use redirect(...) after successful record deletion. But that is not one-size-fits-all because developers need to provide target URL in every case. Then I planned to somehow compulsively replace the form object with a string such as "delete ok", but it would cause backward compatibility problem when a customized view file expecting a real form object. Finally I got the idea. SQLFORM.accepts() can disable all form fields after deletion, to indicating a successful deletion and also avoid further operation! crud also benefits from this improvement. Try the patch. >From line 920 of sqlhtml.py: if record_delete: .. self.errors.clear() self.components.append(SCRIPT("""jQuery(document).ready(function(){ jQuery('input, select').attr('disabled', 'disabled'); })""", _type="text/javascript")) # to emphasize the record is deleted and avoid further operation return True [1] http://web2py.wordpress.com/2010/05/02/record-deletion-and-keepvalues-in-forms/ Sincerely, Iceberg, 2010-May-28, 03:07(AM), Fri
[web2py] Re: Better record deletion in SQLFORM
Hi tiger, Sqlite is typeless. So as long as your app works fine with your latest adjustment, I think it is ok. By the way, please don't hijack a thread. It easily makes subsequent readers distracted from the original post. Thanks for cooperation. On May29, 7:28am, GoldenTiger wrote: > Another extrange behaviour I noted is in T3. > > 1) I defined a table and I inserted a value in a int record. > > 2) I noted I was worng with the type field, I wanted a string, so I > deleted the record and redefined type field in define_table > > 3) I changed the type of record from int to string, web2py > respoonded me OK > > 4) reallyr web2py doesn't changes type field, but models has type > string at define_table > > I had to use SqliteManager to change table. > > On 28 mayo, 17:55, Iceberg wrote: > > > > > Hello Massimo, > > > This proposal tries to address the last point mentioned in [1], quoted > > below. > > > ".. when deleting a record, form variables should be cleared > > which is not the case here. In my openion this’s not a good idea in > > fact, and needs to be fixed because it’s really tempting to see the > > variables still in the form and makes one clicks the ['submit'] button > > again to see what would happen and it returns ‘object not found’ error > > message." > > > An easy idea, which was also suggested in [1], is to use redirect(...) > > after successful record deletion. But that is not one-size-fits-all > > because developers need to provide target URL in every case. > > > Then I planned to somehow compulsively replace the form object with a > > string such as "delete ok", but it would cause backward compatibility > > problem when a customized view file expecting a real form object. > > > Finally I got the idea. SQLFORM.accepts() can disable all form fields > > after deletion, to indicating a successful deletion and also avoid > > further operation! crud also benefits from this improvement. Try the > > patch. > > > From line 920 of sqlhtml.py: > > > if record_delete: > > .. > > self.errors.clear() > > > self.components.append(SCRIPT("""jQuery(document).ready(function(){ > > jQuery('input, select').attr('disabled', > > 'disabled'); })""", > > _type="text/javascript")) # to emphasize the record is > > deleted and avoid further operation > > return True > > > [1]http://web2py.wordpress.com/2010/05/02/record-deletion-and-keepvalues... > > > Sincerely, > > Iceberg, 2010-May-28, 03:07(AM), Fri
[web2py] Re: "wizard" style forms in web2py
It is always fun to see Massimo asking questions, because he can usually comes up with a clean solution based on some unpopular web2py trick. :) This time, it is the SQLFORM(..., fields=...) that I did not notice. Thanks. :) Thadeus also gives a good suggestion. And this kind of logic is better implemented by a client side technic to gain faster UI response. -- Iceberg On May29, 11:57pm, Thadeus Burgess wrote: > I would use the jQuery form wizard plugin. It is very nice and dose > the pagination for you. > > The only issue is if the data in the second step depend on what is in > the first step, then you would need to use some ajax/javascript to > alter accordingly. > > -- > Thadeus > > On Sat, May 29, 2010 at 10:39 AM, Mathieu Clabaut > > > > wrote: > > Nice idea ! > > I needed something similar... I'll give a try.. > > Thanks ! > > > On Sat, May 29, 2010 at 17:19, mdipierro wrote: > > >> db.define_table('mytable', > >> Field('field1'), Field('field2'), Field('field3'), > >> Field('field4')) > > >> make sure they all have defaults. > > >> def wizard(): > >> fields=[['field1'], # first page > >> ['field2','field3'], # second page > >> ['field4']] # third page > >> record_id =int(request.args(0) or 0) > >> page=int(request.args(1) or 0) > >> form = SQLFORM(db.mytable,record_id,fields=fields[page]) > >> if form.accepts(request.vars,session): > >> if page >> redirect(r=request,args=(form.vars.id,page+1)) > >> else: redirect(r=request,f='form_completed')) > >> return dict(form=form, page=page) > > >> I did not try it. May need some debugging. > > >> On May 28, 6:20 pm, "Robert O'Connor" wrote: > >> > Hey, > > >> > I need to implement a "wizard" style form. (things will exist on > >> > different screens; each "step" or page will post to the next page and > >> > have those values stored and used in the next step. > > >> > Now here's the problem: there's seems to be very few examples in > >> > developing something like this in web2py... Does anybody know either > >> > of an app that does this that I can look at for examples or perhaps a > >> > strategy of implementing this? > > >> > If you're in the United States -- Happy Memorial Day weekend! > >> > -Robert O'Connor
[web2py] Re: Email "perfect" regex
On May30, 10:36am, blackthorne wrote: > http://fightingforalostcause.net/misc/2006/compare-email-regex.php > > Take it as a suggestion for a better email regex validator... +1. The post contains implementations as well as test cases. It should be easy to convert them into a web2py validator WITH built-in doctest! By the way, the post also mention "This one will work in JavaScript". So it will also be great that a web2py email widget will contain the javascript validating code, so that the input will be checked at client-side for much quicker UI responsive experience, while keeping the server-side double validation. My two cents.
[web2py] Re: 1.79.0rc1 please check it out
On May30, 1:17pm, mdipierro wrote: > http://web2py.com/examples/static/nightly/web2py_src.ziphttp://web2py.com/examples/static/nightly/web2py_win.ziphttp://web2py.com/examples/static/nightly/web2py_osxzip > > x509 emails, thanks Gyuris > attachment and html in Mail on GAE, thanks PanosJee > fixed docstring in SQLTABLE, thanks aabelyakov > TAG(html) parese html into helpers (experimental, still some problems > with unicode, , th\ > anks RobertVa for unicode help) > DIV.elements(find=re.compile()) > DIV.flatten() > DIV.elements('') supports jQuery syntax in '' > better it-it.py and it.py, thanks Marcello Della Longa > Many Bug fixes: > improved support for DAL and joins in postgresql/oracle, thanks Nico > de Groot > bux fixex in html.py, thanks Ian > fixed an issue with registration_key==None, thanks Jay Kelkar > fixed bug in gql.py, thanks NoNoNo > fixed problem with multiple and checkboxes, thanks MIchael Howden > fixed bug in gae, thanks NoNoNo > restored 2.4 compatibility, thanks Paolo Gasparello > auth.update() when pictures in profile Revision: c29660517c with log message "fixed problem with multiple and checkboxes, thanks MIchael Howden" causes my current app fails. Did not take careful look yet, but it seems changing html.py's line 2154 from: value, _value = self['value'] = self['_value'] # Is it a typo anyway? to: value, _value = self['value'], self['_value'] can fix the problem. Check it out please. The error trace, if needed. File "C:/DOWNLOAD/google_appengine/web2py/applications/test/ controllers/default.py", line 34, in index Field('bar', requires=IS_IN_SET(range(5),multiple=True), widget=CheckboxesWidget.widget), File "C:\DOWNLOAD\google_appengine\web2py\gluon\sqlhtml.py", line 1033, in factory **attributes) File "C:\DOWNLOAD\google_appengine\web2py\gluon\sqlhtml.py", line 689, in __init__ inp = self.widgets.boolean.widget(field, default) File "C:\DOWNLOAD\google_appengine\web2py\gluon\sqlhtml.py", line 153, in widget return INPUT(**attr) File "C:\DOWNLOAD\google_appengine\web2py\gluon\html.py", line 327, in __init__ self._postprocessing() File "C:\DOWNLOAD\google_appengine\web2py\gluon\html.py", line 1254, in _postprocessing value, _value = self['value'] = self['_value'] TypeError: 'NoneType' object is not iterable
[web2py] Re: Dependent drop downs
Very likely your javascript has some error. Perhaps the latest "change()" is not good. On May30, 5:29pm, Neveen Adel wrote: > Hello, > > i tried it but it didn't call the action? > > i did the following : > > In html Page: > $("#project_project_category").change(function() { > $.ajax('get_objective_category', > ['project_project_category'],'project_project_objective' ) > }) > .change(); // making sure the event runs on initialization for > default value > > where > get_objective_category: is the function > 'project_project_category' : is the drop down id that i take the > selected value from it > project_project_objective: is the id of the drop down that its values > will be computed according to the selection of the previous drop down. > > And finally in default.py i wrote: > def get_objective_category(): > print "=>" > print request.vars.project_category > return dict() > > But The print statements didn't printed so it didn't call the > function? > > could anyone help me ? > > Thanks in Advance
[web2py] Re: Dependent drop downs
Then why not put another alert() BEHIND the $.ajax(...)? I bet this time it does not fire, indicating that your $.ajax(...) does contain some error. I assume you don't need more hint right now? :-) On May30, 6:09pm, Neveen Adel wrote: > But still didn't call the function get_objective_category() > > On May 30, 12:44 pm, Neveen Adel wrote: > > > > > I tested it by putting alert() function as > > > $("#project_project_category").change(function() { > > alert("==>"); > > $.ajax('get_objective_category', > > ['project_project_category'],'project_project_objective' ) > > }) .change(); > > > and it works fine. > > > On May 30, 12:36 pm, Iceberg wrote: > > > > Very likely your javascript has some error. Perhaps the latest > > > "change()" is not good. > > > > On May30, 5:29pm, Neveen Adel wrote: > > > > > Hello, > > > > > i tried it but it didn't call the action? > > > > > i did the following : > > > > > In html Page: > > > > $("#project_project_category").change(function() { > > > > $.ajax('get_objective_category', > > > > ['project_project_category'],'project_project_objective' ) > > > > }) > > > > .change(); // making sure the event runs on initialization for > > > > default value > > > > > where > > > > get_objective_category: is the function > > > > 'project_project_category' : is the drop down id that i take the > > > > selected value from it > > > > project_project_objective: is the id of the drop down that its values > > > > will be computed according to the selection of the previous drop down. > > > > > And finally in default.py i wrote: > > > > def get_objective_category(): > > > > print "=>" > > > > print request.vars.project_category > > > > return dict() > > > > > But The print statements didn't printed so it didn't call the > > > > function? > > > > > could anyone help me ? > > > > > Thanks in Advance
[web2py] Re: How to present status of other system by web2py?
You can use web2py's cron feature to trigger a data collector, which use "3. command line utility" you mentioned to gather data, insert into your web2py app's db, then you can show it in the way you like. http://web2py.com/book/default/section/4/17?search=cron On May31, 10:44am, dlin wrote: > I'm a newbie of web2py. > I wish to use web2py to present my other system's status. > As I know web2py is event driven, I don't know how to plugin my C > system into it. > > What's the suggest architecture? > > My other system is built by C++ program. > The different system status is provided three methods: > 1. put in common shared memory. > 2. broadcast by udp socket. > 3. command line utility. > > Is there any example could let me try?
[web2py] Re: how to generate barcode label ?
Thanks. Then what choices do you recommend to read barcodes? Both make and read are needed to complete any full solution, aren't they? On Jun1, 11:17am, Jason Brower wrote: > There are alot of functions that can make barcodes. I think google has a > web api for barcodes. I made one that ran a script in the background to > make one. Search for any program that can make barcodes on your > computer and you can use it. Python scripts are powerful enough to do > just about anything. The first program I ever made in web2py made 2d > barcodes. It would be cool to have a plugin that could make all kinds > from all the libraries. > I think reportlab is another barcode maker, that ones a bit fancy but it > is all python. :D > Best Regards, > Jason Brower > > > > On Mon, 2010-05-31 at 11:46 -0700, Yarko Tymciurak wrote: > > On May 31, 12:53 pm, ceriox wrote: > > > like object... > > > > i need to generate a label with barcode > > > > anybody have an example? > > > In general, you need to generate an image of some sort, based on data. > > > To print images on badges, you could look at the mk_barcode() function > > in > >http://code.google.com/p/web2conf/source/browse/applications/register... > > > Although I haven't tried this, you might also look at: > >http://javascript-library-tips.changblog.com/2009/12/jquery-barcode.html > > > - Yarko > > > > thanks
[web2py] Re: cancel button in update and create work differently [closed]
history.go(-1) will not work if the current page is the first page of current browser session. Will this help you? On Jun1, 8:00pm, annet wrote: > Setting the cancel button to: > > form[0][-1] > [1].append(INPUT(_type="button",_value="Cancel",_onclick='javascript:histor > y.go(-1);')) > > at least gives the user a way to cancel the function, not the way I > wanted it, but it's better than getting an error. > > Annet
[web2py] Re: How to present status of other system by web2py?
In python? Yes. Python's built-in socket has udp support. But anyway you still need to feed the data into web2py if you want to use web2py as a front-end. Unfortunately your "other system" doesn't support HTTP output. BTW, you are from taiwan? I'm from China mainland. Nice to meet you here. On Jun1, 9:05pm, dlin wrote: > Is it possible to have multi-thread in python to listen udp socket and > just collect the status in ram instead of DB? > > On 5月31日, 上午11時46分, Iceberg wrote: > > > > > You can use web2py's cron feature to trigger a data collector, which > > use "3. command line utility" you mentioned to gather data, insert > > into your web2py app's db, then you can show it in the way you like. > > >http://web2py.com/book/default/section/4/17?search=cron > > > On May31, 10:44am, dlin wrote: > > > > I'm a newbie of web2py. > > > I wish to use web2py to present my other system's status. > > > As I know web2py is event driven, I don't know how to plugin my C > > > system into it. > > > > What's the suggest architecture? > > > > My other system is built by C++ program. > > > The different system status is provided three methods: > > > 1. put in common shared memory. > > > 2. broadcast by udp socket. > > > 3. command line utility. > > > > Is there any example could let me try?
[web2py] Re: VoltDB
Wow, "outperformed traditional OLTP database systems by a factor of 45". That is awesome! Oscar wrote: > Hi there, > > There is a new DBMS in the block, a new kind of DBMS. Plese read > http://cl.ly/1EO3 for more information. > > Massimo, can you add support for it. it's worth. > > Best Regards, > > Oscar.
[web2py] Re: how test if a table have record in a if statement ?
How come the syntax? I do not know that. I would use: if db(db.mytable.id>0).count(): On Jun2, 2:17am, ceriox wrote: > i need to test if a table are empty in if statement ... i try with: > > if db.Prestiti.id.count==0: > vuoto='if ' > else: > vuoto='else ' > > it go under else in both cases (table Prestiti with no record or with > record)
[web2py] Re: sender's name in mail
Try specify your sender's name as: "XYZ" On Jun2, 2:52pm, Rohan wrote: > I want to add sender's name in emails. Currently I am able to send > mails from ad...@example.com but sender's name is displayed as admin > which is not conveying the proper information. Can I add senders' name > to mail settings so that sender's name is displayed as Example Admin > or XYZ instead of admin?
[web2py] Re: variables turning into lists
Did not look into your code. But this kind of situation usually is caused by a form receives variables from both GET and POST. In this case, request.vars.myvar=['blah', 'blah'], but request.get_vars.myvar='blah', and request.post_vars.myvar='blah'. So you can choose to use only one of it. On Jun2, 9:15pm, Andrew Buchan wrote: > Hello, > > I've had this issue before, where a string which is passed as part of > request.vars somehow becomes a list when the form is submitted. The > way I got round it at the time was by doing: > > if isinstance(thread_id, list): > thread_id = thread_id[0] > > However, that just doesn't feel right, and will only work where the > value never changes (i.e. I can assume that all items in the list have > the same value so [0] is as good as any), and more to the point, it > doesn't address why this is happening in the first place. > > I tried the suggestion in post 17355 of this mailing group which seems > to suggest explicitly passing the vars on submit by adding the > following to the submit button: > > _action=URL(r=request,args=request.args) > > However, that doesn't work either. > > I've posted some code below where this is happening to the variable > "thread_id", if you look at the 8th & 9th line of function > addreplacementpage() you'll see that I test whether the variable is a > list or not, and it proves positive only when the form is submitted, > i.e. the function goes round the loop a second time (self-submitting > form). > > Has anyone else experienced this or have a solution to the problem, or > even better: advice on how to figure out what's going on in these kind > of situations? > Also, feel free to bash the code, constructively... > > regards, > > Andy. > - > > def addreplacement(): > #Call this function from other pages, it will initialise the > PartLists and SelectedParts session > #variables if required, generate a thread_id and then redirect to > addreplacementpage function below. > #These two session variables store the partlist and currently- > selected-item-in-partlist(for delete/edit purposes) > #for the replacement currently being worked on (either newly > raised or amended) > #The 'thread_id' var is used to allow multiple replacements to be > edited within the same session, > #so for the replacement currently being edited use > session.PartLists[thread_id] to obtain prt list > #and session.SelectedParts[thread_id] to obtain selected part. > Complaint_Base_id = request.vars.record > title = 'Complaint Raised' > if not (Complaint_Base_id ): > return ComplaintSystem.__ShowSimplePage(globals(), > dict(message = "Record id was not supplied with request." , > title=title)) > thread_id = int(uuid.uuid4()) > if not session.PartLists: > session.PartLists = dict() > session.PartLists[thread_id] = dict() > if not session.SelectedParts: > session.SelectedParts = dict() > session.SelectedParts[thread_id] = -1 > redirect(URL(r=request, f='addreplacementpage', > vars={'record':Complaint_Base_id, 'thread_id':thread_id})) > > def addreplacementpage(): > #This must only ever be called by function 'addreplacement' > title = 'Complaint Raised' > Complaint_Base_id = request.vars.record > thread_id = request.vars.thread_id > assert(Complaint_Base_id ) > assert(thread_id) > if isinstance(thread_id, list): > return 'its a list!' > response.view = 'Complaints/AddReplacement.html' > response.title = title > Table = db.Replacement > form = GenerateReplacementForm( thread_id = thread_id ) > if form.accepts(request.vars, session): > FieldValues = dict() > for f in Table.fields: > if form.vars.has_key(f): > FieldValues[f] = form.vars[f] > FieldValues['Complaint_Base_id'] = Complaint_Base_id > ReplacementId = Table.insert(**FieldValues) > for key, value in session.PartLists[thread_id].items(): > db.Replacement_Part.insert(Replacement_id=ReplacementId, > Row_Index=key, Part_Number=value[0], Description=value[1], > Cost=value[2], Quantity=value[3]) > return ComplaintSystem.__ShowSimplePage(globals(), > dict(message='New record created', title='Record Created', links = > links)) > return dict(form = form, id = Complaint_Base_id ) > > def GenerateReplacementForm( thread_id , Rec_ID = None): > Table = db.Replacement > Fields = list(db.Replacement.fields) > for i in ['Complaint_Base_id', 'Status', 'Date_Authorised', > 'Project_Coordinator']: > Fields.remove(i) > if Rec_ID : > form = SQLFORM(Table, record = Rec_ID , showid=False, fields = > Fields) > else: > form = SQLFORM(Table, fields = Fields) > > form.custom.submit = INPUT(_type="submit", _value="Submit", > _action=URL(r=request,args=request.args)) > > ajaxAddPart = "ajax('%s', %s, 'partfielderrors');ajax('%s', > %s,'target');" % \
[web2py] proposal of introducing generic.load
Hi Massimo, I just came up with a handy myapp/views/generic.load, and I wonder whether you will like to accept it as part of web2py scaffold. It is already self-documented. {{ ''' With this generic.load file, you can use same action to serve two purposes. Example modified from http://www.web2py.com/AlterEgo/default/show/252: def index(): return { 'part1':'hello world', 'part2': LOAD( url=URL(r=request,f='auxiliary.load'), # Notice the ".load" extention ajax=True), } def auxiliary(): form=SQLFORM.factory(Field('name')) if form.accepts(request.vars): return {'': "Hello %s" % form.vars.name} return {'':form} # Need NOT to write it as "return form" any more! >From now on, single auxiliary() can serve two purposes: http://.../auxiliary.load serves as a raw component LOADed by other action http://.../auxiliary serves as a normal html page as usual # PS: Please keep all above explanation for people to know when and how to use it. # License: Public Domain # Author: Iceberg at 21cn dot com ''' }} {{ # Does NOT extend layout.html, purposely.}} {{response.headers['Content-Type']='text/html'}} {{if len(response._vars)==1 and not response._vars.keys()[0]:}} {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly colon }} {{else:}} {{=BEAUTIFY(response._vars)}} {{pass}}
[web2py] Re: date operation
Search doc for python built-in timedelta please. On Jun3, 10:30pm, ceriox wrote: > hi, > how i can increment a data field of x days? > > example > i have > db.Prestiti.Data_richiesta=2010-06-03 16:13:14 > db.Prestiti.Durata=30 > > i want generate > fineprestito=2010-07-03 16:13:14 > > i wanna add 30 days to a data field
[web2py] Re: date operation
delta = date1 - date2 and then delta is a timedelta instance. And you reverse it by: date2 + delta == date1 Isn't it simple maths? :-) So be a python lover. It is intuitive and it won't let you down. On Jun3, 11:06pm, ceriox wrote: > i'm looking for it but timedelta retun the difference from 2 date , > i need to add 30 days to a date > like my example > i have a date field and an integer field with the number of days, > i wanna add the number of days to a data field. > > (i'm not an expert pyton programmer) > > On 3 Giu, 16:32, Iceberg wrote: > > > > > Search doc for python built-in timedelta please. > > > On Jun3, 10:30pm, ceriox wrote: > > > > hi, > > > how i can increment a data field of x days? > > > > example > > > i have > > > db.Prestiti.Data_richiesta=2010-06-03 16:13:14 > > > db.Prestiti.Durata=30 > > > > i want generate > > > fineprestito=2010-07-03 16:13:14 > > > > i wanna add 30 days to a data field
[web2py] Re: Multiple instances of same application
I think Doug's puzzle deserves a more general solution. The requirement and challenge is: R1. The app's central source code should contain default setting. R2. The app's multiple deployment instances should be allowed to contain its local setting. R3. And after the next "hg update", the default setting in (R1) should not override the local setting in (R2). My solution contains two steps: Step1: Use myapp/models/0_config.py to store default setting, such as: MY_HOST = 'http://localhost' MY_EMAIL = 'f...@bar.com' MY_PASSWORD = 'blah' MY_DB = 'sqlite://storage.sqlite' Step2: Use myapp/models/0_local_config_pls_dont_pack_dont_commit.py to store instance-wide local setting, such as: MY_HOST = 'http://myaccount.my_vps_provider.com' MY_EMAIL = 'my_real_acco...@for_example_hotmail.com' MY_PASSWORD = 'i_will_never_share_it' MY_DB = 'mysql://10.1.1.1.' To reach this goal, two things need to be adjusted in web2py source code: Thing1: add 0_local_config_pls_dont_pack_dont_commit.py into / web2py/.hgignore Thing2: adjust the admin's pack code, to NOT pack the new 0_local_config_pls_dont_pack_dont_commit.py On Jun3, 10:23pm, mdipierro wrote: > they can see request.env.host_name and you can use hostnames like bla bla>.yourdomain.com > > you can symlink different apps to the same one so you have one but it > will see different request.application depending on the request > > On Jun 3, 8:50 am, Doug Warren wrote: > > > > > Is there a preferred way to handle multiple instances of the same > > application installed on the same machine? Say for instance is > > there's 3 dev environments and 2 staging environments on one server > > pointing at different databases? Is there a preferred way of getting > > the configuration to each unique app? IE: Can a view/db/controller > > see a parameter placed in either options_std or parameters_PORTNO? I > > guess what I'm really after is a way to specify at a minimum the > > database that an application can point at but have it contained > > outside the application itself. > > > IE: > > foo.w2p is uploaded > > foo.w2p is installed as foo > > foo.w2p is installed as foo-dev > > foo.w2p is installed as foo-dev2 > > foo.w2p is installed as foo-stag > > > Without having to edit db.py in each of those environments I'd like to > > have a way of saying foo-stag should use this connect string, and have > > it survive the next time I upload a new foo.w2p and overwrite the one > > that's there.
[web2py] Re: checkboxes and radio widget failed with multiple validators
Maybe your patch is ok. But wouldn't it be not necessary to use requires=[IS_IN_SET(...), IS_NOT_EMPTY()]? Because you must already mention all the allowed values in the IS_IN_SET() and usually empty value in not inside. On Jun4, 1:36am, Mathieu Clabaut wrote: > Hello, > > Is there any interest in this problem ? Is there any chance a correction may > be integrated into trunk ? > > -Mathieu > > On Thu, May 27, 2010 at 20:20, Mathieu Clabaut > > > > > > wrote: > > Reported ashttp://code.google.com/p/web2py/issues/detail?id=80 > > > Hello, > > > I've met a problem with checkboxes and rzdio widgets: > > > The following works: > > Field('status', 'string', requires=IS_IN_SET(STATUS_TYPE, multiple=True), > > widget=SQLFORM.widgets.checkboxes.widget) > > > However if I add another validator, it doesn't work anymore : > > Field('status', 'string', requires=[IS_IN_SET(STATUS_TYPE, multiple=True), > > IS_NOT_EMPTY()], > > widget=SQLFORM.widgets.checkboxes.widget) > > > Any suggestion ? > > > -Mathieu > > On Thu, May 27, 2010 at 20:38, Mathieu Clabaut > wrote: > > > > > Patch : > > > diff -r 9802a87428fa gluon/sqlhtml.py > > --- a/gluon/sqlhtml.py Wed May 26 17:17:46 2010 +0200 > > +++ b/gluon/sqlhtml.py Thu May 27 20:37:56 2010 +0200 > > @@ -223,10 +223,15 @@ > > > attr = OptionsWidget._attributes(field, {}, **attributes) > > > - if hasattr(field.requires, 'options'): > > - options = field.requires.options() > > - else: > > - raise SyntaxError, 'widget cannot determine options of %s' % > > field > > + requires = field.requires > > + if not isinstance(requires, (list, tuple)): > > + requires = [requires] > > + if requires: > > + if hasattr(requires[0], 'options'): > > + options = requires[0].options() > > + else: > > + raise SyntaxError, 'widget cannot determine options of %s' > > \ > > + % field > > opts = [TR(INPUT(_type='radio', _name=field.name, > > requires=attr.get('requires',None), > > hideerror=True, _value=k, > > @@ -250,10 +255,15 @@ > > > attr = OptionsWidget._attributes(field, {}, **attributes) > > > - if hasattr(field.requires, 'options'): > > - options = field.requires.options() > > - else: > > - raise SyntaxError, 'widget cannot determine options of %s' % > > field > > + requires = field.requires > > + if not isinstance(requires, (list, tuple)): > > + requires = [requires] > > + if requires: > > + if hasattr(requires[0], 'options'): > > + options = requires[0].options() > > + else: > > + raise SyntaxError, 'widget cannot determine options of %s' > > \ > > + % field > > > options = [(k, v) for k, v in options if k!=''] > > opts = []
[web2py] Re: Multiple instances of same application
IMHO, flask and my lightweight proposal try to solve same problem. Both can load configuration for sure. My proposal's loading ability relies only on python's built-in import (via web2py's model mechanism), therefore no need to introducing extra module. Isn't it clean? The basic challenge is how to separate and manage local setting from default setting, and how to prevent the local setting being distributed via app.w2p or Mercurial. Flask uses environment variable YOURAPPLICATION_SETTINGS=/path/to/settings.cfg, to specify a local setting. I like that too, but it can not be done via pure web2py admin interface, so administrator need to ssh into their production machine and make adjustments, and perhaps a kill-and-restart is needed. On the contrary, in my proposal, although I did not emphasis this in earlier post, administrator only need to visit standard web2py admin interface and setup a new 0_local_setting.py. No ssh nor restart is needed, again I rely on web2py's native behavior. Isn't it lightweight? Of course, I don't like the 0_local_config_pls_dont_pack_dont_commit.py naming convention neither, but I just did not come up with another descriptive name. The point here, is we need a config file which can be used by a web2py app, but not packed with the app. Well, if we really just don't like the long and clumsy name convention, then we can do it in a decent way: 1. introduce a applications/myapp/local_config directory, local settings go into there. 2. adjust web2py to NOT pack, and NOT commit local_config directory 3. but we need more work for web2py's admin UI, to support add/edit/ view/delete setting file. We can choose. On Jun4, 3:26am, Thadeus Burgess wrote: > Or... we can copy flask and integrate a configuration module.. > > God I pray we never use something like > `0_local_config_pls_dont_pack_dont_commit.py` INTO web2py. web2py and > its naming conventions >.< > > -- > Thadeus > > > > On Thu, Jun 3, 2010 at 10:22 AM, Iceberg wrote: > > I think Doug's puzzle deserves a more general solution. The > > requirement and challenge is: > > R1. The app's central source code should contain default setting. > > R2. The app's multiple deployment instances should be allowed to > > contain its local setting. > > R3. And after the next "hg update", the default setting in (R1) should > > not override the local setting in (R2). > > > My solution contains two steps: > > Step1: Use myapp/models/0_config.py to store default setting, such as: > > MY_HOST = 'http://localhost' > > MY_EMAIL = '@bar.com' > > MY_PASSWORD = 'blah' > > MY_DB = 'sqlite://storage.sqlite' > > > Step2: Use myapp/models/0_local_config_pls_dont_pack_dont_commit.py to > > store instance-wide local setting, such as: > > MY_HOST = 'http://myaccount.my_vps_provider.com' > > MY_EMAIL = 'my_real_acco...@for_example_hotmail.com' > > MY_PASSWORD = 'i_will_never_share_it' > > MY_DB = 'mysql://10.1.1.1.' > > > To reach this goal, two things need to be adjusted in web2py source > > code: > > > Thing1: add 0_local_config_pls_dont_pack_dont_commit.py into / > > web2py/.hgignore > > > Thing2: adjust the admin's pack code, to NOT pack the new > > 0_local_config_pls_dont_pack_dont_commit.py > > > On Jun3, 10:23pm, mdipierro wrote: > >> they can see request.env.host_name and you can use hostnames like >> bla bla>.yourdomain.com > > >> you can symlink different apps to the same one so you have one but it > >> will see different request.application depending on the request > > >> On Jun 3, 8:50 am, Doug Warren wrote: > > >> > Is there a preferred way to handle multiple instances of the same > >> > application installed on the same machine? Say for instance is > >> > there's 3 dev environments and 2 staging environments on one server > >> > pointing at different databases? Is there a preferred way of getting > >> > the configuration to each unique app? IE: Can a view/db/controller > >> > see a parameter placed in either options_std or parameters_PORTNO? I > >> > guess what I'm really after is a way to specify at a minimum the > >> > database that an application can point at but have it contained > >> > outside the application itself. > > >> > IE: > >> > foo.w2p is uploaded > >> > foo.w2p is installed as foo > >> > foo.w2p is installed as foo-dev > >> > foo.w2p is installed as foo-dev2 > >> > foo.w2p is installed as foo-stag > > >> > Without having to edit db.py in each of those environments I'd like to > >> > have a way of saying foo-stag should use this connect string, and have > >> > it survive the next time I upload a new foo.w2p and overwrite the one > >> > that's there.
[web2py] Re: Multiple instances of same application
Aside from the config issue, a flag when packaging that does not package the database/ folder, would be the long missing piece. And when this flag is available, I think I can have my own databases/ my_config.py to solve the local config problem in my style. :-) So +1 for the "flag when packaging that does not package the database/ folder". On Jun4, 2:20pm, mdipierro wrote: > I normally use > > #in models/0.py > from gluon.storage import Storage > settings=Storage() > settings.development=True > settings.email_sender=...@example.com' > ... > > Anyway, this does not address Iceberg's problem of packing some config > files and not others. I am not convinced this scenario should be > handled at the web2py level. This is better handled using .hgignore > and mercurial or other version control system. > > I am thinking anyway, to allow a flag when packaging that does not > package the database/ folder. So in principle one could create > function that updates parameters from a DAL('sqlite://settings.db') > > On Jun 4, 1:10 am, Iceberg wrote: > > > > > IMHO, flask and my lightweight proposal try to solve same problem. > > Both can load configuration for sure. My proposal's loading ability > > relies only on python's built-in import (via web2py's model > > mechanism), therefore no need to introducing extra module. Isn't it > > clean? > > > The basic challenge is how to separate and manage local setting from > > default setting, and how to prevent the local setting being > > distributed via app.w2p or Mercurial. Flask uses environment variable > > YOURAPPLICATION_SETTINGS=/path/to/settings.cfg, to specify a local > > setting. I like that too, but it can not be done via pure web2py admin > > interface, so administrator need to ssh into their production machine > > and make adjustments, and perhaps a kill-and-restart is needed. On the > > contrary, in my proposal, although I did not emphasis this in earlier > > post, administrator only need to visit standard web2py admin interface > > and setup a new 0_local_setting.py. No ssh nor restart is needed, > > again I rely on web2py's native behavior. Isn't it lightweight? > > > Of course, I don't like the > > 0_local_config_pls_dont_pack_dont_commit.py naming convention neither, > > but I just did not come up with another descriptive name. The point > > here, is we need a config file which can be used by a web2py app, but > > not packed with the app. > > > Well, if we really just don't like the long and clumsy name > > convention, then we can do it in a decent way: > > 1. introduce a applications/myapp/local_config directory, local > > settings go into there. > > 2. adjust web2py to NOT pack, and NOT commit local_config directory > > 3. but we need more work for web2py's admin UI, to support add/edit/ > > view/delete setting file. > > > We can choose. > > > On Jun4, 3:26am, Thadeus Burgess wrote: > > > > Or... we can copy flask and integrate a configuration module.. > > > > God I pray we never use something like > > > `0_local_config_pls_dont_pack_dont_commit.py` INTO web2py. web2py and > > > its naming conventions >.< > > > > -- > > > Thadeus > > > > On Thu, Jun 3, 2010 at 10:22 AM, Iceberg wrote: > > > > I think Doug's puzzle deserves a more general solution. The > > > > requirement and challenge is: > > > > R1. The app's central source code should contain default setting. > > > > R2. The app's multiple deployment instances should be allowed to > > > > contain its local setting. > > > > R3. And after the next "hg update", the default setting in (R1) should > > > > not override the local setting in (R2). > > > > > My solution contains two steps: > > > > Step1: Use myapp/models/0_config.py to store default setting, such as: > > > > MY_HOST = 'http://localhost' > > > > MY_EMAIL = '@bar.com' > > > > MY_PASSWORD = 'blah' > > > > MY_DB = 'sqlite://storage.sqlite' > > > > > Step2: Use myapp/models/0_local_config_pls_dont_pack_dont_commit.py to > > > > store instance-wide local setting, such as: > > > > MY_HOST = 'http://myaccount.my_vps_provider.com' > > > > MY_EMAIL = 'my_real_acco...@for_example_hotmail.com' > > > > MY_PASSWORD = 'i_will_never_share_it' > > > > MY_DB = 'mysql://10.1.1.1.
[web2py] Re: Multiple instances of same application
Let me clarify and then summarize. First, .hgignore is one thing, "packing" is another. Ok we can leave the .hgignore out of web2py level, let each developer controls it by themselves. But when talking about "packing", I mean the "pack" feature on http://localhost:8000/admin/default/site for each app. It is a web2py way to built app.w2p package, especially for non-open- source project. So far, there is no way to built a w2p without leaking your current copy's local config content, even when .hgignore already setup by developer. So, perhaps we could, at least, agree on a new "pack without databases" feature on http://localhost:8000/admin/default/site for each app? (Then I can put my own local_config.ini inside there) Regards, iceberg On Jun5, 1:55am, Thadeus Burgess wrote: > I agree with Massimo, the NOT packing facility could be handled by .hgignore. > > As for configuration, I have used 0_config.py in blogitizor so that I > can run two versions, my personal version and the one that is open > source, this way my database and email information doesn't get leaked > out into the internetz. > > I use the following, > > http://code.google.com/p/blogitizor/source/browse/src/models/A_config... > > And then rename it to A_config.py and it won't get committed since > src/models/A_config.py is placed in my .hgignore file. > > However this isn't a web2py mechanism just a personal one, I don't > like the idea of making web2py in charge of this because then I the > developer lose control and can't change the way it works without > forking web2py. > > -- > Thadeus > > > > On Fri, Jun 4, 2010 at 3:28 AM, Iceberg wrote: > > Aside from the config issue, a flag when packaging that does not > > package the database/ folder, would be the long missing piece. And > > when this flag is available, I think I can have my own databases/ > > my_config.py to solve the local config problem in my style. :-) > > > So +1 for the "flag when packaging that does not package the database/ > > folder". > > > On Jun4, 2:20pm, mdipierro wrote: > >> I normally use > > >> #in models/0.py > >> from gluon.storage import Storage > >> settings=Storage() > >> settings.development=True > >> settings.email_sender=...@example.com' > >> ... > > >> Anyway, this does not address Iceberg's problem of packing some config > >> files and not others. I am not convinced this scenario should be > >> handled at the web2py level. This is better handled using .hgignore > >> and mercurial or other version control system. > > >> I am thinking anyway, to allow a flag when packaging that does not > >> package the database/ folder. So in principle one could create > >> function that updates parameters from a DAL('sqlite://settings.db') > > >> On Jun 4, 1:10 am, Iceberg wrote: > > >> > IMHO, flask and my lightweight proposal try to solve same problem. > >> > Both can load configuration for sure. My proposal's loading ability > >> > relies only on python's built-in import (via web2py's model > >> > mechanism), therefore no need to introducing extra module. Isn't it > >> > clean? > > >> > The basic challenge is how to separate and manage local setting from > >> > default setting, and how to prevent the local setting being > >> > distributed via app.w2p or Mercurial. Flask uses environment variable > >> > YOURAPPLICATION_SETTINGS=/path/to/settings.cfg, to specify a local > >> > setting. I like that too, but it can not be done via pure web2py admin > >> > interface, so administrator need to ssh into their production machine > >> > and make adjustments, and perhaps a kill-and-restart is needed. On the > >> > contrary, in my proposal, although I did not emphasis this in earlier > >> > post, administrator only need to visit standard web2py admin interface > >> > and setup a new 0_local_setting.py. No ssh nor restart is needed, > >> > again I rely on web2py's native behavior. Isn't it lightweight? > > >> > Of course, I don't like the > >> > 0_local_config_pls_dont_pack_dont_commit.py naming convention neither, > >> > but I just did not come up with another descriptive name. The point > >> > here, is we need a config file which can be used by a web2py app, but > >> > not packed with the app. > > >> > Well, if we really just don't like the long and clumsy name > >> > convention, then we c
[web2py] Re: convert field to multiple view values?
And in the controller/view, you can use db.foo.height.represent = lambda v: 'xx feet yy inch zz fraction' to display it, therefore you need not depend on javascript. On Jun6, 7:12am, MikeEllis wrote: > Oops hit send by accident. > > so after the form.accepts(request.vars, session), you'll need code to > convert the feet, inches, and fractions to a double and stuff it into > the database. Some of the more experienced web2py users may have a > better way, but this approach is working for me. > > Cheers, > Mike > > On Jun 5, 7:08 pm, MikeEllis wrote: > > > > > I've been using SQLFORM.factory() for cases where what's in the db > > needs to be presented to the user in a different format. The online > > book has some good examples. For your case, my first thought would be > > to define a function in the model that generates the form, e.g. > > > def fooform(): > > fields = [] > > ... > > fields.append('Feet', 'integer', ...) > > fields.append('Inches', 'integer', requires=IS_IN_SET(range(0-12))) > > fields.append('Fraction', 'string', requires=IS_IN_SET(["0", "1/4", > > "1/2", "3/4"])) > > ... > > return SQLFORM.factory(*fields) > > > Then in your controller, > > form = fooform() > > if form.accepts(): > > > form = fooform() > > if form.accepts(): > > > On Jun 4, 12:09 pm, Keith wrote: > > > > I'm new to web2py and the I did this previously was with javascript > > > but I was hoping to avoid that this go around. > > > > In my database table I have a single field something like this below: > > > > db.define_table('foo', > > > Field('height', 'double'), > > > > In the controller/view I need to be able to translate that so when > > > viewing a record they see: > > > Feet, Inches, and Fractions of a Inch. > > > > When adding a record it would need to be a text field for feet and > > > drop down lists for inches and fractions of a inch. > > > > I know how to do that in javascript, but I don't like relying on > > > javascript if possible. I'm hoping there is a way to do this in the > > > controller or model. > > > > Thanks for any suggestions.
[web2py] Re: python web console
Off topic: The last commit of chinese translation of admin app somehow missed the word "shell". No wonder I can't find the [shell] feature in chinese UI. It happened before and it will probably happen in the future. So, instead of just patching the missing translation, I suggest Massimo to adjust the translation mechanism a little bit (pseudo code below): if the_original_string not in current_language: translated_msg = the_original_string else: translated_msg = current_language.get(the_original_string) On Jun7, 5:02am, mdipierro wrote: > There is a button [shell] from the admin/edit page for each app. > > On Jun 6, 3:15 pm, Tomas Pelka wrote: > > > > > Hi all, > > if I'm correct web2py had a web (java script) python console. I can't > > find it now, is it still included? > > > Thanks > > > -- > > Tomas Pelka
[web2py] Re: parsehtml
Hi Massimo, did you include it in your latest commit? If so, I guess you forget to add a new gluon/decoder.py as well. And a side note, I recommend you maintain two web2py environment for yourself, one for developing and then commit new features, the other is used for "hg pull" and "hg update" and "web2py.py -a1" and your test such as [1]. This way, you will immediately find any forgot-to- commit-new-file problem, faster than anyone else. [1] http://www.web2py.com/examples/static/nightly/tests.log On Jun 8, 7:37 am, mdipierro wrote: > I will include this in web2py. Thank you > > On Jun 7, 5:12 pm, Alexandre Andrade wrote: > > > > > Try also: > > >http://code.activestate.com/recipes/52257/ > > > 2010/6/7 mdipierro > > > > Amazing. Very similar. One thing that web2py TAG is missing it the > > > ability to guess encoding. It fails and.or does mistakes if the source > > > is not UTF8 encoded. > > > > On Jun 6, 10:57 pm, Álvaro Justen wrote: > > > > This project:http://github.com/gabrielfalcao/dominic#readme > > > > was created by a Brazilian. > > > > Maybe it can helps with web2py HTMLParser. > > > > > -- > > > > Álvaro Justen - Turicas > > > > http://blog.justen.eng.br/ > > > > 21 9898-0141 > > > -- > > Atenciosamente > > > -- > > = > > Alexandre Andrade > > Hipercenter.com
[web2py] Re: python web console
Massimo and Yarko, Thanks for your concern. So I trace it down. The result is ... interesting. I guess you both are right, the last few lines of current gluon/ languages.py already fall back to original source language, like this: def translate(self, message, symbols): mt = self.t.get(message, None) if mt == None: self.t[message] = mt = message However, there IS explicit "empty definition" in latest zh-ch.py language file. See this page [1], you don't need to know Chinese to notice three words, "TM", "db", "shell", are "translated" into ''. Our code self.t.get(message)==None can not catch this kind of "translation". Well, adding proper translation to those three words, is just piece of cake for me. But I doubt that would be worthy, because I already fixed them in my earlier revisions [2], from a even much buggy revision [3]. Coincidently, the buggy revision [1] and [3] are from same person. I wonder where goes wrong in his translating work flow. Changing languages.py's code into these: mt = self.t.get(message) if not mt: self.t[message] = mt = message might NOT be an option, because we might occasionally need a English word to be translated into empty on purpose. Say, a single word "the" is not always meaningful. That is why I proposed we need carefully chosen bilinguals to become door-keepers (a.k.a. editors) for each language [4]. [1] http://code.google.com/p/web2py/source/browse/applications/admin/languages/zh-cn.py [2] http://code.google.com/p/web2py/source/browse/applications/admin/languages/zh-cn.py?r=14d5522549423ef2cf4a52fcba6c5edfebb04556 [3] http://code.google.com/p/web2py/source/browse/applications/admin/languages/zh-cn.py?r=063cc48352eacc0be534f288781840261717caa2 [4] http://groups.google.com/group/web2py/browse_frm/thread/4a1224741bb8ac06 On Jun 8, 2:56 am, Yarko Tymciurak wrote: > Iceberg: could you debug / trace? I too thought the behavior you > asked for was already the case, so it is probably getting "short > circuited" somewhere - would be good to see where. > > - Yarko > > On Jun 7, 1:11 pm, mdipierro wrote: > > > Not sure I understand. This should be already the default behavior. > > > On Jun 7, 2:59 am, Iceberg wrote: > > > > Off topic: The last commit of chinese translation of admin app somehow > > > missed the > > > word "shell". No wonder I can't find the [shell] feature in chinese > > > UI. It happened before and it will probably happen in the future. So, > > > instead of just patching the missing translation, I suggest Massimo to > > > adjust the translation mechanism a little bit (pseudo code below): > > > if the_original_string not in current_language: > > > translated_msg = the_original_string > > > else: > > > translated_msg = current_language.get(the_original_string) > > > > On Jun7, 5:02am, mdipierro wrote: > > > > > There is a button [shell] from the admin/edit page for each app. >
[web2py] Re: widgets
On Jun12, 12:47pm, leone wrote: > I coded a widget to use with a Field object. > Because I need some javascript actions i wrote pure html-javascript > code that my widget returns. > It runs, but when I accept the form values are in request.vars, but > not in form.vars. > How can i store values in form.vars without using input widgets > defined by SQLFORM.widgets...? > Thanks in advance > leone You'd better let your widget derive from the default widgets, or you need to make sure yours contain proper _id and _name etc. See also http://web2py.com/book/default/section/7/5?search=widgets
[web2py] Re: widgets
On Jun12, 12:47pm, leone wrote: > I coded a widget to use with a Field object. > Because I need some javascript actions i wrote pure html-javascript > code that my widget returns. > It runs, but when I accept the form values are in request.vars, but > not in form.vars. > How can i store values in form.vars without using input widgets > defined by SQLFORM.widgets...? > Thanks in advance > leone You'd better let your widget derive from the default widgets, or you need to make sure yours contain proper _id and _name etc. See also http://web2py.com/book/default/section/7/5?search=widgets
[web2py] Re: widgets
On Jun12, 12:47pm, leone wrote: > I coded a widget to use with a Field object. > Because I need some javascript actions i wrote pure html-javascript > code that my widget returns. > It runs, but when I accept the form values are in request.vars, but > not in form.vars. > How can i store values in form.vars without using input widgets > defined by SQLFORM.widgets...? > Thanks in advance > leone You'd better let your widget derive from the default widgets, or you need to make sure yours contain proper _id and _name etc. See also http://web2py.com/book/default/section/7/5?search=widgets
[web2py] Re: form in layout.html?
Wow, thanks very much for sharing this trick. I knew it could be easy and elegant! :-) On Jun20, 10:15pm, mdipierro wrote: > Because the form is submitted and returned via ajax the usual > mechanism does not work but you can do: > > def form(): > form=SQLFORM.factory( > Field('name', requires=IS_NOT_EMPTY())) > if form.accepts(request.vars, session): > response.headers['web2py-component-flash'] = 'form accepted' > else: > response.headers['web2py-component-flash'] = 'form has errors' > return form > > I.E. place the flash in a HTTP header and web2py will read it and > place it in the flash box. > > On Jun 19, 11:23 am, Julius Minka wrote: > > > > > def form(): > > form=SQLFORM.factory( > > Field('name', requires=IS_NOT_EMPTY())) > > if form.accepts(request.vars, session): > > response.flash = 'form accepted' > > else: > > response.flash = 'form has errors' > > return form > > > Flash is not displayed in this place, elsewhere is working. Why? > > Or, how let user know about the result of form submission? > > > V Sobota, 19. jún 2010 o 00:41 -0700, mdipierro napísal(a): > > > > Just do > > > > def contact(): > > > form=SQLFORM.factory() > > > if form.accepts() > > > return form # not dict(form=form) > > > > and in layout.html > > > > {{=LOAD('default','contact')}} > > > > On Jun 18, 11:26 am, Julius Minka wrote: > > > > I need a contact form (name, address,...) on every page of a web site. > > > > Thinking about putting the form into layout.html and use some Ajax to > > > > send entered values to be processed by a controller. I would like to > > > > avoid page reload on form submission. > > > > > I found 2 possible solutions in the archive: > > > > 1.http://groups.google.com/group/web2py/browse_thread/thread/f162f35e4a... > > > > Is this incomplete? How process function is called? > > > > > 2.http://groups.google.com/group/web2py/browse_thread/thread/82fad17e26... > > > > I ran application mentioned in the thread. This is probably close, but > > > > complicated. > > > > > What is good and simple approach to this issue? I do not have much > > > > experience with Ajax. > > > > > Thanks > > > > Julius
[web2py] Re: for fun
Thanks for sharing. But ... I put exactly same code on your page to a myapp/controllers/maze.py, even use your version of processing.min.js, processing.init.js, jquery.js, but it just does not work exactly the same as your demo. When I click somewhere in the maze, say coordinate (x,y), my maze reacts as if I am clicking another place at (x+blah, y+sth) Did I miss something? Thanks in advance. On Jun21, 6:20am, mdipierro wrote: > source is NOW posted on the page > > On Jun 17, 10:50 am, mdipierro wrote: > >http://www.web2py.com/mazes
[web2py] Re: for fun
Thanks for the tips! So here comes my modified version with a calibration feature, so that one-file-fits-all! var calibrated=0; var offsetX=0; var offsetY=0; ... alert('Click the upper-left corner for calibration.'); void mousePressed() { if(!calibrated){ // There is a bug in processing the mouseX and mouseY return wrong // coordinates depending on the location of the canvas in the page. offsetX=mouseX; offsetY=mouseY; calibrated=1; } // when the mouse is pressed or dragged draw shortest path to start of maze drawnow(); strokeWeight(max((n-2)/2,2)); x=int((mouseX-offsetX)/n); y=int((mouseY-offsetY)/n); ... On Jun22, 12:54am, mdipierro wrote: > See these lines: > > x=int((mouseX-20)/ > n); > y=int((mouseY-20)/n); > > There is a bug in processing the mouseX and mouseY return wrong > coordinates depending on the location of the canvas in the page. the > "-20" fixes the offset for me. For you it may be different. > > On Jun 21, 11:44 am, Iceberg wrote: > > > > > Thanks for sharing. But ... > > > I put exactly same code on your page to a myapp/controllers/maze.py, > > even use your version of processing.min.js, processing.init.js, > > jquery.js, but it just does not work exactly the same as your demo. > > When I click somewhere in the maze, say coordinate (x,y), my maze > > reacts as if I am clicking another place at (x+blah, y+sth) > > > Did I miss something? Thanks in advance. > > > On Jun21, 6:20am, mdipierro wrote: > > > > source is NOW posted on the page > > > > On Jun 17, 10:50 am, mdipierro wrote: > > > >http://www.web2py.com/mazes
[web2py] Re: proposal of introducing generic.load
Hi Massimo, thanks for your sharing another undocumented magic of web2py, the response.headers['web2py-component-flash'], in this post, http://groups.google.com/group/web2py/msg/6049af89fbfa2bfc That makes me think that is just another example to justify my proposal, this time it is refined to automatically convert reponse.flash into response.headers['web2py-component-flash'] when needed. Check this out. It is self-documented. {{ ''' With this generic.load file, you can use same action to serve two purposes. Example modified from http://www.web2py.com/AlterEgo/default/show/252: def index(): return { 'part1':'hello world', 'part2': LOAD( url=URL(r=request,f='auxiliary.load'), # Notice the ".load" extention ajax=True), } def auxiliary(): form=SQLFORM.factory(Field('name')) if form.accepts(request.vars): response.flash = 'ok' # No need for this anymore: response.headers['web2py-component-flash'] = 'ok' return {'': "Hello %s" % form.vars.name} return {'':form} # No need for "return form" anymore! >From now on, single auxiliary() can serve two purposes: http://.../auxiliary.load serves as a raw component LOADed by other action http://.../auxiliary serves as a normal html page as usual # PS: Please keep all above explanation for people to know when and how to use it. # License: Public Domain # Author: Iceberg at 21cn dot com ''' }} {{ # Does NOT extend layout.html, purposely.}} {{response.headers['Content-Type']='text/html'}} {{if response.flash: response.headers['web2py-component-flash'] = response.flash}} {{if len(response._vars)==1 and not response._vars.keys()[0]:}} {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly colon }} {{else:}} {{=BEAUTIFY(response._vars)}} {{pass}} On Jun3日, 10:21pm, mdipierro wrote: > I am not convinced this is general enought but I like the idea. Let me > think about it. > > On Jun 3, 7:17 am, Iceberg wrote: > > > > > Hi Massimo, > > > I just came up with a handy myapp/views/generic.load, and I wonder > > whether you will like to accept it as part of web2py scaffold. It is > > already self-documented. > > > > > > {{ ''' > > With this generic.load file, you can use same action to serve two > > purposes. > > > Example modified fromhttp://www.web2py.com/AlterEgo/default/show/252: > > > def index(): > > return { > > 'part1':'hello world', > > 'part2': LOAD( > > url=URL(r=request,f='auxiliary.load'), # Notice the > > ".load" extention > > ajax=True), > > } > > > def auxiliary(): > > form=SQLFORM.factory(Field('name')) > > if form.accepts(request.vars): > > return {'': "Hello %s" % form.vars.name} > > return {'':form} # Need NOT to write it as "return form" any more! > > > From now on, single auxiliary() can serve two > > purposes:http://.../auxiliary.load serves as a raw component LOADed by other > > actionhttp://.../auxiliary serves as a normal html page as usual > > > # PS: Please keep all above explanation for people to know when and > > how to use it. > > # License: Public Domain > > # Author: Iceberg at 21cn dot com > > ''' > > > }} > > > {{ # Does NOT extend layout.html, purposely.}} > > {{response.headers['Content-Type']='text/html'}} > > {{if len(response._vars)==1 and not response._vars.keys()[0]:}} > > {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly > > colon }} > > {{else:}} > > {{=BEAUTIFY(response._vars)}} > > {{pass}}
[web2py] Re: Web2py free hosting?
People here know some cheap hosts, but "free" sounds better than "cheap". :-) Hope your searching adventure can bring back some info to the group. By the way, I just saw this but did not try them. http://www.free-webhosts.com/webhosting-01.php On Jun20, 4:34am, Giuseppe Luca Scrofani wrote: > Hey Jason you are a very nice person. Ill' consider your generous > offer if I dont find a suitable free hosting. I need only a week, so > your proposal is perfect for me. Lets see what is the situation with > free hosting first. > From my searches, for now there is this:http://www.heliohost.orgseem > worth a try. If installing web2py reveal's possible I will let the > group know. If someone knows other feel free to post! > > Thanks in advance! (sorry for my english) > > > > > I can host you app in one of my instances. It can no be perminently there. > > But i can give you a deal if you need a place. > > Br... > > Jb
[web2py] Re: proposal of introducing generic.load
Massimo, {{=BEAUTIFY(response._vars.values()[0])}} is still preferred in case the controller returns something like {'': ['a', 'b', {'foo': 'bar'}]} By the way, here is another proposal. Since you agree on at least "let me think", please also consider change the generic.html into this. {{extend 'layout.html'}} {{if len(response._vars)==1 and not response._vars.keys()[0]:}} {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly colon }} {{else:}} {{=BEAUTIFY(response._vars)}} {{pass}} The point here is such pattern suits a typical controller action like this: def index(): form = SQLFORM(...) if form.accepts(...): blah_blah return { '' : form } therefore I do NOT need to write many boring views file again and again like this: {{extend 'layout.html'}} {{=form}} I used such generic.html in all my apps for more than one year. It did save my numerous time. Regards, Iceberg On Jun22, 3:34am, mdipierro wrote: > I like the idea. Let me think a little bit about the implementation > until the end of this week. > Why {{=BEAUTIFY(response._vars.values()[0])}} and not > {{=response._vars.values()[0]}} > > On Jun 21, 1:09 pm, Iceberg wrote: > > > > > Hi Massimo, thanks for your sharing another undocumented magic of > > web2py, the response.headers['web2py-component-flash'], in this > > post,http://groups.google.com/group/web2py/msg/6049af89fbfa2bfc > > > That makes me think that is just another example to justify my > > proposal, this time it is refined to automatically convert > > reponse.flash into response.headers['web2py-component-flash'] when > > needed. > > > Check this out. It is self-documented. > > > {{ ''' > > With this generic.load file, you can use same action to serve two > > purposes. > > > Example modified fromhttp://www.web2py.com/AlterEgo/default/show/252: > > > def index(): > > return { > > 'part1':'hello world', > > 'part2': LOAD( > > url=URL(r=request,f='auxiliary.load'), # Notice the > > ".load" extention > > ajax=True), > > } > > > def auxiliary(): > > form=SQLFORM.factory(Field('name')) > > if form.accepts(request.vars): > > response.flash = 'ok' # No need for this anymore: > > response.headers['web2py-component-flash'] = 'ok' > > return {'': "Hello %s" % form.vars.name} > > return {'':form} # No need for "return form" anymore! > > > From now on, single auxiliary() can serve two > > purposes:http://.../auxiliary.load serves as a raw component LOADed by other > > actionhttp://.../auxiliary serves as a normal html page as usual > > > # PS: Please keep all above explanation for people to know when and > > how to use it. > > # License: Public Domain > > # Author: Iceberg at 21cn dot com > > ''' > > > }} > > > {{ # Does NOT extend layout.html, purposely.}} > > {{response.headers['Content-Type']='text/html'}} > > {{if response.flash: response.headers['web2py-component-flash'] = > > response.flash}} > > {{if len(response._vars)==1 and not response._vars.keys()[0]:}} > > {{=BEAUTIFY(response._vars.values()[0])}} {{ # To bypass the silly > > colon }} > > {{else:}} > > {{=BEAUTIFY(response._vars)}} > > {{pass}} >
[web2py] Re: built in web2py datepicker bug with Google Chrome
On Jun30, 4:56am, Jean-Guy wrote: > Hello, > > Is there other user that are having datepicker coming blank when > changing the year or mouth couples of time with Google Chrome? > > I test it with firefox no problem. > > I use web2py 1.7.8 > > Jonhy Thank you, Jonhy!!! I met this issue recently. And thank you so much for the nudge about suspecting Chrome. That gave me the direction, then I found comment 232 of this thread: http://www.dynarch.com/projects/calendar/old/ I think Massimo need to include that patch into web2py's welcome app. Regards, Iceberg
[web2py] Re: language files can not edit directly
On Jun28, 11:34am, Álvaro Justen wrote: > On Sun, Jun 27, 2010 at 23:51, dlin wrote: > > About the Q1, I know that web interface. But, I'm wonder why not > > provide direct file edit? That's will let my version control system > > easier to track and view the differences. And I can use my editor to > > global replace. > > > About the Q2, if the sentences is similar, why not reduce them? > > > Q3: Sometimes, one English word mapping to difference meaning of > > Chinese. How can I deal with this? For example, if 'eat' means 'eat' > > and 'kill' in Chinese. Then, the translate table will be > > { > > 'eat_1' : 'eat', > > 'eat_2' : 'kill' > > } > > > But, in English view, it will appear eat_1, eat_2, how to solve this > > problem? > > > Q4: Can I suggest sort the translation table in ignore case alpha > > order? That's let me easier to translate similar sentences. > > > Q5: Is there any function to force display all possible T() words in > > tranlation table? > > > Q6: If the words is not translated, could it display different color > > to let us easier to modify it? > > Maybe we should provide the developer to use a very stable > internationalization system, like python gettext[1]. > Other projects use it and I don't know why we don't: it is shipped > with Python by default and people that wrote gettext have experience > on this, so probably they asked all those (any many more) questions > about i18n. > With the gettext domains (examples: myapp.chinese1, myapp.chinese2) > you can separate your translation strings and have different > translations for the same string (in different domains). > > For your case specifically, you can use a very dirty hack: > T('some_string') and T('some_string ') (with spaces). Probably the > space in the second string will not affect you if you put it on HTML - > so you have 2 strings and can translate it the way you want. > > [1]http://docs.python.org/library/gettext.html > > -- > Álvaro Justen - Turicas > http://blog.justen.eng.br/ > 21 9898-0141 My several cents... About Q1, I had exactly same thought as dlin's, every time when I diff the applications/admin/languages/foo-bar.py via VCS and saw those human-unfriendly \x12\x34 etc. Then I tried to solve the problem in fundamental gluon/languages.py but ended up giving up, every time when I failed to find another implementation to beat current gluon/ languages.py 's simplicity. Current languages.py uses repr() to gracefully escape possible single quotation mark, double quotation mark, line-feed, etc inside those language messages, by: fp.write('%s: %s,\n' % (repr(key), repr(contents[key]))) Those \x12\x34 thing is the side effect of expr(...), sad but true. The language resource file is a python dict, therefore can be easily read by a simple: lang_text = fp.read() return eval(lang_text) On the contrary, gettext uses a complicate language file format, [1], no wonder the python/lib/gettext.py has three times of size than web2py/gluon/languages.py, no doubt the latter is easier to understand and maintain. Still hope someone smart can figure out another simple way without using repr(...) About Q2, those duplicate similar sentences are caused by carelessly writing messages in T(...), IMHO. I even saw these: 'A new version of web2py is available: Version 1.79.1 (2010-06-05 19:48:42)\n' 'A new version of web2py is available: Version 1.79.2 (2010-06-08 22:45:26)\n' We should avoid using any easy-changing sentence inside T(...). Q3 is out of the scope of any i18n system, I think. The solution is use longer string in your app to avoid various meaning, and always translate in a context rather than just do word-to-word translating. Q4: I guess dlin can try to change line 60 of gluon/languages.py from: for key in sorted(contents): to: for key in sorted(contents, key=str.lower): Q5 & Q6: Perhaps you can change admin's translate interface, and Massimo will take your patch. Regards, Iceberg
[web2py] Re: local_import
Sorry gentlemen, I don't get it. First of all, the new implementation, even with the latest bugfix, does not use the "force" parameter at all, neither python reload(). I reckon that Jose did not test the reload feature when he said "Now works!". Actually now the reload feature is gone. Second, I would recommend Massimo to test the new code before committing it. Even we don't have to follow TDD (test-driven development), but a TAD (test-after-development) should be a minimal rule. Otherwise you actually put those enthusiastic web2py users on a really "bleeding" edge, with unnecessary "blood", and therefore potentially discourage them from checking out the latest trunk often. The last, well, and the least, I would like to suggest "If It Works, Don't Fix It". I remember local_import(...) was not an easy job. More than 7 months ago, it experienced some back and forth adjustment, until Massimo commented out the "old implementation" and code stabilized since then. So, why the sophisticated local_import(...) is being reimplemented 2 days ago, introducing all this hustle? On Jul3, 7:45am, mdipierro wrote: > I think I fixed it. Please try again. Also check whether reload works > or not. > > On 2 Lug, 18:26, Jose wrote: > > > > > In the modules directory of my application I have mymodule.py > > > When run from the controller: > > mymodule = local_import ('mymodule', reload = True) > > > this produces no error, but when I access the functions or classes of > > the module, > > > myobject = mymodule.MyClass(...) > > > it fails: > > > AttributeError: 'module' object has no attribute 'MyClass' > > > You understand? > > > This worked well until yesterday, after upgrading from the trunk, > > started the error. > > > Jose
[web2py] Will rocket close connections if it takes long time?
Hi Candid and everyone, Candid mentioned "rocket should close the connections if request is taking longer than 10 seconds (default timeout)" in here [1]. Would somebody clarify, is that true? My concern is that, one of my old app need some periodical maintenance job which could take dozes of seconds to finish. I knew the normal solution is run another daemon for that, but, for simplicity reasons, I still chose to use web2py 's builtin cron feature to visit http://localhost:8000/myapp/default/maintenance every hour. This trick worked well on my windows XP development laptop. I don't know whether situation is changed since then. [1] http://groups.google.com/group/web2py/msg/0416ed025f3e33f8 Regards, Iceberg
[web2py] Re: built in web2py datepicker bug with Google Chrome
On Jul1, 8:01pm, Iceberg wrote: > On Jun30, 4:56am, Jean-Guy wrote: > > > Hello, > > > Is there other user that are having datepicker coming blank when > > changing the year or mouth couples of time with Google Chrome? > > > I test it with firefox no problem. > > > I use web2py 1.7.8 > > > Jonhy > > Thank you, Jonhy!!! > > I met this issue recently. And thank you so much for the nudge about > suspecting Chrome. That gave me the direction, then I found comment > 232 of this thread: > http://www.dynarch.com/projects/calendar/old/ > > I think Massimo need to include that patch into web2py's welcome app. > > Regards, > Iceberg Hi Massimo, I've sent you the patch. Did you get it? You might need to check your spam folder. :-/
[web2py] Re: Will rocket close connections if it takes long time?
Thanks for clarifying. And I take a glance into gluon/widget.py, main.py and rocket.py to confirm there is some timeout=10. So from the design aspect, I'd better avoid expecting a long-run request to finish my app's time-consuming maintenance job. On the other hand, I confirmed that, with latest trunk, running Windows XP, my maintenance request did last for more than 10 seconds, magically. Does it indicate the DoS-resistant timeout fuse somehow fail? Do you think it is ok or unacceptable? My maintenance job's log: WARNING:root:job.id=33, elapsed=18.812638 s Another evidence in web2py/httpserver.log 127.0.0.1, 2010-07-03 21:49:20, GET, /myapp/default/longrun, HTTP/ 1.1, 200, 21.75 Regard, Iceberg On Jul3, 8:31pm, mdipierro wrote: > The web server threads MUST have a timeout (the shorter the better) > else they are vulnerable to denial of service attacks. > > On 3 Lug, 06:23, Iceberg wrote: > > > > > Hi Candid and everyone, > > > Candid mentioned "rocket should close the connections if request is > > taking longer than 10 seconds (default timeout)" in here [1]. Would > > somebody clarify, is that true? > > > My concern is that, one of my old app need some periodical maintenance > > job which could take dozes of seconds to finish. I knew the normal > > solution is run another daemon for that, but, for simplicity reasons, > > I still chose to use web2py 's builtin cron feature to > > visithttp://localhost:8000/myapp/default/maintenanceeveryhour. This trick > > worked well on my windows XP development laptop. I don't know whether > > situation is changed since then. > > > [1]http://groups.google.com/group/web2py/msg/0416ed025f3e33f8 > > > Regards, > > Iceberg
[web2py] Re: local_import
Are you so sure __import__() always reloads? I don't believe so, and that is also why there is a built-in reload(). At least __import__() does not reload in my following simple test. Jose, would you please also try this one? # myapp/modules/foo.py def bar(): return 'hello world' # myapp/controllers/test.py def index(): return local_import('foo', reload=True) Visit http://localhost:8000/myapp/test and you will see "hello world". Fine. Don't restart web2py, now change bar() as return 'something else', refresh your browser. So far I still see "hello world" but not "something else". Besides, the myapp/modules/foo.pyc is NOT rebuilt according to its file create timestamp, thus another evidence that the reload did not happen. I am using latest trunk on Windows XP, Python 2.5.4 By the way, an equivalent, cleaner and faster refactoring is legitimate, as long as it works. I will agree on a __import__() feels better than an exec(...), so let's first get things right. On Jul3, 7:49pm, mdipierro wrote: > It is true that force is ignored. That is because __import__ always > reloads. This may seem slower but actually it may be faster than the > previous solution using exec with force=False. > > The reason for the change is that the new implementation is supposed to > be equivalent, cleaner and faster. > Does it work for you? > > Massimo > > On 3 Lug, 06:05, Iceberg wrote: > > > > > Sorry gentlemen, I don't get it. > > > First of all, the new implementation, even with the latest bugfix, > > does not use the "force" parameter at all, neither python reload(). I > > reckon that Jose did not test the reload feature when he said "Now > > works!". Actually now the reload feature is gone. > > > Second, I would recommend Massimo to test the new code before > > committing it. Even we don't have to follow TDD (test-driven > > development), but a TAD (test-after-development) should be a minimal > > rule. Otherwise you actually put those enthusiastic web2py users on a > > really "bleeding" edge, with unnecessary "blood", and therefore > > potentially discourage them from checking out the latest trunk often. > > > The last, well, and the least, I would like to suggest "If It Works, > > Don't Fix It". I remember local_import(...) was not an easy job. More > > than 7 months ago, it experienced some back and forth adjustment, > > until Massimo commented out the "old implementation" and code > > stabilized since then. So, why the sophisticated local_import(...) is > > being reimplemented 2 days ago, introducing all this hustle? > > > On Jul3, 7:45am, mdipierro wrote: > > > > I think I fixed it. Please try again. Also check whether reload works > > > or not. > > > > On 2 Lug, 18:26, Jose wrote: > > > > > In the modules directory of my application I have mymodule.py > > > > > When run from the controller: > > > > mymodule = local_import ('mymodule', reload = True) > > > > > this produces no error, but when I access the functions or classes of > > > > the module, > > > > > myobject = mymodule.MyClass(...) > > > > > it fails: > > > > > AttributeError: 'module' object has no attribute 'MyClass' > > > > > You understand? > > > > > This worked well until yesterday, after upgrading from the trunk, > > > > started the error. > > > > > Jose
[web2py] Re: Will rocket close connections if it takes long time?
Thanks for all these info, Tim. You said: "The timeout ... is a timeout based on inactivity between http requests. So the long requests that Iceberg is seeing are perfectly normal and acceptable." According to my reading of the rocket-science code (and I could be wrong), here is my understanding and questions: 1. The timeout is a timeout based on inactivity since one request socket's latest select-and-readable event. The time gap could be caused by two http requests which somehow reuse the socket (because keep-alive?), or caused by one very slow http request from a client (possibly a DoS attack). 2. BUT the timeout check is only performed after the request's socket encountered socket.timeout exception. According to line 800 of rocket.py: if typ == SocketTimeout: self.err_log.debug('Socket timed out') self.wait_queue.put(self.conn) And then the request's control is transferred to the Monitor, the timeout check is at line 449 of rocket.py: if now - c.start_time >= self.timeout: stale.add(c) 3. What if, a normal request is read from client side within seconds, then being calculated for quite some time on the server side, will this situation trigger the timeout protection? I guess not, because no socket.timeout will be raised during the calculation, although the final calculated result will probably not be sent due to the socket is already timeout or even closed from the client side. If this is true (is it?), then my maintenance scenario is still doable because no result is expected, I only need the maintenance job can be triggered and can run as long as it takes. 4. On the other hand, at least on Windows XP, python 2.5.4, by default, socket has no socket.timeout, so the above check is not performed at all, is it? So the rocket timeout protection is not activated anyway. -- Iceberg On Jul4, 9:26am, Timbo wrote: > Rocket has a longer default wait time before it closes connections in > comparison to CherryPy. You might check web2py code, it is not likely > using the same default timeout as Rocket proper. > See:http://packages.python.org/rocket/usage.html#timeout > > This is a DoS vulnerability on CherryPy but not Rocket because Rocket > pushes waiting threads to a monitor queue so that they don't occupy > worker threads. The monitor queue can easily handle the socket limit > of connections. In this manner, Rocket can handle many thousands of > connections without causing new connections to have to wait as > CherryPy does. There is a limit on number of active connections, but > that limit is the number of worker threads which is > configurable:http://packages.python.org/rocket/usage.html#max-threads > > The timeout mentioned in the link above is a timeout based on > inactivity between http requests. So the long requests that Iceberg > is seeing are perfectly normal and acceptable. > > Browsers such as Chrome and FF will leave a connection open for quite > some time or until the tab is closed (even if the user has browsed > away from the Rocket-running server domain). Rocket basically wants > to keep those connections open since they don't cost significantly to > wait in the monitor queue. > > -tim > > On Jul 3, 9:35 am, mdipierro wrote: > > > > > Let's wait for Tim to respond. The timeout should be enforced. > > > On 3 Lug, 09:07, Iceberg wrote: > > > > Thanks for clarifying. And I take a glance into gluon/widget.py, > > > main.py and rocket.py to confirm there is some timeout=10. So from the > > > design aspect, I'd better avoid expecting a long-run request to finish > > > my app's time-consuming maintenance job. > > > > On the other hand, I confirmed that, with latest trunk, running > > > Windows XP, my maintenance request did last for more than 10 seconds, > > > magically. Does it indicate the DoS-resistant timeout fuse somehow > > > fail? Do you think it is ok or unacceptable? > > > > My maintenance job's log: > > > WARNING:root:job.id=33, elapsed=18.812638 s > > > > Another evidence in web2py/httpserver.log > > > 127.0.0.1, 2010-07-03 21:49:20, GET, /myapp/default/longrun, HTTP/ > > > 1.1, 200, 21.75 > > > > Regard, > > > Iceberg > > > > On Jul3, 8:31pm, mdipierro wrote: > > > > > The web server threads MUST have a timeout (the shorter the better) > > > > else they are vulnerable to denial of service attacks. > > > > > On 3 Lug, 06:23, Iceberg wrote: > > > > > > Hi Candid and everyone, > > > > > > Candid mentioned "rocket should close the connections if request is > &
[web2py] Re: local_import
Thanks for quick action! I also confirm latest trunk has reload feature now. So we have a happy ending, for the Independent Day. :-) On Jul4, 3:36pm, mdipierro wrote: > You are right. I fixed it in trunk and it works for me now. > > Massimo > > On 4 Lug, 01:22, Iceberg wrote: > > > Are you so sure __import__() always reloads? I don't believe so, and > > that is also why there is a built-in reload(). At least __import__() > > does not reload in my following simple test. Jose, would you please > > also try this one? > > > # myapp/modules/foo.py > > def bar(): > > return 'hello world' > > > # myapp/controllers/test.py > > def index(): > > return local_import('foo', reload=True) > > > Visithttp://localhost:8000/myapp/testandyou will see "hello world". > > Fine. Don't restart web2py, now change bar() as return 'something > > else', refresh your browser. So far I still see "hello world" but not > > "something else". Besides, the myapp/modules/foo.pyc is NOT rebuilt > > according to its file create timestamp, thus another evidence that the > > reload did not happen. I am using latest trunk on Windows XP, Python > > 2.5.4 > > > By the way, an equivalent, cleaner and faster refactoring is > > legitimate, as long as it works. I will agree on a __import__() feels > > better than an exec(...), so let's first get things right.
[web2py] Re: Will rocket close connections if it takes long time?
My twisted words just show my twisted mind during my learning rocket- science. :-) I guess I was trying to express, the design goal is (1), the implementation is (2), therefore the long run server side calculation such as (3) is allowed, rather than being terminated early which is a typical misunderstanding. And thanks for clarifying the (4). I love rocket! :-) On Jul5, 12:33pm, Timbo wrote: > 1) True > 2) Basically true. You seem to indicate that 1 & 2 should not co- > exist or are somehow at odds with each other. If that's what you're > indicating, I'm not following your logic as to why they should be > mutually exclusive. Can you explain a little more? > 3) In Rocket's case, no. While a client could disconnect at anytime, > Rocket will allow the application server to run a request as long as > it likes. If the client connection is still open when it's ready to > send it's response, it will send successfully. Rocket does not kill > threads that run for "too long". > 4) Rocket always applies the socket timeout (rocket.py line 854), this > should override Py2.5's default (whatever it may be). Rocket enables > Python's socket timeout protection on every Python platform that > supports it. > > Does this clear things up? > > On Jul 4, 4:30 am, Iceberg wrote: > > > > > Thanks for all these info, Tim. You said: > > "The timeout ... is a timeout based on inactivity between http > > requests. So the long requests that Iceberg is seeing are perfectly > > normal and acceptable." > > > According to my reading of the rocket-science code (and I could be > > wrong), here is my understanding and questions: > > > 1. The timeout is a timeout based on inactivity since one request > > socket's latest select-and-readable event. The time gap could be > > caused by two http requests which somehow reuse the socket (because > > keep-alive?), or caused by one very slow http request from a client > > (possibly a DoS attack). > > > 2. BUT the timeout check is only performed after the request's > > socket encountered socket.timeout exception. According to line 800 of > > rocket.py: > > if typ == SocketTimeout: > > self.err_log.debug('Socket timed out') > > self.wait_queue.put(self.conn) > > And then the request's control is transferred to the Monitor, the > > timeout check is at line 449 of rocket.py: > > if now - c.start_time >= self.timeout: > > stale.add(c) > > > 3. What if, a normal request is read from client side within > > seconds, then being calculated for quite some time on the server side, > > will this situation trigger the timeout protection? I guess not, > > because no socket.timeout will be raised during the calculation, > > although the final calculated result will probably not be sent due to > > the socket is already timeout or even closed from the client side. If > > this is true (is it?), then my maintenance scenario is still doable > > because no result is expected, I only need the maintenance job can be > > triggered and can run as long as it takes. > > > 4. On the other hand, at least on Windows XP, python 2.5.4, by > > default, socket has no socket.timeout, so the above check is not > > performed at all, is it? So the rocket timeout protection is not > > activated anyway. > > > -- > > Iceberg > > > On Jul4, 9:26am, Timbo wrote: > > > > Rocket has a longer default wait time before it closes connections in > > > comparison to CherryPy. You might check web2py code, it is not likely > > > using the same default timeout as Rocket proper. > > > See:http://packages.python.org/rocket/usage.html#timeout > > > > This is a DoS vulnerability on CherryPy but not Rocket because Rocket > > > pushes waiting threads to a monitor queue so that they don't occupy > > > worker threads. The monitor queue can easily handle the socket limit > > > of connections. In this manner, Rocket can handle many thousands of > > > connections without causing new connections to have to wait as > > > CherryPy does. There is a limit on number of active connections, but > > > that limit is the number of worker threads which is > > > configurable:http://packages.python.org/rocket/usage.html#max-threads > > > > The timeout mentioned in the link above is a timeout based on > > > inactivity between http requests. So the long requests that Iceberg > > > is seeing are perfectly normal and acceptable. > >
[web2py] Re: built in web2py datepicker bug with Google Chrome
Hi everyone, Tips: the patch is accepted in trunk. But, "hg pull; hg update" is not enough to make it work. You need to tell web2py to reload the new scaffold app by manually touch a file /home/you/web2py/NEWINSTALL and then restart your web2py. On Jul1, 8:01pm, Iceberg wrote: > > > I met this issue recently. And thank you so much for the nudge about > > > suspecting Chrome. That gave me the direction, then I found comment > > > 232 of this thread: > > > http://www.dynarch.com/projects/calendar/old/ > > > > I think Massimo need to include that patch into web2py's welcome app. > > > > Regards, > > > Iceberg
Re: [web2py] Re: Will rocket close connections if it takes long time?
I have different opinion, Candid. As Timbo and I have discussed in this thread, rocket differentiates "long running requests", seeing it is caused by client side or server side. Rocket only terminates long request comes from the client side, say, a very slow http request from a client (possibly a DoS attack). On the contrary, on the server side, it is the app (a.k.a. its developer) 's responsibility to ensure most requests can be served quickly, and it is also developer's right to occasionally do long time calculation whenever needed. Rocket gives developer the flexibility to choose what they want. That is better than killing a (long) running thread unconditionally. I love rocket. :-) Best regards, Iceberg, 2010-Jul-07, 21:47(PM), Wed --- Original Message --- From:Candid Sender: web2py@googlegroups.com To: web2py-users Date:Wed, 7 Jul 2010 05:21:16 -0700 (PDT) Subject: [web2py] Re: Will rocket close connections if it takes long time? --- > Thank you for clarification, Timbo. > > Is not #3 a problem though? If Rocket doesn't terminate the request if > it's running for too long, is not Rocket's thread pool going to be > exhausted if it runs too many long running requests? The problem here > is that one application could potentially exhaust all working thread, > preventing rocket from serving request for other applications. It > looks like this is what's happening to one of my server - see this > discussion: > http://groups.google.com/group/web2py/browse_thread/thread/34f5411692dcbd35 > > Am I missing something or is this how it's supposed to be? > > On Jul 5, 12:33�am, Timbo wrote: > > 1) True > > 2) Basically true. �You seem to indicate that 1 & 2 should not co- > > exist or are somehow at odds with each other. �If that's what you're > > indicating, I'm not following your logic as to why they should be > > mutually exclusive. �Can you explain a little more? > > 3) In Rocket's case, no. �While a client could disconnect at anytime, > > Rocket will allow the application server to run a request as long as > > it likes. �If the client connection is still open when it's ready to > > send it's response, it will send successfully. �Rocket does not kill > > threads that run for "too long". > > 4) Rocket always applies the socket timeout (rocket.py line 854), this > > should override Py2.5's default (whatever it may be). �Rocket enables > > Python's socket timeout protection on every Python platform that > > supports it. > > > > Does this clear things up? > > > > On Jul 4, 4:30�am, Iceberg wrote: > > > > > > > > > Thanks for all these info, Tim. You said: > > > � � "The timeout ... is a timeout based on inactivity between http > > > requests. �So the long requests that Iceberg is seeing are perfectly > > > normal and acceptable." > > > > > According to my reading of the rocket-science code (and I could be > > > wrong), here is my understanding and questions: > > > > > � � 1. The timeout is a timeout based on inactivity since one request > > > socket's latest select-and-readable event. The time gap could be > > > caused by two http requests which somehow reuse the socket (because > > > keep-alive?), or caused by one very slow http request from a client > > > (possibly a DoS attack). > > > > > � � 2. BUT the timeout check is only performed after the request's > > > socket encountered socket.timeout exception. According to line 800 of > > > rocket.py: > > > � � � � if typ == SocketTimeout: > > > � � � � � � self.err_log.debug('Socket timed out') > > > � � � � � � self.wait_queue.put(self.conn) > > > And then the request's control is transferred to the Monitor, the > > > timeout check is at line 449 of rocket.py: > > > � � � � if now - c.start_time >= self.timeout: > > > � � � � � � � � � � � � stale.add(c) > > > > > � � 3. What if, a normal request is read from client side within > > > seconds, then being calculated for quite some time on the server side, > > > will this situation trigger the timeout protection? I guess not, > > > because no socket.timeout will be raised during the calculation, > > > although the final calculated result will probably not be sent due to > > > the socket is already timeout or even closed from the client side. If > > > this is true (is it?), then my maintenance scenario is still doable > >
Re: [web2py] Re: web2py performance issue or rather my fault?
Me too experience similar issue as Rahul did. Issue: > > [sometimes, once every few hits, it loads signifacantly slower > > weirdest thing is when you re-click the link it loads instantly, when > > you left it working to load on itself, it is slow.. like 4 to > > 8seconds ] ... or even dozens of seconds. :-/ My findings, well, not really: - Both my develop machine (windows xp home edition with latest ServicePack), and my production machine (a Linux), have such issue occasionally. Both environments uses web2py's built-in server, rocket or cherrypy. Both serve no more than 10 people or so. - I could not find a pattern to reproduce the problem. On my development laptop, I just got an impression that it is more likely to happen for the first request after the web2py has been idle for long time due to no workload. So perhaps it is because the OS had swapped out all memory owned by web2py, therefore web2py need to "warm up" again. This is not web2py's fault, I think. On my Linux production server, similar "pattern" exists (but I am not sure, did not dig into httpserver.log to confirm that). Besides, the out-of-response is also likely to happen when user visit my app's statistics page with 10+ charts showed by flash. Perhaps the sudden burst of 10+ concurrent requests race each other? @Massimo: You can check your production server's httpserver.log to see what is the longest (slowest) response time. If it is small enough, that is good, otherwise ... oh by the way, do you use web2py's built-in server (now rocket), or do you use apache-like frontend? That could make difference. Best regards, Iceberg, 2010-Jul-08, 20:50(PM), Thu --- Original Message --- From:mdipierro Sender: web2py@googlegroups.com To: web2py-users Date:Thu, 8 Jul 2010 02:23:56 -0700 (PDT) Subject: [web2py] Re: web2py performance issue or rather my fault? --- > Whatever the problem is it must be resolved. The strange thing is I do > not experience this on my production system (~5 hits/day and > distinct 1600 visitors/day). > > What could it be? > - cron when it runs spikes CPU usage. DO NOT USE. In production run > web2py cron in a separate process, not the one that runs the web > server. > - web2py session lock (the the same user can only access one page at > the time unless the lock is released via session._unlock()) > - sqlite lock (depending on the query and the complexity of > transaction this may take long) > - db connection pooling locks (when look up for open connection) > - cache locks (it is a global lock, to ensure data integrity) > - cache.ram can cause memory leaks if the key depends on variables > - problem with web server (Rocket or the apache or mod_wsgi, etc.) > > > > > On 8 Lug, 02:48, Rahul wrote: > > Hi All, > > � � � � I have experienced a similar issue with web2py. Issue: > > [sometimes, once every few hits, it loads signifacantly slower > > weirdest thing is when you re-click the link it loads instantly, when > > you left it working to load on itself, it is slow.. like 4 to > > 8seconds ] Earlier I reported this kind of �issue in a separate > > thread. > > > > Some findings > > Office Env: > > My web2py powered site will be up in production soon and I am awaiting > > for getting in-house feedback. I am testing this on my local system > > with the below config > > OS: Win xp professional version 2002 with sp2 (old but works fine) > > Machine: Intel P4, 2.8 GHz and 1 GB ram. > > Web2py version latest (Version 1.79.2 (2010-06-08 22:45:26) ) > > I encounter the above said issue every time the system is left idle > > for some minutes (Ex: If I start the web2py server and I am using my > > web2py application continuously, it works well but if left idle for > > some 5 mins or so, it becomes slow as mentioned above) > > > > At home tough: > > Home Env: > > OS: Win xp professional version 2002 with sp2 > > Machine: Core2 Duo with 2 GB Ram > > Web2py version 1.76.5 (prior to server change) > > I deploy the same app and my site in the applications directory and I > > never get such delays... > > > > Conclusions: > > 1- May be its my system setup that could be the culprit > > 2- May be some thing is wrong with web2py or my code. > > > > One more thing I noticed was (when using executesql the query or page > > hit was a tad slower than when using the sql syntax provided by DAL) > > so I changed all executesql statements to equivalent DAL statements > > and these seemed to perform a bit faster. > > > > Finally, I'll check the existi
[web2py] Re: storing hierarchical data in web2py database
Just a quick thought. 1. Each plugin's owner can store the source code in code.google.com 2. Too bad that code.google.com can not provide a live show about the plugin's look-and-feel, so we can setup a plugins' "sandbox" on web2py.com, nightly checkout plugins' source code, then user can visit a link, say http://web2py.com/plugins_stage, to see all plugins live. On Jul15, 4:04pm, mdipierro wrote: > We really need a better way to post plugins and keep track of features/ > versions than web2py.com/plugins. > > On 14 Lug, 18:03, Thadeus Burgess wrote: > > > > > I have this code implemented in plugin_category.py let me just find it > > =/ > > > Ah yes, here it is > > >http://code.google.com/p/blogitizor/source/browse/src/modules/plugin_... > > > You can see example usage in blogitizor. > > > -- > > Thadeus
[web2py] Re: Best way for a config file
On Jul13, 3:06pm, Narendran wrote: > Hi, > I have been trying to work without a config file, but it is a little > difficult to work across multiple (dev, test and prod) envs. I'd like > to know the solution if this has been already discussed: > 1. The db configuration in db.py changes in dev, test and prod env. > 2. App name changes in different env. > 3. Other global variables that can change in different envs. > > -- > Thanks > Narendran Your app can change to whatever name, as long as it does not hardcode its name inside the source code. Tips: a. Use local_import() for easier import local module without mentioning self app name. b. If you use cron, try to avoid defining your job script in absolute path format. c. Use URL(r=request, c='static', f='...') to reference your app's static resource. d. Use request.application to dynamically find your other resource Other global variables can be handled by either Massimo's models/0.py, or Mathieu's db approach. If you use the former, and a version control system to sync your source code among different environments, make sure you don't commit one env's models/0.py into repository and then pollute others.
[web2py] Re: Menu Refresh
One more comment. If your app is simple enough (most are), to use just one controller, it does not have much difference between define your menu in models/menu.py or at the beginning of controllers/default.py, and the latter gives you most flexibility to control what your menu shows up. On Jul12, 9:57pm, mdipierro wrote: > Hello Casey, > > the problem is models files (including menu.py) are executed > alphabetically before the controller.py. It is possible that your menu > is built before the session variables are updated. This is likely the > case if the session is modified in the controller. > > If only a few functions make changes to the session that should affect > the menu, I suggest rebuild the menu in those controller functions. If > this is a gereral issue, please post an example of how you build the > menu and I'll post an example of how you get it executed after every > controller (as opposed to before). > > Massimo > > On Jul 12, 8:51 am, Casey Schroeder wrote: > > > > > Hi to all, > > > I had a question: > > > I noticed that when i tried to make my response.menu dynamic, based on > > the values in the session, there was a lag in the update: i.e. I would > > set the session values in the controller for the current page, but the > > menu appears to already be rendered based on the values set on the > > previous page (controller) - even though the current values show on > > the session dump on the current page. To get around this, I just set > > my response.menu directly in the controller, so nbd. I'm just > > wondering if it is always the case for the model files and whether > > there is something else i should look out for because of this. > > > Thanks, > > > Casey
[web2py] Re: csv: a showstopper for me. Is there another way?
On Jul13, 6:51am, mdipierro wrote: > errata > > db.define_table('animal',Field('name')) > > def index(): > > form=SQLFORM.factory(Field('name',default=request.vars.name,requires=IS_NOT > _EMPTY())) > if form.accepts(request.vars): > redirect(URL(r=request,f='animals',vars=request.vars)) > return dict(form=form) > > def animals(): > query=db.animal.name.like('%'+request.vars.name+'%') > rows = db(query).select() > if request.extension=='csv': return str(rows) # as csv > link > =A('download',_href=URL(r=request,f='animals.html',vars=request.vars)) > return dict(table=SQLTABLE(rows),link=link) > > Hope I got it right this time... Seeing your code like this: > if request.extension=='csv': return str(rows) # as csv makes me feel perhaps we can have a views/generic.csv which at least contain: response.headers['Content-Type']='text/csv' as well as the Content-Disposition, according to [1] [1] http://stackoverflow.com/questions/393647/response-content-type-as-csv
[web2py] Re: Rocket cache response
On Jul 20, 1:11am, Jonathan Lundell wrote: > On Jul 19, 2010, at 10:05 AM, Timbo wrote: > > > It's defaulting to text/html since it's not actually sending a file. > > This is a section of the HTTP spec that I missed. > >http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlsays that no > > entity headers (Content-* should be sent in a 304 instance) > > > I think I can have a patch by this evening. > > > However, I've never seen this behavior before so I'll need for someone > > to be able to test this to see if this is actually the cause of the > > problem. Have we confirmed that the delay behavior happens in > > different browsers? I only see chrome above. > > I'm doubtful that the content-type is related to the delay; it seems more > like a cosmetic issue. Still, since Chrome complains about it > Tim, I think Chrome is more sensitive than others to complain incorrect content-types. It is easy to see it in a Chrome (mine is 5.0.379.99 on WinXP). Just start your local web2py server, then visit http://127.0.0.1:8000/welcome and right-click at the background and choose the last item to pop-up a "Developer Tools" window, then refresh the welcome page, now you can see those Warnings such as "Resource interpreted as image but transferred with MIME type text/html." It should not be harmful to satisfy chrome by Tim's coming patch. Even it might not be relevant to the delay behavior. With respect to the delay behavior, I think it is cross browser, albeit I don't have direct evidence. Most of my app's end users use IE6/7/8, sometimes they complain some page take long time to load, but usually a manually refresh (retry) can bypass the problem. :-/ Regards, Iceberg
Re: [web2py] Re: web2py performance issue or rather my fault?
Hi Massimo, do you hint that all these measure are needed to minimize (if not get rid of) the occasional slow response? 1) set migrate=False in the web2py code 2) ... (N/A) 3) disable session feature as long as your app does not need it. (But how to? Is session.forget() enough?) 4) bytecode compile the app to avoid execfile() call I have to admit that my apps do not follow any of above suggestion because I thought they were not a must. Tell me if I was wrong. On the other hand, Kuba, who started this thread, later said "I moved to apache/WSGI from Rocket. For me the problem disappears." So I guess there is a standalone rule #5: Use apache/WSGI etc. instead of the built-in Rocket ? Best regards, Iceberg, 2010-Jul-21, 18:01(PM), Wed --- Original Message --- From:mdipierro Sender: web2py@googlegroups.com To: web2py-users Date:Wed, 21 Jul 2010 01:55:27 -0700 (PDT) Subject: [web2py] Re: web2py performance issue or rather my fault? --- > One more thing because of design flask with generate and reuse pyc > file. In the case of web2py python code is executed. You have to > explicitly "bytecode compile" via admin. I am not sure if you have > done that. > > Massimo > > On Jul 21, 3:36�am, mdipierro wrote: > > Hi Thadeus, > > > > I looked at the code you used for comparing web2py and Flask. > > > > � � �This is NOT A FAIR COMPARISON > > > > Here is why: > > > > 1) you did not set migrate=False in web2py. This means at every > > request you lock the entire database table metadata to check whether > > the table has migrated. You do this while you have an open transaction > > with the postgresql database. For such short code, this essentially > > serializes all your requests. You should run it once with migrate=True > > and then run the tests with migrate=False. > > > > 2) in the case of Flask you use raw SQL for the queries. In the case > > of web2py you use DAL syntax. On such a short program I cannot say > > what the DAL overhead may be but certainly you have it in one case and > > not the other. > > > > 3) The web2py program has sessions enables (has to parse cookies, > > create and parse session files, store the session, files, generate new > > cookies and lock session files - at every request). You did not even > > set session.forget() which means a new session file is saved at every > > http request. The Flask program is doing nothing of this. > > > > Of course the Flask program under this conditions performs better. > > > > A more fair test would be: > > 1) set migrate=False in the web2py code > > 2) use SQLAchemy syntax for database queries in the flask code > > 3) enable serverside session in Flask code > > > > Massimo > > > > On Jul 18, 12:20�pm, Thadeus Burgess wrote: > > > > > Massimo, web2py.com is not a valid application to be testing this on. Most > > > of what web2py.com does is just render a template and display it, it > > > hardly > > > does any kind of strenuous dbio. > > > > > As you know I have a few separate servers running different > > > configurations. > > > > > I mainly decided to do this testing as to the problems I have had with my > > > application at work (which runs apache + mod_wsgi). I wondered if my blog > > > had the same issue (which when I ran ab tests on it and spiked its usage, > > > it > > > did). Interesting thing is my blog ran on cherokee + uwsgi. I doubt it is > > > a > > > configuration issue since I still have the same problem on two completely > > > different apps running completely different setups all different except > > > web2py. They both use postgres as well. > > > > > I am attaching the two apps that I tested, as well as a text file that > > > contains the raw ab tests that I collected to run > > > > > -- > > > Thadeus
[web2py] Re: SQLite Logging
Just a quick thought. Since web2py itself already handles SQLite db well under multi-thread situation, so a quick tweak to your sqlitehandler.py may be putting the web2py db instance, rather than a filename, to initialize your SQLiteHandler() class. Best regards, Iceberg, 2010-Jul-22, 10:28(AM), Thu --- Original Message --- From:Yarin To: web2py-users Cc: johann.scheibelho...@easytouch-edv.com, mdipie...@cs.depaul.edu, iceb...@21cn.com Date:Wed, 21 Jul 2010 19:15:55 -0700 (PDT) Subject: SQLite Logging --- > I'd like to elicit some help in putting together a SQLite-based > logging solution for web2py. > > Logging to a file was covered earlier in this forum (See "Global > logging to file"): > http://groups.google.com/group/web2py/browse_thread/thread/e20d0bd2e542aa14/e248314770225225 > log.py: > https://sites.google.com/site/ykessler/main/log.py > > I've written a SQLite logging handler: > https://sites.google.com/site/ykessler/main/sqlitehandler.py > > However, although the SQLite handler works great in normal Python > environments, it errors out with the global logging solution because > the logger emits on multiple threads, and SQLite objects are > restricted to the thread they're created on. > > Any ideas on how to sync these two solutions?
[web2py] Re: Cache query results on the server side
In case you forget this: localhost:8000/yourapp/appadmin/ccache this page gives an overall stat about your cache On Jul 23, 6:23pm, mdipierro wrote: > correction > > cache.ram.storage['web2py_cache_statistics']['total_hits'] > > counts total calls to cache function while > > cache.ram.storage['web2py_cache_statistics']['misses'] > > counts misses, i.e. result not found in cache and recomputed. > I guess you want to monitor the latter. > > Massimo > > On Jul 23, 5:21 am, mdipierro wrote: > > > > > cache.ram.storage['web2py_cache_statistics']['total_hits'] is a > > counter and you can read its status before and after. > > Mind it will be affected by other concurrent ptocesses. > > > On Jul 23, 5:09 am, Adi wrote: > > > > Seems to work. One last question - how can I check if a particular > > > call hit the db or not? > > > > On Jul 23, 3:03 pm, Adi wrote: > > > > > Great. That's what I was looking for - in memory filtering. Will try > > > > and let you know! > > > > > On Jul 23, 3:02 pm, mdipierro wrote: > > > > > > No because they two queries are different. The second query will not > > > > > find the cached results from the first and pull them again. > > > > > > You can do > > > > > > def index(): > > > > > videos = db( myquery ).select(cache=(cache.ram,0)) # myquery is > > > > > across multiple tables, with joins. > > > > > > def favorites(): > > > > > fav_videos =db( myquery ).select(cache=(cache.ram, > > > > > 3600)).find(lambda row: row.video.folder=='favorites') > > > > > > The find command will give you a subset of an existing Rows object (in > > > > > this case the cached one) > > > > > > On Jul 23, 4:52 am, Adi wrote: > > > > > > > Ok I'm going to bug you a little more till I understand this well > > > > > > enough :) > > > > > > > there are two functions in controller: > > > > > > def index(): > > > > > > # here I will hit database because user first comes here > > > > > > videos = db( myquery ).select(cache=(cache.ram,0)) # myquery is > > > > > > across multiple tables, with joins. > > > > > > > def favorites(): > > > > > > # here I want to get a subset of "videos" > > > > > > fav_videos = db( myquery & db.videos.folder == > > > > > > 'favorites').select(cache=(cache.ram, 3600)) > > > > > > # this query should not hit database because of the earlier query > > > > > > in index() > > > > > > > Is this the correct behavior? > > > > > > > On Jul 23, 2:45 pm, mdipierro wrote: > > > > > > > > You place > > > > > > > > videos=db(db.video.id>0).select(cache=(cache.ram,0)) > > > > > > > > where you want the videos to be extracted from db. > > > > > > > > videos=db(db.video.id>0).select(cache=(cache.ram,3600)) > > > > > > > > everywhere you need to get the list of videos. > > > > > > > > On Jul 23, 4:38 am, Adi wrote: > > > > > > > > > But where will I place this query, for "videos" to be accessible > > > > > > > > everywhere else? > > > > > > > > > On Jul 23, 2:29 pm, mdipierro wrote: > > > > > > > > > > videos=db(db.video.id>0).select(cache=(cache.ram,3600)) > > > > > > > > > > 3600 are seconds and it is the cache time. If you replace the > > > > > > > > > value > > > > > > > > > with 0, it will be re-computed. > > > > > > > > > > On Jul 23, 4:13 am, Adi wrote: > > > > > > > > > > > Hi all, > > > > > > > > > > > I have this use-case: > > > > > > > > > > > There is a set of rows being queried from the database. > > > > > > > > > > > videos=db(db.video.id>0).select() > > > > > > > > > > > Now I have three different views (in same controller) where > > > > > > > > > > I want to > > > > > > > > > > access these rows (with additional filters), but I want to > > > > > > > > > > prevent > > > > > > > > > > multiple db calls. > > > > > > > > > > > def index(): > > > > > > > > > > # use videos here with an additional filter > > > > > > > > > > home_videos = [v for v in videos if v.folder == 'home'] > > > > > > > > > > > def favorites(): > > > > > > > > > > fav_videos = [v for v in videos if v.folder == > > > > > > > > > > 'favorites'] > > > > > > > > > > > These views essentially fetch subset of the same dataset > > > > > > > > > > and display > > > > > > > > > > them. > > > > > > > > > > > Question: > > > > > > > > > > - > > > > > > > > > > Is there a way to "cache" the first db call "videos = ... " > > > > > > > > > > and be > > > > > > > > > > able to access "videos" variable without hitting database > > > > > > > > > > again, as > > > > > > > > > > long as this session exists? > > > > > > > > > > > I am not sure if and how I can use global variables here, > > > > > > > > > > and will > > > > > > > > > > they reliably persist.