Re: [TurboGears] Pass variables to admin template

2020-03-26 Thread S.C. Justice
if you look in the auto generated root controller you'll see an example of
using tmpl_context. On  your controller make a _before method which will
set tmpl_context.pages = getPages()

On Thu, Mar 26, 2020 at 9:50 AM Mikhail  wrote:

> Thank you!
>
> Looks like tmpl_context is what I want. Just one more thing: Where to put
> it to be accessible from admin template? Here is my code:
>
> class RootController(BaseController):
> tmpl_context.pages = getPages()
> admin = AdminController(model, DBSession,
> config_type=CustomAdminConfig)
>
> If I put it like this tmpl_context.pages is avaliable only on first page
> load after engine restart.
> This:
>
> admin.tmpl_context.pages = getPages()
>
> gives me AttributeError: 'AdminController' object has no attribute
> 'tmpl_context'
>
>
> суббота, 7 марта 2020 г., 17:07:03 UTC+3 пользователь Alessandro Molina
> написал:
>>
>> There are few ways you can pass variables to all templates independently
>> from what the controller is providing.
>> The most simple one is to use tg.tmpl_context which is meant to be a
>> container for variables that should be shared by all templates, as
>> tmpl_context is always available to all templates.
>> Otherwise you can set a variable_provider option in app_cfg, which can be
>> set to a function (must return a dict) that will be executed when rendering
>> the template to provide additional variables.
>>
>> In regard of editing the pages content themselves. The most simple
>> solutions are to add the section in master.xhtml with a py:if that makes it
>> visibile only when in the admin, or to use template patches (
>> https://github.com/TurboGears/tgext.pluggable#patching-templates ) to
>> patch the templates with extra sections.
>> Otherwise Admin obviously support changing the expositions of the
>> controllers and replacing the templates, but that will require providing
>> new templates instead of just patching the existing ones.
>>
>> On Fri, Feb 28, 2020 at 6:13 PM Mikhail  wrote:
>>
>>> Hello!
>>>
>>> I have master.xhtml with some kind of menu:
>>> 
>>> 
>>> Page
>>> 
>>>
>>> 
>>>
>>> Now when I am using AdminController I get error "builtins.NameError".
>>> NameError: name 'pages' is not defined
>>>
>>> *Question*: Is there a way to pass pages to AdminController's output?
>>>
>>> As workaround I tried to use custom layout without menu:
>>> class CustomAdminConfig(TGAdminConfig):
>>> default_index_template = 'admin.xhtml'
>>>
>>> class RootController(BaseController):
>>> admin = AdminController(model, DBSession, config_type=
>>> CustomAdminConfig)
>>>
>>> But it seems that admin.xhtml only applied to /admin page, not any of
>>> subpages such as /admin/users. And I prefer to have menu on all pages,
>>> including admin.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "TurboGears" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to turbo...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/turbogears/5a5db6e0-ab34-4a4d-8d32-82f622c5db7c%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to turbogears+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/turbogears/06fdbafd-10af-454f-addc-cabb78d81b62%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to turbogears+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/CAMhmP7QrTzBFA%2Bgxy0n6x6UK27VXsjRnfcHREn82UXqNHKWYaA%40mail.gmail.com.


Re: [TurboGears] Pass variables to admin template

2020-03-26 Thread Mikhail
Thank you!

Looks like tmpl_context is what I want. Just one more thing: Where to put 
it to be accessible from admin template? Here is my code:

class RootController(BaseController):
tmpl_context.pages = getPages()
admin = AdminController(model, DBSession, config_type=CustomAdminConfig)

If I put it like this tmpl_context.pages is avaliable only on first page 
load after engine restart.
This:

admin.tmpl_context.pages = getPages()

gives me AttributeError: 'AdminController' object has no attribute 
'tmpl_context'


суббота, 7 марта 2020 г., 17:07:03 UTC+3 пользователь Alessandro Molina 
написал:
>
> There are few ways you can pass variables to all templates independently 
> from what the controller is providing.
> The most simple one is to use tg.tmpl_context which is meant to be a 
> container for variables that should be shared by all templates, as 
> tmpl_context is always available to all templates.
> Otherwise you can set a variable_provider option in app_cfg, which can be 
> set to a function (must return a dict) that will be executed when rendering 
> the template to provide additional variables. 
>
> In regard of editing the pages content themselves. The most simple 
> solutions are to add the section in master.xhtml with a py:if that makes it 
> visibile only when in the admin, or to use template patches ( 
> https://github.com/TurboGears/tgext.pluggable#patching-templates ) to 
> patch the templates with extra sections.
> Otherwise Admin obviously support changing the expositions of the 
> controllers and replacing the templates, but that will require providing 
> new templates instead of just patching the existing ones.
>
> On Fri, Feb 28, 2020 at 6:13 PM Mikhail > 
> wrote:
>
>> Hello!
>>
>> I have master.xhtml with some kind of menu:
>> 
>> 
>> Page
>> 
>>
>> 
>>
>> Now when I am using AdminController I get error "builtins.NameError". 
>> NameError: name 'pages' is not defined
>>
>> *Question*: Is there a way to pass pages to AdminController's output?
>>
>> As workaround I tried to use custom layout without menu:
>> class CustomAdminConfig(TGAdminConfig):
>> default_index_template = 'admin.xhtml'
>>
>> class RootController(BaseController):
>> admin = AdminController(model, DBSession, config_type=
>> CustomAdminConfig)
>>
>> But it seems that admin.xhtml only applied to /admin page, not any of 
>> subpages such as /admin/users. And I prefer to have menu on all pages, 
>> including admin.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "TurboGears" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to turbo...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/turbogears/5a5db6e0-ab34-4a4d-8d32-82f622c5db7c%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to turbogears+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/06fdbafd-10af-454f-addc-cabb78d81b62%40googlegroups.com.


Re: [TurboGears] Pass variables to admin template

2020-03-07 Thread Alessandro Molina
There are few ways you can pass variables to all templates independently
from what the controller is providing.
The most simple one is to use tg.tmpl_context which is meant to be a
container for variables that should be shared by all templates, as
tmpl_context is always available to all templates.
Otherwise you can set a variable_provider option in app_cfg, which can be
set to a function (must return a dict) that will be executed when rendering
the template to provide additional variables.

In regard of editing the pages content themselves. The most simple
solutions are to add the section in master.xhtml with a py:if that makes it
visibile only when in the admin, or to use template patches (
https://github.com/TurboGears/tgext.pluggable#patching-templates ) to patch
the templates with extra sections.
Otherwise Admin obviously support changing the expositions of the
controllers and replacing the templates, but that will require providing
new templates instead of just patching the existing ones.

On Fri, Feb 28, 2020 at 6:13 PM Mikhail  wrote:

> Hello!
>
> I have master.xhtml with some kind of menu:
> 
> 
> Page
> 
>
> 
>
> Now when I am using AdminController I get error "builtins.NameError".
> NameError: name 'pages' is not defined
>
> *Question*: Is there a way to pass pages to AdminController's output?
>
> As workaround I tried to use custom layout without menu:
> class CustomAdminConfig(TGAdminConfig):
> default_index_template = 'admin.xhtml'
>
> class RootController(BaseController):
> admin = AdminController(model, DBSession, config_type=
> CustomAdminConfig)
>
> But it seems that admin.xhtml only applied to /admin page, not any of
> subpages such as /admin/users. And I prefer to have menu on all pages,
> including admin.
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to turbogears+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/turbogears/5a5db6e0-ab34-4a4d-8d32-82f622c5db7c%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to turbogears+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/CAJfq2JEqtmUnUphy0CrsZXA-Ofkj9u6XDRDZmz5Bob9%3DnwSpvw%40mail.gmail.com.