[web2py] Re: response.js after redirect

2017-06-29 Thread Filipe Reis
Ohh nice thinking, I forgot that I could do such thing :) 

Anyways I asked this in other thread but do you know something about this?

How to use signature with web2py_component? (I changed web2py_ajax_page to 
web2py_component since I saw that this calls the ajax_page)

So when a request is done to the page it only shows if was triggered the 
that call only. This is what I think that @auth.requires_signature() does

-- 
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: JSON field with MySQL database

2017-06-29 Thread Anthony
On Thursday, June 29, 2017 at 12:49:16 PM UTC-4, narcissus wrote:
>
> Thanks for your answer.
> Option 1) In my case I cannot change fields into the original database.
> Option 2) and 3) can you provide implementation examples for my specific 
> case
>

I'm not familiar with how MySQL JSON fields work, so not entirely sure what 
would be appropriate. Note, the filter_in/filter_out example in the book is 
a JSON example, so maybe start there.

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: response.js after redirect

2017-06-29 Thread Anthony
You don't need to do it that way. Just import json -- see 
https://groups.google.com/d/msg/web2py/9WnoALNHxTI/54cTUgHNBgAJ.

Anthony

On Thursday, June 29, 2017 at 12:36:42 PM UTC-4, Filipe Reis wrote:
>
> Got it all working now. It was a problem with using response.json to parse 
> the flash message.
>
> To future reference this is how it is:
>
> var w2p_flash = {{=XML(response.flash) if response.flash else 'null'}};
> if (w2p_flash) {
>var w2p_flash = jQuery.parseJSON(JSON.stringify(w2p_flash));
>$.notific8(w2p_flash.message, w2p_flash.options);
> }
>
>

-- 
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: Advice needed on complex SQL operation

2017-06-29 Thread Karoly Kantor
Thank you, that looks helpful, I will start along these lines. I have some 
questions, though:

1. Will this work if more than one fields are set to "group"? 

2. What's up with count, does it ever make sense to have more than one 
field set to "count", and if yes, what would be the difference between 
them? 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: web2py.component equivalent for =LOAD

2017-06-29 Thread Filipe Reis
By any chance did you understand how to use signature with web2py_component?

So when a request is done to the page it only shows if was triggered the 
that call only. This is what I think that @auth.requires_signature() doe

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: web2py.component equivalent for =LOAD

2017-06-29 Thread Filipe Reis
By any chance did you understand how to use signature with web2py_component?

So when a request is done to the page it only shows if was triggered the 
that call only. This is what I think that @auth.requires_signature() does.

-- 
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: JSON field with MySQL database

2017-06-29 Thread narcissus
Thanks for your answer.
Option 1) In my case I cannot change fields into the original database.
Option 2) and 3) can you provide implementation examples for my specific 
case
Option 4) I think I'll do it

Il giorno giovedì 29 giugno 2017 15:23:37 UTC+2, Anthony ha scritto:
>
> In most databases (including MySQL), the DAL simply stores JSON in a text 
> field and converts to and from Python objects when writing/reading the 
> data. The Postgres adapter makes use of the Postgres native JSON field 
> type, but the MySQL adapter does not yet do so.
>
> Some options might be to convert the JSON field to a text field, define a 
> DAL custom field type 
> ,
>  
> or define filter_in/filter_out 
> 
>  
> functions. Or submit a pull request to support the MySQL JSON field type.
>
> Anthony
>
> On Thursday, June 29, 2017 at 9:10:16 AM UTC-4, narcissus wrote:
>>
>> Hi,
>> I've created a database model containing a field of type json to access a 
>> pre-existent MySQL database (created with mysql server version > 5.7.11) 
>> containing the same field of type json into the same table.
>> I cannot understand why the json data stored into the database are read 
>> always as null by web2py DAL functions.
>> This happens only when I access to MySQL database (ex: Postgres works). 
>> It seems that no converter has been implemented for MySQL json field into 
>> web2py DAL.
>>
>> Thanks in advanced for helping me
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Filipe Reis
Got it all working now. It was a problem with using response.json to parse 
the flash message.

