[web2py] Re: web2py: How to execute further code after ajax call

2022-08-13 Thread Anthony
FYI, already answered at https://stackoverflow.com/a/73338318/440323.

On Saturday, August 13, 2022 at 10:37:06 PM UTC-4 JPlata wrote:

> 
>
> I have two dropdown/select widgets on a form. I am trying to set the 
> options of the second select through an ajax call in jQuery, and then 
> execute further code. The ajax call is successful and correctly sets the 
> second select options, but it seems the code after the ajax call is not 
> executed at all. How to correct this?
>
> view:
>
>
> {{extend 'layout.html'}}` {{=title}} /This is the 
> library/edit_user.html template {{=grid}}  
> jQuery("#no_table_region_id").change(function(){ region_id = $(this).val(); 
> branch_id = jQuery('#no_table_branch_id').val(); ajax("{{=URL('library', 
> 'branches')}}" + '?region_id=' + region_id, [], 'no_table_branch_id'); 
> jQuery('#no_table_branch_id').val(branch_id); # this does not execute }); 
> jQuery(document).ready(function(){ // todo: solve the unsettable branch_id 
> jQuery("#no_table_region_id").change(); });  
>
> controller:
>
> def branches(): if request.vars.region_id: branches = 
> db(db.branch.region_id==request.vars.region_id).select(db.branch.ALL) 
> ops1 = [''] ops = ops1 + [f" 'id']}>{i['branch_name']}" for i in branches] else: ops = '' 
> return ops 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/4b1863dc-4f9b-41d8-9d10-2c9e2c971662n%40googlegroups.com.


[web2py] Re: html helper: CODE (scroll or word-wrap)

2021-10-04 Thread Anthony
As noted in the CODE documentation 
<http://web2py.com/books/default/chapter/29/05/the-views#CODE>, you can 
pass in a styles dictionary to override the default styles controlling the 
display of the code. To see the keys of that dictionary that can be used to 
override various styles, see the source code 
at https://github.com/web2py/web2py/blob/master/gluon/highlight.py#L192 
and https://github.com/web2py/web2py/blob/master/gluon/highlight.py#L284.

In particular, the default styles for the "CODE" key (which get applied to 
each pre element) are:

'''
font-size: 11px;
font-family: Bitstream Vera Sans Mono,monospace;
background-color: transparent;
margin: 0;
padding: 5px;
border: none;
overflow: auto;
white-space: pre !important;
'''

Notice that white-space is set to pre, which only wraps at newlines and  
elements. You can override that by supplying a custom set of "CODE" styles:

code_styles = '''
font-size: 11px;
font-family: Bitstream Vera Sans Mono,monospace;
background-color: transparent;
margin: 0;
padding: 5px;
border: none;
overflow: auto;
white-space: pre-wrap;
'''

code = CODE(my_code, styles=dict(CODE=code))

The above sets white-space to pre-wrap, which will allow wrapping (though 
note that it will not preserve indentation on the wrapped lines, so may not 
look great).

To add scrollbars, you can simply set the overflow CSS property on the 
container element:

div = DIV(CODE(my_code), _style="width:50%; overflow: scroll")

Given the above, if the table created by CODE exceeds the width of the 
containing div, a horizontal scrollbar will be added. Of course, the above 
can also be achieved via CSS rules in a stylesheet.

Anthony

On Sunday, September 19, 2021 at 7:32:39 AM UTC-4 lucas wrote:

> hello one and all,
>
> using the CODE() html helper, how can we get either a scrollbar enabled 
> when the code window doesn't fit in its container, OR, word-wrap enabled to 
> soft linefeed long lines of code?  i see that it outputs a table of the 
> scripted code but are there setting to facilitate the latter two 
> possibilities?
>
> thank you in advance, lucas
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/098611c4-5e19-435c-8e7f-bbdcde43c241n%40googlegroups.com.


[web2py] Re: Twinning tables in DAL

2021-10-04 Thread Anthony
See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Table-inheritance.

On Saturday, October 2, 2021 at 6:21:42 PM UTC-4 snide...@gmail.com wrote:

> I need a reminder:
>
> If I want a given table structure to be used in multiple tables (different 
> instances existing at the same time), how do I set up my model?  For small 
> tables (lines of def) and a small number of tables, I can do a block copy, 
> but is there a more, um, dynamic way to do this?
>
> /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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d9547bfe-50ba-406a-a7c3-9942b9a0ef46n%40googlegroups.com.


[web2py] Developers

2020-08-21 Thread Anthony Smith
Hi are there any programmers in Australia looking for work 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/157d048d-99b9-4ff4-bae0-38c1712e4aaen%40googlegroups.com.


[web2py] Re: Why URL(..., scheme=True, ...) is implemented differently than request.is_https?

2019-07-17 Thread Anthony
Feel free to submit a pull request. Or just set scheme='https' if you know 
it is HTTPS.

Anthony

On Tuesday, July 16, 2019 at 4:31:06 AM UTC-4, Ray (a.k.a. Iceberg) wrote:
>
> Hi there,
>
> I tend to use
>
> URL(..., scheme=True, ...)
>
> in my apps to generate an absolute URL, as documented here 
> <http://web2py.com/books/default/chapter/29/04/the-core#Absolute-urls>.
>
> However, one of my app which has been deployed behind Apache wsgi with 
> https, I noticed that the generated absolute URLs still use non-secure 
> "http://...;.
>
> It is said that there can be some special situation that the wsgi setting 
> would be inaccurate 
> <https://stackoverflow.com/questions/43906350/djangos-request-meta-getwsgi-url-scheme-returns-http-instead-of-https>.
>  
> However my question here for web2py is, why URL(..., scheme=True, ...) is 
> implemented to depend on wsgi_url_scheme ONLY 
> <https://github.com/web2py/web2py/blob/R-2.18.3/gluon/rewrite.py#L207>, 
> while the is_https is more sophisticated 
> <https://github.com/web2py/web2py/blob/R-2.18.3/gluon/main.py#L366-L367>? 
> And, why does URL(..., scheme=True, ...) NOT depend on the more 
> sophisticated is_https instead?
>
> Regards,
> Ray
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f495a9c3-97c7-4e02-a3e0-f1429b266729%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Error in app: the variable was lost

2019-06-22 Thread Anthony
Can you show the full traceback?

On Saturday, June 22, 2019 at 3:25:23 AM UTC-4, Константин Комков wrote:
>
> In my controller I have function:
> def send_app():
> if session.abit_email is None:redirect('
> https://oas.timacad.ru/application', client_side=True)
> const = {rec.NAME:rec.TEXT for rec in 
> db((db.t_const.NAME=='RECTOR_RANKU') 
> | (db.t_const.NAME=='PREDSEDU') | (db.t_const.NAME=='VUZ')).select(
> db.t_const.NAME,db.t_const.TEXT)}
> rectorRank = const['RECTOR_RANKU']
> rectorName = const['PREDSEDU']
> *vuzName* = const['VUZ']
> statement=create_application_for_edit(rectorRank,rectorName,vuzName)
> ...
> and it's code create_application_for_edit function:
> def create_application_for_edit(rectorRank,rectorName,vuzName):
> ...
> if session.edu_course_name!='Без курсов':
> edu = edu + 'Закончил(-а) подготовительные курсы {0}: {1}. 
> '.format(*vuzName*,session.edu_course_name)
> ...
> Today I see one user get error 10 times:
> NameError(name 'vuzName' is not defined) 
> After that I see automatic letter from him on email. It means that error 
> was and something happened and error was gone and that user can send 
> automatic letter from my function. How it is possible? 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/da61f285-7624-4783-900a-a25a03171570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: orderby=['alias'] - works in sqlite, but not in postgres

2019-06-18 Thread Anthony
On Tuesday, June 18, 2019 at 11:04:16 AM UTC-4, Vlad wrote:
>
> Anthony, it works like a charm, thank you very much!! 
>
> (Val's solution with also worked great, but it felt awkward to use the 
> whole thing when an alias was created, so emotionally this solution with 
> alias feels better :)
>

You can always do:

sum = db.cart_sharing.stats.sum()

And then use sum in multiple places.
 

> On a side note, for SQLite orderby=['~shares'] works perfect - it indeed 
> sorts it out properly. Just in case I've verified it again now.
>

I suppose it works in your case, as you are sorting integers, so the 
bitwise negation yields the expected order. However, it won't work in all 
cases (e.g., sorting strings). It is simply not the appropriate syntax for 
ordering in SQL.
 

> By the way, Val's solution was orderby=[~db.cart_sharing.stats.count()] - 
> with tilda, and it worked even in Postgres. Somehow tilda doesn't work 
> specifically with an alias - but without an alias it's just fine on both 
> dbs.
>

~db.cart_sharing.stats.sum() is Python code, not SQL. Here, the ~ is part 
of the DAL syntax, and the DAL translates that to:

SUM("cart_sharing"."stats") DESC

So, Postgres never sees the tilde, only "DESC".

But in any case, orderby=['shares DESC'] works everywhere flawlessly and 
> feels good too, so it's a winner :)
>

Note in this case, 'shares DESC' is just a string, not Python code. The DAL 
therefore simply passes that string directly to the database as SQL code. 
Also, note there is no reason to put it inside a list.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d89ca392-0d5f-4320-81b5-633ca95d51c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: orderby=['alias'] - works in sqlite, but not in postgres

2019-06-18 Thread Anthony
In SQLite, the tilde (~) is a unary operator used for bitwise negation. If 
used as a prefix for an order by column, SQLite will not throw an error (as 
it is a valid operator), but nor will sort they way you expect. In 
Postgres, the tilde is not a unary operator but a regular expression 
operator, so when used in this way, it will throw an error. In any case, in 
SQL, "DESC" is used to indicate descending order ("ASC" for ascending).

So, you can do:

orderby='shares DESC'

Anthony

On Monday, June 17, 2019 at 11:48:51 PM UTC-4, Vlad wrote:
>
> This works perfect in SQLite:
>
>rows = db(query).select(db.cart_sharing.created_by.with_alias('sharer'
> ),
>db.cart_sharing.stats.count().with_alias(
> 'carts'),
>db.cart_sharing.stats.sum().with_alias('shares'
> ),
>groupby=db.cart_sharing.created_by,
>orderby=['~shares'])
>
>
> 'shares' is alias to sum(), and sqlite understands exactly what's needed - 
> sorts by the number of shares. 
>
> Posgres doesn't like it: 
>column "shares" does not exist 
> LINE 1: ...NULL) GROUP BY "cart_sharing"."created_by" ORDER BY ~shares; ^
>
> What's the proper DAL syntax for such a thing compatible with Postgres? 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1defc9ec-6991-4170-96d4-997b5d03c60e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: T() in modules

2019-06-18 Thread Anthony
See 
http://web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules.
 
You can use current.T.

Anthony

On Tuesday, June 18, 2019 at 6:39:21 AM UTC-4, 黄祥 wrote:
>
> web2py™ Version 2.18.5-stable
> tryin to use T() in modules
> Traceback (most recent call last):
>   File "/Users/sugizo/learn/python/web2py/gluon/restricted.py", line 219, 
> in restricted
> exec(ccode, environment)
>   File 
> "/Users/sugizo/learn/python/web2py/applications/test/controllers/api.py", 
> line 4, in 
> import test_db
>   File "/Users/sugizo/learn/python/web2py/gluon/custom_import.py", line 74
> , in custom_importer
> modules_prefix, globals, locals, (itemname,), level)
>   File 
> "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", 
> line 59, in 
> format = lambda r: \
>   File 
> "/Users/sugizo/learn/python/web2py/gluon/packages/dal/pydal/base.py", 
> line 592, in define_table
> table = self.lazy_define_table(tablename, *fields, **kwargs)
>   File 
> "/Users/sugizo/learn/python/web2py/gluon/packages/dal/pydal/base.py", 
> line 633, in lazy_define_table
> on_define(table)
>   File 
> "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", 
> line 36, in on_define_address
> table.zip_code.requires = IS_EMPTY_OR(IS_MATCH('^\d{5,5}$', 
> error_message = T('not a Zip Code') ) )
> NameError: name 'T' is not defined
>
> tryin to import languages but still got an error
> from gluon.languages import *
>
> Traceback (most recent call last):
>   File "/Users/sugizo/learn/python/web2py/gluon/restricted.py", line 219, 
> in restricted
> exec(ccode, environment)
>   File 
> "/Users/sugizo/learn/python/web2py/applications/test/controllers/api.py", 
> line 4, in 
> import test_db
>   File "/Users/sugizo/learn/python/web2py/gluon/custom_import.py", line 74
> , in custom_importer
> modules_prefix, globals, locals, (itemname,), level)
>   File 
> "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", 
> line 7, in 
> from gluon.languages import *
> AttributeError: module 'gluon.languages' has no attribute 'translator'
>
> any hints ?
>
> thx n 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/159718bc-96f8-4d8c-8348-f7696b163e77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how safe is it to rely on a value stored as a session variable?

2019-06-07 Thread Anthony
Users can neither read nor write to the session (even cookie based 
sessions, which are encrypted), so it is "safe" in that regard. Of course, 
we don't know what your app code is writing to the session -- if you take 
user input and write it to the session, then it may not be safe.

Anthony

On Thursday, June 6, 2019 at 10:11:19 PM UTC-4, Vlad wrote:
>
> I don't really understand how it works internally, so wondering if it's 
> safe to rely on a value stored as a session storage variable. 
> More specifically, I am authorizing one user to do certain actions on 
> behalf of another user, and the currently assumed user is stored in 
> session.user (even if auth.user_id is somebody else). 
> If somebody can hack session and change the value of session.user - it 
> would be potentially dangerous situation, so if it's not safe - I would 
> have to figure out something else.It's just easy and tempting to use some 
> variables in a session. 
> Any ideas on how safe it is? 
>
> p.s. I don't care if somebody can read it - my only concern is that they 
> shouldn't be able to overwrite it, because this would give them authority 
> to perform certain actions.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/dcdff220-c9dd-4273-9b4f-028fe56b0489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: auth.settings.login_next doesn't redirect after login -

2019-06-07 Thread Anthony
On Thursday, June 6, 2019 at 3:54:59 PM UTC-4, Vlad wrote:
>
> What could be the reason the following code wouldn't redirect to the 
> appropriate URL after login? (still brings to default/index page)
>
> def login_to_url():
>
>auth.settings.login_next=URL(request.args(0),request.args(1))
>
>logger.warning(auth.settings.login_next)
>
>redirect(URL('default','user',args='login'))
>
>
Above you set the login_next setting inside the login_to_url() action but 
then redirect to /default/user. The redirect results in the browser sending 
a new HTTP request to web2py, and in that new request, your setting is not 
made. Instead, maybe try:

def login_to_url():
   login_next = URL(request.args(0), request.args(1))
   redirect(URL('default','user', args='login', vars=dict(_next=login_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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1457f394-aa1a-458c-935d-e6ddf4888e24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to make this code work ...

2019-06-04 Thread Anthony
What are you trying to do? That code should work fine in web2py, as it's 
just Javascript. You just need to have it call a web2py URL. Of course, 
web2py includes some built-in mechanisms for handling Ajax requests, such 
as the ajax() Javascript function and the LOAD() helper to create Ajax 
components.

Anthony

On Tuesday, June 4, 2019 at 3:23:11 PM UTC-4, Ben Duncan wrote:
>
> Ok, the following is code from w3 schools:
> https://www.w3schools.com/js/js_ajax_intro.asp
>
> The code is as follows :
>
> 
> 
> 
>
> 
> The XMLHttpRequest Object
> Change Content
> 
>
> 
> function loadDoc() {
>   var xhttp = new XMLHttpRequest();
>   xhttp.onreadystatechange = function() {
> if (this.readyState == 4 && this.status == 200) {
>   document.getElementById("demo").innerHTML =
>   this.responseText;
> }
>   };
>   xhttp.open("GET", "ajax_info.txt", true);
>   xhttp.send();
> }
> 
>
> 
> 
>
> The question is how do I get this code to run under web2py ?
>
> Thanks ...
>
> *Ben Duncan*
> DBA / Chief Software Architect 
> Mississippi State Supreme Court
> Electronic Filing Division
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/9b9fa219-3038-4d61-9206-a5ab134f783e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: web2py delimiters conflict with vue.jsz

2019-06-04 Thread Anthony
See response.delimiters 
at http://web2py.com/books/default/chapter/29/04/the-core#response. You can 
set it in a model file to apply to all views, or within a particular 
controller or view to apply to a specific view.

Anthony

On Tuesday, June 4, 2019 at 2:20:30 PM UTC-4, Craig Matthews wrote:
>
> I am currently running web2py Version 
> 2.14.6-stable+timestamp.2016.05.10.00.21.47.
>
> Even though that is old, it is meeting my needs.
>
> I am currently learning vue.js and hoping to include it in my offerings.
>
> The obvious problem is that both web2py and vue.js use "{{" and "}}" as 
> delimiters in their templates.
>
> Is there a single place in web2py that I can change this to something else?
>
> In web2py\gluon\globals.py there is:
> class Response(Storage):
> and within the __init__ there is:
> self.delimiters = ('{{', '}}')
>
> Could this be the place?
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1a5e0320-20e8-4e04-93e7-09595ca6cdc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: string vs text db field question

2019-06-04 Thread Anthony
SQLite doesn't make a distinction between string and text nor have a length 
limit, so yes, you're just "lucky" at the moment. If you plan to migrate to 
something like Postgres, either explicitly set a higher limit or just use a 
text field.

Anthony

On Tuesday, June 4, 2019 at 5:30:05 AM UTC-4, Vlad wrote:
>
> I've used a string field to keep certain info, and it works just fine, but 
> I've just noticed that the strings I ended up saving in this field were 
> around 1,000 characters long, sometimes even closer to 2,000. 
> According to the docs, the default limit for a string field is 512. The 
> limit doesn't seem to be a problem now, so I am wondering what's the nature 
> of the limit. Is it safe to use longer strings because DAL handles them 
> somehow? Or I'm just lucky at the moment, and should increase the size or 
> switch to a text field? (I am still developing, so using sqlite for the 
> time being)
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/adc52c5a-c85d-44da-8b18-fb67f12c7f42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: submitting a form from a LOAD component - request.post_vars is empty

2019-06-01 Thread Anthony
In order for web2py to submit forms inside LOAD components via Ajax, it 
must set up its own event handler to "trap" the form submission, so it can 
be intercepted -- this is done here: 
https://github.com/web2py/web2py/blob/master/applications/welcome/static/js/web2py.js#L307
.

If you don't want web2py to trap the form, try:



Alternatively, create the entire form via Javascript *after* the component 
has been loaded.

Anthony

On Friday, May 31, 2019 at 3:57:50 PM UTC-5, Vlad wrote:
>
> sorry for keeping posting about this. I am just totally stuck. I am sure 
> that I am missing something very basic. Here is the complete code: 
>
>  "payment-form2">
>Submit
> 
>
>
> 

[web2py] Re: IS_NOT_EMPTY() "takes away" a dropbox with a list of items referenced by a foreign key -

2019-05-19 Thread Anthony
The default validator for a reference field is IS_EMPTY_OR(IS_IN_DB(...)). 
When SQLFORM encounters a field without an explicit "widget" specified but 
with an IS_IN_SET or IS_IN_DB validator, it automatically generates a 
select widget with options derived from the validator.

In your case, you have replaced the default validator with your own, so you 
no longer get the default select widget.

Instead, try just use an IS_IN_DB() validator, which will require the 
selection of a value.

Anthony

On Sunday, May 19, 2019 at 1:38:10 AM UTC-4, Vlad wrote:
>
> In the following table - 
>
> db.define_table('products_group_content',
> Field('products_group','reference 
> products_group',requires=[IS_NOT_EMPTY()]),
> Field('product','reference product'),
> auth.signature)
>
> when I add a record (using grid functionality or in the admin interface) - 
> the products_group field doesn't have a drop box with a list of groups (it 
> has a regular text edit field), even though this field is referencing 
> another table. 
> on the other hand, the product field does have a drop box with a list of 
> products to pick from. 
>
> Why the difference? Seems to me, in both cases the drop box should be in 
> place. I have no clue why requires parameter makes any difference at all. 
> What am I missing?? 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/935daab8-e037-4583-a08b-df03e7f47997%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: A question about ajax function (passing a string parameter over)

2019-05-17 Thread Anthony
On Friday, May 17, 2019 at 5:17:09 PM UTC-4, Vlad wrote:
>
> Also, I think it would be nice if URL helper would have ability to handle 
> this, without a need to figure out the encoding/decoding subject... 
>

You don't need the encoding -- just put the values in the query string.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/e8fba811-0792-4789-b057-da6690053432%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: A question about ajax function (passing a string parameter over)

2019-05-17 Thread Anthony
On Friday, May 17, 2019 at 12:20:37 PM UTC-4, Vlad wrote:
>
> It works almost, but not 100% :) 
>
> with encodeURIComponent :
>
> abc def (test)
> comes back as
> abc_def__test_
>

Please show your exact code. Doesn't sound like you are using the query 
string.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d24a071c-77db-40f3-a991-17b0c2705e90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: A question about ajax function (passing a string parameter over)

2019-05-17 Thread Anthony
On Thursday, May 16, 2019 at 3:43:58 PM UTC-4, Vlad wrote:
>
> I have the following javascript in the view: 
>
> var id = $('#CurrentCartId').text();
> var description = $(this).text();
> var url='{{=URL('cart','description')}}';
> url += '/' + id + '/';
> url += description;
> ajax(url,[],':eval');
>

How about putting the variables in the query string:

const id = $('#CurrentCartId').text();
const description = $(this).text();
const url='{{=URL('cart','description')}}';
ajax(
`${url}?id=${encodeURIComponent(id)}=${encodeURIComponent(description)}`
, [], ':eval');

Then in the controller, access request.vars.id and request.vars.description.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/e574b961-7bc2-4dba-86d4-1f231da4d008%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: new DBAPI in pydal for both web2py and web3py

2019-05-15 Thread Anthony
On Wednesday, May 15, 2019 at 12:53:27 AM UTC-4, Massimo Di Pierro wrote:
>
> We can change the name but api is too ambiguous. Any other idea?
>

Not sure. RESTAPI? HTTPAPI? 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/20f64dc6-1a51-4f95-a5cb-9838bce77fe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: new DBAPI in pydal for both web2py and web3py

2019-05-14 Thread Anthony
Looks great. You might want to consider an alternative name to avoid 
confusion with the Python DB-API 
 specification (maybe 
just call the class API -- i.e., pydal.API rather than pydal.DBAPI).

On Tuesday, May 14, 2019 at 2:18:42 AM UTC-4, Massimo Di Pierro wrote:
>
> You may have missed this but there is a new functionality in PyDAL that 
> allows you to create very powerful APIs. It is called DBAPI.
> It is still not 100% stable but it is working and I could use some help 
> testing it.
> web3py's equivalent of appadmin will be called dbadmin (90% done) and it 
> is based on DBAPI.
> Even if primarily designed for web3py it works for web2py too and you can 
> find some preliminary examples below.
> Hope it is self-explanatory.
>
> DBAPI EXAMPLES 
>
> Inspired by GraphQL but not quite the same
>
> Less powerful but simpler to use
>
> Self descriptive (@model=True) and policy based (policy set serverside)
>
> Support complex queries like: 
>
>- name.eq=Clark Kent
>- name.ne=Clark Kent
>- name.gt=Clark Kent
>- name.lt=Clark Kent
>- name.ge=Clark Kent
>- name.le=Clark Kent
>- name.startswith=Clark
>- name.contains=Kent
>- not.real_identity.name.contains=Wayne
>- not.superhero.tag.superpower.description.eq=Flight
>
> Support de-normalization: 
>
>- @lookup=real_identity
>- @lookup=real_identity[name]
>- @lookup=real_identity[name,job]
>- @lookup=identity:real_identity[name,job]
>- @lookup=identity!:real_identity[name,job]
>- @lookup=superhero.tag
>- @lookup=superhero.tag[strength]
>- @lookup=superhero.tag[strength].superpower
>- @lookup=superhero.tag[strength].superpower.description
>
> Fast. Even the most complex query is implemented with at most 2 selects + 
> 1 select for each denormalized link table
> Example Model 
>
> db.define_table(
> 'person',
> Field('name'),
> Field('job'))
>
> db.define_table(
> 'superhero',
> Field('name'),
> Field('real_identity', 'reference person'))
>
> db.define_table(
> 'superpower',
> Field('description'))
>
> db.define_table(
> 'tag',
> Field('superhero', 'reference superhero'),
> Field('superpower', 'reference superpower'),
> Field('strength', 'integer'))
>
> Example Controller 
>
> from pydal.dbapi import DBAPI, Policy
> policy = Policy()
> policy.set('*', 'GET', authorize=lambda tablename, id, get_vars, 
> post_vars:True, allowed_patterns=['*'])
> policy.set('*', 'PUT', authorize=lambda tablename, id, get_vars, 
> post_vars:False)
> policy.set('*', 'POST', authorize=lambda tablename, id, get_vars, 
> post_vars:False)
> policy.set('*', 'DELETE', authorize=lambda tablename, id, get_vars, 
> post_vars:False)
>
> def api():
> return DBAPI(db, policy)(request.method, request.args(0), request.args(1),
>  request.get_vars, request.post_vars)
>
> Example GET URLs 
> /superheroes/default/api.json/superhero 
>
> {
> "count": 3,
> "status": "success",
> "code": 200,
> "items": [
> {
> "real_identity": 1,
> "name": "Superman",
> "id": 1
> },
> {
> "real_identity": 2,
> "name": "Spiderman",
> "id": 2
> },
> {
> "real_identity": 3,
> "name": "Batman",
> "id": 3
> }
> ],
> "timestamp": "2019-05-14T06:14:06.764966",
> "api_version": "0.1"
> }
>
> /superheroes/default/api.json/superhero&@model=true 
>
> {
> "status": "error",
> "timestamp": "2019-05-14T06:14:06.997662",
> "message": "Invalid table name: superhero_amp_@model=true",
> "code": 400,
> "api_version": "0.1"
> }
>
> /superheroes/default/api.json/superhero?@lookup=real_identity 
>
> {
> "count": 3,
> "status": "success",
> "code": 200,
> "items": [
> {
> "real_identity": {
> "name": "Clark Kent",
> "job": "Journalist",
> "id": 1
> },
> "name": "Superman",
> "id": 1
> },
> {
> "real_identity": {
> "name": "Peter Park",
> "job": "Photographer",
> "id": 2
> },
> "name": "Spiderman",
> "id": 2
> },
> {
> "real_identity": {
> "name": "Bruce Wayne",
> "job": "CEO",
> "id": 3
> },
> "name": "Batman",
> "id": 3
> }
> ],
> "timestamp": "2019-05-14T06:14:06.931746",
> "api_version": "0.1"
> }
>
> /superheroes/default/api.json/superhero?@lookup=identity:real_identity 
>
> {
> "count": 3,
> "status": "success",
> "code": 200,
> "items": [
> {
> "real_identity": 1,
> "name": "Superman",
> "id": 1,
> 

[web2py] Re: Compiled pack always includes databases and private dirs. Is there any way to pack w/o those?

2019-05-12 Thread Anthony
Click on the folder to expand.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/6bc22868-d736-4d50-9e60-2b5367cdb8e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: I would like to log of all SQL commands web2py sends to SQLite. Is it possible?

2019-05-05 Thread Anthony
Logger is defined here: 
https://github.com/web2py/pydal/blob/master/pydal/base.py#L254

Debug logging is set up here: 
https://github.com/web2py/pydal/blob/9d30c5a7c65d2fbcf52a9254b9523cba500269dd/pydal/adapters/base.py#L373

Not sure what the problem is. Anyway, as already noted, you can just use 
db._timings.

Anthony

On Sunday, May 5, 2019 at 4:40:04 PM UTC-4, jcrma...@gmail.com wrote:
>
> Just to give you some feedback, I tried adding debug=True to the DAL 
> command and creating a pyDAL logger. Nothing is shown in the logging file. 
> It gets created (so the logging is working) but nothing shows up.
> Also tried pydal instead of pyDAL as the name of the logger with the same 
> result.
>
>
> domingo, 17 de Março de 2019 às 00:26:54 UTC, Anthony escreveu:
>>
>> Also, if you set DAL(..., debug=True), I believe all SQL commands will be 
>> logged to the "pyDAL" logger.
>>
>> Anthony
>>
>> On Saturday, March 16, 2019 at 5:57:47 PM UTC-4, Anthony wrote:
>>>
>>> Commands issued during migration operations are already saved to 
>>> /databases/sql.log. If you want all commands (i.e., queries), note that on 
>>> each request, there is db._timings, which is a list of tuples, where the 
>>> first element of each tuple is the SQL command issued and the second 
>>> element is the amount of time it took to execute. At the end of every 
>>> request, you could dump the contents of db._timings to a log. You can do 
>>> that by assigning a callback function to response._caller(), which wraps 
>>> all calls to controller actions. Note, it will therefore miss any queries 
>>> that are run in views, but it's probably not a good idea to run queries in 
>>> views anyway. You could also set up middleware to do the logging: 
>>> http://web2py.com/books/default/chapter/29/04/the-core?search=_caller#WSGI
>>> .
>>>
>>> Anthony
>>>
>>> On Saturday, March 16, 2019 at 4:54:52 PM UTC-4, João Matos wrote:
>>>>
>>>> Hello,
>>>>
>>>> I would like to log of all SQL commands web2py sends to SQLlite. Is it 
>>>> possible?
>>>>
>>>> Thanks,
>>>>
>>>> JM
>>>>
>>>

-- 
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 pass a query set string or a string with a select/count to be executed in another controller?

2019-05-04 Thread Anthony
In each controller:

from mymodule import shared_function
rows = shared_function(pass, some, args)

Not clear why you instead need to use the session and have another 
controller action involved.

Anthony

On Friday, May 3, 2019 at 8:35:53 AM UTC-4, jcrma...@gmail.com wrote:
>
> That was what I was trying to do.
> The problem is that the queries that were going to be executed in the 
> destination (shared function) vary according to the requesting controller. 
> The query string passed through the session would solve this, but because 
> the only way to execute it in the destination would be to use eval, I 
> dismissed the idea.
>
>
> sexta-feira, 3 de Maio de 2019 às 12:42:05 UTC+1, Anthony escreveu:
>>
>> It might help to show some code. Why don't you just put the shared 
>> function in a model or module and call it directly from each controller?
>
>

-- 
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 pass a query set string or a string with a select/count to be executed in another controller?

2019-05-03 Thread Anthony
It might help to show some code. Why don't you just put the shared function in 
a model or module and call it directly from each controller?

-- 
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 pass a query set string or a string with a select/count to be executed in another controller?

2019-05-02 Thread Anthony
On Wednesday, May 1, 2019 at 4:53:25 PM UTC-4, jcrma...@gmail.com wrote:
>
> Got the answer in the Telegram chat. Using eval.
> It's a dangerous solution but works.
>

So dangerous you probably shouldn't do it.

Also, do you want to use the value of request.args[0] from the original 
request where the query is saved to the session, or from the subsequent 
request where the query is retrieved from the session? Storing the query 
object itself would achieve the former, whereas using eval would achieve 
the latter.

In either case, the best approach is just to store the data needed to 
generate the query in the session (e.g., table and field name, and the 
request.args value). Then construct the query in the second action. There 
is no need to store the query itself (or a text representation of the query 
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: pyDAL -> jsDAL?

2019-04-30 Thread Anthony
There is no SQLite in the browser, unless you are talking about something 
like https://github.com/kripken/sql.js, though that is very heavy and is 
in-memory only. There are a number of packages that provide an abstraction 
over IndexedDB, such as Dexie.js, AlaSQL, Nano-SQL, Lovefield, etc. Maybe 
have a look at their codebases to get a sense of the complexity involved.

Anthony

On Monday, April 29, 2019 at 8:47:36 PM UTC-4, Scott Hunter wrote:
>
>
> The direction from web2py to web3py seems to be applications where the 
> server is responsible for (relatively) static pages which use Javascript 
> for their dynamic aspects & talking to the server via an API, primarily for 
> interaction w/ the database.
>
> In the spirit of Progressive Web Apps, one could imagine getting to the 
> point where instead of making calls to the server, Javascript functions are 
> called instead to interact w/ an SQLite DB under the browser's control. 
>  Doing so via something like pyDAL, but replacing Python with Javascript & 
> only needing to support SQLite would not only ease the burden of writing 
> such code, but make it easier to make a transition between these two DB 
> locations.
>
> I'm actually thinking specifically of being able to deploy a pared-down 
> version of a "normal" application which could perform most of its 
> functionality off-line, and use online access only for transferring 
> information in bulk between the local DB and the one in the cloud.  The 
> more that those applications can share code, the better.  (I've 
> accomplished this goal, somewhat clunkily, by deploying the web2py binary 
> w/ a limited version of the app in the cloud; an approach as I've described 
> above seems that it wouldn't be nearly as brittle.)
>
> Does this make any sense?  Would something like a jsDAL be prohibitively 
> difficult to write, or not really worth the effort?
>

-- 
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: Grid search and clear buttons don't restore request.args. Where can I correct that?

2019-04-29 Thread Anthony
What do you mean by master-child pages? Are you using smartgrid? Can you 
show some code?

On Monday, April 29, 2019 at 6:15:30 PM UTC-4, jcrma...@gmail.com wrote:
>
> Grid search and clear buttons don't restore request.args. Where can I 
> correct that?
>
>
> If using master-child pages, the master grid search works fine (because 
> there are no request.args), but the child grid (which has request.args, 
> from the master record) doesn't because the search and clear buttons don't 
> restore the request.args.
>
>
> web2py 2.18.5
> Python 3.7.1 x86
> Firefox 66.0.3 x64
> Windows 7 Pro x64 SP1+all upds
>

-- 
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: Grid search collects all records from all fields on each request. Isn't this bad for performance?

2019-04-29 Thread Anthony
On Monday, April 29, 2019 at 6:22:26 PM UTC-4, jcrma...@gmail.com wrote:
>
> Grid search collects all records from all fields on each request. Isn't 
> this bad for performance?
>

Are you referring to "reference" fields, which result in a select element 
showing associated values from the foreign table? If so, that is the result 
of the default IS_IN_DB validator given to such fields, which results in a 
select element being created when the field appears in forms as well as the 
search menu. You can override this behavior by putting the validator in a 
list:

db.mytable.myreferencefield.requires = [db.mytable.myreferencefield]

However, in that case, forms and the search menu will simply present a 
numeric input field, and you would need to search by the record ID, so 
probably not very useful. Alternatively, you can specify an autocomplete 
widget, but that won't help in the grid search menu.
 

> Isn't it possible to change this behavior to only load the records when 
> the user selects a specific field to do the search?
>

Feel free to submit a pull request. Alternatively, you can specify both a 
custom search menu and a custom search function via the "search_widget" and 
"searchable" arguments, respectively. For ideas on the former, see 
SQLFORM.search_menu, and for the latter, see SQLFORM.build_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: Grid sorting sorts by id (in case of a FK) instead of shown value (eg. name). Is this normal?

2019-04-29 Thread Anthony
Yes. It shows the values from the foreign table via "recursive selects" 
(i.e., a separate query for each displayed row after the initial set of 
records is fetched from the database), so it is not able to use that 
information for sorting (which would require the initial query to be a join 
with the foreign table).

Anthony

On Monday, April 29, 2019 at 6:26:10 PM UTC-4, jcrma...@gmail.com wrote:
>
> Grid sorting sorts by id (in case of a FK) instead of shown value (eg. 
> name). Is this normal?
>
> The only way I found to correct this behavior was to change the grid's 
> table to a query, where in this query I include all the foreign fields (eg. 
> name) directly and remove al the foreign keys.
> Is this the correct/only way to solve it?
>
>
> web2py 2.18.5
> Python 3.7.1 x86
> Firefox 66.0.3 x64
> Windows 7 Pro x64 SP1+all upds
>

-- 
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: Is it possible to write a virtual method field that modifies the row?

2019-04-26 Thread Anthony
def change_name(row, name):
row.person.update_record(name=name)

The above will update the database and the local Row object.

Anthony

On Friday, April 26, 2019 at 5:00:34 PM UTC-4, Lisandro wrote:
>
> Hi Anthony, thank you for your time.
> I tried the method you suggested, but here is my problem: after calling 
> the method, the row object isn't updated.
>
> row = db.person(1)
> row.change_name('Lisandro')
> print(row.name)
>
> This doesn't print "Lisandro". 
> Instead, it prints the name the person had before the call.
> If I want to print the new name, I have to retrieve the row again like 
> this:
>
> row = db.person(1)
> row.change_name('Lisandro')
> row = db.person(1)
> print(row.name)
>
> I was wondering if it was possible to avoid having to retrieve the record 
> again.
>
>
> El viernes, 26 de abril de 2019, 17:16:10 (UTC-3), Anthony escribió:
>>
>> def change_name(row, name):
>> db(db.person.id == row.person.id).update(name=name)
>>
>> db.define_table('person',
>> Field('name'),
>> Field.Method('change_name', change_name))
>>
>> row = db.person(1)
>> row.change_name('Lisandro')
>>
>> Anthony
>>
>> On Friday, April 26, 2019 at 12:21:28 PM UTC-4, Lisandro wrote:
>>>
>>> I've been working with Virtual Fields for a while, but now I'm 
>>> wondering, how could I write a Virtual Field method that modifies the row 
>>> itself?
>>>
>>> I mean, I would like to do something similar that what the 
>>> .update_record() method does. When you call row.update_record(), the row 
>>> object is updated with the new values. 
>>>
>>> I've tried returning the row object in the method definition function 
>>> but it doesn't work.
>>>
>>> I'm wondering, is it even possible to implement something like that? Any 
>>> comment or suggestion will be much appreciated.
>>>
>>> Thanks!
>>> Warm regards,
>>> Lisandro.
>>>
>>

-- 
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: URL with link to anchor tag

2019-04-26 Thread Anthony
On Friday, April 26, 2019 at 2:25:10 PM UTC-4, Jörg Schneider wrote:
>
> Is it possible to have request args and link like 
> www.domain.org/a/c/index.html#anchor/args ?
>

The "#anchor/args" part of the URL does not get sent to the server. What 
are you trying to achieve? 

-- 
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: Is it possible to write a virtual method field that modifies the row?

2019-04-26 Thread Anthony
def change_name(row, name):
db(db.person.id == row.person.id).update(name=name)

db.define_table('person',
Field('name'),
Field.Method('change_name', change_name))

row = db.person(1)
row.change_name('Lisandro')

Anthony

On Friday, April 26, 2019 at 12:21:28 PM UTC-4, Lisandro wrote:
>
> I've been working with Virtual Fields for a while, but now I'm wondering, 
> how could I write a Virtual Field method that modifies the row itself?
>
> I mean, I would like to do something similar that what the 
> .update_record() method does. When you call row.update_record(), the row 
> object is updated with the new values. 
>
> I've tried returning the row object in the method definition function but 
> it doesn't work.
>
> I'm wondering, is it even possible to implement something like that? Any 
> comment or suggestion will be much appreciated.
>
> Thanks!
> Warm regards,
> Lisandro.
>

-- 
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: Unable to edit grid record if I add @auth.requires_signature() to action. Is this normal?

2019-04-24 Thread Anthony

>
> My though in replacing the @auth.requires_login() with 
> @auth.requires_signature() (I believe @auth.requires_signature() also 
> requires login, correct?) was adding another security layer, but with the 
> limitation you explained, I think I will not do it.
> What is your opinion on this?
>
> With this severe limitation to @auth.requires_signature(), in what 
> situation do you recommend using it?
>

It's not so much a limitation of @auth.requires_signature as it is with 
using it with the grid if there is something in the query string that must 
be protected from tampering.

In any case, it's not clear @auth.requires_signature adds any value over 
@auth.requires_login in this case.

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: Unable to edit grid record if I add @auth.requires_signature() to action. Is this normal?

2019-04-22 Thread Anthony
On Monday, April 22, 2019 at 8:14:10 AM UTC-4, João Matos wrote:
>
> It is called from the menu (models\menu.py). This is the code:
>
> ...
> if auth.is_logged_in():
> response.menu = [
> (T('Home'), False, URL('default', 'index', user_signature=True)),
> (T('Open work orders'), False, URL('open_wo', 'index', 
> user_signature=True)),
> (T('Tables'),
>  False,
>  None,
>  [
> (db.opt_cat._plural, False, URL('opt_cat', 'index', vars={
> 'sid': request.vars.sid}, user_signature=True)),
> ...
>
> Didn't test the sorting or search then, but I tested now and they also 
> don't work, returning the same Not Authorized message.
>

The problem is that you need the grid to generate signed URLs, which it 
does, but it does so without including the query string variables in 
constructing the signature. However, your menu URL does include the query 
string when creating the signature, and your @auth.requires_signature 
decorator also expects the signature to be based on the query string. You 
can try excluding the query string as follows:

@auth.requires_signature(hash_vars=False)

and to create the menu link:

URL('opt_cat', 'index', vars={'sid': request.vars.sid}, user_signature=True, 
hash_vars=False)

Note, that is a little less secure, as the signature will work with any URL 
with a full matching path, even if the query string is different.

Anyway, why do you need signed URLs in this case? Why is 
@auth.requires_login not sufficient?

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: Unable to edit grid record if I add @auth.requires_signature() to action. Is this normal?

2019-04-22 Thread Anthony
When using signed URLs, how do users get to that function (given that the 
URL requires a signature)? How do you construct the URL?

When using @auth.requires_signature(), does sorting and searching the grid 
work? Only edit fails?

Anthony

On Sunday, April 21, 2019 at 12:30:29 PM UTC-4, João Matos wrote:
>
> Here is the correct version (my previous post, which I deleted, was 
> another version):
>
> #@auth.requires_signature()
> @auth.requires_login()
> def index():
> # type: () -> Dict[str, gluon.DIV]
> """Index page.
>
> :return: Dict with grid.
> """
> if session.return_to:
> del session.return_to
>
> session.table = 'opt_cat'
>
> # Hidden fields in grid and edit/view form.
> db.opt_cat.id.readable = False
>
> db.opt_cat.one_opt_only.show_if = db.opt_cat.mandatory == False
>
> if SUPERVISOR_ROLE_ID in auth.user_groups:
> # Uses covering index opt_cat_is_active_name_en.
> # Uses auto index sqlite_autoindex_opt_cat_1.
> grid = SQLFORM.grid(
> db.opt_cat,
> csv=False,
> details=False,
> # Disable delete checkbox in edit form.
> editargs=dict(deletable=False),
> maxtextlength=GRID_COL_LEN_FOR_TEXT,
> ondelete=on_delete,  # Grid only.
> onvalidation=on_validation,  # And onupdate are form only.
> orderby=db.opt_cat.name,
> paginate=session.auth.user.pagination,
> # represent_none='',  # Grid and view form only.
> )  # type: gluon.DIV
> else:
> # Hidden fields in grid and edit/view form.
> db.opt_cat.canceled_on.readable = False
> db.opt_cat.canceled_by.readable = False
> db.opt_cat.cancel_approved_by.readable = False
>
> # Uses covering index opt_cat_is_active_name_en (is_active=?).
> # Uses index opt_cat_is_active_name (is_active=?).
> grid = SQLFORM.grid(
> db.opt_cat.is_active == True,
> create=False,
> csv=False,
> deletable=False,
> details=False,
> editable=False,
> maxtextlength=GRID_COL_LEN_FOR_TEXT,
> orderby=db.opt_cat.name,
> paginate=session.auth.user.pagination,
> # represent_none='',  # Grid and view form only.
> )
>
> # Remove icons from default buttons.
> grid.elements('span.icon', replace=None)
>
> if request.args:
> # Remove delete button.
> grid.element('#delete_with_approval', replace=None)
>
> if not request.args:
> # Sort grid's search fields list.
> grid.element('#w2p_query_fields').components = 
> sort_grid_search_fields_list(grid)
>
> if session.opt_cat_modified_on:
> del session.opt_cat_modified_on
> elif 'edit' in request.args:
> # Edit uses opt_cat Pk.
>
> form = grid.update_form  # type: gluon.sqlhtml.SQLFORM
> # form['hidden'].update(mon=form.record.modified_on)
> # Solves the record changed while editing, but doesn't solve it
> # if the user 1st tries something that returns form.errors (eg.
> # changing a unique field to something that already exists) and
> # only after that he tries to save the record (which was changed
> # by another user). For this the only solution I've found was
> # using a session var.
>
> if not session.opt_cat_modified_on:
> session.opt_cat_modified_on = form.record.modified_on
>
> if not form.record.is_active and not SUPERVISOR_ROLE_ID in auth.
> user_groups:
> session.flash = T('Record was deleted while you were viewing 
> the grid.')
> redirect(URL(user_signature=True))
>
> return dict(grid=grid)
>
>
>
>
> domingo, 21 de Abril de 2019 às 17:22:44 UTC+1, Anthony escreveu:
>>
>> On Sunday, April 21, 2019 at 10:53:08 AM UTC-4, João Matos wrote:
>>>
>>> I wanted to have signed URL everywhere.
>>> For that, I added user_signature=True to all my URL(). The grid has that 
>>> as a default.
>>> At this point everything worked with @requires_login() except one 
>>> special case (I believe this special case may be related to the same issue 
>>> I'm facing with this I describe here).
>>>
>>> Then I added a var called sid (for session id) to every URL() which I 
>>> use to identify the session (this way I'm able to distinguish ebetween 2 
>>> browser tabs).
>>> At this point everything worked with @requires_login() exce

[web2py] Re: Unable to edit grid record if I add @auth.requires_signature() to action. Is this normal?

2019-04-21 Thread Anthony
On Sunday, April 21, 2019 at 10:53:08 AM UTC-4, João Matos wrote:
>
> I wanted to have signed URL everywhere.
> For that, I added user_signature=True to all my URL(). The grid has that 
> as a default.
> At this point everything worked with @requires_login() except one special 
> case (I believe this special case may be related to the same issue I'm 
> facing with this I describe here).
>
> Then I added a var called sid (for session id) to every URL() which I use 
> to identify the session (this way I'm able to distinguish ebetween 2 
> browser tabs).
> At this point everything worked with @requires_login() except the special 
> case I mentioned above.
>
> Then I replaced @auth.requires_login() with @auth.requires_signature() and 
> I'm able to access the grid but not the edit form. I receive a Not 
> Authorized message.
>
> In all these tests I'm logged in.
>
> If I remove the sid var and keep the @auth.requires_signature() everything 
> works.
>
> If I replace the@auth.requires_signature() with @auth.requires_login() and 
> keep the sid var everything works.
>
> Only the combination of both doesn't work.
>

Need to see the code.

-- 
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: Unable to edit grid record if I add @auth.requires_signature() to action. Is this normal?

2019-04-21 Thread Anthony
Can you show your code? I cannot reproduce this exact behavior.

Note, because the default behavior of @auth.requires_signature() is to 
include the query string when creating the signature, any functionality of 
the grid that uses the query string should not work, as the grid does not 
generate signatures for those links.

In any case, the grid already has built-in support for signed URLs for any 
write operations -- do you need more than that?

Anthony

On Saturday, April 20, 2019 at 4:03:17 PM UTC-4, João Matos wrote:
>
> If I replace @auth_requires_login() with @auth.requires_signature() to my 
> index function (controller's main function) where a grid is created, the 
> grid shows up without any issue, but if I try to edit a row, I get a Not 
> Authorized message.
>
> Anyone has any idea why this is happening?
>
> If I replace @auth.requires_signature() with @auth.requires_login() 
> everything works.
>

-- 
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: Where do I find the user/profiel and user/change_password forms?

2019-04-21 Thread Anthony
On Sunday, April 21, 2019 at 7:32:50 AM UTC-4, João Matos wrote:
>
> I'd like to make changes to the user/profile and user/change_password 
> forms, but I can't find them.
>

In the associated methods in tools.py:

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L3646 

-- 
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.smartgrid selectable return string or list

2019-04-20 Thread Anthony
On Saturday, April 20, 2019 at 8:52:01 AM UTC-4, icodk wrote:
>
> Hi Antony
>
> My selectable looks like :
>
> selectable = [('Add 100 to price',lambda ids: redirect(URL('product', 
> 'modify_price', args=request.args, vars=dict(id=ids, inc=100,
>
>
Why do a redirect rather than simply doing the work in the same function? 
Also, this redirect puts the ids in the URL query string, resulting in the 
ultimate update being a GET request rather than a POST -- this is 
undesirable because a refresh of that page will result in the entire 
operation being repeated, which you don't want.
 

>
> and my function in the product controller looks like this:
>
> def modify_price():
>
> if type(request.vars.id) is str:
>
> id_list = request.vars.id.split(',') #convertint to list
>
> else:
>
> id_list = request.vars.id
>
> db(db.product.id.belongs(id_list)).update(product_price=db.product.product_price+request.vars.inc)
>
>
>  Simply following the documentation in the book
>
> I also tried:
>
> selectable=  lambda ids: modify_price
>
>
> But the function neve called
>

It's not that the function never gets called but that the function is not 
written to work this way. The function expects to find ids in 
request.vars.id, but that is actually None in the case where you call it 
this way (the real values are in request.vars.records). Is modify_price a 
controller action that needs to be accessible separately from this 
particular operation? If not, just make it a helper function that accepts 
an "ids" argument, and set selectable=modify_price.

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: Web3py

2019-04-20 Thread Anthony
On Friday, April 19, 2019 at 6:41:34 PM UTC-4, Carlos Cesar Caballero wrote:
>
> Well, that's a really fair concern, I was just mentioning, because I like 
> ORMs and other popular projects like SQLAlchemy includes a DAL (they call 
> it SQL abstraction toolkit) and an ORM on top of it, and if you look at 
> popular web development full stack frameworks, almost all of them are 
> relaying their models to ORMs.
>

The SQLAlchemy ORM adds a lot of functionality that is not available with 
its DAL alone, and most of that extra functionality already exists in 
pyDAL. As far as I can tell, the weppy ORM does not really add any 
functionality to the DAL -- it is mostly an alternative syntax. I'm not 
saying there isn't value there, just that it is a lot of code maintenance 
to take on for maybe only a very modest benefit.

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: Web3py

2019-04-20 Thread Anthony
On Friday, April 19, 2019 at 5:47:31 PM UTC-4, Carlos Cesar Caballero wrote:
>
> Yes, but that's not about the number of code lines, that's about the code 
> organization and readability.
>

At least with the example given, I don't see a lot of difference in 
organization or readability (particularly not enough to warrant 
introduction of the ORM codebase as well as the confusion that can come 
with having multiple ways to do the same thing).

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: Web3py

2019-04-19 Thread Anthony
On Thursday, April 18, 2019 at 6:48:09 PM UTC-4, Carlos Cesar Caballero 
wrote:
>
> Hi Massimo, here is it: https://github.com/cccaballero/pydal-orm. I 
> think including something like this with pydal will be a really good 
> improvement.
>

My only concern is whether the benefits are worth having to adopt all that 
new code (and update it when changes are made to pyDAL). Maybe it should 
remain an external package rather than being folded into pyDAL.

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: Web3py

2019-04-19 Thread Anthony
On Friday, April 19, 2019 at 10:54:11 AM UTC-4, Carlos Cesar Caballero 
wrote:
>
> As almost everything in our world ORMs has advantages and disadvantages. 
> The main criticism about ORMs is that they are leaky abstractions, that 
> means they leaks details that it is supposed to abstract away, because 
> there are times when you just need to use, for example, SQL directly or 
> work with raw rows when making complex queries or improving performance 
> because that is one of the ORMs disadvantages, they include an extra 
> logical layer that, depending on the implementation can affect performance 
> more or less.
>
> But there are lot of people out there using ORMs and this is because they 
> have advantages, compared with PyDAL, mostly when you are using big models, 
> for example, compare this PyDAL model:
>
> def _get_somethig_plus_age(row, extra):
> return row.person.age + extra
>
> db.define_table('person', 
> Field('name')
> Field('age', 'integer')
> Field.Method('get_somethig_plus_age', _get_somethig_plus_age)
> )
>
> against this ORM-style model:
>
> class Person(Model):
> name = Field()
> age = Field('integer')
>
> def get_somethig_plus_age(self, extra):
> return self.age + extra
>
> In an ORM, a model class represents a table, and when you query the DB, 
> you get the class instance objects representing rows. Using this approach 
> you can directly benefit from the advantages of the OOP and the code 
> readability and organization improves a lot, mostly when models starts grow 
> big.
>

In the case of the weppy ORM in particular, though, I think it really is 
just alternative syntax for everything that can already be done via pyDAL, 
typically with the same number of lines of code (note, the above examples 
would have the same number of lines if you added the 
@rowattr('get_something_plus_age') decorator required by weppy to the 
instance method).

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: SQLFORM.smartgrid selectable return string or list

2019-04-19 Thread Anthony
It should be request.vars.records, not request.vars.id.

Note, request.vars is processed by the core framework, not by 
SQLFORM.smartgrid, so it will be a single value if the browser sends only 
one "records" field in the form data and a list otherwise. The core code 
that populates request.vars has no way of knowing that a given field 
containing a single value is supposed to be a list -- that has to be 
handled elsewhere. SQLFORM.smartgrid itself handles this properly, but if 
you are going to intercept request.vars and run some custom code outside of 
the grid, then it is up to you to do the check and convert to a list.

Keep in mind, the "selectable" argument to the grid should be a function 
that takes the list of ids -- presumably you can move your code into that 
function, in which case, you won't have to worry about this, as the grid 
will handle the conversion to a list.

Anthony

On Friday, April 19, 2019 at 9:28:21 AM UTC-4, icodk wrote:
>
> SQLFORM.smartgrid selectable  return string if only one checkbox was 
> slected and returns a list if 2 or more was selected.
> This  inconsitancy force me to check for type before processing can 
> continue
> For example, If I have a button that update selected records in the 
> database call a function that do:
>
>
> db(db.product.id.belongs(request.vars.id)).update(price=db.product.price+request.vars.inc_price)
>
>
> However if only one line selected in the grid request.vars.id is a string and 
> not a list, which cause an error
>
>

-- 
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: Does web2py support SSE (server sent events) from HTML5?

2019-04-16 Thread Anthony
On Tuesday, April 16, 2019 at 11:14:10 AM UTC-4, João Matos wrote:
>
> Thanks Anthony, but I'm using Apache. 
>
> Do you know any current solution for Apache?
>

You should be able to run Centrifugo or Pushpin side-by-side with Apache 
(on a different port). You could even run Nginx alongside Apache, or even 
proxy from Nginx to Apache.
 

> Do you recommend Nginx over Apache? If so, why?
>

Nginx + uWSGI seems to be a common combination for web2py (and other Python 
frameworks) these days. Do some searches for pros and cons of each web 
server. I believe Nginx will be faster for serving static files, and of 
course it can serve as a reverse proxy, so it can serve both your Python 
app via uWSGI as well as proxy to something like Nchan or Centrifugo for 
real-time push connections.

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: Is it possible to update a Rows object with another Rows object?

2019-04-16 Thread Anthony
On Tuesday, April 16, 2019 at 11:11:09 AM UTC-4, João Matos wrote:
>
> Is it possible to update a Rows object with another Rows object?
>
> I would like to do something similar to this (except that update does not 
> exist in Rows)
>
> rows = db(db.wo.id == int(request.args[0])).select()
> if len(request.args) > 1:
> for id_ in request.args[1:]:
> rows.update(db(db.wo.id == int(id_)).select()
>
>
Why not a single query to get all records:

rows = db(db.wo.id.belongs(request.args)).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: Does web2py support SSE (server sent events) from HTML5?

2019-04-16 Thread Anthony
If you are using Nginx as a proxy server, you might consider Nchan 
<https://nchan.io/>. It holds the HTTP/websocket connections and has a 
pubsub system, and your web2py app simply sends and receives regular 
short-lived HTTP requests. Similar alternatives are Centrifugo 
<https://github.com/centrifugal/centrifugo/> and Pushpin 
<https://pushpin.org/>.

Anthony

On Saturday, April 13, 2019 at 3:06:46 PM UTC-4, João Matos wrote:
>
> It would be great if web3py would support SSE.
>
> For now, the websocket solution would work with Apache?
>
> sábado, 13 de Abril de 2019 às 16:26:13 UTC+1, Massimo Di Pierro escreveu:
>>
>> No. we do provide a web2py/gluon/contrib/websocket_messaging.py which 
>> uses tornado and webocket for the same purpose.
>> web3py may provide this functionality.
>>
>> On Friday, 12 April 2019 15:36:38 UTC-7, João Matos wrote:
>>>
>>> Does web2py support SSE (server sent events) from HTML5?
>>> https://www.w3schools.com/html/html5_serversentevents.asp
>>>
>>

-- 
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: Does anyone know if it's possible & how I can distinguish, from web2py perspective, 2 browser tabs?

2019-04-13 Thread Anthony
On Saturday, April 13, 2019 at 5:28:11 PM UTC-4, João Matos wrote:
>
> I have several tables that use common controllers. To do that I must pass 
> the table name using a request var in the 1st call, which I save to session 
> (I must do this because that controller calls others and I don't want to 
> have to pass the table var every time).
>

It would help to see some code, but I don't see why the table name can't 
simply be part of the URL for any given page that needs it. The alternative 
is to add some kind of session ID to every URL, which is actually more 
complicated to manage.
 

> And there is other state vars I save to session.
>
> Because of this and to allow the users to have several tabs, I must be 
> able to distinguish between them.
>

To distinguish the tabs, you would need to add some kind of ID to the URL, 
and then to ensure the user does not break out of that tab-specific 
session, all links on the page would need that ID as well.

Alternatively, if this tab-specific state is needed in only a small portion 
of the app, you might consider making that part of the app a single page 
where all the interaction is controlled client-side via Javascript, making 
Ajax calls to the server. In that case, you could either store the relevant 
state in the browser (and send whatever is needed to the server with the 
Ajax requests), or just have a session ID in the page that gets sent with 
every Ajax request.

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: Is it possible to send all args & vars from a view/controller to another using POST instead of GET?

2019-04-13 Thread Anthony
On Saturday, April 13, 2019 at 3:00:06 PM UTC-4, João Matos wrote:
>
> What I would like is to "hide" all the args and vars from the end user.
> Couldn't the browser send the args and vars using POST to the web2py 
> server? I believe so.
>

Of course, via a form post or an Ajax request -- but not via a redirect.

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: Datatables Object ID

2019-04-13 Thread Anthony
As described here <https://stackoverflow.com/a/55667115/440323>, you can 
instead just do joins to include data from related tables. The resulting 
JSON will be an array of objects with nested records from each table. 
Datatables can handle such nested objects: 
https://editor.datatables.net/examples/advanced/deepObjects.html. The code 
is much simpler on the web2py side (even when joining multiple tables), and 
handling the nested objects in Datatables is very simple.

Anthony

On Saturday, April 13, 2019 at 4:23:09 PM UTC-4, Cristina Sig wrote:
>
> Thank you for the reply!
>
> I applied it and it works but I was thinking that this method is a little 
> bit tricky when it comes to tables that have more than one reference to 
> other tables.
> In my case, I have another table called Students which have references to 
> other two tables so in that case the code would look complex.
> Is there any other way to work with Datatables child row to show extra 
> information (reference information from other tables)?
>
>
> El sábado, 13 de abril de 2019, 12:46:03 (UTC-3), Massimo Di Pierro 
> escribió:
>>
>> Since you are using datatable you do not have mach choice and you have to 
>> handle this serverside. You want the json to contain the nationality 
>> description instead of the nationality id. This can be done in the 
>> controller.
>>
>> Before you do that two observation: User is a reserved keywork so I am 
>> going to use Person. Table Nationality should be defined before table 
>> Person to avoid trouble. So, given:
>>
>> db.define_table('Person',
>> Field('first_name', 'string'),
>> Field('last_name', 'string'),
>> Field('email','string'),
>> Field('username','string'),
>> Field('nationality','reference Nationality', requires = 
>> IS_IN_DB(db,db.Nationality.id,'%(description)s')
>>)
>>
>>
>> db.define_table('Nationality',
>> Field('description','string'),
>> format = '%(description)s'
>>)
>>
>> You can do:
>>
>> def user():
>> import json
>> rows = jdb(db.Person.id>0).select()
>> ids = [row.nationality for row in rows] # find the nationalities
>> mapping = db(db.Nationality.id.belongs(ids)).select().as_dict() # 
>> build a mapping in one extra query
>> for row in rows: row.nationality=mapping[row.nationality].description 
>> # applly the mapping
>> return dict(formListar=XML(rows.as_json()))
>>
>>
>>
>>
>> On Friday, 12 April 2019 20:58:36 UTC-7, Cristina Sig wrote:
>>
>>> Hello everybody,
>>>
>>> I have two tables and I am working with Datatables and what I would like 
>>> to do is use the child row to show more information about a particular row. 
>>> For example, on the table I will display first name, last name, username, 
>>> and email and on the child or expandable row, I will show the nationality 
>>> of that user.
>>> The problem I am having is that when I expand the row, it shows only the 
>>> id from the 'User' table  and not the description associated to that id.
>>> this is my first time dealing with Datatables so I don't have my 
>>> experience with it.
>>>
>>> Any suggestions to solve this issue?
>>>
>>> Thanks :)
>>>
>>> DB
>>> db.define_table('User',
>>> Field('first_name', 'string'),
>>> Field('last_name', 'string'),
>>> Field('email','string'),
>>> Field('username','string'),
>>> Field('nationality','reference Nationality', requires = 
>>> IS_IN_DB(db,db.Nationality.id,'%(description)s')
>>>)
>>>
>>>
>>> db.define_table('Nationality',
>>> Field('description','string'),
>>> format = '%(descripcion)s'
>>>)
>>>
>>>
>>>
>>> My controler
>>> def user():
>>> import json
>>> usuario = json.dumps(db(db.auth_user.id>0).select().as_list())
>>> return dict(formListar=XML(usuario))
>>>
>>>
>>>
>>>
>>> My view
>>> 
>>> var tabla;
>>> $(document).ready(function(){
>>>tabla=  $('#tablaGenerica').DataTable({
>>>  "data":  {{=formListar}},
>>> "scrollX": false,
>>>

[web2py] Re: Does anyone know if it's possible & how I can distinguish, from web2py perspective, 2 browser tabs?

2019-04-13 Thread Anthony
On Saturday, April 13, 2019 at 2:57:43 PM UTC-4, João Matos wrote:
>
> After authenticating to my web2py app a user can open different tabs and 
> use any of them or all of them to access the app.
> I want to be able to distinguish between the tabs.
>

Yes, but why do you need to distinguish between the tabs? What are you 
trying to achieve?

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: Is it possible to send all args & vars from a view/controller to another using POST instead of GET?

2019-04-13 Thread Anthony
On Friday, April 12, 2019 at 7:41:43 PM UTC-4, João Matos wrote:
>
> So no option for redirect with POST. That is a shame.
>

That's just how browsers work. A redirect is simply a response sent to the 
browser with a 303 HTTP code and a new URL location -- the browser then 
requests the new URL. You could handle this via Javascript and Ajax, but 
there may be a simpler option, depending on your goal.
 

> The book mentions request.post_vars. In what situation would one use it?
>

When a post request comes in, the post data are stored in 
request.post_vars, allowing you code to access the data. FORM and SQLFORM, 
for example, read data from request.post_vars.

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: Does anyone know if it's possible & how I can distinguish, from web2py perspective, 2 browser tabs?

2019-04-13 Thread Anthony
What are you trying to do?

On Friday, April 12, 2019 at 6:10:47 PM UTC-4, João Matos wrote:
>
> Does anyone know if it is possible and how I can distinguish, from web2py 
> perspective, 2 tabs or windows (not Firefox containers) from the same 
> browser?
>

-- 
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: Datatables Object ID

2019-04-13 Thread Anthony
See https://stackoverflow.com/a/55667115/440323.

On Friday, April 12, 2019 at 11:58:36 PM UTC-4, Cristina Sig wrote:
>
> Hello everybody,
>
> I have two tables and I am working with Datatables and what I would like 
> to do is use the child row to show more information about a particular row. 
> For example, on the table I will display first name, last name, username, 
> and email and on the child or expandable row, I will show the nationality 
> of that user.
> The problem I am having is that when I expand the row, it shows only the 
> id from the 'User' table  and not the description associated to that id.
> this is my first time dealing with Datatables so I don't have my 
> experience with it.
>
> Any suggestions to solve this issue?
>
> Thanks :)
>
> DB
> db.define_table('User',
> Field('first_name', 'string'),
> Field('last_name', 'string'),
> Field('email','string'),
> Field('username','string'),
> Field('nationality','reference Nationality', requires = 
> IS_IN_DB(db,db.Nationality.id,'%(description)s')
>)
>
>
> db.define_table('Nationality',
> Field('description','string'),
> format = '%(descripcion)s'
>)
>
>
>
> My controler
> def user():
> import json
> usuario = json.dumps(db(db.auth_user.id>0).select().as_list())
> return dict(formListar=XML(usuario))
>
>
>
>
> My view
> 
> var tabla;
> $(document).ready(function(){
>tabla=  $('#tablaGenerica').DataTable({
>  "data":  {{=formListar}},
> "scrollX": false,
>  "dom": 'lrtip',
>  "searching": true,
>  "sRowSelect": "single",
>   "columns": [
>   {
>  "class":"details-control",
>  "orderable":false,
>  "data":null,
>  "defaultContent": ""
>   },
>   { data: 'first_name' },
>   { data: 'last_name' },
>   { data: 'email' },
>   { data: 'username' },
>   ]
> });
>
>  $('#tablaGenerica tbody').on('click', 'td.details-control', function () {
> var tr = $(this).closest('tr');
> var row = tabla.row( tr );
> if ( row.child.isShown() ) {
> // This row is already open - close it
> row.child.hide();
> tr.removeClass('shown');
> }
> else {
> // Open this row
> row.child( format(row.data()) ).show();
> tr.addClass('shown');
> }
> } );
>
> function format ( d ) {
> // `d` is the original data object for the row
> return ' style="padding-left:50px;">'+
> ''+
> ''+
> ''+
> ''+
> '
Nationality:'+d.nationality+'
'; > } > > > > > cellspacing="0" width="100%" > > > > > First name > Last name > Email > Username > > > > > > > > -- 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: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-11 Thread Anthony
Your error has nothing to do with using append -- I was just suggesting the 
alternative as cleaner/simpler code. Please look at the code in layout.html 
that is actually throwing the exception and you will see that code does not 
expect any of the menu items to be a single HTML helper -- it expects 
lists/tuples with 3 values. Either change your menu or change the code in 
the layout.

Anthony

On Thursday, April 11, 2019 at 8:18:00 PM UTC-4, lucas wrote:
>
> ok, i tried it without the appends, instead just direct:
>
> response.menu[1][3] = [
> (T('Dashboard'), False, URL('main', 'students')),
> A('', _class="divider"),
> (T('Assessments'), False, None),
> (T('History'), False, None),
> (T('Join a Class'), False, None)
> ]
>
> and it still bugs unless the A tag is commented out, then it is fine 
> again.  and i agree with you that its expecting a particular structure, but 
> i've used the separator inserts in the past and they've worked fine and i 
> thought the code allowed for the separators in the present form also.
>

-- 
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: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-11 Thread Anthony
Yes, I agree that the line you identified is the ultimate source of the 
error, but it is not the line that actually results in the exception, which 
is in the view. The problem, is the code in the view expects the menu items 
to have a particular structure, and the item you have added does not match 
that structure (hence the index out of range error). I suggest you look at 
the menu code in the layout to see where things are going wrong. You can 
either change the code in the layout or your menu code.

Also, instead of the code below, why not just:

response.menu[1][3] = [
(T('Dashboard'), False, URL('main', 'students')),
...
]

Anthony

On Thursday, April 11, 2019 at 5:59:04 PM UTC-4, lucas wrote:
>
> alright, so just to be absolutely sure.  i copied the layout.html and the 
> default/index.html files from the 2.18.5 welcome app and stuck them in the 
> proper places in my app.  i still get the same error.  i do NOT get the 
> error if i comment out the separator line, as commented below.  here is all 
> of my code in the menu.py file as it stands now with layout.html and 
> index.html being the unmodified default:
>
> # -*- coding: utf-8 -*-
> response.title = "IQa weInstruct:::uLearn"
> response.menu = [
> [T('Lectures'), False, URL('default', 'subjects')],
> [T('Students'), False, URL('main', 'students'), []],
> [T('Professors'), False, URL('main', 'professors'), []],
> [T('Blog'), False, URL('default', 'blog')],
> [T('News'), False, URL('default', 'news')]
> ]
>
> if auth.is_logged_in():
> response.menu[1][0] = T('Student:')
> response.menu[1][3].append((T('Dashboard'), False, URL('main', 
> 'students')))
> #response.menu[1][3].append(A('', _class="divider"))
> response.menu[1][3].append((T('Assessments'), False, None))
> response.menu[1][3].append((T('History'), False, None))
> response.menu[1][3].append((T('Join a Class'), False, None))
>
>

-- 
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 in grid's edit validation.

2019-04-11 Thread Anthony
On Thursday, April 11, 2019 at 2:03:00 PM UTC-4, João Matos wrote:
>
> 'll check out the db.mytable._before_delete callback.
>
> You said 
> " I would probably simply disable the "delete" checkbox in the edit form 
> (via editargs=dict(deletable=False)
> ), and only allow deletion via the grid buttons (which you can then 
> intercept via the ondelete callback)."
>
> ondelete works but has a drawback (at least I couldn't figure out a 
> solution). It works fine if what we have to do doesn't require a 
> redirection to another page. If it does, it doesn't work.
>

Deletes via the grid buttons happen via Ajax, so you need a client-side 
redirect:

def ondelete(table, id):
redirect(URL(...), client_side=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] Re: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-11 Thread Anthony
That traceback comes from code in your index.html view, not the code you 
have shown. There is an HTML helper that is being indexed, and whatever 
index value is being used is higher than the number of components in the 
helper. Hard to say more without seeing the relevant code.

Anthony

On Thursday, April 11, 2019 at 11:49:26 AM UTC-4, lucas wrote:
>
> web2py™ Version 2.18.5-stable+timestamp.2019.04.08.04.22.03
> Python Python 2.7.5: /usr/bin/uwsgi (prefix: /usr)Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
>
> Traceback (most recent call last):
>   File "/opt/web2py_apps/web2py_2-18-5/gluon/restricted.py", line 219, in 
> restricted
> exec(ccode, environment)
>   File 
> "/opt/web2py_apps/web2py_2-18-5/applications/instruct/views/default/index.html",
>  line 62, in 
>   File "/opt/web2py_apps/web2py_2-18-5/gluon/html.py", line 807, in 
> __getitem__
> return self.components[i]
> IndexError: list index out of range
>
>

-- 
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 in grid's edit validation.

2019-04-11 Thread Anthony
On Thursday, April 11, 2019 at 11:33:16 AM UTC-4, João Matos wrote:
>
> I'm sorry, but I can't agree with you about the consistency.
> I'm aware that the onvalidation is called after the validation.
> The inconsistency is why is it sometimes called when the delete checkbox 
> is selected and not in others?
> If the assumption is that it has nothing to do with deletion, then it 
> should never be called if the delete checkbox is selected. Which is not the 
> case.
>

I agree it should never be called on deletion, but if it worked that way, 
it would make no difference for your use case. (As an aside, the reason the 
validation process proceeds even on deletion is likely due to the fact that 
SQLFORM is implemented by extending FORM, so the usual FORM processing 
happens before SQLFORM deals with the delete.)

I suppose instead you would like onvalidaton to run in *all *cases (when 
delete is checked), but I don't think that is the best solution for your 
use cases, as it would still require custom internal logic to distinguish 
deletions (not to mention that it would break backward compatibility). 
Instead, if we were going to make changes to accommodate these use cases, a 
better approach would be a separate before delete hook, and possibly an 
after delete hook. But even without these additional hooks, it is fairly 
easy to accommodate these cases with the DAL callbacks or simply with some 
code that runs before or after the grid code.
 

> There is a way to distinguish an edit from a delete from within 
> onvalidation. I use 
>
> if form.vars.delete_this_record: 
>
> and it works.
>

Yes. The point is the need for such custom logic makes onvalidation less 
suitable for what you want to do. A separate callback would be more useful. 
Otherwise, you might as well just put that logic outside of onvalidation.
 

> On the 2nd case, I must correct you that ondelete is run before the delete 
> happens. I use it to mark the record inactive and stop the deletion, when 
> the user "deletes" the record from the grid itself.
>

Yes, good point. Actually, in your case, I would probably simply disable 
the "delete" checkbox in the edit form (via editargs=dict(deletable=False)), 
and only allow deletion via the grid buttons (which you can then intercept 
via the ondelete callback).

An even better approach would be to use the db.mytable._before_delete 
callback, which is exactly how the built-in record versioning works (it 
adds a _before_delete callback that intercepts all deletes and instead 
updates the is_active field to False). This would catch deletion via the 
grid buttons or edit forms.
 

> There is case I mentioned and that you didn't consider which is before the 
> delete, doing something that doesn't require a separate workflow, which is 
> exactly my problem. I just want to mark the record inactive. From the 5 
> scenarios I explained, all of which originate from the grid's edit form, 3 
> go to onvalidation (and are deleting the record) and 2 don't. Again, this 
> is an inconsistency.
>

See above -- onvalidation is not the place for that logic. Though if you 
*must*, you can simply put that logic in both the onupdate and onfailure 
callbacks of the grid, or specify onvalidation as a dictionary, with 
onsuccess and onfailure callbacks that both include that logic.
 

> Thanks for the explanation about the arguments.
>
> I tried with
> if SQLFORM.FIELDNAME_REQUEST_DELETE in request.post_vars:
> and this catches the missing cases.
>
> But I must say it is a ugly solution. My point being that all the 
> validation and checking is usually done in the onvalidation, ondelete, etc. 
> And this to work must be at the top of the action instead of in one of the 
> on* functions.
> It works, but IMO is not a pretty solution.
>

Callbacks are necessary when you need to run some custom code in the middle 
of some other process, but less important when your custom logic can run 
entirely before or entirely after the process in question. In that regard, 
as noted above, before and after delete callbacks in SQLFORM might be nice, 
but certainly aren't a necessity (particularly given that in many, if not 
most, cases, the DAL callbacks would suffice).

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: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-11 Thread Anthony
Just post the traceback code directly -- don't need a ticket attachment.

On Thursday, April 11, 2019 at 7:45:24 AM UTC-4, lucas wrote:
>
> attached and thank you.  and for the record, I've tried everything I can 
> think of the for the past few days.  and if it turns out I'm just a dumb 
> butt, then I'm going to be really pissed at myself.  lol.
>

-- 
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: Apps created using web2py 2.14 version doesn't open in 2.18

2019-04-11 Thread Anthony
Any details on what is happening?

On Thursday, April 11, 2019 at 8:15:31 AM UTC-4, Ron Chatterjee wrote:
>
> Does anyone know how to mitigate the issue?
>

-- 
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 in grid's edit validation.

2019-04-11 Thread Anthony
On Thursday, April 11, 2019 at 7:54:46 AM UTC-4, João Matos wrote:
>
> They don't. I have everything working (the redirection to request for 
> supervisor password on record deletion in the grid, using a link), the 
> checks for record deletion in the edit form also work, except for the cases 
> I pointed out.
>

Yes, but just because everything is working does not mean (a) that was the 
easiest way to achieve the end goal or (b) you haven't compromised user 
experience to stay within the bounds of the available built-in 
functionality. For example, if a special password is needed to delete a 
record, it would be simpler to just enter it up front rather than first 
submit the delete request and then have to enter the password on a separate 
page. Not only is that an unnecessary extra step, but it may surprise the 
user if the UI makes no indication ahead of time that a special password is 
required.

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 in grid's edit validation.

2019-04-11 Thread Anthony
On Thursday, April 11, 2019 at 7:52:18 AM UTC-4, João Matos wrote:
>
> Thanks for the explanations.
>
> You don't understand. I don't care if the changes made at the same time 
> the deleted checkbox is selected, are saved when submitting. That is not 
> the problem. 
> It is a question of consistency.
>
> Either web2py should call on_validation when the delete checkbox is 
> selected or not. What happens now is that in some scenarios it is called 
> but not in others.
> My opinion is that it should always be called, but above all, it should be 
> consistent.
>

The "onvalidation" function is supposed to be called "upon validation" 
(hence the name), meaning after a successful validation of the submitted 
field values. It is not intended to be run in order to make checks before 
or after deletion of a record. In other words, onvalidation runs when 
particular conditions are met, and it does so *consistently*. It just so 
happens that you want to run it under different conditions, which is not 
its intended purpose. Even if it did run when you want, you would still 
need a way to distinguish a regular update request from a delete request, 
and you can do that just as easily outside of the onvalidation function 
(see below).

I think there are three types of cases to handle regarding deletes:

First, you might want to simply allow/disallow a delete, and that case is 
handled by the "deletable" argument.

Second, you might want to run some code *after* a successful delete. The 
grid has an "ondelete" argument to handle that in case the "Delete" button 
is clicked, but nothing for the case when a delete happens via an edit 
form. However, this can be handled in all cases via the 
db.mytable._after_delete callback. In any case, the onvalidation function 
would not be the best place for this logic as it (a) runs *before *the 
delete happens, and (b) would still require some logic to determine that a 
delete was requested. It might be nice if SQLFORM had a separate "ondelete" 
argument of its own.

Finally, you might want to allow the user to request a delete and then kick 
off a separate workflow, such as requiring a special password. However, 
that is really a special case that is application specific, and it is not 
even well accommodated by the current UI (i.e., it would be a better user 
experience to request the special password up front rather than making it a 
two step process). If you need something like that, you should really be 
implementing custom logic. And again, the onvalidation function is not the 
best place for such logic, as it would still require detection of the 
delete request.

As an aside, note that the "onvalidation" argument can actually be a 
dictionary with separate "onsuccess", "onfailure", and "onchange" 
callbacks. The grid also has "onupdate" (run after successful update) and 
"onfailure" (run after failed update) arguments, as well as the "ondelete" 
argument. Some combination of these callbacks could be used to run some 
code whenever a delete is requested, though it is probably simpler to just 
do a check like the following before calling grid():

if SQLFORM.FIELDNAME_REQUEST_DELETE in request.post_vars or 'delete' in 
request.args:
[code to handle delete workflow]
 
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: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-11 Thread Anthony
OK, got it. I cannot reproduce the problem. Please show the full traceback.

On Wednesday, April 10, 2019 at 3:52:04 PM UTC-4, lucas wrote:
>
> oh yes I agree with you.  I think you're referring to the 3 in 
> "response.menu[1][3].append".  the list to append to the submenu is the 4th 
> element, so the 3 is correct.  but I tried the 2 instead of the 3 anyway 
> and I got the same error.  the only not to get the error is to remove or 
> comment out the "response.menu[1][3].append(LI(_class="dropdown-divider"))" 
> line altogether.  I also tried using A instead of LI since current web2py 
> converts the tuple into A when in the submenu, that gave the same error 
> also.
>
> On Wednesday, April 10, 2019 at 3:41:08 PM UTC-4, Anthony wrote:
>>
>> Indexing is zero-based in Python, so the index of the third element is 2, 
>> not 3.
>>
>> 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 in grid's edit validation.

2019-04-11 Thread Anthony
I should also point out, at some point, if your requirements deviate too 
far from the built-in functionality of the grid, it might be easier to not 
use the grid and simply code your own solution.

On Thursday, April 11, 2019 at 7:24:35 AM UTC-4, Anthony wrote:
>
> On Wednesday, April 10, 2019 at 4:04:35 PM UTC-4, João Matos wrote:
>>
>> Because in my case the record is not deleted simply deactivated.
>>
>
> Whether or not the record is being permanently deleted or simply 
> deactivated, it would not generally make sense to validate submitted 
> changes, as the expectation would be that the changes would not be 
> persisted. If you have a specific use case for allowing simultaneous update 
> and deactivation (i.e., "save these changes and then immediately deactivate 
> the record"), then you'll have to code that logic yourself (though I would 
> recommend making the user experience more clear in that case, as the 
> current UI and workflow does not make it clear that updates would be 
> persisted prior to deletion). I don't think it makes sense for that to be 
> the default behavior.
>  
>
>> But there are other scenarios:
>>  - Making additional checks before allowing the record deletion;
>>
>
> That is what the "deletable" argument is for. It can be a function that 
> receives a Row object and determines if the record is allowed to be 
> deleted. If not allowed, (a) no delete button will appear next to that 
> record in the grid, and (b) the "delete record" checkbox will not appear on 
> the edit form.
>  
>
>>  - Asking for the password of a supervisor before allowing the record 
>> deletion;
>>
>
> This kind of functionality would go beyond the scope of "onvalidation" 
> anyway, as you would have to redirect elsewhere and start a new workflow. 
> You might as well code your own logic to handle this.
>  
>
>>  - Making some changes to other tables as a consequence of the record 
>> deletion;
>>  - Wanting to receive an email when someone deletes a record from a 
>> special table;
>>  - Doing some house keeping or some other task when someone deletes a 
>> record.
>>
>
> Better to use the db.mytable._after_delete callback for these cases.
>
> 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 in grid's edit validation.

2019-04-11 Thread Anthony
On Wednesday, April 10, 2019 at 4:04:35 PM UTC-4, João Matos wrote:
>
> Because in my case the record is not deleted simply deactivated.
>

Whether or not the record is being permanently deleted or simply 
deactivated, it would not generally make sense to validate submitted 
changes, as the expectation would be that the changes would not be 
persisted. If you have a specific use case for allowing simultaneous update 
and deactivation (i.e., "save these changes and then immediately deactivate 
the record"), then you'll have to code that logic yourself (though I would 
recommend making the user experience more clear in that case, as the 
current UI and workflow does not make it clear that updates would be 
persisted prior to deletion). I don't think it makes sense for that to be 
the default behavior.
 

> But there are other scenarios:
>  - Making additional checks before allowing the record deletion;
>

That is what the "deletable" argument is for. It can be a function that 
receives a Row object and determines if the record is allowed to be 
deleted. If not allowed, (a) no delete button will appear next to that 
record in the grid, and (b) the "delete record" checkbox will not appear on 
the edit form.
 

>  - Asking for the password of a supervisor before allowing the record 
> deletion;
>

This kind of functionality would go beyond the scope of "onvalidation" 
anyway, as you would have to redirect elsewhere and start a new workflow. 
You might as well code your own logic to handle this.
 

>  - Making some changes to other tables as a consequence of the record 
> deletion;
>  - Wanting to receive an email when someone deletes a record from a 
> special table;
>  - Doing some house keeping or some other task when someone deletes a 
> record.
>

Better to use the db.mytable._after_delete callback for these cases.

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: 2.18.5 LI(_class="dropdown-divider") bug?

2019-04-10 Thread Anthony
Indexing is zero-based in Python, so the index of the third element is 2, 
not 3.

Anthony

On Tuesday, April 9, 2019 at 10:23:47 PM UTC-4, lucas wrote:
>
> hey all,
>
> I have the following code under menu.py under 2.18.5:
>
> response.menu = [
> (T('Lectures'), False, URL('default', 'subjects')),
> (T('Students'), False, URL('default', 'student')),
> (T('Professors'), False, URL('default', 'professor')),
> (T('Blog'), False, URL('default', 'blog')),
> (T('News'), False, URL('default', 'news'))
> ]
>
> if auth.is_logged_in():
> response.menu.insert(1, (T('JumpTo:'), False, None, []))
> response.menu[1][3].append((T('Classes'), False, None))
> response.menu[1][3].append(LI(_class="dropdown-divider"))
> response.menu[1][3].append((T('Question Pool'), False, None))
>
> web2py is fine until I add the 
> "response.menu[1][3].append(LI(_class="dropdown-divider"))" line in which 
> case the exception is: "IndexError: list index out of range".  I can not 
> for the life of me figure out why all the other appends, the appends of the 
> tuples work but the append with the LI bugs like hell.
>
> thanx in advance, Lucas
>
>

-- 
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 in grid's edit validation.

2019-04-10 Thread Anthony

>
> I found a bug in the grid's edit validation.
> I follow this procedure:
>  - Select a record to edit.
>  - Change one of the fields that must be unique and change it to a value 
> that already exists.
>  - web2py shows an error message (which is correct and happens before 
> going to onvalidation, which is also correct).
>  - Change the value to something that doesn't already exist in the table.
>  - Mark the record for deletion.
>  - Submit the record.
>
> The bug I found is that web2py was supposed to go to onvalidation before 
> deleting the record and that doesn't happen.
>

If the record is being deleted, why would you need to validate the 
submitted values (given that they will not be applied)?

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 support of MongoDB is still experimental?

2019-04-09 Thread Anthony
I don't think so -- just that the book was never updated.

On Tuesday, April 9, 2019 at 6:37:04 PM UTC-4, João Matos wrote:
>
> Hello,
>
> The support of MongoDB is still experimental?
>
> Thanks,
>
> JM
>

-- 
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: Convert in line Javascript to file

2019-04-09 Thread Anthony
Get rid of the 

[web2py] Re: Clearing cache for multiple processes / threads

2019-04-08 Thread Anthony
cache.ram is separate per process. What is the logic that you are currently 
using to clear the cache?

On Monday, April 8, 2019 at 3:08:49 PM UTC-4, William wrote:
>
> Hi all, I have been trying to clear cache using cache.ram(key, None), but 
> the cleared cached value still appears even after clearing. I suspect this 
> is due to multiple processes / threads. 
>
> Does anyone know how I can clear cache for all running processes? 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: auth_user change field order

2019-04-08 Thread Anthony
Definitely works for me. Are you using the built-in Auth profile 
functionality? If so, you'll have to do some debugging -- check 
/gluon/tools.py around line 3646 (where the profile form is created and 
auth.settings.profile_fields is passed to SQLFORM.

Note, you can also create a custom form in the view.

Anthony

On Monday, April 8, 2019 at 10:20:27 AM UTC-4, lucas wrote:
>
> i tried this before and after auth.define_tables and it had no effect:
>
> auth.settings.profile_fields = ['prefix_title', 'first_name', 'last_name', 
> 'gender', 'birthdate', 'zip', 'email']
>
>

-- 
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: auth_user automatically lowercase all email fields

2019-04-08 Thread Anthony
On Monday, April 8, 2019 at 10:11:33 AM UTC-4, lucas wrote:
>
> students log into this site i've had.  and they type all kinds of crazy 
> stuff.  i don't want to preserve what the students type because students 
> are inconsistent when they login.  so i want to force it to lowercase so at 
> least i know what is definitely stored in the db.
>

Yes, by default Auth already forces email addresses to lowercase. You have 
to set auth.settings.email_case_sensitive = True to *not *get that behavior.

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: auth_user change field order

2019-04-08 Thread Anthony
auth.settings.profile_fields = ['prefix_title', 'first_name', 'last_name', 
...]

Anthony

On Monday, April 8, 2019 at 9:38:06 AM UTC-4, lucas wrote:
>
> hello one and all,
>
> i'm using web2py 2.17>.
>
> what is the best method to change the field order on the view's 
> user/profile and user/register when adding fields like???
>
> auth.settings.extra_fields['auth_user'] = [
> Field('prefix_title', length=4, 
> requires=IS_IN_SET(('Mr.','Ms.','Mrs.','Dr.')), comment='Enter your Name 
> Prefix.'),
> Field('birthdate', 'date', requires=NE, comment='Enter in Format: 
> "-MM-DD"'),
> Field('zip', length=9, requires=NE, comment='Your Zip or Postal 
> Code.'),
> Field('gender', length=6, default='FEMALE', 
> requires=IS_IN_SET(('FEMALE','MALE')), comment='Enter your Gender.'),
> Field('input_date', 'date', comment="format -MM-DD", requires=NE, 
> default=datetime.date.today(), writable=False, readable=False)
> ]
>
> thank you in advance.  lucas
>

-- 
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: auth_user automatically lowercase all email fields

2019-04-08 Thread Anthony
That's already the default behavior. If you wanted to preserve the case 
entered by the user, you would do:

auth.settings.email_case_sensitive = True

Anthony

On Monday, April 8, 2019 at 9:40:52 AM UTC-4, lucas wrote:
>
> hello one and all,
>
> i'm using web2py 2.17>.
>
> what is the best method to impose and automatically update the email field 
> to all lowercase characters without making the user have to retype the 
> email???  i want web2py to lowercase no matter its a new registration 
> (insert) or profile (update).
>
> thank you in advance.  lucas
>

-- 
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: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-07 Thread Anthony
Yes, as noted, that code inverts the sort order for date/time fields when 
the field is clicked, but there is no inversion when using the orderby 
argument. I'm not sure why the order is inverted for such fields. Maybe 
bring it up in the developers group.

On Sunday, April 7, 2019 at 3:19:51 PM UTC-4, João Matos wrote:
>
> I think I found the source of the problem.
> After following the function in the previous message, I arrived at this 
> code inside the linsert function (line 2779) .
>
> exception = sort_field.type in ('date', 'datetime', 'time'
> )
> if exception:
> desc_icon, asc_icon = sorter_icons
> orderby = (order[:1] == '~' and sort_field) or ~
> sort_field
> else:
> orderby = (order[:1] == '~' and ~sort_field) or 
> sort_field
>
> If I change it to
>
> exception = sort_field.type in ('date', 'datetime', 'time'
> )
> # if exception:
> #desc_icon, asc_icon = sorter_icons
> #orderby = (order[:1] == '~' and sort_field) or 
> ~sort_field
> #else:
> orderby = (order[:1] == '~' and ~sort_field) or sort_field
>
> Now the date sorting works fine.
>
> There is also another code segment in line 2641 with the same purpose that 
> may need the same change, but that segment isn't run with my application, 
> only the segment at line 2779.
>
>
> domingo, 7 de Abril de 2019 às 19:43:50 UTC+1, João Matos escreveu:
>>
>> I think I found the problem (I don't have the solution).
>>
>> In gluon\sqlhtml.py there is this function
>>
>> def fix_orderby(orderby):
>> if not auto_pagination:
>> return orderby
>> # enforce always an ORDER clause to avoid
>> # pagination errors. field_id is needed anyhow,
>> # is unique and usually indexed. See issue #679
>> if not orderby:
>> orderby = field_id
>> elif isinstance(orderby, list):
>> orderby = reduce(lambda a,b: a|b, orderby)
>> elif isinstance(orderby, Field) and orderby is not field_id:
>> print('inside2')
>> # here we're with an ASC order on a field stored as 
>> orderby
>> orderby = orderby | field_id
>> elif (isinstance(orderby, Expression) and
>>   orderby.first and orderby.first is not field_id):
>> print('inside3')
>> # here we're with a DESC order on a field stored as 
>> orderby.first
>> orderby = orderby | field_id
>> return orderby
>>
>> where I added the 2 prints.
>> A field that works correct shows inside2 on the first run and inside3 on 
>> the second.
>> The date field always shows inside2.
>>
>> Any ideas?
>>
>> Do you use Telegram? There is an online web2py international group. It 
>> would be great if you and others web2py core devs joined.
>>
>>
>>
>>
>> domingo, 7 de Abril de 2019 às 19:22:34 UTC+1, Anthony escreveu:
>>>
>>> On Saturday, April 6, 2019 at 3:41:50 PM UTC-4, João Matos wrote:
>>>>
>>>> Thanks Anthony. I will open an issue (I still haven't enough know how 
>>>> to make a PR). I hope some time in the future.
>>>>
>>>> I don't want to abuse your help, but I have another issue that is 
>>>> viewable with the minimal app I sent you.
>>>> If you create 2 records with different dates, and try to change the 
>>>> grid's sort order you will notice that the URL changes, the page reloads 
>>>> but the grid doesn't change.
>>>> I checked the db stats SQL statements and they stay the same (they 
>>>> don't change the ORDER).
>>>> I think there is a bug with the sorting of date columns when they are 
>>>> the predefined orderby. Can you try it and give me your input.
>>>>
>>>
>>> Definitely a bug -- feel free to report on Github. May have to do with 
>>> the fact that when clicking to sort, the grid code inverts the order for 
>>> date/time fields, but does not appear to do so when a date/time field is 
>>> specified in the orderby argument.
>>>
>>> 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: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-07 Thread Anthony
On Saturday, April 6, 2019 at 3:41:50 PM UTC-4, João Matos wrote:
>
> Thanks Anthony. I will open an issue (I still haven't enough know how to 
> make a PR). I hope some time in the future.
>
> I don't want to abuse your help, but I have another issue that is viewable 
> with the minimal app I sent you.
> If you create 2 records with different dates, and try to change the grid's 
> sort order you will notice that the URL changes, the page reloads but the 
> grid doesn't change.
> I checked the db stats SQL statements and they stay the same (they don't 
> change the ORDER).
> I think there is a bug with the sorting of date columns when they are the 
> predefined orderby. Can you try it and give me your input.
>

Definitely a bug -- feel free to report on Github. May have to do with the 
fact that when clicking to sort, the grid code inverts the order for 
date/time fields, but does not appear to do so when a date/time field is 
specified in the orderby argument.

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: web3py again....

2019-04-07 Thread Anthony
Not sure what that means -- Massimo will have to reply. Once a module has 
been loaded within a given Python process, it won't be repeatedly reloaded 
-- see https://docs.python.org/3/reference/import.html#the-module-cache. 
web2py model and controller files are executed on every request -- if they 
import a module, there will be a very small performance hit to look up the 
module in sys.modules on each request (trivial relative to the cost of 
initializing the module on the very first request), but given web2py's 
execution model, there is nothing you will do to eliminate that.

Anthony

On Sunday, April 7, 2019 at 1:55:06 PM UTC-4, João Matos wrote:
>
> That was the word used by Massimo.
> He stated
> "In web2py we do not reload the modules. we reimport them at every 
> request. this causes a performance penalty and is only needed in 
> development."
> My question was if it is possible to disable module reimport at every 
> request in production or it just how web2py is built.
>
>
> domingo, 7 de Abril de 2019 às 18:51:09 UTC+1, Anthony escreveu:
>>
>> On Sunday, April 7, 2019 at 1:33:22 PM UTC-4, João Matos wrote:
>>>
>>> @Anthony
>>>
>>> I was asking about reimport not reload.
>>> Does track_changes appy to both?
>>>
>>
>> What do you mean by "reimport"?
>>
>> 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: web3py again....

2019-04-07 Thread Anthony
On Sunday, April 7, 2019 at 1:33:22 PM UTC-4, João Matos wrote:
>
> @Anthony
>
> I was asking about reimport not reload.
> Does track_changes appy to both?
>

What do you mean by "reimport"?

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: web3py again....

2019-04-07 Thread Anthony
On Sunday, April 7, 2019 at 1:19:08 PM UTC-4, João Matos wrote:
>
> @Massimo
>
> You state
> "In web2py we do not reload the modules. we reimport them at every 
> request. this causes a performance penalty and is only needed in 
> development."
>
> Does this mean it is possible to disable module reimport at every request 
> in web2py when in production (or did I misunderstood you)? How?
>

Unless you have the following in a model file:

from gluon.custom_import import track_changes; track_changes(True)

 
modules are not reloaded. And even with the above, they are only reloaded 
if they have changed.

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: Custom validator broken in 2.18.4, working in 2.17.2

2019-04-06 Thread Anthony
The book should be update, but we should also decide if we're OK breaking 
backward compatibility in this way.

Anthony

On Saturday, April 6, 2019 at 3:06:20 PM UTC-4, David Manns wrote:
>
> Changed my import to:
>
> from pydal.validators import Validator, ValidationError
>
> class IS_MEMBERSHIP_YEAR_END(Validator):
> def __init__(self, error_message='Not a membership year end'):
> self.error_message = error_message
> def validate(self, value):
> yearend =  datetime.date(2018,9,30)
> if value.month==yearend.month and value.day==yearend.day:
> return value
> else:
> raise ValidationError(self.translator(self.error_message))
>
> Now works with 2.18.4, thank you!
>
> The 'book' needs to be updated!
>
> On Thursday, April 4, 2019 at 4:52:37 PM UTC-4, David Manns wrote:
>>
>> The table in question has a field:
>>
>> Field('Paiddate', 'date', requires = [IS_EMPTY_OR(IS_DATE()), 
>> IS_EMPTY_OR(IS_MEMBERSHIP_YEAR_END())]),
>>
>> The custom validator is:
>>
>> class IS_MEMBERSHIP_YEAR_END(object):
>> def __init__(self, error_message='Not a membership year end'):
>> self.error_message = error_message
>> def __call__(self, value):
>> yearend = datetime.date(2018,9,30)
>> if value.month==yearend.month and value.day==yearend.day:
>> return (value, None)
>> return (value, self.error_message)
>>
>> This works in 2.17.2
>>
>> I updated my test environment to 2.18.4 and it fails.
>>
>> On the console I see:
>>
>> web2py Web Framework
>> Created by Massimo Di Pierro, Copyright 2007-2019
>> Version 2.18.4-stable+timestamp.2019.03.13.05.27.54
>> Database drivers available: sqlite3, imaplib, pyodbc, pymysql
>> please visit:
>> ('\t', 'http://127.0.0.1:8000/')
>> starting browser...
>> Traceback (most recent call last):
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\html.py", line 1890, in _validate
>> (value, errors) = validator(value)
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\packages\dal\pydal\validators.py", line 144, in 
>> __call__
>> return self.validate(value), None
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\packages\dal\pydal\validators.py", line 2754, in 
>> validate
>> return self.other.validate(value)
>> AttributeError: 'IS_MEMBERSHIP_YEAR_END' object has no attribute 
>> 'validate'
>>
>> The ticket shows:
>>
>> Error ticket for "init" Ticket ID 
>>
>> 127.0.0.1.2019-04-04.16-41-08.0dce185d-d8d2-4d36-9e47-8c82bc1d54f5
>>  Validation error, field:Paiddate 
>>  Version 
>> web2py™ Version 2.18.4-stable+timestamp.2019.03.13.05.27.54 
>> Python Python 2.7.14: C:\Python27\python.exe (prefix: C:\Python27) 
>> Traceback 
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>> 23.
>> 24.
>> 25.
>> 26.
>> 27.
>> 28.
>> 29.
>> 30.
>>
>> Traceback (most recent call last):
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\restricted.py", line 219, in restricted
>> exec(ccode, environment)
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\applications\init\controllers/default.py", line 1747, in 
>> 
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\globals.py", line 421, in 
>> self._caller = lambda f: f()
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\applications\init\models\db.py", line 109, in wrapped_f
>> return f(*args)
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\applications\init\controllers/default.py", line 214, in 
>> memberform
>> deletable = dltbl, onvalidation=setmodified, onaccept=modmember, 
>> ondelete=delmember)
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE.2.1\gluon\tools.py", line 4322, in update
>> detect_record_change=self.settings.detect_record_change):
>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>> Site\OxCamNE

[web2py] Re: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-06 Thread Anthony
The problem is unique to the IS_*_IN_RANGE validators, all of which create 
a translated error message at the time they are instantiated rather than at 
validation time. For example, here is the init code for 
IS_INT_IN_RANGE: 
https://github.com/web2py/pydal/blob/e973f27b69a8499e4e30e5663f3fba74bf87364c/pydal/validators.py#L817.

So, you need to set the translation language before defining one of these 
validators. Note, this has nothing to do with Auth extra_fields, just with 
the point in the code at which the validators are defined.

I don't see why the error message logic cannot be moved from the __init__ 
method to the validate method in these range validators, which would push 
the translation to validation time, as with all the other validators. So, 
feel free to submit an issue about this in the pydal repo and refer to this 
post (or better yet, make a pull request).

Anthony

On Saturday, April 6, 2019 at 2:07:16 PM UTC-4, João Matos wrote:
>
> The app will start in Portuguese. You can change that by uncommenting the 
> T.force() in db1.py, but it would be good to do the testing with Portuguese 
> first to see the problem.
> After registering, create a new record and in the field ùltimo atribuído 
> (last_assigned) input -1 which will return a validation error message in 
> Portuguese (correct behavior).
> If you go to Perfil (Profile) and to the same to one of the Paginação 
> (Pagination) fields it will return a validation error message in English 
> (the pagination fields are the extra_fields).
> If you comment the T.force() from db1.py and uncomment the T.force() that 
> is present in db.py before the extra_fields creation and redo the 2 tests, 
> you will see that both who in Portuguese.
>
> I'm unable to add the app file as an attachment. It always returns an 
> error.
> So you can find it in WeTransfer in this link
>
> https://wetransfer.com/downloads/5d1a0f5303b2a61ee27f64a9ce73ed7c20190406180555/90183abbd7bf1cbaab5ab1011cbdafed20190406180555/81e5a8
>
>

-- 
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: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-06 Thread Anthony
Yes, post the app.

On Saturday, April 6, 2019 at 12:49:15 PM UTC-4, João Matos wrote:
>
> I created a minimal app and it showed the problem.
> I di some further testing and confirmed that there is a relation with the 
> positioning of the T.force().
> If the T.force() is after the extra_fields creation (which reside in 
> db.py), the fields validation messages are always in English, even after 
> changing the language (the changing language code resides in db1.py, but 
> before the table defs).
> If I change the language changing code to before the extra_fields. The 
> extra_fields validation messages show up with the correct language.
>
> Do you still want me to send you the minimal app?
>
>
> sábado, 6 de Abril de 2019 às 17:01:24 UTC+1, Anthony escreveu:
>>
>> Can you post a minimal app the reproduces the problem?
>>
>> On Saturday, April 6, 2019 at 4:24:12 AM UTC-4, João Matos wrote:
>>>
>>> All my grids and forms get auto-translated validation messages 
>>> correctly. Here is an example
>>>
>>> table = db.sn_counter  # type: Table
>>>
>>> grid = SQLFORM.grid(
>>> table,
>>> csv=False,
>>> details=False,
>>> ondelete=on_delete,  # Grid only.
>>> onvalidation=on_validation,  # Form only.
>>> orderby=db.sn_counter.name,
>>> paginate=session.auth.user.pagination,
>>> # represent_none='',  # Grid and view form only.
>>> sortable=False,
>>> )  # type: gluon.DIV
>>>
>>> which uses this table
>>>
>>> db.define_table('sn_counter',
>>> Field('name', 'string', label=T('Name'), length=NAME_LEN
>>> , notnull=True,
>>>   required=True, unique=True),
>>> Field('last_assigned', 'integer', default=0, label=T('Last 
>>> assigned'),
>>>   notnull=True, required=True),
>>> Field('canceled_on', 'datetime', label=T('Canceled on'), 
>>> writable=False),
>>> Field('canceled_by', 'reference auth_user', 
>>> label=T('Canceled 
>>> by'),
>>>   writable=False),
>>> Field('cancel_approved_by', 'reference auth_user',
>>>   label=T('Cancel approved by'), writable=False),
>>> auth.signature,
>>> # common_filter = lambda query: db.sn_counter.is_active 
>>> == True,
>>> format='%(name)s',
>>> # plural=T('sn counters'), singular=T('sn counter'),
>>> )
>>>
>>> # db.sn_counter.name.requires = (IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '
>>> sn_counter.name'))
>>> db.sn_counter.last_assigned.requires = IS_INT_IN_RANGE(0, 10)
>>>
>>> I give the option to the user to change the language between PT and EN. 
>>> Yes, it overrides T.force('pt') with T.force('en') and update sthe page.
>>> My original code didn't have a T.force('pt') before the extra_fields and 
>>> so all my validation messages appeared correctly in PT or EN, except for 
>>> the validation messages of the extra_fields (they always appeared in EN).
>>> If I add the T.force('pt') before adding the extra_fields, all my 
>>> validation messages appear correctly in PT or EN, but all the extra_fields 
>>> validation messages appear only in PT.
>>>
>>> No, I'm using just one application.
>>>
>>>
>>> sexta-feira, 5 de Abril de 2019 às 23:35:38 UTC+1, Anthony escreveu:
>>>>
>>>> Hmm, I see that the framework does add the T translator to the 
>>>> Validator class, so validation messages should be getting translated. 
>>>> There 
>>>> is nothing special about Auth extra_fields -- the validators you add there 
>>>> are no different from the validators added to other fields.
>>>>
>>>> Can you give an example of code using the same validator where the 
>>>> message is translated outside of extra_fields but not within extra_fields?
>>>>
>>>> Also, in your example, you mentioned when setting T.force('pt'), all 
>>>> messages came out in Portuguese, even if you "change the language to 
>>>> English". What do you mean by "change the language to English" there? 
>>>> Setting T.force('pt') should force all translations to Portuguese unless 
>>>> you

[web2py] Re: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-06 Thread Anthony
Can you post a minimal app the reproduces the problem?

On Saturday, April 6, 2019 at 4:24:12 AM UTC-4, João Matos wrote:
>
> All my grids and forms get auto-translated validation messages correctly. 
> Here is an example
>
> table = db.sn_counter  # type: Table
>
> grid = SQLFORM.grid(
> table,
> csv=False,
> details=False,
> ondelete=on_delete,  # Grid only.
> onvalidation=on_validation,  # Form only.
> orderby=db.sn_counter.name,
> paginate=session.auth.user.pagination,
> # represent_none='',  # Grid and view form only.
> sortable=False,
> )  # type: gluon.DIV
>
> which uses this table
>
> db.define_table('sn_counter',
> Field('name', 'string', label=T('Name'), length=NAME_LEN, 
> notnull=True,
>   required=True, unique=True),
> Field('last_assigned', 'integer', default=0, label=T('Last 
> assigned'),
>   notnull=True, required=True),
> Field('canceled_on', 'datetime', label=T('Canceled on'), 
> writable=False),
> Field('canceled_by', 'reference auth_user', label=T('Canceled 
> by'),
>   writable=False),
> Field('cancel_approved_by', 'reference auth_user',
>   label=T('Cancel approved by'), writable=False),
> auth.signature,
> # common_filter = lambda query: db.sn_counter.is_active 
> == True,
> format='%(name)s',
> # plural=T('sn counters'), singular=T('sn counter'),
> )
>
> # db.sn_counter.name.requires = (IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '
> sn_counter.name'))
> db.sn_counter.last_assigned.requires = IS_INT_IN_RANGE(0, 10)
>
> I give the option to the user to change the language between PT and EN. 
> Yes, it overrides T.force('pt') with T.force('en') and update sthe page.
> My original code didn't have a T.force('pt') before the extra_fields and 
> so all my validation messages appeared correctly in PT or EN, except for 
> the validation messages of the extra_fields (they always appeared in EN).
> If I add the T.force('pt') before adding the extra_fields, all my 
> validation messages appear correctly in PT or EN, but all the extra_fields 
> validation messages appear only in PT.
>
> No, I'm using just one application.
>
>
> sexta-feira, 5 de Abril de 2019 às 23:35:38 UTC+1, Anthony escreveu:
>>
>> Hmm, I see that the framework does add the T translator to the Validator 
>> class, so validation messages should be getting translated. There is 
>> nothing special about Auth extra_fields -- the validators you add there are 
>> no different from the validators added to other fields.
>>
>> Can you give an example of code using the same validator where the 
>> message is translated outside of extra_fields but not within extra_fields?
>>
>> Also, in your example, you mentioned when setting T.force('pt'), all 
>> messages came out in Portuguese, even if you "change the language to 
>> English". What do you mean by "change the language to English" there? 
>> Setting T.force('pt') should force all translations to Portuguese unless 
>> you override the T.force('pt').
>>
>> Finally, are you running/sending requests to more than one application, 
>> not all of which have the same translation files?
>>
>> Anthony
>>
>> On Friday, April 5, 2019 at 2:03:57 PM UTC-4, João Matos wrote:
>>>
>>> All my other error messages (from built-in validators) are 
>>> auto-translated. Including for the default auth_user fields (eg. username). 
>>> Only the extra_fields are not.
>>>
>>> Is there a fix?
>>>
>>>
>>> sexta-feira, 5 de Abril de 2019 às 18:56:10 UTC+1, Anthony escreveu:
>>>>
>>>> Note, this is due to the recent refactoring of all built-in validators 
>>>> (moved from web2py to pydal). Previously, all default error messages were 
>>>> translated, but that is no longer the case. Although the automatic 
>>>> translation was not documented, I would still consider this a break in 
>>>> backward compatibility (particularly given that all Auth error messages 
>>>> are 
>>>> still being translated automatically).
>>>>
>>>> Anthony
>>>>
>>>> On Thursday, April 4, 2019 at 3:25:10 PM UTC-4, João Matos wrote:
>>>>>
>>>>> When creating extra fields for auth_user, the validation messages for 
&g

[web2py] Re: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-05 Thread Anthony
Hmm, I see that the framework does add the T translator to the Validator 
class, so validation messages should be getting translated. There is 
nothing special about Auth extra_fields -- the validators you add there are 
no different from the validators added to other fields.

Can you give an example of code using the same validator where the message 
is translated outside of extra_fields but not within extra_fields?

Also, in your example, you mentioned when setting T.force('pt'), all 
messages came out in Portuguese, even if you "change the language to 
English". What do you mean by "change the language to English" there? 
Setting T.force('pt') should force all translations to Portuguese unless 
you override the T.force('pt').

Finally, are you running/sending requests to more than one application, not 
all of which have the same translation files?

Anthony

On Friday, April 5, 2019 at 2:03:57 PM UTC-4, João Matos wrote:
>
> All my other error messages (from built-in validators) are 
> auto-translated. Including for the default auth_user fields (eg. username). 
> Only the extra_fields are not.
>
> Is there a fix?
>
>
> sexta-feira, 5 de Abril de 2019 às 18:56:10 UTC+1, Anthony escreveu:
>>
>> Note, this is due to the recent refactoring of all built-in validators 
>> (moved from web2py to pydal). Previously, all default error messages were 
>> translated, but that is no longer the case. Although the automatic 
>> translation was not documented, I would still consider this a break in 
>> backward compatibility (particularly given that all Auth error messages are 
>> still being translated automatically).
>>
>> Anthony
>>
>> On Thursday, April 4, 2019 at 3:25:10 PM UTC-4, João Matos wrote:
>>>
>>> When creating extra fields for auth_user, the validation messages for 
>>> those fields are always in English. They don't comply with the translations 
>>> available.
>>>
>>> This does not happen on the default fields.
>>>
>>>
>>> I added this to db.py
>>>
>>>
>>> auth.settings.extra_fields['auth_user'] = [Field('pagination', 'integer'
>>> , default=9, label=T('Pagination'), notnull=True, required=True, 
>>> requires=IS_INT_IN_RANGE(5, 51))] 
>>>
>>>
>>> When inserting an invalid value, the returned message is always
>>>
>>> Enter an integer between 5 and 50
>>>>
>>> even when the web2py language is not English and the languages files 
>>> have the correct translation available.
>>>
>>>
>>> web2py 2.18.4
>>> Python 3.7.1 x86
>>> Firefox 66.0.2 x64
>>> Windows 7 Pro x64 SP1+all updates
>>>
>>

-- 
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: Custom validator broken in 2.18.4, working in 2.17.2

2019-04-05 Thread Anthony
Though that breaks backward compatibility, as the interface for custom 
validators is provided in the official documentation.

On Friday, April 5, 2019 at 2:07:22 PM UTC-4, Leonel Câmara wrote:
>
> The way validators are in 2.18.4 you need to do it like this:
>
>
> class IS_MEMBERSHIP_YEAR_END(Validator)
> :
> def __init__(self, error_message='Not a membership year end'):
> self.error_message = error_message
>
> def validate(self, value):
> yearend = datetime.date(2018,9,30)
> if value.month==yearend.month and value.day==yearend.day:
> return value
> else:
> raise ValidationError(self.translator(self.error_message))
>

-- 
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: Validation messages of extra fields in auth_user don't comply with available translations

2019-04-05 Thread Anthony
Note, this is due to the recent refactoring of all built-in validators 
(moved from web2py to pydal). Previously, all default error messages were 
translated, but that is no longer the case. Although the automatic 
translation was not documented, I would still consider this a break in 
backward compatibility (particularly given that all Auth error messages are 
still being translated automatically).

Anthony

On Thursday, April 4, 2019 at 3:25:10 PM UTC-4, João Matos wrote:
>
> When creating extra fields for auth_user, the validation messages for 
> those fields are always in English. They don't comply with the translations 
> available.
>
> This does not happen on the default fields.
>
>
> I added this to db.py
>
>
> auth.settings.extra_fields['auth_user'] = [Field('pagination', 'integer', 
> default=9, label=T('Pagination'), notnull=True, required=True, requires=
> IS_INT_IN_RANGE(5, 51))] 
>
>
> When inserting an invalid value, the returned message is always
>
> Enter an integer between 5 and 50
>>
> even when the web2py language is not English and the languages files have 
> the correct translation available.
>
>
> web2py 2.18.4
> Python 3.7.1 x86
> Firefox 66.0.2 x64
> Windows 7 Pro x64 SP1+all updates
>

-- 
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: Error Ticket Includes Sensitive Information

2019-04-04 Thread Anthony
On Thursday, April 4, 2019 at 10:47:10 AM UTC-4, Kevin Keller wrote:
>
> Can errror messags and tickets in production not be restricted to server 
> log files and disabled to be displayed for users or at least the ticket 
> itself made inaccessbile to normal users?
>

Normal users can never see error tickets. The problem is writing sensitive 
information to the server storage.

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 block logins from users with is_active == False?

2019-04-03 Thread Anthony
How are you setting is_active to False? Are you doing it manually, or is it 
happening via a delete with record versioning enabled (as described here 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-versioning>)?
 
If the latter, you don't need to do any check, as a common filter 
automatically excludes all records with in_active == False from all queries.

If you are setting it manually, you can set up your own common filter 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Common-filters>
:

db.auth_user._common_filter = lambda query: db.auth_user.is_active == True

By default, the above will affect all queries against the db.auth_user 
table (though can be disabled for specific queries).

If you want to be able to show an error message as in your code below for 
users who are in the system but simply not active (as opposed to users who 
are not in the system at all), then your approach is probably best.

Anthony

On Tuesday, April 2, 2019 at 8:52:20 PM UTC-4, João Matos wrote:
>
> Found a solution
>
> def check_if_user_is_active(form):
> """Check if user is active."""
> if not db.auth_user(username=form.vars.username).is_active:
> session.flash = T('That username is not active.')
> redirect(URL('user', 'login'))
>
>
> auth.settings.login_onvalidation.append(check_if_user_is_active)
>
>
> Is there a better way?
>
>
> quarta-feira, 3 de Abril de 2019 às 01:25:22 UTC+1, João Matos escreveu:
>>
>> Hello,
>>
>> How can I block logins from users with is_active == False?
>>
>> Thanks,
>>
>> JM
>>
>>

-- 
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: Is it possible to show the results from a SELECT (made with SQLite using db.executesql) in a grid?

2019-04-02 Thread Anthony
Note, you do not need to set fake_migrate, as long as migrate=False (the 
DAL will simply ignore migrations for that table).

On Tuesday, April 2, 2019 at 1:43:41 AM UTC-4, Val K wrote:
>
> Create view in sqlite "CREATE VIEW your_tbl_name AS SELECT ..." using 
> executesql and define corresponding  web2py table with migrate=False, 
> fake_migrate=True

-- 
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 add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony
Need to see the code that generated the KeyError, as well as the full 
traceback, and details about how/when the error was generated.

On Saturday, March 30, 2019 at 3:31:41 PM UTC-4, João Matos wrote:
>
> This is my code
> form = SQLFORM.factory(
> Field('equipment_id',
>   label=T('Equipment'),
>   requires=IS_IN_SET({wo.equipment_id: db.equipment(wo.
> equipment_id).name},
>  zero=None),
> ),
> Field('sn',
>   label=T('SN'),
>   widget=lambda field, value: (
> SQLFORM.widgets.string.widget(field, value, _readonly=True
> )),
> ),
> Field('code',
>   label=T('WO'),
>   requires=IS_EMPTY_OR(IS_IN_DB(db(query), 'wo.code', distinct
> =True)),
> ),
> Field('client_id',
>   label=T('Client'),
>   requires=IS_IN_DB(db, 'client.id', '%(name)s', zero=T('Choose 
> one...')),
> ),
> Field('manual_lang_id',
>   label=T('Manual language'),
>   requires=IS_IN_DB(db,
> 'manual_lang.id',
> '%(name)s',
> zero=T('Choose one...'),
>   ),
> ),
> Field('co_code', default='', label=T('Customer order')),
> Field('so_code', default='', label=T('Supplier order')),
> Field('export', 'boolean', default=False, label=T('Export')),
> Field('notes', default='', label=T('Notes')),
> Field('observations', default='', label=T('Observations')),
> Field('est_finish',
>   'date',
>   label=T('Estimated finish'),
>   notnull=True,
>   required=True,
>   requires=IS_DATE_IN_RANGE(  # format=T('%Y-%m-%d'),
> minimum=request.now.date() + 
> timedelta(days=1),
> # maximum=request.now.date() + ,
> error_message=T('Must be a future 
> date.')
>   )
> ),
> *factory_fields,
> )
>
>
> sábado, 30 de Março de 2019 às 19:03:40 UTC, Anthony escreveu:
>>
>> Hard to say without seeing your code, but it definitely works for me.
>>
>> On Saturday, March 30, 2019 at 2:37:27 PM UTC-4, João Matos wrote:
>>>
>>> How can I use the fields argument without a db?
>>> I tried
>>> fields=['sn']
>>> but it returns an KeyError.
>>>
>>>
>>> sábado, 30 de Março de 2019 às 18:27:11 UTC, Anthony escreveu:
>>>>
>>>> I don't see any advantage in using the fields parameter because the 
>>>>> change I found
>>>>> form.element('#no_table_sn')['_readonly'] = 'readonly' 
>>>>> and the suggestion you made
>>>>> widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True
>>>>> )
>>>>> only change 1 line, and using the fields would make me change all the 
>>>>> Fields lines (if I'm not mistaken).
>>>>>
>>>>
>>>> No, "fields" is an argument of SQLFORM:
>>>>
>>>> form = SQLFORM.factory(..., fields=['field1', 'field2', ...])
>>>>
>>>> Anyway, setting the _readonly attribute of the input widget and setting 
>>>> writable=False in the Field() definition do two different things. The 
>>>> former makes the input element read-only in the UI but is less secure 
>>>> because it does not prevent writes on the server. The latter does not use 
>>>> an input element to display the data in the UI, and it also prevents 
>>>> writes 
>>>> on the server.
>>>>
>>>> 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 add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony
Hard to say without seeing your code, but it definitely works for me.

On Saturday, March 30, 2019 at 2:37:27 PM UTC-4, João Matos wrote:
>
> How can I use the fields argument without a db?
> I tried
> fields=['sn']
> but it returns an KeyError.
>
>
> sábado, 30 de Março de 2019 às 18:27:11 UTC, Anthony escreveu:
>>
>> I don't see any advantage in using the fields parameter because the 
>>> change I found
>>> form.element('#no_table_sn')['_readonly'] = 'readonly' 
>>> and the suggestion you made
>>> widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True)
>>> only change 1 line, and using the fields would make me change all the 
>>> Fields lines (if I'm not mistaken).
>>>
>>
>> No, "fields" is an argument of SQLFORM:
>>
>> form = SQLFORM.factory(..., fields=['field1', 'field2', ...])
>>
>> Anyway, setting the _readonly attribute of the input widget and setting 
>> writable=False in the Field() definition do two different things. The 
>> former makes the input element read-only in the UI but is less secure 
>> because it does not prevent writes on the server. The latter does not use 
>> an input element to display the data in the UI, and it also prevents writes 
>> on the server.
>>
>> 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 add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony

>
> I don't see any advantage in using the fields parameter because the change 
> I found
> form.element('#no_table_sn')['_readonly'] = 'readonly' 
> and the suggestion you made
> widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True)
> only change 1 line, and using the fields would make me change all the 
> Fields lines (if I'm not mistaken).
>

No, "fields" is an argument of SQLFORM:

form = SQLFORM.factory(..., fields=['field1', 'field2', ...])

Anyway, setting the _readonly attribute of the input widget and setting 
writable=False in the Field() definition do two different things. The 
former makes the input element read-only in the UI but is less secure 
because it does not prevent writes on the server. The latter does not use 
an input element to display the data in the UI, and it also prevents writes 
on the server.

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 add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
On Friday, March 29, 2019 at 5:42:10 PM UTC-4, João Matos wrote:
>
> Found a solution (more like a kludge) :)
>
> form.element('#no_table_sn')['_readonly'] = 'readonly' 
>
I even tried adding 
>
> _readonly='readonly'
>
> to the Field, but didn't work.
>
> Only works after the form exists.
>

Field('sn', widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, 
_readonly=True))


> Is there a better way?
>

As noted earlier, you can use the "fields" argument.

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 add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
On Friday, March 29, 2019 at 5:04:41 PM UTC-4, João Matos wrote:
>
> @Anthony
> This is a SQLFORM.factory not a SQLFORM.
> There is no database.
> Are you sure fields parameter is applicable to SQLFORM.factory w/o a db?
>

Yes, it does work with SQLFORM.factory.

>

-- 
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: placeholder for update record field names

2019-03-29 Thread Anthony
You can create a dictionary of field names and values and then do:

workrecord.update_record(**dict_of_new_values)

Anthony

On Friday, March 29, 2019 at 4:49:28 PM UTC-4, Steve wrote:
>
> Hi All,
>
> When updating a record i would like to make some column names variable.
> I have the next statement : workrecord.update_record(starttime=iid.start, 
> t1=worktime, c1=amount)
>
> I would like to make the field t1 variable so that ik can replace the 1 
> with another number.!
> Any a suggestion if this is possible and if so how.
>
> The %s or %d does not work on fieldnames
>
> Steve
>

-- 
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 add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
By default, non-writable fields are excluded from create forms (though 
shown in edit forms if readable=True). However, you can override that 
behavior by specifying the "fields" argument with a list of field names to 
include in the form.

Anthony

On Friday, March 29, 2019 at 4:32:27 PM UTC-4, João Matos wrote:
>
> Tried that, doesn't work.
> With writable=False the field isn't shown.
>
>
> sexta-feira, 29 de Março de 2019 às 20:12:45 UTC, Jim S escreveu:
>>
>> Set writable=False
>>
>> Field('end', 'date', requires=IS_DATE('%m/%d/%Y'), default=default_end, 
>> writable=False)
>>
>> -Jim
>>
>> On Friday, March 29, 2019 at 2:39:58 PM UTC-5, João Matos wrote:
>>>
>>> Hello,
>>>
>>> How can I add a read-only field to a SQLFORM.factory?
>>>
>>> Thanks,
>>>
>>> JM
>>>
>>>

-- 
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: Is there a way to differentiate between a form refresh (F5) and a submit that calls back the form?

2019-03-28 Thread Anthony

>
> which I changed now to this
>
>   elif request.post_vars.modified_on != str(db.client(request.vars.id).
> modified_on):
>  session.flash = T('Record was changed while you were editing. '
>'This is the updated record.')
>  redirect(URL(args=request.args, vars=request.get_vars, user_signature
> =True))
>

Why not put the above inside the "edit" condition, as it is not relevant 
otherwise (and won't work on record creation)? Also, given that this is in 
the onvalidation function, why not use form.record rather than 
unnecessarily re-selecting the record via db.client(request.vars.id)?

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: Is there a way to differentiate between a form refresh (F5) and a submit that calls back the form?

2019-03-27 Thread Anthony
I don't see any code that checks for record change, but you could do 
something like:

elif request.args and request.args[0] == 'edit':
if request.vars.modified_on != str(form.record.modified_on):
session.flash = 'Record change detected. Please try again.'
redirect(URL(args=request.args, vars=request.get_vars))

That will redirect to the same URL, which will load the same record (with 
the updated data), and show the message after redirect.

Anthony

On Wednesday, March 27, 2019 at 3:06:16 PM UTC-4, João Matos wrote:
>
> This is my code for the another table (it has the same situation, but 
> without using a SQLFORM.factory).
> I posted this instead of the SQLFORM.factory, because it is simpler code.
>
> My index function contains the grid
>
> grid = SQLFORM.grid(
> query,
> csv=False, deletable=False, details=False,
> links=[
> lambda row: A(
> SPAN(T('Delete'), _class='buttontext button', _title=
> 'Delete'),
> _href=URL('get_approval', args=[row.id], 
> user_signature=True),
> _class='button btn btn-default btn-secondary',
> ),
> ],
> onvalidation=on_validation,  # Form only.
> orderby=db.client.name,
> paginate=session.auth.user.pagination,
> # represent_none='',  # Grid and view form only.
> )
>
>
> if 'edit' in request.args:
> form = grid.update_form
> form['hidden'].update(modified_on=form.record.modified_on)
>
> My onvalidation function
>
> if request.args and request.args[0] == 'new':
> # Fix for SQLite instead of for_update=True. When for_update is
> # fixed for SQLite, only the first SELECT in the function should
> # have for_update=True.
> while True:
> try:
> # SQLite only does database lock.
> db.executesql('BEGIN IMMEDIATE TRANSACTION')
> break
> except sqlite3.OperationalError:
> sleep(0.5)
> elif not db.client(request.vars.id).is_active:
> session.flash = T('Record was deleted while you were editing.')
> redirect(URL(user_signature=True))
> elif request.post_vars.modified_on != str(db.client(request.vars.id).
> modified_on):
> form.errors.code = T('Record was changed while you were editing. '
>  'Press F5 to refresh and press Resend in the 
> '
>  'browser question.')
> elif form.vars.delete_this_record:
> # Fix for SQLite instead of for_update=True. When for_update is
> # fixed for SQLite, only the first SELECT in the function should
> # have for_update=True.
> while True:
> try:
> # SQLite only does database lock.
> db.executesql('BEGIN IMMEDIATE TRANSACTION')
> break
> except sqlite3.OperationalError:
> sleep(0.5)
>
> db.client(request.vars.id).update_record(
> cancel_approved_by=auth.user_id,
> canceled_by=auth.user_id,
> canceled_on=request.now,
> is_active=False,
> )
>
> db.commit()
>
> session.flash = T('Done.')
> redirect(URL(user_signature=True))
> elif request.args and request.args[0] == 'edit':
> # Fix for SQLite instead of for_update=True. When for_update is
> # fixed for SQLite, only the first SELECT in the function should
> # have for_update=True.
> while True:
> try:
> # SQLite only does database lock.
> db.executesql('BEGIN IMMEDIATE TRANSACTION')
> break
> except sqlite3.OperationalError:
> sleep(0.5)
>
>
>
> quarta-feira, 27 de Março de 2019 às 18:47:33 UTC, Anthony escreveu:
>>
>> Need to see your code.
>>
>> On Wednesday, March 27, 2019 at 2:47:01 PM UTC-4, João Matos wrote:
>>>
>>> You mean to update the editing form with the new values from the record 
>>> on the db without telling the user to press F5?
>>> How can I do it?
>>>
>>> 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.


  1   2   3   4   5   6   7   8   9   10   >