pylons / pyramid_layout Goto Github PK
View Code? Open in Web Editor NEWPyramid add-on for managing UI layouts.
License: Other
Pyramid add-on for managing UI layouts.
License: Other
Can we have a panel_defaults
decorator, just like we have a view_defaults
decorator?
which prevents this package from being built for a linux distribution properly.
Sorry for not providing a patch/pull target as I'm completely overcharged ATM..
https://gist.github.com/aa4178006a0e6e655d0c
Works when done as a function.
Here's the relevant traceback
File "/path/to/pyramid_layout-0.8-py2.7.egg/pyramid_layout/config.py", line 359, in register
template = helper.renderer.implementation()
pyramid.exceptions.ConfigurationExecutionError: <type 'exceptions.AttributeError'>: 'MakoLookupTemplateRenderer' object has no attribute 'implementation'
Latest versions of pyramid_mako and pyramid_jinja removed this private api. Same error apply for add_panel, not just add_layout.
Maybe it will be more good to change namespace of zcml to pyramid as in pyramid_zcml?
What would be required for a new release?
I just evaluated this and it pretty much does what I would like it to do. I would spend the time to fix some stuff I identified if that would lead to a release. I think I already am a contributor to Pylons stuff.
I personally still need compatibility for Pyramid 1.x, but also 2.x. So the first thing I identified is PR #35 which doesn't seem to have a test which actually shows the issue, so I would try to write one and add testing with pyramid<2
.
How important are #38 (I currently get coverage failures with tox) and #39? I might also hit #33 at some point, so I would most likely take a look at that as well.
I found in the panel template there is no 'view' renderer global variable there, I was trying to get it through the introspectable but failed. Is there an easy way to get it?
I am getting a type error when serving static files in a project that is using pyramid_layout. This seems to be the case for certain file types only. .js files seem to work fine whereas others cause the traceback below.
I worked around it by testing if the path of the request starts with /static/ but I don't think that this is a good solution:
def add_renderer_globals(event):
request = event['request']
# if the rendering is done from a script or otherwise outside a
# regular request, the request will be None, so globals can't be set
if request is None or request.path.startswith('/static/'):
return
012-11-09 12:12:13,118 ERROR [waitress][Dummy-3] Exception when serving /static/src/dijit/templates/test.htm
Traceback (most recent call last):
File "C:\Data\prodash\env\lib\site-packages\waitress-0.8.1-py2.7.egg\waitress\channel.py", line 329, in service
task.service()
File "C:\Data\prodash\env\lib\site-packages\waitress-0.8.1-py2.7.egg\waitress\task.py", line 173, in service
self.execute()
File "C:\Data\prodash\env\lib\site-packages\waitress-0.8.1-py2.7.egg\waitress\task.py", line 380, in execute
app_iter = self.channel.server.application(env, start_response)
File "C:\Data\prodash\env\lib\site-packages\pyramid-1.3.3-py2.7.egg\pyramid\router.py", line 187, in call
response = self.handle_request(request)
File "C:\Data\prodash\env\lib\site-packages\pyramid_debugtoolbar-1.0.2-py2.7.egg\pyramid_debugtoolbar\toolbar.py", line 165, in toolbar_tween
toolbar.process_response(response)
File "C:\Data\prodash\env\lib\site-packages\pyramid_debugtoolbar-1.0.2-py2.7.egg\pyramid_debugtoolbar\toolbar.py", line 56, in process_response
vars, request=request)
File "C:\Data\prodash\env\lib\site-packages\pyramid-1.3.3-py2.7.egg\pyramid\renderers.py", line 81, in render
return helper.render(value, None, request=request)
File "C:\Data\prodash\env\lib\site-packages\pyramid-1.3.3-py2.7.egg\pyramid\renderers.py", line 420, in render
registry.notify(system_values)
File "C:\Data\prodash\env\lib\site-packages\pyramid-1.3.3-py2.7.egg\pyramid\registry.py", line 74, in notify
[ _ for _ in self.subscribers(events, None) ]
File "C:\Data\prodash\env\lib\site-packages\zope.interface-4.0.1-py2.7-win32.egg\zope\interface\registry.py", line 323, in subscribers
return self.adapters.subscribers(objects, provided)
File "C:\Data\prodash\env\lib\site-packages\zope.interface-4.0.1-py2.7-win32.egg\zope\interface\adapter.py", line 601, in subscribers
subscription(*objects)
File "C:\Data\prodash\env\lib\site-packages\pyramid_layout-0.5-py2.7.egg\pyramid_layout\config.py", line 35, in add_renderer_globals
layout = layout_manager.layout
File "C:\Data\prodash\env\lib\site-packages\pyramid-1.3.3-py2.7.egg\pyramid\decorator.py", line 17, in get
val = self.wrapped(inst)
File "C:\Data\prodash\env\lib\site-packages\pyramid_layout-0.5-py2.7.egg\pyramid_layout\layout.py", line 41, in layout
return find_layout(self.context, self.request)
File "C:\Data\prodash\env\lib\site-packages\pyramid_layout-0.5-py2.7.egg\pyramid_layout\layout.py", line 64, in find_layout
return layout(context, request)
TypeError: 'NoneType' object is not callable
The bug is in this function in config.py
def derived(context, request, *args, **kw):
result = wrapped(context, request, *args, **kw)
if isinstance(result, basestring):
return result
system = {'panel': panel,
'renderer_info': renderer,
'context': context,
'request': request
}
rendered = renderer.render(result, system, request=request)
return rendered
The system variable that is passed to the renderer needs to have the renderer_name key, according to the documentation here: http://docs.pylonsproject.org/projects/pyramid/en/master/narr/templates.html#system-values-used-during-rendering
My problem comes from this code in Kotti, that assumes that all system variables (presented as event, in this case), have the renderer_name keyword. Even a None value as renderer_name would suffice, in this case:
def add_renderer_globals(event):
if event['renderer_name'] != 'json':
request = event['request']
api = getattr(request, 'template_api', None)
if api is None and request is not None:
api = template_api(event['context'], event['request'])
event['api'] = api
I'm using pyramid_fullauth's mako-based templates inside a panel, which I'm then including inside a jinja2 template, which has a jinja2 layout.
Here's the jinja2 template, panel syntax guessed from the pyramid_layout docs:
{% extends main_template %}
{% block body %}
{% panel('login_panel') %}
{% endblock %}
But I get the following error:
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'panel'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.
Is this a bug? Or did I try the wrong syntax?
Thanks!
Receiving AttributeError: 'Request' object has no attribute 'layout_manager'
on startup running under uwsgi. This is the line that is causing it: https://github.com/Pylons/pyramid_layout/blob/master/pyramid_layout/config.py#L79
I am still looking into the correct course of action when this occurs.
Note that Sphinx 4.0 might break a docs build. If needed, temporarily pin to <4.0, and open an issue in the relevant project.
Error when try to use zcml configure.
Configurator.with_context was deprecated in Pyramid 1.3 seems.
Maybe it will be more good to change namespace of zcml to pyramid as in pyramid_zcml?
Removed method is used here:
https://github.com/Pylons/pyramid_layout/blob/master/pyramid_layout/zcml.py#L40
See Pyramid 1.3a9 release notes:
http://docs.pylonsproject.org/projects/pyramid/en/latest/changes.html#id24
File "path/to/environment/lib/python3.3/site-packages/pyramid_layout/zcml.py", line 76, in layout
config = Configurator.with_context(config_context)
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "path/to/project/commons/configure.zcml", line 13.4-14.62
AttributeError: type object 'Configurator' has no attribute 'with_context'
When using pyramid_layout with a non default layout, the request_param view predicates is not matched anymore.
Starting with the demo app, add following lines in views.py
@view_config(
route_name='home.mako',
request_param='view=html',
renderer='demo:templates/home2.mako',
)
@view_config(
route_name='home.jinja2',
request_param='view=html',
renderer='demo:templates/home2.jinja2',
)
def home2(request):
return {}
Add a home2.mako and a home2.jinja2 in the demo/templates directory
<div>It works</div>
Restart the demo server
If you go to
http://0.0.0.0:6543/?view=html
you get the expected 'It works' text.
If you go to
http://0.0.0.0:6543/home.jinja2?view=html
You fill on the home page and not on the expected one.
soon after wsgi launching:
.../site-packages/pyramid_layout/panel.py", line 34, in callback
config.add_panel(panel=ob, **settings)
.../site-packages/pyramid/config/__init__.py", line 811, in __getattr__
raise AttributeError(name)
AttributeError: add_panel
From Robert Forkel:
I have a library of layouts and panels which may be used in
several apps so they get all registered in the includeme function of
the library. But some apps may have to override a panel or a layout.
But re-registering didn't work (ConfigurationConflictError) and
there's no "remove_panel" method on the configurator.
So how would i go about when I'd like to register a panel class
(possibly derived from the panel in the library) instead of it's base
class which has been registered before?
Example of problem:
from pyramid.config import Configurator
from pyramid_layout.layout import layout_config
@layout_config(template='templates/mytemplate.pt')
class AppLayout(object):
def init(self, context, request):
self.context = context
self.request = request
@layout_config(template='templates/mytemplate.pt')
class DerivedLayout(AppLayout):
pass
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_layout')
#config.add_layout(AppLayout, 'templates/mytemplate.pt')
#config.add_layout(DerivedLayout, 'templates/mytemplate.pt')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.