To future reference this is how it is:

var w2p_flash = {{=XML(response.flash) if response.flash else 'null'}};
if (w2p_flash) {
   var w2p_flash = jQuery.parseJSON(JSON.stringify(w2p_flash));
   $.notific8(w2p_flash.message, w2p_flash.options);
}

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Filipe Reis
Yeah that did it, however still getting the same issue: Resource 
interpreted as Document but transferred with MIME type application/json.

This is for sure happening when using the session.flash with a dict.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Anthony
Try wrapping it in XML():

var w2p_flash = {{=XML(response.json(response.flash)) if response.flash else 
'null'}};

Anthony

On Thursday, June 29, 2017 at 11:25:20 AM UTC-4, Filipe Reis wrote:
>
> Was looking better it seems that this is a problem with how response.flash 
> passes the value.
>
> var w2p_flash = {message: New client inserted into 
> database., options: {theme: lime, 
> heading: Success}};
>
>
> This is how the flash is passed to the view, is there any way to get it 
> right with " instead of  since response.json cannot handle it this 
> way?
>
> For the view that is loaded via ajax and not showing the flash would you 
> say that I need to do the same for this particular view?
>
> Thanks for all your time.
>

-- 
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: Totally app-internal routing

2017-06-29 Thread Anthony
You need to have at least a basic routes.py in the root /web2py folder, but 
for application specific routing, you can also put a routes.py file in the 
application folder (i.e., in /web2py/applications/myapp/). If you are using 
the pattern-based rewrite system, you'll need to use routes_app in the root 
routes.py file (as described at the end of this section of the book 
) 
to route to the app. If you are using the parameter-based system, the root 
routes.py file just needs a basic "router" dict (it could be empty or 
include a simple "BASE" dict). The app-specific routes.py file would then 
include a router specified like this:

router = dict(
myapp = dict(
...
)
)

where "myapp" is the name of the application. The rewrite system will 
compose the "router" from the root routes.py file with the "router" from 
the application routes.py file.

Anthony

On Wednesday, June 28, 2017 at 6:39:47 PM UTC-4, Brendan Barnwell wrote:
>
> Looking at the routing discussion in the docs, it seems that any kind of 
> custom routing has to be defined at the global level of the entire web2py 
> install.  Is that correct?  This seems awkward if I want to write an app 
> that carries with it its own knowledge of how it wants to route its 
> internal URLs, so that it can be dropped into an existing web2py install 
> without requiring extra global config (as web2py apps usually can be).
>
> Given that the usual web2py URL scheme is 
> host/app/controller/function/extra , what I'm wondering is, is there a way 
> for an application to hook into ONLY the /controller/function/extra part?  
> What I would like is to be able to get in AFTER web2py decides which app is 
> being accessed, but BEFORE it decides which controller file to load.  This 
> way I could, for instance, do URL rewrite rules that change /myapp/somepage 
> to /myapp/somecontroller/somepage --- again, without requiring any changes 
> to code outside the application's own folder.  Is this 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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Filipe Reis
Was looking better it seems that this is a problem with how response.flash 
passes the value.

var w2p_flash = {message: New client inserted into 
database., options: {theme: lime, 
heading: Success}};


This is how the flash is passed to the view, is there any way to get it 
right with " instead of  since response.json cannot handle it this 
way?

For the view that is loaded via ajax and not showing the flash would you 
say that I need to do the same for this particular view?

Thanks for all your time.

-- 
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: Violating unique constraint in Field doesn't go to standard 500 page

2017-06-29 Thread Anthony
Have you specified routes_onerror? If so, what does that code look like? It 
looks like your error handler itself may be generating an error.

Anthony

