Re: [web2py] Re: standalone templates

2019-01-28 Thread Carlos Cesar Caballero Díaz
Nothing, but I was looking for a way that the user could directly call 
render and pass his own arguments and render the template with some 
objects passed to the environment by default. But don't worry, now I 
have included the possibility to use more than one template engine, so I 
will make some kind of wrapper function and include the defaults.


Greetings.

El 28/1/19 a las 11:14 a.m., Anthony escribió:
On Monday, January 28, 2019 at 8:45:53 AM UTC-5, Carlos Cesar 
Caballero wrote:


Hi Antony, Thanks. I am experimenting with the Massimo idea of a
bottle based framework using web2py components, And I was looking
if there was an equivalent of the jinja2 "Environment.globals".
The code is in https://github.com/daxslab/ron


Looks like you're using the render() function, so what's wrong with 
using the "context" argument to add globals to the template execution 
environment?


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.


Re: [web2py] Re: standalone templates

2019-01-28 Thread Anthony
On Monday, January 28, 2019 at 8:45:53 AM UTC-5, Carlos Cesar Caballero 
wrote:
>
> Hi Antony, Thanks. I am experimenting with the Massimo idea of a bottle 
> based framework using web2py components, And I was looking if there was an 
> equivalent of the jinja2 "Environment.globals". The code is in 
> https://github.com/daxslab/ron
>

Looks like you're using the render() function, so what's wrong with using 
the "context" argument to add globals to the template execution environment?

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: Dont allow delete specific records in grid

2019-01-28 Thread Carlos Cesar Caballero Díaz

Thanks a lot Antony, that's exactly what I need.

Greetings.

El 28/1/19 a las 8:22 a.m., Anthony escribió:

You might find this helpful: https://stackoverflow.com/a/54200430/440323

Note, using the deletable argument in this case could be a bit 
inefficient because it will need to do a database select for each row 
in the grid to determine if there are any children. I suppose you 
could instead do a single join query before creating the grid to fetch 
the same set of records along with a count of any children and then 
just do a lookup in that local Rows object from the deletable function.


Anthony

On Sunday, January 27, 2019 at 12:55:04 PM UTC-5, Carlos Cesar 
Caballero wrote:


Hi, is possible to don't allow deleting specific records in the grid?

Basically, I have a one to many relation "parent has childs", but
it is
in cascade mode and I can't change it, so, I need to forbid
deleting of
parent records who has childs.


Greetings.


--
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] Re: standalone templates

2019-01-28 Thread Carlos Cesar Caballero Díaz
Hi Antony, Thanks. I am experimenting with the Massimo idea of a bottle 
based framework using web2py components, And I was looking if there was 
an equivalent of the jinja2 "Environment.globals". The code is in 
https://github.com/daxslab/ron


Greetings.



El 28/1/19 a las 8:16 a.m., Anthony escribió:
Can you show some code or describe in more detail what you are trying 
to do?


If you are using the render() function from gluon.template, note that 
it takes a context argument, which is a dictionary used to generate an 
execution environment. You can do:


|
ENV ={
'var1':'value 1',
'var2':'value 2'
}

output =render(filename='mytemplate.html',context=ENV)
|

In the template, you can then reference var1 and var2 (e.g., {{=var1}}).

If you want to create an environment similar to the web2py 
environment, have a look 
at https://github.com/web2py/web2py/blob/cef31f127796c638753297235f4e886f6a9e5410/gluon/compileapp.py#L387-L450 
to see how web2py sets up its environment.


Anthony

On Wednesday, January 23, 2019 at 8:09:34 AM UTC-5, Carlos Cesar 
Caballero wrote:


Hi guys, I am using the web2py templates in a side project and I
want to
include some variables in the environment by default, something
like how
helpers, request and response are included in the framework, but I
can't
find how this is done. Any idea?

Greetings.


--
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: Dont allow delete specific records in grid

2019-01-28 Thread Anthony
You might find this helpful: https://stackoverflow.com/a/54200430/440323

Note, using the deletable argument in this case could be a bit inefficient 
because it will need to do a database select for each row in the grid to 
determine if there are any children. I suppose you could instead do a 
single join query before creating the grid to fetch the same set of records 
along with a count of any children and then just do a lookup in that local 
Rows object from the deletable function.

Anthony

On Sunday, January 27, 2019 at 12:55:04 PM UTC-5, Carlos Cesar Caballero 
wrote:
>
> Hi, is possible to don't allow deleting specific records in the grid? 
>
> Basically, I have a one to many relation "parent has childs", but it is 
> in cascade mode and I can't change it, so, I need to forbid deleting of 
> parent records who has childs. 
>
>
> Greetings. 
>
>
>

-- 
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: standalone templates

2019-01-28 Thread Anthony
Can you show some code or describe in more detail what you are trying to do?

If you are using the render() function from gluon.template, note that it 
takes a context argument, which is a dictionary used to generate an 
execution environment. You can do:

ENV = {
'var1': 'value 1',
'var2': 'value 2'
}

output = render(filename='mytemplate.html', context=ENV)

In the template, you can then reference var1 and var2 (e.g., {{=var1}}).

If you want to create an environment similar to the web2py environment, 
have a look 
at 
https://github.com/web2py/web2py/blob/cef31f127796c638753297235f4e886f6a9e5410/gluon/compileapp.py#L387-L450
 
to see how web2py sets up its environment.

Anthony

On Wednesday, January 23, 2019 at 8:09:34 AM UTC-5, Carlos Cesar Caballero 
wrote:
>
> Hi guys, I am using the web2py templates in a side project and I want to 
> include some variables in the environment by default, something like how 
> helpers, request and response are included in the framework, but I can't 
> find how this is done. Any idea? 
>
> Greetings. 
>
>
>

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