[web2py] Re: Setting a header
On Thursday, November 2, 2017 at 12:19:14 AM UTC-4, Dave S wrote: > > > > On Wednesday, November 1, 2017 at 7:15:11 PM UTC-7, Anthony wrote: >> >> It's response.headers. >> > > Indeed, but that isn't a sufficient correction. > > /dps > > >> >> Anthony >> >> On Wednesday, November 1, 2017 at 1:18:07 AM UTC-4, Dave S wrote: >>> >>> I wanted to set the refresh on a page according to how often an event is >>> occurring, and so I tried adding this to my controller function: >>> >>> response.header["meta"]='http-equiv="refresh" content="30"' >>> >>> However, it doesn't seem to show up. I'm also not seeing the >>> 'X-Powered-By' header that is set coming into my function, according to a >>> print response.headers >>> >>> If I put that print statement in my view, the result is None. >>> >> Note that putting a print statement in a view will have no effect. Anyway, http-equiv goes inside a tag in the section of the HTML page -- it does not get sent as an HTTP response header as you are doing. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Data Representation SQLFORM.factory /linked tables
> > db.define_table('drench', > Field('status', requires=IS_IN_SET(STATUSES), > default=STATUSES[0]), > Field('assigned_to', db.auth_user), #, default=auth.user_id > Field('start_date', 'date',default=request.now), > Field('completed_date', 'date',default=request.now), > Field('mob',db.stock), > Field('count'), > Field('estimated_weight','integer', default=0), > > Field('product',requires=IS_IN_DB(db,db.product.product_name, > '%(product_name)s %(batch_no)s')), > You have defined the "product" field as a string field, not a reference field. The default representation of a string field in a grid or read-only form is simply the string itself. If you want a different representation, you must specify the "represent" attribute of the field. The IS_IN_DB validator is used to generate a select widget in forms, so the "label" argument you specified in that validator controls that values shown in the select widget, but that has no effect on the representation in grids and read-only forms. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Setting a header
It's response.headers. Anthony On Wednesday, November 1, 2017 at 1:18:07 AM UTC-4, Dave S wrote: > > I wanted to set the refresh on a page according to how often an event is > occurring, and so I tried adding this to my controller function: > > response.header["meta"]='http-equiv="refresh" content="30"' > > However, it doesn't seem to show up. I'm also not seeing the > 'X-Powered-By' header that is set coming into my function, according to a > print response.headers > > If I put that print statement in my view, the result is None. > > I'm using Firefox's "inspect element" and also "view source". Lots of > other headers, but not these two. What should I be doing to get my > refresh header in? > > I've tried this with both 2.14.6 and 2.15.4. > > Thanks > > /dps > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: crud.read labels
Not via any settings, but you can always set the label attributes of the DAL fields: Field(..., label='mylabel') or after table definition: db.mytable.myfield.label = 'mylabel' Also, note that Crud is no longer recommended -- in most cases, you should be able to get similar results with some combination of SQLFORM .process() and .grid(). Anthony On Wednesday, November 1, 2017 at 3:40:15 PM UTC-4, Andrea Fae' wrote: > > Is it possibile to manage crud.read field labels? > Thanks > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
> > Btw, on the web2py.com website I see a similar problem. When you first go > to the web2py site you land on this URL: http://web2py.com/ then after > you visit an other page and then go back to the index page, the URL changes > to this:http://web2py.com/init/default/index > It's possible that there is no routes.py set up for the web2py.com site. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
> > In any case, can you advise me on how to fix this problem? My directory > structure is clearly wrong: > /home/username/web2py/applications/my_app_directory/applications/init > > Can you please post how the correct structure should look like on > pythonanywhere? > It should just be the usual folder structure: /web2py/applications/init Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Data Representation SQLFORM.factory /linked tables
Hi All, I have been pulling my hair out with this. Wen I view the drenches grid I shows the assigned to = the full name of the auth user which is correct , but when I add a product it only displays the name of the product and does not include the batch no which I require. I am lost as to why. Thanks Anthony I have the following tables: db.define_table('product', Field('product_name'), Field('active_ingredient'), Field('batch_no'), Field('expiry_date','date',default = request.now), Field('product_type', requires=IS_IN_SET(PRODUCTTYPES),default= PRODUCTTYPES[0]), Field('product_usage', requires=IS_IN_SET(PRODUCTSUBTYPES),default= PRODUCTSUBTYPES[0]), Field('withholding_period','integer',requires=[IS_NOT_EMPTY()]), Field('ESI_withholding','integer',requires=[IS_NOT_EMPTY()]), Field('qty','integer'), Field('date_purchased','date', default = request.now), Field('purchased_from', requires=IS_IN_DB(db,'person.company','%(company)s')), auth.signature, format='%(product_name)s %(batch_no)s') db.define_table('drench', Field('status', requires=IS_IN_SET(STATUSES), default=STATUSES[0]), Field('assigned_to', db.auth_user), #, default=auth.user_id Field('start_date', 'date',default=request.now), Field('completed_date', 'date',default=request.now), Field('mob',db.stock), Field('count'), Field('estimated_weight','integer', default=0), Field('product',requires=IS_IN_DB(db,db.product.product_name, '%(product_name)s %(batch_no)s')), Field('dose_rate'), Field('withhold_until_date', 'date'), Field('ESI_withhold_until_date', 'date'), Field('paddock', requires=IS_IN_DB(db,db.paddock.paddock_name,'%(paddock_name)s')), auth.signature) In my controller I am using the following: def manage_stock_tasks(): grid = SQLFORM.smartgrid(db.stock,linked_tables=['drench','vaccinate','joining', 'marking','feeding','footbath'], user_signature=False) return dict(grid=grid) def drench(): form= SQLFORM.factory( Field('status', requires=IS_IN_SET(STATUSES), default=STATUSES[0]), Field('assigned_to', requires=IS_IN_DB(db.auth_user.id,'%(first_name)s %(last_name)s')), Field('start_date', 'date',default=request.now), Field('completed_date', 'date',default=request.now), Field('mob',requires=IS_IN_DB(db,db.stock.id,'%(mob_name)s')), Field('count'), Field('estimated_weight','integer', default=0), Field('product', requires=IS_IN_DB(db.product.id,'%(product_name)s %(batch_no)s')), Field('dose_rate','integer'), Field('withhold_until_date', 'date'), Field('ESI_withhold_until_date', 'date'), #default=withheld), # need to use the completed date and product withhold peroid Field('paddock', requires=IS_IN_DB(db,db.paddock.id,'%(paddock_name)s'))) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get the last few records except the last record
> > Perhaps the issue is not knowing how many records there are. Solvable by >>> doing a count(), but then you're making two queries (to get the count, and >>> then to get the records). >>> >> >> If limitby(0, 10) followed by slicing off the last record via [:-1] gets >> you the records you want, then so does limitby(0, 9) with no slicing, >> regardless of the overall record count. >> >> Anthony >> > > What you say is true, but I took limitby(0,10) to be a specific example, > and that the general case was the real question, where you don't know how > many records are involved. > I don't see a "general case" related to this particular issue that would require knowing the total record count (unless the general case is that the database does not support *descending *orderby). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: How to get the last few records except the last record
I'm not quite sure what you were going for with the original query, as it is not even valid Python syntax let alone valid DAL code, but if you want the 2nd through 9th most recent records, you could do: db(db.post.author == auth.user_id).select(orderby=~db.post.modified_on, limitby=(1, 10)) The ~db.post.modified_on value for orderby sorts the records in descending ordering according to the modified time (assuming you have such a field in the table). The limitby value of (1, 10) then limits the results to the 2nd through 10th records in the sorted list. If there is no field that stores the update time (or creation time) for each record, you could use orderby=~db.post.id, which generally should sort based on creation time (assuming the IDs in your database are ascending). Anthony On Monday, October 30, 2017 at 2:24:44 PM UTC-4, Maurice Waka wrote: > > I had about 10 records. The more records I put in the more it did not > work, i.e pick the last 10. I get the whole db records. I think the > select().count() comes in handy here. Only how to work it out... > > On 30 Oct 2017 9:03 PM, "Dave S" wrote: > > > > On Saturday, October 28, 2017 at 12:10:19 PM UTC-7, Anthony wrote: >> >> On Friday, October 27, 2017 at 7:37:40 PM UTC-4, Dave S wrote: >>> >>> >>> >>> On Thursday, October 26, 2017 at 7:26:48 AM UTC-7, Anthony wrote: >>>> >>>> There's no need to select the extra record and then drop it via Python. >>>> Instead you can just change the range of the limitby tuple to get exactly >>>> the records you want. >>>> >>>> >>> Perhaps the issue is not knowing how many records there are. Solvable >>> by doing a count(), but then you're making two queries (to get the count, >>> and then to get the records). >>> >> >> If limitby(0, 10) followed by slicing off the last record via [:-1] gets >> you the records you want, then so does limitby(0, 9) with no slicing, >> regardless of the overall record count. >> >> Anthony >> > > What you say is true, but I took limitby(0,10) to be a specific example, > and that the general case was the real question, where you don't know how > many records are involved. On the other hand, I am familiar with the idea > of just getting a snapshot of the most recent records; I do that in one of > my projects, and a fixed limitby() works beautifully, given the proper > orderby(). > > /dps > > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/jOt3JLi8vJw/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Update last web2py
On Monday, October 30, 2017 at 4:15:04 AM UTC-4, Anatoli Hristov wrote: > > Hi Anthony, > > I have tried both, the stable and to clone the git. > > As I have my own routes, I had to put it in the root folder of web2py, and > then the problem persist. > The traceback you showed suggests a routes.py in the application folder. What is the traceback when using only a root routes.py? > > Do you know if this can be fixed? > Not sure what the problem is. Feel free to open an issue on Github. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Update last web2py
By default, the application folder includes a routes.example.py file. Presumably, you have renamed that file to routes.py (otherwise, web2py would not read the file). The error is coming from that file, not from the routes.py file in the root /web2py folder (though if you remove the root routes.py file, you will also prevent the routes.py file in the application's folder from being read). Do you observe the problem in the latest stable release of web2py, or only in a clone of the latest master from Github? I can only reproduce with the latest from master (not sure what the problem is). Anthony On Sunday, October 29, 2017 at 12:48:48 PM UTC-4, Anatoli Hristov wrote: > > Hi, > > I updated to last web2py just now, and now I cannot start my apps. > > root@id1:/home/tol/web2py# python web2py.py -S mypcu -M > Traceback (most recent call last): > File "web2py.py", line 21, in > import gluon.widget > File "/home/tol/web2py/gluon/widget.py", line 26, in > from gluon import main, newcron > File "/home/tol/web2py/gluon/main.py", line 121, in > load_routes() > File "/home/tol/web2py/gluon/rewrite.py", line 379, in load > load(routes, appname) > File "/home/tol/web2py/gluon/rewrite.py", line 319, in load > exec(data, symbols) > File "", line 23, in > ImportError: cannot import name abspath > > I had to delete the routes.py from the web2py in order to start. What > could be wrong? > > Thank you > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: name 'average' is not defined
On Sunday, October 29, 2017 at 2:24:47 AM UTC-4, mostwanted wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *I AM TRYING TO CALCULATE THE AVARAGE IN AMY VIEW, I ADDED A VARIABLE > CALLED average TO HOLD THE RESULTS OF THE AVAERAGE CALCULATIONS BUT I KEEP > GETTING THIS ERROR: name 'average' is not > definedI DONT UNDERSTAND WHAT I'M DOING WRONG!!!HERE IS MY CODE:{{extend > 'layout.html'}}..Term > SubjectMark AcquiredTotal Mark > (%) AcquiredGradeTeacher's > Comment{{for report in form: > perc=(float(report.marks)/float(report.total))*float(100)if > perc>=75:grade='A'elif perc>=65:grade='B' > elif perc>=55:grade='C'elif perc>=45: > grade='D'#THE CALCULATION FOR AVARAGE IS DONE HERE average+=perc* > You cannot increment a variable without first initializing it somewhere. Before the for loop starts, you should have something like: average = 0 More generally, I would say this is too much logic in the view. You should probably calculate the grades and average in the controller (or via virtual fields if reports are DAL records). Also, be careful with code like report.subject.subject_name inside a loop -- if that is a recursive select on a DAL record, it will generate an additional database query for every single record. You might be better off with a join to get all the related data in a single query. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get the last few records except the last record
On Friday, October 27, 2017 at 7:37:40 PM UTC-4, Dave S wrote: > > > > On Thursday, October 26, 2017 at 7:26:48 AM UTC-7, Anthony wrote: >> >> There's no need to select the extra record and then drop it via Python. >> Instead you can just change the range of the limitby tuple to get exactly >> the records you want. >> >> > Perhaps the issue is not knowing how many records there are. Solvable by > doing a count(), but then you're making two queries (to get the count, and > then to get the records). > If limitby(0, 10) followed by slicing off the last record via [:-1] gets you the records you want, then so does limitby(0, 9) with no slicing, regardless of the overall record count. Anthony > > /dps > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: to be or not to be... run by scheduler
On Thursday, October 26, 2017 at 3:57:11 AM UTC-4, Manuele wrote: > It seams that the parameter request.is_scheduler is always set to false > on my colleague windows system > > could it be a possible bug? Any other experience? That was a bug but should be fixed in web2py 2.15. If you can't upgrade, as an alternative, see: https://groups.google.com/d/msg/web2py/JeE6jLP-qjI/MXS0MVdOCQAJ Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: _next-Parameter to become an array during login
The Auth login method adds _next as a hidden input in the login form, so _next ends up in both request.get_vars and request.post_vars. Because request.vars combines get_vars and post_vars and each of those includes a "_next" key, request.vars ends up with _next being a list including the values from both get_vars and post_vars (which should be the same). So, if you just want _next from the URL query string, you can use request.get_vars._next. But why do you need that -- the auth.login() action already handles redirecting to the _next URL after successful login? Anthony On Friday, October 27, 2017 at 4:46:14 AM UTC-4, Silvan Marco Fin wrote: > > Hi! > > I found the _next-parameter to become an array during login and I wonder > if this is a feature and if I'm using it "the right way(tm)". > > Situation is as follows: > > def user(): > import logging > logging.warn('default/user _next={}'.format(request.vars._next)) > return dict(form=auth(), next=request.vars._next) > > Browser displays page 'myapp/customer/accounts', the user is not logged in. > There is a login button pointing to > 'myapp/default/user/login?_next=/myapp/customer/accounts'. > The user presses the login-button, gives credentials, everything fine so > far. > > The user method is run twice as I understand, first to generate the form > and then to handle the submission. > > I get the following output: > WARNING:root:default/user _next=/myapp/customer/accounts > WARNING:root:default/user _next=['/myapp/customer/accounts', > '/myapp/customer/accounts'] > > Next thing I do is something like > auth.settings.login_onaccept.append(my_login_hook) > and I expected a single valued parameter _next and I get a multi valued > array. > > Is this intentional? > > Are the values always the same or may the values in the array differ? > Which one is the "right one"? > > Kind regards, > Silvan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get the last few records except the last record
There's no need to select the extra record and then drop it via Python. Instead you can just change the range of the limitby tuple to get exactly the records you want. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: New syntax error?
I cannot reproduce, and I can't think of anything web2py would be doing that would be relevant, as this is a standard Python exception. I was thinking maybe you switched to Python 3, but in that case, I would expect a more specific error message indicating the parentheses are missing (unless you're using an older version of Python 3 and the message is different in that version). Anthony On Monday, October 23, 2017 at 6:38:27 PM UTC-4, Dave S wrote: > > In my 2.15.x testing, I've been concentrating on the https interface, but > I now tried to do a -M -S that would queue up a Scheduler task. And I ran > into an unexpected problem with syntax errors on print statements. > >if when: > print "ri_s: when " + when > > Even when I shorten the line to remove the concatenation, I get a syntax > error: > > Traceback (most recent call last): > File "web2py.py", line 33, in > gluon.widget.start(cron=True) > File "/home/ec2-user/web2py/web2py-2.15.4/web2py/gluon/widget.py", line > 1152, in start > cronjob=options.cronjob) > File "/home/ec2-user/web2py/web2py-2.15.4/web2py/gluon/shell.py", line > 258, in run > execfile(pyfile, _env) > File "applications/updater/controllers/default.py", line 140 > print "ri_s: when " > ^ > SyntaxError: invalid syntax > > I tried changing the variable name to "pwhen" in case this was an > if-statement/keyword issue, but still "invalid syntax". > > As you might guess, default.py loads fine for https requests, and this > code loads fine with -S under 2.14.6, so I'm not sure what's going on here. > > /dps > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] confirm_registration form 'hardcoded' labels
On Monday, October 23, 2017 at 1:24:44 PM UTC-4, tomasz bandura wrote: > > Thanks, > > I will try to open an issue. > > Regarding button - label is translated...strange, I'll check it why :) > Oh yeah, don't worry about that -- submit_button ends up getting wrapped in T() by the SQLFORM code. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] confirm_registration form 'hardcoded' labels
Feel free to open an issue or submit a pull request. Note, looks like the submit button label is hard coded as well. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How can i change background picture of web2py site
Have you tried doing a force refresh in the browser? On Monday, October 23, 2017 at 11:00:15 AM UTC-4, Dan Carroll wrote: > > It is not that easy. I replace the background.jpg with another image and > the old image replaces my new image. Over and over. Very frustrating. > > > On Wednesday, June 22, 2016 at 2:56:21 PM UTC-4, Dave S wrote: >> >> >> >> On Wednesday, June 22, 2016 at 10:23:56 AM UTC-7, Filip Bogdanovski wrote: >>> >>> Title >> >> >> >> You have 2 easy choices for the standard bootstrap-styled apps (like the >> welcome app): replace yourapp/static/images/background.jpg with your >> desired background, or tweak yourapp/static/css/web2py-bootstrap3.css; line >> 107 is the settings for the background. >> >> In the stupid.css apps, like the examples app, I'm not sure a background >> is set, but you could probably add one in layout.html or in an additional >> css file (look at examples.css, although it is set up to display the web2py >> book without a background image). >> >> /dps >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: LOAD() component redirect destroys session
Hard to say without seeing your code. Nothing about a redirect affects the session, so your code must be making the changes. Anthony On Monday, October 23, 2017 at 10:13:44 AM UTC-4, Auden RovelleQuartz wrote: > > if I am on page_one that has a LOAD() component on it that runs say every > 5 seconds (timeout = 5000) > > and if while on that page I have > > session.parameter_one = some value > session.parameter_two = some value > session.parameter_three = some value > > if based on certain conditions the component redirects to page_two, then I > notice that > > session.parameter_one = None > session.parameter_two = None > session.parameter_three = None > > is there some way to redirect to a page from a component where all session > variables are kept intact? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: migrating database and updating it
It's not quite clear exactly what you have copied and/or changed, so hard to say what you need to do. But in general, if you want to update your code and have the production database migrated to match the new code, you should copy everything *except* the contents of the /databases directory (leave the production /databases directory untouched). Then after the code has been copied, make sure migrations are enabled, and on the first request, the production database will be migrated to match the new models. Sounds like you didn't follow that process and things have gotten out of sync. Anthony On Monday, October 23, 2017 at 6:54:22 AM UTC-4, Yebach wrote: > > Hello > > So as said I copied the whole app directory to my new server, also > restored my database on postgres. > First my settings for migrate and false_migrate are set to False and > immediately I get an error: relation of table auth_user already exists. I > set the migrate for this table (auth.define_tables(username=False, > signature=False, *migrate = False*) ) to False, then I get an error > relation of table scheduler already exists. So i set migrate = False for > that table also in my scheduler.py file. And afterwards the app itself > works. > > I already find this kind of behavior strange since I copied "stuff" and > things don't work --> I would appreciate guidance for further migrations > already here. I need to keep my auth_user table data etc. > > Now I want to use my new db.py file and if I set migrate to True - I get > an error immediately that table xyz already exists. > > Any suggestions > > 2017-10-18 16:48 GMT+02:00 Anthony: > >> On Wednesday, October 18, 2017 at 10:37:17 AM UTC-4, Yebach wrote: >>> >>> I am trying to keep my production db with all its data but update the >>> structure with the new web2py db code >>> >> >> Yes, then as noted below, just update the web2py code, make sure >> migrations are on, and do *not* touch the production /databases folder >> (the *.table files there provide a record of the current state of the >> production database, so web2py knows what migrations to run to make the >> database match the new model code). >> >> Anthony >> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "web2py-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/web2py/opmKbIW-7LA/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> web2py+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Lep pozdrav > > Vid Ogris > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: response view with markdown
On Tuesday, October 17, 2017 at 5:29:24 PM UTC-4, 黄祥 wrote: > > why web2py can't render the views in markdown format that been assign > (*.md) in most simple way? > e.g. > def testmd(): > response.view = 'default/testmd.md' > #response.render = 'default/testmd.md' > return locals() > > think about github pages can render it > The web2py template engine does not do any specialized rendering of content outside the {{...}} delimiters. It processes the Python code inside the template delimiters and returns everything else as is. What you ask is simply not part of the design of the template system (nor most other template systems, I think). Of course, you can pass markdown content to a web2py template and have it rendered to HTML using a markdown-to-html converter. Or you can do the conversion in the controller and return the output directly rather than using a view. I'm not sure how Github Pages is relevant here. The issue is not a technical one (there are libraries to generate HTML from Markdown) -- this is already doable in web2py. It's just that the template system is not designed to do any special post-processing of the template content. Note, we couldn't add this functionality without breaking backward compatibility -- the framework can't start automatically assuming any view with a .md extension includes Markdown to be transformed to HTML (existing apps might be using the .md extension for some other purpose or be designed to return actual Markdown content). We could probably create a generic.md view that looks for a named view associated with the current requested function (perhaps with a different extension, such as .markdown), renders that view, and then converts it from Markdown to HTML. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Bug with URL encoding?
By default, characters in args that do not match the '[^\w/.@=-]' regular expression are replaced with underscores. To override that behavior, there are two options: 1. In routes.py, set routes_apps_raw to a list of applications that will handle their own args parsing. In those apps, the entire args part of the URL (everything in path_info after /app/controller/function) will be available in request.raw_args, and you will have to parse it yourself. 2. Use the parameter-based rewrite system and specify args_match to suit your needs (the default args_match regex is '([\w@ =-]|(?<=[\w@ -])[.])*$'. Anthony On Thursday, October 19, 2017 at 1:30:09 PM UTC-4, Francisco Ribeiro wrote: > > Hi, > > I have found that when I do request.args(), colons ':' even when properly > URL encoded become an underscore '_' . > > def echo(): > print request.args(0) > return dict() > > A request http://.../echo/%a_ will become : > __ > > which prevents me from distinguishing one from another. > > Am I missing something? shouldn't request.args() take care of URL encoding > / decoding for me? > > Thank you > Kind regards, > Francisco Ribeiro > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: to be or not to be... run by scheduler
If it is a scheduler execution, request.is_scheduler will be True. Anthony On Friday, October 20, 2017 at 9:09:40 AM UTC-4, Manuele wrote: > > Hi *! > > Is there a way to distinguish from within a function if it's run from > the scheduler or not? > > thanks a lot > > M. > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: migrating database and updating it
On Wednesday, October 18, 2017 at 10:37:17 AM UTC-4, Yebach wrote: > > I am trying to keep my production db with all its data but update the > structure with the new web2py db code > Yes, then as noted below, just update the web2py code, make sure migrations are on, and do *not* touch the production /databases folder (the *.table files there provide a record of the current state of the production database, so web2py knows what migrations to run to make the database match the new model code). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Error ticket handling
Scroll down to the "Context" section and click the "Session" button -- if the user was logged in, there should be an "auth" key in the session, which will include the "user" record. Anthony On Wednesday, October 18, 2017 at 10:27:19 AM UTC-4, Anshil Bhansali wrote: > > is there any way to display the user id who generated the error ticket? > the user id from the auth_user table > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: migrating database and updating it
Are you trying to keep the production database and just run migrations on it, or just create a whole new production database from scratch to match the new code? If the former, don't touch the /databases folder on production -- just update the code and leave migrations on, and the DAL will run the proper migrations to make the production database match the new models. Anthony On Wednesday, October 11, 2017 at 7:49:07 AM UTC-4, Yebach wrote: > > Hello > > So based on all the material I have read about migration etc some of the > updates are not working. I will explain what I am doing and please correct > me where my steps are wrong > > I going from develop to production version and the key is to keep the > database with its current data. > > >1. I backup my production database >2. I created new directory with my develop web2py files - DAL is >different in a way i have some new tables and some new fields compare to > my >production version of the database >3. copied all the files and folders to create a new app >4. deleted ALL files in App/database folder >5. restored database on Postgres under new name >6. Set migrate = True and fake_migrate = True in 0.py file >7. run web2py with web2py.exe -i 192.168.100.47 -p 8000 -a 12345 -K >WoShiTest -X > > Now the tables are not updated and also new tables are not added. > > What am I doing wrong? > > I am using the version of web2py downloaded on 11.10.2017 > > Thank you > > Best regards > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
On Friday, October 13, 2017 at 7:22:42 PM UTC-4, Joe wrote: > > Hi Dave, I have reloaded the apps in web2py if that's what you mean. I > can't restart web2py, I can only reload the apps, I guess. > Is there an other way on pythonanywhere? I mean, restarting web2py instead > of reloading the apps? > > *Re: robots.txt* > If I put robots.txt in my static folder the URL will still have to be > *mysite.com/init/static/robots.txt > <http://mysite.com/init/static/robots.txt>* to reach it- this is the > issue I am trying to solve - I am trying have *mysite.com/robots.txt > <http://mysite.com/robots.txt>* > Are you sure you have created /web2py/routes.py as described above and either reloaded the routes via the button in the web2py admin app or reloaded the web app via the PythonAnywhere "Web" tab? Note that routes.py must be in the root /web2py folder. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
On Friday, October 13, 2017 at 5:12:13 AM UTC-4, Joe wrote: > > Thanks very much Anthony for all your help with this one. I copied the > exact code you posted but nothing changed. > > I wonder if this has to do with having multiple apps in the web2py > directory. > No, the above example also includes multiple apps. > Btw, even if I was to manage somehow to get rid off the "init", is it > possible to have this URL *mysite.com/robot.txt > <http://mysite.com/robot.txt>* - probably not possible, right? > Sure, just set the root_static key in the router, as described here <https://github.com/web2py/web2py/blob/5975e4767fd7339b5c588305ec9e8eebd9c079c5/examples/routes.parametric.example.py#L56>. Actually, you don't have to bother setting that explicitly, as "robots.txt" is already set to be served from the root URL (note, it is "robots.txt", not "robot.txt"). > But, I can't even get rid of the "init", which is frustrating. I asked > about this on pythonanywhere, but they don't know. They say it's a web2py > issue. > Hard to say what the problem is, but https://w2ptest.pythonanywhere.com/ <https://www.google.com/url?q=https%3A%2F%2Fw2ptest.pythonanywhere.com%2F&sa=D&sntz=1&usg=AFQjCNEGRowkNGI04V6puqZsomxXem1MRQ> demonstrates that the desired routing can be made to work on PythonAnywhere. Maybe start from scratch with a whole new PythonAnywhere web app or account. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: New plugin: Authman
Very nice. Thanks for posting. This appears to be much more complete, but note that every app includes some basic functionality for managing users, roles, and permissions via the URL /myapp/appadmin/manage/auth. All you have to do is include the following line in a model: auth.settings.auth_manager_role = 'my_auth_admin_role' and anyone in the 'my_auth_admin_role' group will have access to the functionality. This is a special case of the more general auth.settings.manager_actions functionality described at http://web2py.com/books/default/chapter/29/09/access-control#Application-Management-via-privileged-users--Experimental-. Anthony On Sunday, October 15, 2017 at 9:12:40 AM UTC-4, Bernhard Radermacher wrote: > > I developed a little plugin to facilitate authorization management. It can > be found at: > > https://github.com/bradermacher/web2py-plugin-authman > > I appreciate any comments. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: response view with markdown
It should be: response.view = 'default/testmd.md' Also, anything outside the {{...}} delimiters in a view will simply be returned as is, so any markdown in the file will be sent to the browser untransformed. Anthony On Sunday, October 15, 2017 at 8:32:44 AM UTC-4, 黄祥 wrote: > > i plan to reduce db io by put the static data that rarely change into > markdown file (*.md) > e.g. > *controllers/default.py* > def testmd(): > response.view = 'testmd.md' > return locals() > > views/default/testmd.md content is using web2py README.markdown content > (just for testing) > > when access http://127.0.0.1:8000/a/default/testmd.md it return > invalid view (testmd.md) > > when access http://127.0.0.1:8000/a/default/testmd it return (not created > testmd.html in the views part, just for testing markdown support in web2py > views) > Testmd > > is it possible to have markdown file format in web2py view? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: directory structure of uploaded file
Instead of having SQLFORM automatically insert the new record, you can create custom logic to first insert everything but the file, and then after getting the new record ID, use that to set the uploadfolder and update the record with the file. Anthony On Thursday, October 12, 2017 at 8:26:16 PM UTC-4, Rudy wrote: > > Hi Antony, > > Thanks so much again for sharing your insights. I have been playing with > uploadfolder, your suggestion below and from another thread > (uploadfolder=os.path.join(request.folder, 'uploads', str(auth.user.id) > if auth.user else '') work. However what I really want to do is to separate > the files being uploaded based on a company_id. Say an user comes to my > site, register as admin user for his company based on group assignment, > then he / she will be instructed to register his/her company details > including the logo image (being uploaded). Now I want to set this top-level > upload folder to be company_id, however I will only get the company_id > after i submit the form, I don't want to set the top-level upload folder > based on auth.user.id because this admin user can create more users for > this company for day-to-day tasks, I want to group all the file system > consumption based on company. > > I think about computing the next_company_id by doing below, but if i have > 2 users trying to do the same thing, i will have a race condition and get > error. I search in this forum to see how people deal with auto increment > field, Mathieu suggested Field('ref_number', compute=lambda r: r['id'] + > 100), but i don't seem to be able to apply it in uploadfolder attribute, > any suggestion will be much appreciated. > > company_rows=db().select(db.company.ALL) > if company_rows: > last_company_row=company_rows.last() > next_company_id=last_company_row.id + 1 > else: > next_company_id=1 > > > On Thursday, September 28, 2017 at 12:32:46 AM UTC+8, Anthony wrote: >> >> On Wednesday, September 27, 2017 at 5:04:27 AM UTC-4, Rudy wrote: >>> >>> Dave / Anthony, >>> >>> Thanks for your input and confirmation. I will look into the code to see >>> how i can use the uuid to separate files for multi-tenant purpose. >>> >> >> If you're going to be accessing the uploaded files based on the filenames >> stored in the database, you don't necessarily need to do anything with the >> filesystem to enable multi-tenant functionality. The database records will >> identify the tenants and therefore enable you to identify which files >> belong to which tenants. >> >> However, if you need to easily be able to identify files associated with >> a given tenant from the filesystem only (i.e., without reference to the >> database records), then you could create separate top-level upload folders >> for each client. In your code, you would do that by dynamically specifying >> the "uploadfolder" argument of the Field() constructor to set a unique >> folder for each client. For example: >> >> uploadfolder=os.path.join(request.folder, 'uploads', tenant_id) >> >> You could still leave uploadseparate=True, and then you'll get folders >> like: >> >> /uploads/1/company.logo/ab/ >> /uploads/2/company.logo/dy/ >> >> where 1 and 2 are the id's of different tenants. >> >> Anthony >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Issue with query with join and id in select field list
On Thursday, October 12, 2017 at 12:45:05 PM UTC-4, Ricardo Oliveira wrote: > > Hi Anthony, > > Thanks for your excellent example and explanation. > You're right about the problem with the field names, luckily the problem > occurs only in this example, not in production code, but just out of > curiosity, would using "with_alias()" help? > The results of .as_dict() get messy with .with_alias(), so you would need a slightly different approach. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Issue with query with join and id in select field list
You can call .as_dict() on a row object inside an iteration through .render(). Here is a one-liner to replace all your code: json.dumps(dict(data=[{k: v for sub_row in row.as_dict().values() for (k, v) in sub_row.iteritems()} for row in persons.render()])) The list comprehension iterates through persons.render(), which yields a Row object for each record (with the represent functions applied to each field). For each Row object, there is then a dictionary comprehension with two "for" clauses -- the first converts the Row to a nested dict via .as_dict and then uses .values() to extract the two nested dicts into a list containing the two dicts, and the second then calls .iteritems() on each of the dicts in order to generate a new dictionary. Note, you still have a problem -- you have two fields with the same name (i.e., "name"), so in the combined dictionary, the second will overwrite the first. Anthony On Thursday, October 12, 2017 at 5:19:26 AM UTC-4, Ricardo Oliveira wrote: > > Hi Anthony, > > Thanks for your reply. > That was also my initial solution. > Problem is I need to use render() in order to force the lambdas of the > table fields to be executed, and I can't seem to find a way to combine > render() and as_dict(), that's why I used the approach of iterating through > the Rows. > > Is there some way to do this? That would also work. > > Thanks again. > Ricardo. > > > On Wednesday, October 11, 2017 at 11:05:56 PM UTC+1, Anthony wrote: >> >> The problem is here: >> >> >>> for field in person[table]: >>> >> >> person[table] is a Row object, and when the Row object includes the >> record ID, it also includes the special .update_record and .delete_record >> attributes. So, you'll either have to specify the fields explicitly, or >> check the types (the Row.as_dict method takes the latter approach). >> >> Anthony >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Issue with query with join and id in select field list
The problem is here: > for field in person[table]: > person[table] is a Row object, and when the Row object includes the record ID, it also includes the special .update_record and .delete_record attributes. So, you'll either have to specify the fields explicitly, or check the types (the Row.as_dict method takes the latter approach). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: reference representatnion
See https://stackoverflow.com/a/11275155/440323. On Wednesday, October 11, 2017 at 12:49:18 PM UTC-4, Baiyo Paulo wrote: > > > db.define_table('store', > Field('name', 'string'), > auth.signature, > format='%(name)s', > ) > > db.define_table('stock', > Field('stock_serial', 'string'), > Field('stock_location', 'reference store'), > auth.signature, > format='%(stock_serial)s of %(stock_location)s', > ) > > db.define_table('item', > Field('item_stock', 'reference stock'), > Field('name', 'string'), > Field('cost_price', 'decimal(7,2)'), > auth.signature, > format='%(name)s', > ) > > i have these three tables, when i create new item, in the drop down store > id appears, I need the name to appear > instead of id. help me on what i should do. i am new with web2p. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: SQLForm not processing everytime values in form are changed
> > # Days Form > if session.days: > days_form = > SQLFORM(db.days,record=session.days,submit_button='Save',showid=False, >_id='days_form') > else: > days_form = SQLFORM(db.days, submit_button = 'Save',_id='days_form') > if session.offer: > days_form.vars.offer_id = session.offer['id'] > > if days_form.process().accepted: > response.flash = 'Days form submitted' > session.days = days_form.vars.id > days_form = > SQLFORM(db.days,record=session.days,submit_button='Save',showid=False, >_id='days_form') > > The problem is that you are overwriting days_form with a new SQLFORM object after calling .process() on the first instance of the form. You never call .process() on the second instance, so it doesn't get the hidden _formkey input (used for CSRF protection), which means the subsequent form submission fails due to lack of _formkey. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Understanding the download function
On Monday, October 9, 2017 at 1:42:59 AM UTC-4, Andy W wrote: > > Hi Rudy > > Have you tried re-defining the download function to include the path to the > location you have used for storing the uploaded files? For example, in my > case I ended up with the following in my controller: > > def download(): > import os > file_path = os.path.join(request.folder,'uploads', str(auth.user. > client), request.args(0)) > return response.stream(open(file_path), attachment=False, chunk_size= > 4096) > > This shouldn't be necessary. As long as you have the client id available in the request (e.g., in auth.user.client), you can simply use it to specify the uploadfolder when defining the model. In db.by: db.define_table('company', Field('logo', 'upload', label='Company Logo', uploadfolder=os.path.join(request.folder, 'uploads', auth.user.client if auth.user else ''), uploadseparate=True, autodelete=True)), ...) Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] component rebuild via anchor helper
You might instead consider putting the data in the session and retrieving it from the session when the link is clicked. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Compile controller and module files only
On Friday, October 6, 2017 at 4:10:57 AM UTC-4, Tom Clerckx wrote: > > Is it possible to compile an application, but keep the views and the CSS > 'uncompiled'? > The idea is that other people can change the look and feel without having > access to the code of the controllers and the models. > Sure, just compile that app and delete all the compiled view files. CSS files aren't compiled, so no need to do anything with them. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: how to detect if any view exists
On Thursday, October 5, 2017 at 7:21:58 PM UTC-4, Alex Glaros wrote: > can you give me a tip on checking file system? Google. ;-) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: how to detect if any view exists
Just check if the file exists on the filesystem. On Thursday, October 5, 2017 at 6:21:23 PM UTC-4, Alex Glaros wrote: > > I have a bookmark on every page that appears via layout.html {{include > 'default/menu_favorites.html'}} that reads a small table > > If am testing a new function that does not yet have a view, it raises this > error: 'Rows' object has no attribute > 'fields' > > is there any conditional test to detect if there is a view yet or not? > > not that important but would like to prevent this appearing if anyone > besides myself is programming on the app. As soon as the view is created, > the error goes away. > > thanks > > Alex Glaros > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: OffTopic - Python help
This code uses a decorator to turn a function into an instance of a special Pipe class. The Pipe class uses the Python "magic" method __ror__ to overload the bitwise OR operator (i.e, the | operator). The __or__ magic method determines the behavior of the | operator when the object with the method appears on the left of the | operator, and the __ror__ (i.e., "reverse" __or__) magic method determines the behavior when the object with the method appears on the right of the | operator. In this case, the decorated function is used on the right of the | operator, so the __ror__ method is used. For more details, see http://minhhh.github.io/posts/a-guide-to-pythons-magic-methods#user-content-numeric-magic-methods. The Pipe class also includes a __call__ method, so you can call the object with some arguments, and it returns a new Pipe object, which passes those arguments to the originally decorated function. For example, the module defines a concat function: @Pipe def concat(iterable, separator=", "): return separator.join(map(str,iterable)) With the above decorator, concat becomes an instance of the Pipe class, with self.function set to the function defined above. When you call: [1, 2, 3] | concat The __ror__ method of the Pipe object gets called, with the list on the left passed as the "other" argument. When you call: [1, 2, 3] | concat('#') First, the __call__ method of the Pipe object gets called with "#" as its argument. It then returns a new Pipe object, and the __ror__ method of that new Pipe object gets called with the list as the "other" argument. So, here we've got an example of (a) a decorator implemented as a class with an __init__ and __call__ method, (b) a Python magic method, and (c) operator overloading (implemented via the magic method). Anthony On Thursday, October 5, 2017 at 4:48:43 PM UTC-4, Ramos wrote: > > Reading this > https://github.com/JulienPalard/Pipe > > i tried this simple code > > > import functools > > > class Pipe: > > def __init__(self, function): > self.function = function > functools.update_wrapper(self, function) > > def __ror__(self, other): > return self.function(other) > > def __call__(self, *args, **kwargs): > return Pipe(lambda x: self.function(x, *args, **kwargs)) > @Pipe > def list(x): > return [x] > @Pipe > def count(iterable): > "Count the size of the given iterable, walking thrue it." > count = 0 > for x in iterable: > count += 1 > return count > > > > Can someone tell me why/how this code gives me the | available in the > console to pipe functions > > >> [2,3,4,2,4] | count |list > [5] > > > > > > Regards > António > > > > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> > Sem > vírus. www.avast.com > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> > > <#CAEM0BxNhzsCkpy=uUdH7xXr6=g3JxtrGvo5M48XZjq55EK=zrw@mail.gmail.com_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Question regarding building dynamic queries
> I tried the following > > query = db.orders.id_buyer == auth.user_id > query1 = query & (db.orders.status == status) > > On printing query1, it will print "False", while I want something like > > print db(query1).count() > > Right now, type command returns the following for query and query1. I want > query1 to be a Class > > > > Are you sure the above is your exact code? I tried the same and cannot reproduce your results (both are gluon.dal.Query objects). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: update_or_insert -- I end up with duplicates
update_or_insert first selects the record (if it exists) and then does the create/update. I suppose when two requests come in very close to each other, the second request is checking for the record before the first request has had a chance to commit the insert. I'm not sure I would call that a bug. The alternative would be to lock the database table before the read, but that would stop all other reads on the table and would introduce complexities with web2py's transaction-per-request workflow (e.g., in Postgres, to release a lock, the transaction must end, but if we explicitly commit a transaction in update_or_insert, that would prematurely close the transaction that is intended to remain open for the duration of the HTTP request). I suppose we could add an option to lock the table. Anthony On Wednesday, October 4, 2017 at 10:25:44 AM UTC-4, Brad Miller wrote: > > Hi All, > > I have the following update or insert statement in a controller. > > db.grades.update_or_insert( > ((db.grades.auth_user == student.id) & > (db.grades.assignment == assignment.id)), > auth_user = student.id, > assignment = assignment.id, > score=score) > > The function that this is part of is called as the result of a user > pressing a button on the web page. It could get pressed multiple times in > quick succession. (Yes, I'll fix that too). ButI was surprised that I end > up with duplicate values every now and then. This is on top of Postgresql > with psycopg2 driver. I added a constraint to the table definition to > ensure that user,assignment pairs are unique and now at least I can catch > the IntegrityErrors when they happen. > > Since this is running in an multi-process environment I guess I could see > how this might happen, but it seems like a bug. Or am I doing something > stupid? > > Brad > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Insert into reference:list not working - FOREIGN KEY constraint failed field:upload
On Monday, October 2, 2017 at 9:24:29 PM UTC-4, LoveWeb2py wrote: > > Still receiving same error... > Maybe you didn't properly delete the table. No foreign key constraint is set for a list:reference field, so if you are getting that error, that means the database still has a foreign key constraint on the field, which implies the table was not deleted and re-created. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Insert into reference:list not working - FOREIGN KEY constraint failed field:upload
On Monday, October 2, 2017 at 7:57:19 PM UTC-4, LoveWeb2py wrote: > > Yes... I believe so. > > On Monday, October 2, 2017 at 7:53:13 PM UTC-4, Anthony wrote: >> >> Was that field originally a regular reference field and then you changed >> it to a list:reference field? >> > I think that's the problem. Try re-creating the table (save the data to re-import). Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Insert into reference:list not working - FOREIGN KEY constraint failed field:upload
Was that field originally a regular reference field and then you changed it to a list:reference field? On Monday, October 2, 2017 at 3:45:38 PM UTC-4, LoveWeb2py wrote: > > Anyone have feedback? I have been banging my head against this all day... > > On Sunday, October 1, 2017 at 4:52:39 PM UTC-4, LoveWeb2py wrote: >> >> Hello, I'm trying to create a simple interface that allows users to >> select multiple files and create a name for the bundle. I've followed the >> example in the book but keep getting the same error... FOREIGN KEY >> constraint failed. >> >> When I look in all_files, it has the keys available. >> >> I tried following this example: >> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#listtype-and-contains >> >> I am wondering if it has something to do with the filetype being an >> upload field. >> >> I've even tried getting the reference object id by doing >> >> s = db(db.all_files.id>0).select() >> file_ids = [x.id for x in s if int(x) in all_files] >> >> name = 'test_group_name' >> file_ids = [1L, 2L, 3L] >> >> db.file_groups.insert(group_name=test_id, filename=file_ids) >> >> >> >> Function argument list >> >> (self=, table=> (id, group_name, filename)>, fields=[(, [27, >> 28, 29, 33, 34, 31, 30, 32, 35, 36]), (, >> 'filegroup1')]) >> >> >> >> >> >> db.define_table('all_files', >> Field('filename','upload', unique=True), >> Field('uploaded_by', db.auth_user), >> format="%(filename)s") >> >> db.define_table('file_groups', >> Field('group_name'), >> Field('filename', 'list:reference all_files')) >> >> >> >> Sincerely appreciate any help... >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: syntax error in list join-to-db?
It is already a list, so don't put it inside another list. Should be: mySet = db.auth_user.id.belongs(session.myConnectionsList) Anthony On Monday, October 2, 2017 at 6:40:10 PM UTC-4, Alex Glaros wrote: > > abbreviated display of creating list: > > session.myConnectionsList = [] > for r in iAmMemberConnectionsList: > session.myConnectionsList.append(r.role_owner_user_id_fk) > > Correct user id, 4, appears when I print the list > > [4L] > > Then, I try to create a query for grid by joining list to db, which causes > error: > > mySet = db.auth_user.id.belongs([session.myConnectionsList]) > > * unhashable type: 'list'* > > see anything I'm doing wrong? > > thanks > > Alex Glaros > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: left join and common_filter
On Monday, September 11, 2017 at 5:43:30 AM UTC-4, Marvix wrote: > > Found that was already discussed some years ago, but I think isn't resolved > > > https://groups.google.com/forum/#!topic/web2py/WY2U54uoTno > That was a separate issue. In this case, the problem is that you have not specified any query involving the db.ivrs table, so its common filter does not get applied. Change your query to: ivrs = db(db.ivrs).select(...) In previous versions of the DAL, db().select() worked as expected, but that construction is discouraged now, and in some cases leads to incorrect behavior (e.g., with common filters). We should probably simply no longer allow db() without a query, as an exception would be better than silent data corruption (or at least disallow it when common filters are present). Feel free to report an issue in the pydal repository and link back to this thread. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Insert into reference:list not working - FOREIGN KEY constraint failed field:upload
Please show the full traceback. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Force load an injected LOAD(ajax=True) helper
In Javascript, you can call: $.web2py.component('{{=URL(...)}}', 'my_component') where 'my_component' is the id of the component div. You can use the LOAD helper to generate the div (with LOAD(..., target='my_component')), or just create an empty div with that id. Anthony On Thursday, September 28, 2017 at 3:42:08 PM UTC-4, Yan Wong wrote: > > I have a LOAD() helper in a view, but that view itself gets loaded into my > main page using the jQuery load() function, after a user interaction. That > means the standard web2py events aren't attached to the LOAD() helper, and > it is just permanently displayed as "loading...". Is there some javascript > (presumably defined in web2py.js that I can call on the dive generated by > the LOAD() component to force it to load properly? > > Cheers > > Yan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: how to keep response.headers after redirect
On Thursday, September 28, 2017 at 11:24:48 AM UTC-4, Boyang Li wrote: > > Just a follow-up questions here: > > When I try to use the redirect function raise > HTTP(303,location=URL(...),**request.headers) to redirect to an external > app, > my external app cannot find the redirected authorization header by > accessing request.env.HTTP_AUTHORIZATION. > Two problems. First, there is no request.headers, so presumably the above code generates an exception (resulting in a 500 response), not a 303 response. There is a response.headers, but it would not contain the "Authorization" header, as that is a *request* header. In any case, there would be no point in passing the "Authorization" header back as a *response* header -- what you really need is for the client to generate its next request using the "Authorization" header (which is the responsibility of the client). If the redirect URL was back to the same domain as the original request, the client (presumably a browser) would automatically re-send the original "Authorization" header. However, for security reasons, browsers will not send an "Authorization" header to a different domain. If the initial request is made via Ajax, you can write Javascript code to detect the 303 response and instead of following the redirect, simply make a new Ajax request to the other domain. Actually, if using Ajax, there would be no particular reason to even use a 303 response -- you can simply return a 200 response with a flag (in the headers or body) indicating the external app should be called next. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: DAL question db(db.table.id>0,db.table.field=='x').select()
On Thursday, September 28, 2017 at 4:36:28 AM UTC-4, Ramos wrote: > > would it be more natural > > db(db.table.id>0,db.table.field=='x').select() > First, it's not clear whether those queries would be joined with & or |. Second, because of that, we would still need to use the alternative syntax to support both cases. So, I would prefer the current approach because it is more explicit and doesn't result in yet another way to do the same thing. Note, if you prefer, you can do: db(db.table.id>0)(db.table.field=='x').select() Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: most simple way to change the "page=" parameter in grids
You're on the right track -- you would have to use the pattern-based rewrite system, as the "page" identifier is hard-coded in the grid code. On Wednesday, September 27, 2017 at 3:29:21 AM UTC-4, Thomas Wimmer wrote: > > *push* > > Nobody? No Idea at all? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: directory structure of uploaded file
On Wednesday, September 27, 2017 at 5:04:27 AM UTC-4, Rudy wrote: > > Dave / Anthony, > > Thanks for your input and confirmation. I will look into the code to see > how i can use the uuid to separate files for multi-tenant purpose. > If you're going to be accessing the uploaded files based on the filenames stored in the database, you don't necessarily need to do anything with the filesystem to enable multi-tenant functionality. The database records will identify the tenants and therefore enable you to identify which files belong to which tenants. However, if you need to easily be able to identify files associated with a given tenant from the filesystem only (i.e., without reference to the database records), then you could create separate top-level upload folders for each client. In your code, you would do that by dynamically specifying the "uploadfolder" argument of the Field() constructor to set a unique folder for each client. For example: uploadfolder=os.path.join(request.folder, 'uploads', tenant_id) You could still leave uploadseparate=True, and then you'll get folders like: /uploads/1/company.logo/ab/ /uploads/2/company.logo/dy/ where 1 and 2 are the id's of different tenants. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: "object_type" reserved word in web2py?
You don't have to worry about database table names conflicting with either Python keywords or web2py API objects, as the table names are only used as attributes or keys of a DAL object -- never in the global namespace. You only need to worry about conflicts with SQL reserved words. In any case, if it has been working so far, there is no reason it would suddenly stop working. Anthony On Tuesday, September 26, 2017 at 10:38:13 AM UTC-4, Alex Glaros wrote: > > it is a key table in my app and would be difficult to rename in the future > if there were naming issues > > thanks Anthony > > Alex > > > On Tue, Sep 26, 2017 at 7:07 AM, Anthony wrote: > >> No, why do you ask? >> >> >> On Tuesday, September 26, 2017 at 1:30:43 AM UTC-4, Alex Glaros wrote: >>> >>> "object_type" reserved word in web2py? >>> >>> thanks >>> >>> Alex Glaros >>> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "web2py-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/web2py/b6Ip-dBIE34/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> web2py+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: "object_type" reserved word in web2py?
No, why do you ask? On Tuesday, September 26, 2017 at 1:30:43 AM UTC-4, Alex Glaros wrote: > > "object_type" reserved word in web2py? > > thanks > > Alex Glaros > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: directory structure of uploaded file
On Tuesday, September 26, 2017 at 5:53:30 AM UTC-4, Dave S wrote: > > > > On Monday, September 25, 2017 at 11:03:59 PM UTC-7, Rudy wrote: >> >> Hi i am working to build a multi-tenant application which has a company >> table which stores logo and other data. I defined a company table, added >> extra fields in auth_user and created an action (simplified version) like >> below. web2py uploaded the logo image file under >> myapp/uploads/company.logo/af/company.logo.af.png, but according to >> the document(applications/test/uploads/person.image.X.jpg), I should >> not have had the company.log/af directories, could anyone explain why? >> > > Because you set "uploadseparate"? > Yes, it is because of uploadseparate, which is documented here: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-constructor. The subfolders have the form /tablename.fieldname/[first 2 letters of UUID from fielname]. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: pyDAL - query records newer than a certain date
Answered: https://stackoverflow.com/a/46428432/440323 On Tuesday, September 26, 2017 at 7:25:25 AM UTC-4, Terrence Brannon wrote: > > Since there has been no response here, I have posted my question at Stack > Overflow: > > https://stackoverflow.com/questions/46425184/pydal-query-records-newer-than-a-certain-date > > On Monday, September 25, 2017 at 3:40:10 AM UTC-4, Terrence Brannon wrote: >> >> Hello, I have the following query working in pure SQL on SQLite but do >> not know how to convert it to pyDAL: >> >> SELECT * FROM buy WHERE date('now','-2 days') < timestamp; >> >> The buy table schema is: >> >> CREATE TABLE "buy"( >> "id" INTEGER PRIMARY KEY AUTOINCREMENT, >> "order_id" CHAR(512), >> "market" CHAR(512), >> "purchase_price" DOUBLE, >> "selling_price" DOUBLE, >> "amount" DOUBLE >> , "timestamp" TIMESTAMP, "config_file" CHAR(512)); >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: web2py-15, how to access table name from class ExporterXLS ?
The same issue caused a bug in the TSV export, which was fixed by this pull request: https://github.com/web2py/web2py/pull/1766. Check out that code to see the fix. Anthony On Sunday, September 24, 2017 at 12:38:02 PM UTC-4, Alex Beskopilny wrote: > > Thanks for you answer ! > (it's code works with web2py-14.6) > > db = DAL("postgres://user:pass@localhost:5432/dmdb", lazy_tables=False, > migrate_enabled= True) > > db.define_table('sprf10', > Field("spr",), > ) > > db.define_table('sprf13', > Field("s13",), > ) > > db.define_table('addr', > Field("f1", length= 96), > Field("f2", length= 96), > ... > Field("ptr_r1", 'integer', label= 'id registr'), > ) > > db.define_table('registr', > Field ("dfld2", label= "Регистрационный номер:2", length= 32), > Field ("dfld3", 'date', label= "Дата внесения в реестр:3", requires = > IS_DATE(format=XFMT), default = request.now.today(), ), > Field ("dfld11", length= 512), > Field ("dfld12", length= 96), > Field ("dfld13", length= 1024), > Field ("dfld14", length= 96), > Field ("dfld15", length= 96), > Field ("dfld16", length= 1024, readable=False,writable=False ), > Field ("dfld17", length= 1024, readable=False,writable=False ), > Field("p_client", 'reference reg_client', label= 'id reg_client', > writable= False, readable= False), > Field("p_addr", 'reference addr', label= 'id addr', writable= False, > readable= False ), > Field("p_sprf10", 'reference sprf10', label= 'id sprf10', writable= > False, readable= False), > Field("p_sprf13", 'reference sprf13', label= 'id sprf13', writable= > False, readable= False), > auth.signature, > ) > > > sqlhtml.py > > exportManager = dict( > csv=(ExporterXLS, 'XLS', T('xls')), > xml=(ExporterXML, 'XML', T('XML export of columns shown')), > html=(ExporterHTML, 'HTML', T('HTML export of visible > columns')), > json=(ExporterJSON, 'JSON', T('JSON export of visible > columns')), > ) > . > class ExporterXLS(ExportClass): > label = 'XLS' > file_ext = "xls" > content_type = ".xls" > > def __init__(self, rows): > ExportClass.__init__(self, rows) > > def export(self): > import xlwt, cStringIO > if len(self.rows) == 0: > return 'empty rows-table' > > (table_name,f)=self.rows.colnames[0].split('.') > book = xlwt.Workbook() > sheet = book.add_sheet(table_name) > > def list2xls(row_num,line_list): > for col_num, value in enumerate(line_list): > #if isinstance(value, long): > #value= str(value) > if isinstance(value, str): > value= value.decode('utf8') > if isinstance(value, datetime.datetime) or > isinstance(value, datetime.date): > value= value.strftime('%d.%m.%Y') > sheet.write(row_num, col_num, value) > > fields=[]; labels=[] > for col in self.rows.colnames: > (t,f) = col.split('.') > fields.append(f) > labels.append( self.rows.db[t][f].label ) > list2xls(1,labels) > > for r_num, row in enumerate (self.rows, 2): > llist=[ row[f] for f in fields] > list2xls(r_num, llist) > > s = cStringIO.StringIO() > book.save(s) > return s.getvalue() > -- > controllers/default.py > def index(): > > tbl= 'registr' > query = db[tbl].id >0 > > grid = SQLFORM.grid(query,showbuttontext=False, maxtextlength=200, > deletable = False, create = False, > links=[ lambda row: A('k',_href=URL('cp2_new',args= > row.id), _class="btn btn-success" ), ] , > buttons_placement = 'left', paginate= PAGIN, ) > return dict(grid=grid) > >
[web2py] Re: smartgrid request
Use the constraints argument, as described here: http://web2py.com/books/default/chapter/29/07/forms-and-validators#smartgrid-signature Anthony On Sunday, September 24, 2017 at 10:14:41 AM UTC-4, LC LC wrote: > > Hello, > > def index(): > records = > SQLFORM.smartgrid(dbvoy.voyageur,linked_tables=['voyageur','presence'],user_signature=True,maxtextlength=100,deletable=True,\ >editable=True,create=True,showbuttontext=False, > paginate=200, buttons_placement = 'left',links_placement = 'left') > > I do not find how to add a condtion to replace dbvoy.voyageur by > dbvoy.voyageur.Birth < '2000-09-01' , it does not work the rror shown > 'Query' object has no attribute '_tablename' > Could you help me > thank you > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: web2py-15, how to access table name from class ExporterXLS ?
Please show the full traceback as well as the rest of the relevant code (i.e., table definition and grid code). Anthony On Saturday, September 23, 2017 at 3:17:24 PM UTC-4, Alex Beskopilny wrote: > > > Hi All, > Why It's code work from controller and does error from class Exporter ? > How to access table_name ? > ( AttributeError: 'DAL' object has no attribute '"table_name"' > <https://sun.minfindnr.ru/admin/default/errors/dmlic#> ) > > class ExporterXLS(ExportClass): > label = 'XLS' > file_ext = "xls" > content_type = ".xls" > > def __init__(self, rows): > ExportClass.__init__(self, rows) > > def export(self): > import xlwt, cStringIO > > table_name= self.rows.colnames[0].split('.')[0] > tbl2=[]; row_flds=[]; row_labs=[] > > for col in self.rows.colnames: > (t,f) = col.split('.') > row_flds.append(f) > row_labs.append ( self.rows.db[t][f].label ) > > tbl2.append(row_labs) # table headres > for row in self.rows: > llist=[ row[x] for x in row_flds] > tbl2.append(llist) > # > book = xlwt.Workbook() > sheet1 = book.add_sheet(table_name.decode('utf8')) > > for i, l in enumerate(tbl2): > for j, col in enumerate(l): >if isinstance(col, str): > col=col.decode('utf8') >elif isinstance(col, datetime.datetime) or isinstance(col, > datetime.date): > col = col.strftime('%d.%m.%Y') >else: > col='' > s = cStringIO.StringIO() > book.save(s) > > #- > response.headers['Content-Type'] = '.xls' > response.headers['Content-disposition'] = \ > 'attachment; filename=\"%s_%s.xls\"' % ( > request.now.strftime("%d.%m.%Y_%H%M%S") , table_name) > return s.getvalue() > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Kaspersky problem with web2pyslices.com
The site should be fine. Likely just a false positive by Kaspersky. Anthony On Saturday, September 23, 2017 at 3:17:18 PM UTC-4, fernandisc...@gmail.com wrote: > > Kaspersky is alerting of phising URL when accessing any web2pyslices URL, > and therefore it dennies the access. > > Anyone having the same problem? > > Is it safe to dismiss the alert and go ahead, or has the site been > compromised in some way? > > > > This is the alert: > > KasperskyInternet Security > ACCESS DENIED > The requested URL cannot be provided > > *URL:* > > http://www.web2pyslices.com/home > > *Blocked by Web Anti-Virus* > > Reason: phishing URL > > Click here if you believe that the web page has been blocked mistakenly. > <http://touch.kaspersky.com/kis_CUP_F8F731B4-629F-4B7C-923C-495D87BF7E09/1506152707> > > Detection method: cloud protection > *Message generated at: 10:59:23* > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Basic question about app compile
On Thursday, September 21, 2017 at 11:25:38 AM UTC-4, Jordan Ladora wrote: > > > Thank you both very much for the help. I didn't find that thread you > mentioned, Anthony, before I posted my question yesterday. Thanks for > mentioning all that. > > Incidentally, is there any way to install the compiled & packed app > without appadmin? For security & compactness I run > scripts/make_min_web2py.py & there's no admin. > The .w2p file generated by the admin app is just a gzipped tar file, so you can unpack it as you would any such file. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Build query without DB connection
You might try something like this in your module: dummy_db = DAL('sqlite:memory', do_connect=False, migrate_enabled=False) def define_tables(db): db.define_table('mytable', Field('field1'), Field('field2')) define_tables(dummy_db) query1 = dummy_db.mytable.field1 == 'some value' query2 = dummy_db.mytable.field2 == 'other value' By setting do_connect=False, no connection will be made to the database. Note, the URI used for the dummy database does not have to be the same as the real database, but it should refer to the same type of DBMS (mainly to ensure the the proper SQL dialect is used to generate the SQL). Then in your model and/or controller code: from mymodule import define_tables, query1, query2 db = DAL(...) define_tables(db) rows = db(query1 & query2).select() Note, with the above approach, the dummy DAL object defined in the module is not the same DAL object defined in the model/controller code where the query is executed. However, in order to generate queries in the module, we still need to define the tables on the dummy DAL object. So, the above example puts the table definition code in a function, which can be called within the module as well as the model/controller code in order to define the same tables on the real DAL object as well as the dummy object. Finally, you should consider whether there is really much benefit to defining the queries in a module in this way. Anthony On Thursday, September 21, 2017 at 2:30:10 AM UTC-4, Brendan Barnwell wrote: > > On Wednesday, September 20, 2017 at 10:31:04 PM UTC-7, Massimo Di Pierro > wrote: >> >> In web2py, and in general in code that runs multithreaded you should not >> define variables in modules at top level and then import them because they >> are cached and then shared by multiple threads. That is not thread safe and >> will cause all kind of problems. Modules should define functions and >> classes, not objects. You should only import those functions and classes. >> >> > I think it is a bit extreme to say that modules can only define functions > and classes. Clearly they can also contain, for instance, "constant > declarations" like "something = 2". My question is whether there is a way > to define a query constraint as a "constant" in a similar way. > > An expression like "db.MyTable.myfield > 2" does not conceptually need to > know anything about the field, the table, or even the database at the time > it is created. In this situation "query = db.MyTable.myfield > 2" would be > no different from a constant assignment like "MY_CONSTANT = 7". There is > no reason why the expression itself needs access to any thread state. It > is only when the query is actually executed that it needs to be attached to > a live database connection --- but that may be at a later time. What I'm > asking is if there is a way to use the syntactic sugar of the DAL without > any connection to an actual database, just to create a query expression > that can be LATER attached to a database object. > > It appears the answer is no. Is that what you are saying? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Basic question about app compile
> After compiling the Welcome app, I tried two things. I moved out the > source files from the controllers, models, and views folders, and either > just left the compiled folder in place, > That should work but does not in 2.15 due to a bug, for which I have submitted a pull request. See https://groups.google.com/forum/#!msg/web2py/R7ie7_neg7E/JdFcmriEAgAJ. It should work if you leave the view files but delete the controllers and models. Note, in that case, the errors you see should be "Invalid view", not "Invalid controller". Also, note that you can achieve the above by running "Pack compiled" in the admin app -- it will retain only the compiled files in the packed application. > or went and replaced all the source files from the controllers, models, > and views folders with those files from the compiled folder. Neither of > these attempts worked, throwing 'invalid controller' errors. > This approach will not work and is not intended to. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Compiled and installed apps throw error after updating a folder that is outside web2py
The issue is probably related to opening a subprocess in uWSGI, not the external folder into which you are copying files. Have a look at https://stackoverflow.com/a/17607704. Maybe setting "--close-on-exec" in your uWSGI configuration will work. Alternatively, consider using the web2py scheduler to handle running the task. Anthony On Wednesday, September 20, 2017 at 7:54:24 AM UTC-4, Lisandro wrote: > > Hi, I'm having a hard time to figure out why web2py throws this error in > this scenario. > > I have one web2py installation, with the same app installed **a lot** of > times. The app is a simple app I've designed to create and mantain your own > website. So the app is one, but it's installed several times, each time > it's installed with a different name, and a specific configuration file > that tells the app wich database to connect, wich domain to serve, etc. > > Up to here, everything works ok. I take the opportunity to say that web2py > really rocks, it's completely scalable! I'm using nginx + uwsgi + web2py. > My whole enviroment receives thousands of requests per day (of course, I > had to consider some tunnings as compile the apps, using lazy_tables, > disabling migrations, etc). But I wanted to say that, because in the past > I've seen some posts saying that web2py wasn't scalable. Nothing more far > from the truth. Not only I use web2py in a high load environment, but also > I developed another web2py app to help me with the administrative tasks of > managing all the other apps. I could successfully develop a web2py app that > allows me to install other apps, change nginx configuration, restart uwsgi, > creating/deleting databases, even upgrading the other apps. I say it again: > web2py really rocks!! > > Back to the issue. Everytime I install a copy of my app in that one web2py > installation, I do it cloning a Mercurial repository I have on > bitbucket.org (by the way, I do all that from my cutom administrative > web2py app). > The problem was that this approach would depend on the availability of > bitbucket.org: if the service is down or degraded, I couldn't perform an > update of the apps. So, I thought I would need to have a local copy on the > repository, and do de pull & update from that local repository, so I > wouldn't depend on bitbucket.org. Every time to time, I would need to do > a pull from the bitbucket repository in order to have the local one up to > date. > > My web2py folder structure looks something like this: > > web2py/applications/administrative > web2py/applications/app1 > web2py/applications/app2 > web2py/applications/app3 > web2py/applications/app4 > web2py/local_repository > > > Notice the administrative application, the installed apps, and the > "local_repository" folder having the cloned repository from bitbucket. From > the administrative app, when I need to add a website, I run a custom code > that clones the local repository as a new app, creates the database, etc, > restarts uwsgi, and reloads nginx configuration. Up to here, it's all good > too. > > Now, the problem appeared when I added a simple function inside the > administrative app, in order to do a pull from bitbucket to the > local_repository. The funcion is very simple, and it uses subprocess to run > an hg pull, as simple as that. And it works ok. The problem is that, after > doing that pull, *all the other apps start throwing errors, and I need to > restart uwsgi in order to avoid those errors*. My first thought was that > restarting uwsgi was needed in the same way is needed when I update an > installed app (that is obvious, if I update an app and compile it, I have > to restart uwsgi in order to make the new code visible). > But, considering that doing a pull is trivial and does not affect the > installed running apps, I wanted to avoid restarting uwsgi in that case. So > my first idea was to move the "local_repository" folder out of the web2py > folder, so my structure looks like this: > > folder/web2py/applications/administrative > folder/web2py/applications/app1 > folder/web2py/applications/app2 > folder/web2py/applications/app3 > folder/web2py/applications/app4 > folder/local_repository > > Notice that now the "local_repository" is completely outside the web2py > folder. > However, and *this is the weird part: after doing a pull inside that > local_repository folder, I still need to restart uwsgi, because if I don't, > all the installed apps start throwing error!* > I'm confused about that. *I don't see how the apps need uwsgi to be > restarted after doing a pull in a folder that is completely out
[web2py] Re: the way to return json
On Monday, September 18, 2017 at 9:59:32 PM UTC-4, 黄祥 wrote: > > a, i c, not tested on that yet, will do, btw, > forgot to add service.json() not sure about the difference or performance > compare with json/simplejson, as_json(), response.json(), restful > Again, ultimately, it just calls response.json. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: caching variable data sample
On Monday, September 18, 2017 at 10:09:51 AM UTC-4, Pierre wrote: > > I'd prefer the module option but I need to pass *time_expire* as a > variable (*db.atable.__variableName*), I don't think I can do that in a > module can I ? > You are not limited to using the decorator to cache the results of a function. Instead, you can just do something like this: from mymodule import cache_this myrows = cache.redis('myrows', cache_this, time_expire=myvariable) Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
FYI, here is a Pythonanywhere app with routing working as expected (the app is named "init"): https://w2ptest.pythonanywhere.com/ Below are the exact contents of the /web2py/routes.py file for the above installation: routers = dict( BASE = dict( default_application='init' ), init = dict( default_controller='default', default_function='index', functions=['call', 'download', 'index', 'user'] ) ) Also, note that as long as you are going to use the rewrite system as above, there is no particular reason to name your app "init". The only reason to use "init" is if you are not using the rewrite system and want a default application when accessing a URL with the domain name only. Anthony On Monday, September 18, 2017 at 10:05:31 AM UTC-4, Anthony wrote: > > On Monday, September 18, 2017 at 9:30:26 AM UTC-4, Joe wrote: >> >> Thanks Anthony, when you say "*specify the functions in the default >> controller* ", what do you mean exactly? I just want to make sure I >> understand you correctly. >> > > See https://groups.google.com/d/msg/web2py/FcdWR6VuB6Y/Et3sUGmHBAAJ. > > But that does not appear to be the issue you are experiencing. You might > have to contact Pythonanywhere support, as it sounds like somehow it is > ignoring the routes.py file. > > Anthony > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: the way to return json
On Monday, September 18, 2017 at 9:09:59 AM UTC-4, 黄祥 wrote: > > yes you are right .as_list() will be called automatically when pass it to > response.json() > > rows.as_json() work well too unfortunately it's not documented in book yet: > def json_rows_as_json(): > query = (db.auth_user.id > 0) > rows = db(query).select() > return rows.as_json() > > *not sure about :* > @request.restful, you don't even have to call response.json -- if you make > an 'application/json' request, the result will automatically be converted > to JSON. > *code:* > @request.restful() > def restful_json_rows_as_list(): > response.view = 'generic.json' > def GET(): > query = (db.auth_user.id > 0) > rows = db(query).select() > return rows > return locals() > > *url:* > http://127.0.0.1:8000/test/api/restful_json_rows_as_list.json > As noted, you must request 'application/json', for example: curl -H "Accept: application/json" Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
On Monday, September 18, 2017 at 9:30:26 AM UTC-4, Joe wrote: > > Thanks Anthony, when you say "*specify the functions in the default > controller* ", what do you mean exactly? I just want to make sure I > understand you correctly. > See https://groups.google.com/d/msg/web2py/FcdWR6VuB6Y/Et3sUGmHBAAJ. But that does not appear to be the issue you are experiencing. You might have to contact Pythonanywhere support, as it sounds like somehow it is ignoring the routes.py file. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
First, you can just put all the router code in /web2py/routes.py -- no need for anything specific in the app folder. Second, you need to specify the functions in the default controller if you want /default/index to be gone when there are any request.args. How are your URLs being generated? What happens if you just go to http://yourdomain.com? Anthony On Sunday, September 17, 2017 at 9:24:31 AM UTC-4, Joe wrote: > > Yes, I reloaded the app. Nothing happens, it doesn't change the URL. > > I tried several different ways to change the routes.py. > > In the current situation in the *web2py* folder I have this in the* > routes.py* file: > > routers = dict( > BASE = dict(default_application='init'), > ) > > Then, in the *web2py/applications/myappfolder/applications/init/routes.py* > I have the same code: > > routers = dict( > BASE = dict(default_application='init'), > ) > > > Something doesn't seem right about the above path and folder structure. > Maybe this is the problem, but this seems to be the only way to install the > app on Pythonanywhere. But, this doesn't seem right. > > > > On Sunday, September 17, 2017 at 9:05:05 PM UTC+8, Anthony wrote: >> >> Did you reload routes or restart the server? > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: the way to return json
gluon.contrib.simplejson is not really simplejson but just a dummy module that calls the Python json module, so no difference between the first and second. I suspect response.json will be similar to json.dumps. response.json is gluon.serializers.json, which ultimately calls json.dumps, but it provides a custom "default" function to process objects that cannot otherwise be serialized (e.g., it handles dates, times, Rows objects, HTML helper objects, T() objects, etc.). Also, note, you don't even have to call rows.as_list() before passing to response.json, as .as_list() will be called automatically. In fact, with @request.restful, you don't even have to call response.json -- if you make an 'application/json' request, the result will automatically be converted to JSON. As for @request.restful, it may be a bit slower because the decorator involves some additional logic, but most of the time will probably be spent on the select and the serialization anyway. You can also try rows.as_json() just to keep things simple, but that's probably similar to response.json(rows) or response.json(rows.as_list()), as they all ultimately call the same methods to do the serializing (i.e., row.as_dict, gluon.serializers.json, and json.dumps). And of course, if you really want to know, you should just test it. Anthony On Sunday, September 17, 2017 at 7:42:50 PM UTC-4, 黄祥 wrote: > > just testing several code that return json > *e.g.* > > *controllers/api.py* > def json_rows_as_list(): > import json > query = (db.auth_user.id > 0) > rows = db(query).select() > json_list = json.dumps(rows.as_list(), default = str, sort_keys = True) > return dict(results = XML(json_list) ) > > """ > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/json_rows_as_list > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/json_rows_as_list.json > """ > > def simplejson_rows_as_list(): > import gluon.contrib.simplejson > query = (db.auth_user.id > 0) > rows = db(query).select() > json_list = gluon.contrib.simplejson.dumps(rows.as_list(), default = str, > sort_keys = True) > return dict(results = XML(json_list) ) > > """ > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/simplejson_rows_as_list > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/simplejson_rows_as_list.json > """ > > def response_json_rows_as_list(): > query = (db.auth_user.id > 0) > rows = db(query).select() > return response.json(rows.as_list() ) > > """ > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/response_json_rows_as_list > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/response_json_rows_as_list.json > """ > > @request.restful() > def restful_json_rows_as_list(): > def GET(): > query = (db.auth_user.id > 0) > rows = db(query).select() > return response.json(rows.as_list() ) > return locals() > > """ > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/restful_json_rows_as_list > curl -X GET --user admin:password -i > http://127.0.0.1:8000/test/api/restful_json_rows_as_list.json > """ > > is there any different in performance or anything between the way to > return json ? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: request.requires_https() while using taskqueue.add() in GAE possible?
You can conditionally set request.requires_https() depending on whether the request comes from a GAE Task Queue. Apparently, Task Queue requests will include HTTP headers as noted here: https://stackoverflow.com/a/14838696. So, you can do something like: if 'HTTP_X_APPENGINE_TASKNAME' not in request.env: request.requires_https() Note, any client can send those headers, so if you are worried about someone spoofing such a request and then getting an HTTP connection, you might instead be able to detect Task Queue requests by IP address. According to the docs, Task Queue requests come from IP address 0.1.0.2 <https://cloud.google.com/appengine/docs/standard/python/taskqueue/push/creating-handlers#writing_a_push_task_request_handler>. So, the code would be: if request.env.remote_addr != '0.1.0.2': request.requires_https() Anthony On Sunday, September 17, 2017 at 2:10:27 PM UTC-4, Robert Porter wrote: > > If I use Google's taskqueue.add(), it keeps giving me a 303 error over and > over in the logs because it tries to use the HTTP version of the page the > POST is sent to, but I have request.requires_https() in my db.py. I can't > find a way for taskqueue to attempt an HTTPS connection. > > Removing request.requires_https() solves the issue, but isn't quite ideal. > > Anyone know a way around this? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
Did you reload routes or restart the server? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to customize widgets to act like Onsen UI components
On Saturday, September 16, 2017 at 4:23:43 PM UTC-4, Bernardo Leon wrote: > > Awesome as always Anthony Thank you! > > Yes I am talking about the SQLFORM Field objects. > > So I will need to create a Widget by subclassing FormWidget and return the > Ons tag object and later monkey patch. I will try this way. Thank you for > your ideas :) > Note, you don't have to monkey patch SQLFORM.widgets -- that's only if you want your custom widgets to be used by default without having to do: Field(..., widget=my_custom_widget) Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to customize widgets to act like Onsen UI components
If you are talking about using SQLFORM with a DAL table, when you define Field objects, you can specify a custom widget via the "widget" argument -- it must be a callable object that takes a Field object and a value. For more details, see http://web2py.com/books/default/chapter/29/07/forms-and-validators#Widgets. Also, you can create any custom HTML tag using the TAG helper: TAG['ons-input'](_type='text', _value='hello') produces: Note, if you simply use the TAG helper to generate markup, you won't get the validation behavior of the standard INPUT helper. As an alternative, you can create a custom tag based on the INPUT helper: class OnsInput(INPUT): tag = 'ons-input' You could then do: OnsInput(_type='text', _value='hello', requires=db.myfield.requires) The above will produce the same HTML markup, but the resulting Python object will also be able to validate its input. You could do the same for the SELECT helper. Based on the above, you could create custom widgets -- see the various widget classes in gluon.sqlhtml. Once you've got some custom widgets, you could then monkey patch SQLFORM.widgets by overwriting some or all of its items with your custom classes -- then your custom widgets will be the defaults used by SQLFORM. Anthony On Friday, September 15, 2017 at 10:46:38 PM UTC-4, Bernardo Leon wrote: > > I have been researching about UI Frameworks and stumbled upon Onsen UI > <https://onsen.io/>. It seems easy and provides good results but to use > this UI Framework I need to use their components which are html tags. > > If I have a field that is rendered as an html input how can I customize > its widget so I can use instead of and so on? Thank you! > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: web2py 2.15.4 is OUT
Looks like there's already an issue about that: https://github.com/web2py/pydal/issues/480 Anthony On Thursday, September 14, 2017 at 11:56:26 PM UTC-4, 黄祥 wrote: > > *e.g.* > *models/db.py* > def __before_insert_cash_in(f): > chart_of_account = int(f['chart_of_account'] ) > > # get default value for branch field from coa table field branch > query_coa = (db.chart_of_account.id == chart_of_account) > row_coa = db(query_coa).select().first() > #f['branch'] = '%s' % (row_coa.branch) > f['branch'] = row_coa.branch > > db.cash_in._before_insert.append(__before_insert_cash_in) > db.cash_in.branch.required = True # set True if before insert is fixed > like in 2.14.6 > > *error traceback :* > Traceback (most recent call last): > File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 219, in > restricted > exec(ccode, environment) > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/transaction.py", > line 86, in > File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 414, in > > self._caller = lambda f: f() > File > "/Users/MacBookPro/site/web2py/applications/test/controllers/transaction.py", > line 51, in cash_in > db.cash_in.insert(**db.cash_in._filter_fields(form.vars) ) > File > "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line > 731, in insert > row = self._fields_and_values_for_insert(fields) > File > "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line > 709, in _fields_and_values_for_insert > 'Table: missing required field: %s' % name) > RuntimeError: Table: missing required field: branch > > *temporary solution :* > db.cash_in.branch.required = False > or > db.cash_in.branch.default = 1 > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Storing stuff on request object
It should be OK. The only potential issue is if the framework adds request.some_stuff in the future -- then your app code would be overwriting an attribute used by the framework (unlikely to be an issue if you avoid generic names). Anthony On Friday, September 15, 2017 at 1:10:06 AM UTC-4, Brendan Barnwell wrote: > > Is it considered kosher for controller functions to add their own custom > data to the request object? I didn't see anything in the docs about this. > For instance if a controller wants to do request.some_stuff = 123, is that > "allowed"? > > The reason for this is that I have some library functions called by > controllers that may need access to information that could be in the > request, or they can fall back to a default. I would prefer not to make > these library functions accept this extra information as a parameter, but > rather have them look to see if it is available in the current request, and > use it if so, otherwise fall back to the default. This information would > not normally be available on the request object, but is derived from > request.args, so the controller function could store this "processed" > version of args on the request object for use by other functions later. (I > don't want to store it in session because it really is supposed to be > request-local and shouldn't persist from one request to another.) > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: caching variable data sample
Forgot about that. It's documented here: http://web2py.com/books/default/chapter/29/04/the-core?search=lazy_cache#Warning--Do-not-use-the-current-object-in-global-scope-in-a-module. Yes, that would be the way to go if you want to move the function to a module. Anthony On Friday, September 15, 2017 at 8:15:21 AM UTC-4, Pierre wrote: > > the more digging the deeper one gets : > > > https://groups.google.com/forum/?fromgroups#!searchin/web2py/cache$20in$20module/web2py/AZa5Boj3y3E/_BPMTdXwSaMJ > > and here is the *cache_this* module version : > > from gluon.cache import lazy_cache > > @lazy_cache('data_sample', time_expire=60, cache_model='redis') > def cache_this(): > ... > rows = db(db.atable.id > 0).select(limitby=limitby, cacheable=True) > return rows > > > This seems to do the trick. Is it 'kosher' ? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: caching variable data sample
On Friday, September 15, 2017 at 6:15:44 AM UTC-4, Pierre wrote: > > actually the real function is a little more complex since it returns rows > plus other datas that don't require caching. I tried to move the cache_this > function to a module (don't know if this is orthodox) but then i get a > decorator error: > > @current.cache('data_sample', time_expire=60, > cache_model=current.cache.redis) > attributeError cache object has not attribute redis > Hard to say what's going wrong without seeing your code. But you don't necessarily have to put the function in a module -- it can go in a model or even in the controller (if the function takes no arguments, start its name with a double underscore to prevent it from being exposed as an action). You can even define the function inside the controller function that calls it if that's the only place it is needed. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: How to get rid if the /init/default/ in the URL?
See http://web2py.com/books/default/chapter/29/04/the-core#Parameter-based-system. In routes.py, something like: routers = dict( BASE = dict( default_application='init', default_controller='default', default_function='index' ), init = dict( functions=['list', 'of', 'functions', 'in', 'default', 'controller'] ), ) Anthony On Friday, September 15, 2017 at 2:43:11 AM UTC-4, Joe wrote: > > I've been trying to do this for so long, but with *pythonanywhere* > hosting, it doesn't seem to be possible to get rid of the *init/default/* > part of the URL. > > I think, this nested sub-directories structure is not optimal for SEO and > also makes it difficult to place the *robot,txt* and *sitmap.xml* in a > way that it's easy to find for search engines? > I am not a SEO expert, but I read that this kind of URL structure is not > optimal. > > When I looked at the Web2py website, *which I think is also hosted by > pythonanywhere*, I noticed that, www.web2py.com has not solved this > problem either i.e. http://www.web2py.com/init/default/support > > Is there any way to change this URL structure? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: web2py 2.15.4 is OUT
On Thursday, September 14, 2017 at 9:20:55 PM UTC-4, 黄祥 wrote: > > before_insert callback that insert value to table with required = True is > still error (temporary solution is set required = False, while in 2.14.6 it > works with required = True). > Can you show an example? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: web2py 2.15.4 is OUT
This is a bug. I just submitted a pull request: https://github.com/web2py/web2py/pull/1766 Anthony On Thursday, September 14, 2017 at 4:43:24 AM UTC-4, 黄祥 wrote: > > test SQLFORM.grid() export TSV, return error: > Traceback (most recent call last): > File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 219, in > restricted > exec(ccode, environment) > File "/home/test/web2py/applications/test/controllers/system.py", line > 240, in > File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 414, in > > self._caller = lambda f: f() > File "/home/test/web2py/applications/test/controllers/system.py", line > 60, in user > oncreate, onupdate, ondelete, paginate) > File "applications/test/modules/test_system.py", line 15, in grid_0 > ondelete = ondelete, paginate = paginate) > File "/Users/MacBookPro/site/web2py/gluon/sqlhtml.py", line 2601, in grid > raise HTTP(200, oExp.export(), **response.headers) > File "/Users/MacBookPro/site/web2py/gluon/sqlhtml.py", line 3623, in > export > records = self.represented() > File "/Users/MacBookPro/site/web2py/gluon/sqlhtml.py", line 3574, in > represented > field = self.rows.db[t][f] > File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/base.py", > line 663, in __getitem__ > return self.__getattr__(str(key)) > File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/base.py", > line 670, in __getattr__ > return BasicStorage.__getattribute__(self, key) > AttributeError: 'DAL' object has no attribute '"auth_user"' > > best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: web2py 2.15.4 is OUT
I cannot reproduce the problem. In general, though, code from newer apps should not necessarily be expected to work on older versions of web2py (that is referred to as "forward compatibility", and web2py only promises "backward compatibility"). Anthony On Thursday, September 14, 2017 at 1:04:42 AM UTC-4, 黄祥 wrote: > > trying to run 2.15.4 app in 2.14.6 machine return an error : > Traceback (most recent call last): > File "/home/test/web2py/gluon/main.py", line 445, in wsgibase > serve_controller(request, response, session) > File "/home/test/web2py/gluon/main.py", line 165, in serve_controller > environment = build_environment(request, response, session) > File "/home/test/web2py/gluon/compileapp.py", line 424, in > build_environment > request.env.http_accept_language) > File "/home/test/web2py/gluon/languages.py", line 490, in __init__ > self.set_current_languages() > File "/home/test/web2py/gluon/languages.py", line 563, in > set_current_languages > self.default_t = read_dict(self.default_language_file) > File "/home/test/web2py/gluon/languages.py", line 179, in read_dict > lambda: read_dict_aux(filename)) > File "/home/test/web2py/gluon/cfs.py", line 41, in getcfs > return filter() if callable(filter) else '' > File "/home/test/web2py/gluon/languages.py", line 179, in > lambda: read_dict_aux(filename)) > File "/home/test/web2py/gluon/languages.py", line 164, in read_dict_aux > lang_text = read_locked(filename).replace(b'\r\n', b'\n') > File > "/home/test/web2py/gluon/packages/dal/pydal/contrib/portalocker.py", line > 218, in read_locked > fp = LockedFile(filename, 'rb') > File > "/home/test/web2py/gluon/packages/dal/pydal/contrib/portalocker.py", line > 182, in __init__ > self.file = open_file(filename, mode) > File > "/home/test/web2py/gluon/packages/dal/pydal/contrib/portalocker.py", line > 170, in open_file > f = open(filename, mode) > IOError: [Errno 2] No such file or directory: > '/home/test/web2py/applications/test/languages/default.py' > > the solution is to add default.py on the languages folder > is the new version is not backward compatible ? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Access to github book repositoy
Please review http://web2py.com/books/default/chapter/29/15/helping-web2py#Preparation--using-GitHub. It looks like you are attempting to push commits directly to the web2py book repo. Instead, you should create your own fork of the repo, create a new branch within your fork, push the changes back to your own fork, and then make a pull request from your fork to the web2py repo. Anthony On Thursday, September 14, 2017 at 11:01:58 AM UTC-4, Bernhard Radermacher wrote: > > I tried to upload a small correction to the book as described in chapter > 15 but got the following error: > > $ git push origin [...] > ERROR: Permission to web2py/web2py-book.git denied to [...]. > fatal: Could not read from remote repository. > > Please make sure you have the correct access rights > and the repository exists. > > Please advice. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Get Row Count in Restful Web Services
.parse_as_rest() returns a Row object with one of the attributes being "count" (if you submit a query for multiple records and it is successful): @request.restful() def api(): response.view = 'generic.' + request.extension def GET(*args, **vars): patterns = 'auto' parser = db.parse_as_rest(patterns, args, vars) if parser.status == 200: return dict(content=parser.response, count=parser.get('count')) else: raise HTTP(parser.status, parser.error) ... return locals() The above uses parser.get('count') rather than parser.count because the latter would cause an error if there is no "count" returned. Anthony On Wednesday, September 13, 2017 at 9:03:16 PM UTC-4, Carlos A. Armenta Castro wrote: > > Hi folks > > I want to get the total rows (count) of a query (get request) in a Restful > Web Services ( parse_as_rest ). Is it possible? Or I need to construct my > own custom method for this purpose? > > I know I can limit the number of records by specifying a limit and offset GET > variables > > http:///api/friends?offset=10&limit=1000 > > > But for certains applications this is not enough (at least for me). > > Thank you in advance > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: caching variable data sample
On Thursday, September 14, 2017 at 9:33:42 AM UTC-4, Pierre wrote: > > the cache select mechanism is full of mystery: > > given book example code: > > def cache_db_select(): > logs = db().select(db.log.ALL, cache=(cache.ram, 60)) > return dict(logs=logs) > > > what happens to next cache_db_select call after the 60 seconds has elapsed > ? > Does it overwrite the previously cached rows ? > It is just using the web2py caching mechanism, which is described here: http://web2py.com/books/default/chapter/29/04/the-core#cache. So, yes, if the time has expired, the old cached value will be replaced with a fresh value. > One need to know a key in order to clear a specific cached value > associated with that key. When performing a cache select no key is being > passed so how to clear a specific cached select item (for instance logs) ? > If you need to manually clear cached select, you should probably not use the above mechanism, as the key used is part of the internal implementation (it is the md5 has of the database URI plus the raw SQL query). Instead, you should set cacheable=True in the .select() call, and then just cache the resulting Rows object using cache.ram() with whatever key you like. > this gives me nerve crisesIt should be simple to do a simple thing > however one week digging this and I didn't move 1 inch ahead > Maybe you should have asked a week ago. ;-) Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: caching variable data sample
Looks like you want to cache the results of the entire function -- so why not do that: @cache(some_key, time_expire=60, cache_model=cache.ram) def cache_this(): ... rows = db(db.atable.id > 0).select(..., cacheable=True) return dict(rows=rows) Just be sure to set cacheable=True, which will make the entire Rows object cacheable. Anthony On Wednesday, September 13, 2017 at 4:09:23 PM UTC-4, Pierre wrote: > > purpose is to keep a single renewable pseudo-random data sample live > > the w2p books describes a situation of a constant query : > http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=caching+selects#Caching-selects > def cache_db_select(): > logs = db().select(db.log.ALL, cache=(cache.ram, 60)) > return dict(logs=logs) > > now suppose every call a different query like here : > > def cache_this(): > nget = somevalue > kount = db(db.atable.id > 0).count() > offset = randint(0, kount - nget) > limitby = (offset, offset + nget) > rows = db(db.atable.id > 0).select(limitby=limitby, cache=(cache.redis, > 60)) > return dict(rows=rows) > > > > this accumulates cached 'material' and returns a different rows on every call > how do I make *cache_this* behave like the book example ? > > I could cache kount and offset variables as well : > > kount = db(db.atable.id > 0).count(cache=(cache.redis, 60)) > offset = cache.redis('offset', lambda: randint(0, kount-nget), > time_expire=60) > > > but i suppose this would lead to a synchronization problem and thus possible > duplicate cached select > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Possible problem with loading and installing compiled applications in web2py
OK, it's a bug. I have submitted a pull request to fix it: https://github.com/web2py/web2py/pull/1763. For now, "Pack compiled" will not work because compiled views will not be executed in apps containing only compiled files. As a temporary workaround, you can compile an app and then pack the whole app (not just the compiled files). In that case, the compiled views will be executed, but the non-compiled views need to be present (the problem is that the code checks for the existence of the non-compiled view even though it will ultimately execute the compiled view). Anthony On Wednesday, September 13, 2017 at 4:45:44 AM UTC-4, benjaminato...@gmail.com wrote: > > Hi Anthony > > Many thanks for your response. > > As I mentioned to Dave S above, I deliberately (and specifically) chose > this example of downloading the MacOs version (for Normal Users) directly > from the web2py website and compiling - and then reloading - the 'Welcome' > application to demonstrate the problem as simply and clearly as I thought > possible. > > I therefore tried to - tautology alert! - *exactly mimic* what any > standard user would expect to do and see what would happen. So I - > deliberately - did not restart the web server or reload routes or anything > else for that matter. (However, as it happens when I did restart the web > server the problem still remained). > > Anyway, I am still a bit puzzled! > > Cheers > > > On Tuesday, 12 September 2017 02:22:59 UTC+1, Anthony wrote: >> >> Did you reload routes or restart the web server? >> >> On Monday, September 11, 2017 at 8:31:32 PM UTC-4, benjami...@gmail.com >> wrote: >>> >>> Today I came across some unusual behaviour in web2py when I tried to >>> install a compiled web2py application. Coming home I decided to see if I >>> could replicate the same problem on my Mac (running macos Sierra) and found >>> some equally unusual behaviour. >>> >>> *The problem can be easily demonstrated:* >>> >>> 1. From the web2py website *I downloaded the Mac version of web2py* >>> (for Normal Users) currently version >>> 2.15.4-stable+timestamp.2017.09.02.04.02.22 (Running on Rocket 1.2.6, >>> Python 2.7.3) >>> >>> 2. From the web2py administrative interface *I then compiled the >>> ‘welcome’ application* which is a standard application which comes with >>> web2py >>> >>> *3. I then ‘Packed’ this newly created compiled version of the standard >>> 'welcome' application* >>> >>> 4. I then *Uploaded and installed this newly created compiled >>> application using a different name for the application* >>> >>> 5. The original uncompiled ‘welcome’ application still works but the >>> compiled version of the same application gives: >>> >>> invalid view (default/index.html) >>> >>> Obviously all of this is done on the same (i.e. one) machine with the >>> same web2py version, Python etc and yet the compiled version will not work >>> but the uncompiled version will. >>> >>> Am I missing something obvious? >>> >>> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Has the result of a datetime Field changed?
SQLFORM.factory creates a dummy DAL table via DAL(None). A change was made so that auto-validators no longer get applied to fields with DAL(None), so no fields in a SQLFORM.factory table will get the usual default DAL validators. Datetime fields typically get a default IS_DATETIME() validator (wrapped in IS_EMPTY_OR()), and that is what caused the conversion to a datetime object in the previous version of web2py. The IS_DATETIME() validator is no longer being added, so we no longer get the conversion. This should be corrected somehow. I've posted on the developers list to get a discussion going: https://groups.google.com/forum/#!topic/web2py-developers/aX6CiPi4Dh0. In the meantime, you can explicitly add the validator: SQLFORM.factory(Field('startzeit', 'datetime', requires=IS_EMPTY_OR( IS_DATETIME( Alternatively, you can do something like this: def sqlform_factory(*fields, **attributes): from gluon.dal import _default_validators db = DAL(None) db.validators_method = lambda f: _default_validators(db, f) table = db.define_table('no_table', *fields) return SQLFORM.factory(*table, **attributes) And then: form = sqlform_factory(Field('startzeit', 'datetime')) Anthony On Monday, September 11, 2017 at 3:53:52 PM UTC-4, mweissen wrote: > > What is the type of the result of a Field(...;'datetime') ? > > I think, it should be "datetime" (and I am shure it has been in version > 2.14.x), but web2py 2.15.4 delivers a "str". > > def dttest2(): > form = SQLFORM.factory(Field('startzeit', 'datetime')) > if form.process().accepted: > return \ > str(isinstance(form.vars.startzeit,datetime.datetime)) > return dict(form=form) > > > The result is "False" > > Regards Martin > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: data represent in views is loaded faster using for loop python rather than using response json
> > *views/default/index.html* > ... >
[web2py] Re: How to use flatpickr in web2py in a custom form
Just follow the flatpickr documentation: https://chmln.github.io/flatpickr/getting-started/ Keep in mind that web2py will add class "date" to date inputs and "datetime" to datetime inputs, so you can use those as selectors. Also, be sure not to load the default web2py calender.js file (otherwise, the default web2py picker will interfere). Anthony On Tuesday, September 12, 2017 at 5:54:08 AM UTC-4, Oasis Agano wrote: > > > I have created a custom html form and i want to use flatpickr as the > datepicker inside it, > then send the data to web2py in a date field. > how can i integrate flatpickr on the form to work with web2py date fields. > > kr, > Oasis > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: web2py 2.15.4 is OUT
On Tuesday, September 12, 2017 at 8:39:16 AM UTC-4, 黄祥 wrote: > > just tested that maxtextlengths doesnt have any effects, the long field > value still have ... > *e.g.* > grid = SQLFORM.smartgrid(..., maxtextlengths = {'table_name.field_name' : > 350} ) > is it correct or should i just used maxtextlength = 350 ? > Most of the smartgrid arguments that correspond to grid arguments are actually dictionaries with table names as keys, so it should be: maxtextlengths = {'tablename': {'field_name': 350}} Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Possible problem with loading and installing compiled applications in web2py
Did you reload routes or restart the web server? On Monday, September 11, 2017 at 8:31:32 PM UTC-4, benjaminato...@gmail.com wrote: > > Today I came across some unusual behaviour in web2py when I tried to > install a compiled web2py application. Coming home I decided to see if I > could replicate the same problem on my Mac (running macos Sierra) and found > some equally unusual behaviour. > > *The problem can be easily demonstrated:* > > 1. From the web2py website *I downloaded the Mac version of web2py* (for > Normal Users) currently version 2.15.4-stable+timestamp.2017.09.02.04.02.22 > (Running on Rocket 1.2.6, Python 2.7.3) > > 2. From the web2py administrative interface *I then compiled the > ‘welcome’ application* which is a standard application which comes with > web2py > > *3. I then ‘Packed’ this newly created compiled version of the standard > 'welcome' application* > > 4. I then *Uploaded and installed this newly created compiled application > using a different name for the application* > > 5. The original uncompiled ‘welcome’ application still works but the > compiled version of the same application gives: > > invalid view (default/index.html) > > Obviously all of this is done on the same (i.e. one) machine with the same > web2py version, Python etc and yet the compiled version will not work but > the uncompiled version will. > > Am I missing something obvious? > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Has the result of a datetime Field changed?
On Monday, September 11, 2017 at 6:15:50 PM UTC-4, Dave S wrote: > > > > On Monday, September 11, 2017 at 12:53:52 PM UTC-7, mweissen wrote: >> >> What is the type of the result of a Field(...;'datetime') ? >> >> I think, it should be "datetime" (and I am shure it has been in version >> 2.14.x), but web2py 2.15.4 delivers a "str". >> >> > Which DB engine are you using? In SQLite, a string is the native > implementation, no? > There's no DB here -- it's SQLFORM.factory. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: HTML5 widgets on SQLFORM.factory
On Monday, September 11, 2017 at 4:30:40 PM UTC-4, Fabiano Almeida wrote: > > Hi @ll! > > How to use HTML5 widgets on SQLFORM.factory? > > I have this peace of code: > form = SQLFORM.factory(Field('year', 'integer', label='Year')) > > I like use this HTML5 input type="number" widget. > You can do: Field('year', 'integer', label='Year', widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _type='number' )) You could instead use SQLFORM.widgets.integer.widget (which is the default for integer fields), but that would set class="integer", which would activate web2py's built-in integer validator, which you may not want. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.