On Thursday, June 29, 2017 at 9:42:42 AM UTC-4, Chris wrote:
>
> Hello!
>
> I'm running 2.14.6-stable+timestamp.2016.05.10.00.21.47 and have hit this 
> issue:
>
> If I have a Field where unique=True, inserting a row with a duplicate 
> Field value triggers the constraint, as expected. However, the error does 
> not lead to a page linking to a ticket, but instead to a generic page 
> saying Server Error.
>
> I've traced the error down to this section of globals.py:
>
> @property
> def body(self):
> if self._body is None:
> try:
> self._body = copystream_progress(self)
> except IOError:
> raise HTTP(400, "Bad Request - HTTP body is incomplete")
> return self._body
>
>
> The error thrown by copystream_progress is of type  'socket.timeout'>, and seems to occur because of a timeout opening 
> env['wsgi.input'] (globals.py, copystream_progress)
>
> I haven't been able to trace the error further, but here's the Rocket 
> output to stderr:
>
>
> ERROR:Rocket.Errors.Thread-6:Traceback (most recent call last):
>
>   File "\dynamic\gluon\rocket.py", line 1337, in run
> self.run_app(conn)
>
>   File "\dynamic\gluon\rocket.py", line 1838, in run_app
> output = self.app(environ, self.start_response)
>
>   File "\dynamic\gluon\main.py", line 653, in app_with_logging
> ret[0] = wsgiapp(environ, responder2)
>
>   File "\dynamic\gluon\main.py", line 564, in wsgibase
> return wsgibase(new_environ, responder)
>
>   File "\dynamic\gluon\main.py", line 534, in wsgibase
> if request.body:
>
>   File "\dynamic\gluon\globals.py", line 281, in body
> raise HTTP(400, "Bad Request - HTTP body is incomplete")
>
> HTTP: 400 BAD REQUEST
>
> Any help you can give would be most welcome!
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Anthony
You can instead put that code in the view of the controller. If you need it 
across multiple actions, just create a separate view template for it and 
use {{include ...}} to include it wherever needed.

Anthony

On Thursday, June 29, 2017 at 9:25:00 AM UTC-4, Filipe Reis wrote:
>
> Thanks for your time, this seems to be a solution to exactly what I want 
> however when I try to implement it I get this error:
> Resource interpreted as Document but transferred with MIME type 
> application/json
>
> Should this be a problem because I am including the web2py javascript 
> also? It needs to be included because of these other stuff like the 
> web2py_ajax_page function and others.
>
>
> Also when the post is not successful the flash seems to not work this way 
> since the request is trapped? (because was called via the 
> web2py_ajax_page("GET", url, "", target);)
>

-- 
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] SQLFORM.grid with selectable checkboxes that export CSV files on submit

2017-06-29 Thread 'Matthew J Watts' via web2py-users
Hi all

 I'm trying to modify an SQLFORM.grid so it has selectable check boxes, 
 which allow the user to download selected queries as CSV files once the 
submit button has been clicked. 

Can anyone help me with this?

Thanks in advance

Matt

-- 
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: Broken pipe with mysql

2017-06-29 Thread Richard Vézina
Hello Alexia,

This is a pretty old thread :
https://groups.google.com/d/msg/web2py/Iu36WNoWkX4/bgIob2R6UjsJ

I suggest you to open another one... And tell us more on the issue you
experiment, we don't have enough informaiton (traceback, setup, web2py
version, os, etc) to help. Since 2011 web2py has change a lot. you may face
or not the same issue, I don't know, but we need more info to make sure.

Richard


On Fri, Jun 23, 2017 at 5:25 PM, Alexia Death  wrote:

> This is still an issue. If for whaterver reason db backend closed the
> connection my shell running daemon script will be stuck in 100% cpu
> consuming exception loop and no way to make the model re-establish the db
> connection even if I do catch the exception. As an ugly workarund I could
> drop out of python altogether and restart the daemon script with shell
> tools, but this is so not nice and makes killing the daemon politely just
> that much harder...
>
> Best,
> Alexia
>
> --
> 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.
>

-- 
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] Violating Unique constraint in field doesn't go to standard 500 page

2017-06-29 Thread Richard Vézina
Which web2py version? Which database/adapter??

But I think for unique=True you shouldn't have this error at least if you
had also implement a validator IS_NOT_IN_DB()... unique=True tell the
database to implement unique constrain, but you have to tell the front end
(IS_NOT_IN_DB()) too...

I use to fall on ticket thrown by web2py for unique constrain, but it was
for constrain defined only in the backend/database that applies over more
than one field or involve foreign key field, unique constrain over 2
tables, if I recall... I had to write some logic to catch those error and
return the proper end user error message.

In your case, if you have only a unique constrain over one field, I guess
you can just write the proper validator rule with IS_NOT_IN_DB... To fix
your issue...

Richard

On Thu, Jun 29, 2017 at 9:42 AM, Chris  wrote:

> Hello!
>
> I'm running 2.14.6-stable+timestamp.2016.05.10.00.21.47 and have hit this
> issue:
>
> If I have a Field where unique=True, inserting a row with a duplicate
> Field value triggers the constraint, as expected. However, the error does
> not lead to a page linking to a ticket, but instead to a generic page
> saying Server Error.
>
> I've traced the error down to this section of globals.py:
>
> @property
> def body(self):
> if self._body is None:
> try:
> self._body = copystream_progress(self)
> except IOError:
> raise HTTP(400, "Bad Request - HTTP body is incomplete")
> return self._body
>
>
> The error thrown by copystream_progress is of type  'socket.timeout'>, and seems to occur because of a timeout opening
> env['wsgi.input'] (globals.py, copystream_progress)
>
> I haven't been able to trace the error further, but here's the Rocket
> output to stderr:
>
>
> ERROR:Rocket.Errors.Thread-6:Traceback (most recent call last):
>
>   File "\dynamic\gluon\rocket.py", line 1337, in run
> self.run_app(conn)
>
>   File "\dynamic\gluon\rocket.py", line 1838, in run_app
> output = self.app(environ, self.start_response)
>
>   File "\dynamic\gluon\main.py", line 653, in app_with_logging
> ret[0] = wsgiapp(environ, responder2)
>
>   File "\dynamic\gluon\main.py", line 564, in wsgibase
> return wsgibase(new_environ, responder)
>
>   File "\dynamic\gluon\main.py", line 534, in wsgibase
> if request.body:
>
>   File "\dynamic\gluon\globals.py", line 281, in body
> raise HTTP(400, "Bad Request - HTTP body is incomplete")
>
> HTTP: 400 BAD REQUEST
>
> Any help you can give would be most welcome!
>
> --
> 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.
>

-- 
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] Violating Unique constraint in field doesn't go to standard 500 page

2017-06-29 Thread Chris
Hello!

I'm running 2.14.6-stable+timestamp.2016.05.10.00.21.47 and have hit this 
issue:

If I have a Field where unique=True, inserting a row with a duplicate Field 
value triggers the constraint, as expected. However, the error does not 
lead to a page linking to a ticket, but instead to a generic page saying 
Server Error.

I've traced the error down to this section of globals.py:

@property
def body(self):
if self._body is None:
try:
self._body = copystream_progress(self)
except IOError:
raise HTTP(400, "Bad Request - HTTP body is incomplete")
return self._body


The error thrown by copystream_progress is of type , and seems to occur because of a timeout opening 
env['wsgi.input'] (globals.py, copystream_progress)

I haven't been able to trace the error further, but here's the Rocket 
output to stderr:


ERROR:Rocket.Errors.Thread-6:Traceback (most recent call last):

  File "\dynamic\gluon\rocket.py", line 1337, in run
self.run_app(conn)

  File "\dynamic\gluon\rocket.py", line 1838, in run_app
output = self.app(environ, self.start_response)

  File "\dynamic\gluon\main.py", line 653, in app_with_logging
ret[0] = wsgiapp(environ, responder2)

  File "\dynamic\gluon\main.py", line 564, in wsgibase
return wsgibase(new_environ, responder)

  File "\dynamic\gluon\main.py", line 534, in wsgibase
if request.body:

  File "\dynamic\gluon\globals.py", line 281, in body
raise HTTP(400, "Bad Request - HTTP body is incomplete")

HTTP: 400 BAD REQUEST

Any help you can give would be most welcome!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: response.js after redirect

2017-06-29 Thread Filipe Reis
Thanks for your time, this seems to be a solution to exactly what I want 
however when I try to implement it I get this error:
Resource interpreted as Document but transferred with MIME type 
application/json

Should this be a problem because I am including the web2py javascript also? 
It needs to be included because of these other stuff like the 
web2py_ajax_page function and others.




quinta-feira, 29 de Junho de 2017 às 12:53:33 UTC+1, Anthony escreveu:
>
> Are you using this notification plugin for all flash messages on your 
> site? If so, why not just incorporate it into the layout and use 
> response.flash (and session.flash) as usual? In the layout, you could have 
> something like:
>
> 
> $.notific8('{{=response.flash}}');
> 
>
> If you need to pass in options as well, you could make response.flash a 
> dictionary holding both the message and the options and convert the options 
> part to JSON in the layout:
>
> In controller:
>
> response.flash = dict(message='There is an error.', options=dict(
> heading='Error'))
>
> In layout:
>
> 
> var w2p_flash = {{=response.json(response.flash) if response.flash else 
> 'null'}};
> if (w2p_flash) {
> $.notific8(w2p_flash.message, w2p_flash.options);
> }
> 
>
> Anthony
>
> On Thursday, June 29, 2017 at 6:49:20 AM UTC-4, Filipe Reis wrote:
>>
>> Hello, I was wondering if someone could help me in figuring this out.
>>
>> I have a view that when the user click on a button opens a modal with a 
>> insertion form.
>>
>> I'm calling it by doing this way:
>> web2py_ajax_page("GET", url, "", target);
>>
>> url - being the url like /house/create
>> target - being the div where the form will appear
>>
>> on the form validation I'm trying to use this plugin: 
>> https://github.com/willsteinmetz/notific8 to show flash messages as it 
>> is in javascript when the form is an error I am able to do this:
>> response.js = "$.notific8('Please fill all necessary fields.', {heading: 
>> 'Error'});" 
>>
>> All works ok in here..
>>
>> but if I try the same when the form is success does not work because I do 
>> a redirect after which resets the page and there is no flash message no 
>> more... 
>>
>> I know that session.flash migh work for this cases, but I'm not able to 
>> understand how to make them work together in this case since this 
>> notification plugin works using javascript.
>>
>> Any ideas?
>>
>

-- 
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: JSON field with MySQL database

2017-06-29 Thread Anthony
In most databases (including MySQL), the DAL simply stores JSON in a text 
field and converts to and from Python objects when writing/reading the 
data. The Postgres adapter makes use of the Postgres native JSON field 
type, but the MySQL adapter does not yet do so.

Some options might be to convert the JSON field to a text field, define a 
DAL custom field type 
,
 
or define filter_in/filter_out 

 
functions. Or submit a pull request to support the MySQL JSON field type.

Anthony

On Thursday, June 29, 2017 at 9:10:16 AM UTC-4, narcissus wrote:
>
> Hi,
> I've created a database model containing a field of type json to access a 
> pre-existent MySQL database (created with mysql server version > 5.7.11) 
> containing the same field of type json into the same table.
> I cannot understand why the json data stored into the database are read 
> always as null by web2py DAL functions.
> This happens only when I access to MySQL database (ex: Postgres works). It 
> seems that no converter has been implemented for MySQL json field into 
> web2py DAL.
>
> Thanks in advanced for helping me
>

-- 
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: function lazy_user at ...

2017-06-29 Thread António Ramos
Solved again...

Thank you

2017-06-29 14:03 GMT+01:00 Anthony :

> if not *record["created_by"]()* in ret:
>> ret.append(*record["created_by"]()*)
>>
>>
> That's different from the code you showed earlier. Probably you should
> just do something like this:
>
> created_by = record['created_by']
> created_by = created_by() if callable(created_by) else created_by
> if not created_by in ret:
> ret.append(created_by)
>
> 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.
>

-- 
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] JSON field with MySQL database

2017-06-29 Thread narcissus
Hi,
I've created a database model containing a field of type json to access a 
pre-existent MySQL database (created with mysql server version > 5.7.11) 
containing the same field of type json into the same table.
I cannot understand why the json data stored into the database are read 
always as null by web2py DAL functions.
This happens only when I access to MySQL database (ex: Postgres works). It 
seems that no converter has been implemented for MySQL json field into 
web2py DAL.

Thanks in advanced for helping me

-- 
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: function lazy_user at ...

2017-06-29 Thread Anthony

>
> if not *record["created_by"]()* in ret:
> ret.append(*record["created_by"]()*)
>
>
That's different from the code you showed earlier. Probably you should just 
do something like this:

created_by = record['created_by']
created_by = created_by() if callable(created_by) else created_by
if not created_by in ret:
ret.append(created_by)

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: response.js after redirect

2017-06-29 Thread Anthony
Are you using this notification plugin for all flash messages on your site? 
If so, why not just incorporate it into the layout and use response.flash 
(and session.flash) as usual? In the layout, you could have something like:


$.notific8('{{=response.flash}}');


If you need to pass in options as well, you could make response.flash a 
dictionary holding both the message and the options and convert the options 
part to JSON in the layout.

Anthony

On Thursday, June 29, 2017 at 6:49:20 AM UTC-4, Filipe Reis wrote:
>
> Hello, I was wondering if someone could help me in figuring this out.
>
> I have a view that when the user click on a button opens a modal with a 
> insertion form.
>
> I'm calling it by doing this way:
> web2py_ajax_page("GET", url, "", target);
>
> url - being the url like /house/create
> target - being the div where the form will appear
>
> on the form validation I'm trying to use this plugin: 
> https://github.com/willsteinmetz/notific8 to show flash messages as it is 
> in javascript when the form is an error I am able to do this:
> response.js = "$.notific8('Please fill all necessary fields.', {heading: 
> 'Error'});" 
>
> All works ok in here..
>
> but if I try the same when the form is success does not work because I do 
> a redirect after which resets the page and there is no flash message no 
> more... 
>
> I know that session.flash migh work for this cases, but I'm not able to 
> understand how to make them work together in this case since this 
> notification plugin works using javascript.
>
> Any ideas?
>

-- 
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: function lazy_user at ...

2017-06-29 Thread António Ramos
Aparently not solved...

*function lazy_user at 0x2d82a28*
disappears but the field authors does not update anymore

if i go to admin to save a record i get this error

if not record["created_by"]() in ret:
TypeError: 'int' object is not callable



this is my new code


def get_userIds(rule):
ret=[]
for membership in rule["authors"]:
temp=db(db.auth_membership.group_id==membership).select()
for r in temp:
ret.append(r["user_id"])
return ret

def readers(record):
ret=[]
row=db.status(id=record["status"])
wf=row["workflow"]
rules=db(db.rules.workflow==wf).select()
for rule in rules:
users=get_userIds(rule)
for user in users:
if not user in ret:
ret.append(user)
if not *record["created_by"]()* in ret:
ret.append(*record["created_by"]()*)
return str(ret)


def authors(record):
ret=[]
row=db.status(id=record["status"])
rule=db.rules(workflow=row["workflow"],step=record["status"])
users=get_userIds(rule)
for user in users:
if not user in ret:
ret.append(user)
if ret==[]:
ret.append(*record["created_by"]()*)
return str(ret)



thank you


2017-06-29 10:05 GMT+01:00 António Ramos :

> Solved.
> Thank you again Anthony
>
> 2017-06-28 19:21 GMT+01:00 Anthony :
>
>> In auth.signature, the "created_by" field has a "default" attribute,
>> which is a function (called "lazy_user") that returns auth.user_id. At the
>> point at which the value of the compute field is computed, the row object
>> passed to the compute function simply includes the "lazy_user" function as
>> the value of the "created_by" field -- the function has not been called and
>> returned the auth.user_id value yet (that doesn't happen until after the
>> compute fields are computed). In other words, compute field values are
>> calculated *before* default functions are called, so compute functions
>> should not depend on the values of other fields whose defaults are set via
>> a function.
>>
>> In this case, you have two alternatives:
>>
>> ret.append(record["created_by"]()) # This calls the lazy_user function,
>> which returns auth.user_id
>>
>> or:
>>
>> ret.append(auth.user_id) # Just use auth.user_id directly.
>>
>> Anthony
>>
>>
>> On Wednesday, June 28, 2017 at 12:30:22 PM UTC-4, Ramos wrote:
>>>
>>> Hello i added an authors and readers  computed fields to my table
>>>
>>> db.define_table(
>>> 'entities',
>>>...
>>> Field('authors',compute= lambda r:authors(r)),
>>> ...
>>> )
>>>
>>> when i save a record i get this
>>> :
>>> authors :
>>> [**]
>>> created_by :
>>> 4L
>>> created_on :
>>> datetime.datetime(2017, 6, 28, 16, 16, 24)
>>> delete_record :
>>> 
>>> description :
>>> entity :
>>> saw
>>> event :
>>> 1903
>>> id :
>>> 401L
>>> is_active :
>>> True
>>> last_error :
>>> modified_by :
>>> 4L
>>> modified_on :
>>> datetime.datetime(2017, 6, 28, 16, 16, 24)
>>> readers :
>>> [2L, 1L, 5L, 4L,* *]
>>> status :
>>> 8L
>>> type :
>>> 1L
>>> update_record :
>>> 
>>> uuid :
>>> c12ecf01-0d7b-4334-81c9-b7808c8cf7f9
>>>
>>> if i go to admin and edit the record and save again the fuction
>>> lazy_user goes away..
>>> Why is this and how to make it save properly in my code?
>>>
>>>
>>> my code...
>>>
>>> def *authors*(record):
>>> ret=[]
>>> row=db.status(id=record["status"])
>>> rule=db.rules(workflow=row["workflow"],step=record["status"])
>>> users=get_userIds(rule)
>>> for user in users:
>>> if not user in ret:
>>> ret.append(user)
>>> if ret==[]:
>>> ret.append(record["created_by"])
>>> return str(ret)
>>>
>>> def get_userIds(rule):
>>> ret=[]
>>> for membership in rule["authors"]:
>>> temp=db(db.auth_membership.group_id==membership).select()
>>> for r in temp:
>>> ret.append(r["id"])
>>> return ret
>>>
>>>
>>> Regards
>>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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: Advice needed on complex SQL operation

2017-06-29 Thread tim . nyborg
Below is something similar I've been playing with.  The interface is utter 
garbage, but it shows the general idea.  A form that allows you to select 
fields and aggregation per field:
Manage a list of queries fields, adding in the field or its .sum() or 
.count() method as necessary.  Where you're not using an aggregate, append 
the field to the groupby list.

def test():
table = idb.student

options = []
for field in table.fields:
options.append(Field(field, 'boolean'))
options.append(Field('%s_group' % field, 'string', 
requires=IS_EMPTY_OR(IS_IN_SET(['group', 'count', 'sum']


form = SQLFORM.factory(
*options,
keepvalues=True
)

if form.process().accepted:
fields = []
groupby = []
for field in form.vars:
if '_group' not in field and form.vars[field]:
if form.vars['%s_group' % field] == 'sum':
fields.append(table[field].sum())
if form.vars['%s_group' % field] == 'count':
fields.append(table[field].count())
if form.vars['%s_group' % field] == 'group':
fields.append(table[field])
groupby.append(table[field])

results = idb().select(*fields, groupby=groupby, limitby=(0, 10))

return dict(form=form, results=results)


-- 
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] response.js after redirect

2017-06-29 Thread Filipe Reis
Hello, I was wondering if someone could help me in figuring this out.

I have a view that when the user click on a button opens a modal with a 
insertion form.

I'm calling it by doing this way:
web2py_ajax_page("GET", url, "", target);

url - being the url like /house/create
target - being the div where the form will appear

on the form validation I'm trying to use this 
plugin: https://github.com/willsteinmetz/notific8 to show flash messages as 
it is in javascript when the form is an error I am able to do this:
response.js = "$.notific8('Please fill all necessary fields.', {heading: 
'Error'});" 

All works ok in here..

but if I try the same when the form is success does not work because I do a 
redirect after which resets the page and there is no flash message no 
more... 

I know that session.flash migh work for this cases, but I'm not able to 
understand how to make them work together in this case since this 
notification plugin works using javascript.

Any ideas?

-- 
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: function lazy_user at ...

2017-06-29 Thread António Ramos
Solved.
Thank you again Anthony

2017-06-28 19:21 GMT+01:00 Anthony :

> In auth.signature, the "created_by" field has a "default" attribute, which
> is a function (called "lazy_user") that returns auth.user_id. At the point
> at which the value of the compute field is computed, the row object passed
> to the compute function simply includes the "lazy_user" function as the
> value of the "created_by" field -- the function has not been called and
> returned the auth.user_id value yet (that doesn't happen until after the
> compute fields are computed). In other words, compute field values are
> calculated *before* default functions are called, so compute functions
> should not depend on the values of other fields whose defaults are set via
> a function.
>
> In this case, you have two alternatives:
>
> ret.append(record["created_by"]()) # This calls the lazy_user function,
> which returns auth.user_id
>
> or:
>
> ret.append(auth.user_id) # Just use auth.user_id directly.
>
> Anthony
>
>
> On Wednesday, June 28, 2017 at 12:30:22 PM UTC-4, Ramos wrote:
>>
>> Hello i added an authors and readers  computed fields to my table
>>
>> db.define_table(
>> 'entities',
>>...
>> Field('authors',compute= lambda r:authors(r)),
>> ...
>> )
>>
>> when i save a record i get this
>> :
>> authors :
>> [**]
>> created_by :
>> 4L
>> created_on :
>> datetime.datetime(2017, 6, 28, 16, 16, 24)
>> delete_record :
>> 
>> description :
>> entity :
>> saw
>> event :
>> 1903
>> id :
>> 401L
>> is_active :
>> True
>> last_error :
>> modified_by :
>> 4L
>> modified_on :
>> datetime.datetime(2017, 6, 28, 16, 16, 24)
>> readers :
>> [2L, 1L, 5L, 4L,* *]
>> status :
>> 8L
>> type :
>> 1L
>> update_record :
>> 
>> uuid :
>> c12ecf01-0d7b-4334-81c9-b7808c8cf7f9
>>
>> if i go to admin and edit the record and save again the fuction lazy_user
>> goes away..
>> Why is this and how to make it save properly in my code?
>>
>>
>> my code...
>>
>> def *authors*(record):
>> ret=[]
>> row=db.status(id=record["status"])
>> rule=db.rules(workflow=row["workflow"],step=record["status"])
>> users=get_userIds(rule)
>> for user in users:
>> if not user in ret:
>> ret.append(user)
>> if ret==[]:
>> ret.append(record["created_by"])
>> return str(ret)
>>
>> def get_userIds(rule):
>> ret=[]
>> for membership in rule["authors"]:
>> temp=db(db.auth_membership.group_id==membership).select()
>> for r in temp:
>> ret.append(r["id"])
>> return ret
>>
>>
>> Regards
>>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.