def test_layout_renderer_no_template(self): import player from pyramid.view import render_view_to_response def view(request): return 'test' self.config.add_view( name='view.html', view=view, renderer=player.layout()) self.config.add_layout( '', view=View, renderer='player:tests/test-layout.pt') res = render_view_to_response(Context(), self.request, 'view.html') self.assertEqual('<div>test</div>', res.text.strip())
def test_form_render_view_config_layout(self): import pform, player request = self.make_request() class CustomForm(pform.Form): fields = pform.Fieldset(pform.TextField('test')) self.config.add_view( name='test', view=CustomForm, renderer=player.layout()) self.config.add_layout( renderer='pform:tests/test-layout.jinja2') resp = render_view_to_response(None, request, 'test', False) self.assertIn('<form action="http://example.com"', str(resp))
def test_layout_return_response(self): import player from pyramid.view import render_view_to_response from pyramid.httpexceptions import HTTPFound def view(request): return HTTPFound(location='/') self.config.add_view(name='view.html', renderer=player.layout()) self.config.add_layout('', view=view, renderer='player:tests/test-layout.jinja2') res = render_view_to_response(Context(), self.request, 'view.html') self.assertIsInstance(res, HTTPFound)
def test_layout_return_response(self): import player from pyramid.view import render_view_to_response from pyramid.httpexceptions import HTTPFound def view(request): return HTTPFound(location='/') self.config.add_view( name='view.html', renderer=player.layout()) self.config.add_layout( '', view=view, renderer='player:tests/test-layout.pt') res = render_view_to_response(Context(), self.request, 'view.html') self.assertIsInstance(res, HTTPFound)
def test_layout_renderer_no_template(self): import player from pyramid.view import render_view_to_response def view(request): return 'test' self.config.add_view(name='view.html', view=view, renderer=player.layout()) self.config.add_layout('', view=View, renderer='player:tests/test-layout.jinja2') res = render_view_to_response(Context(), self.request, 'view.html') self.assertEqual('<div>test</div>', res.text.strip())
def test_layout_renderer(self, m): import player m.choice.return_value = 'red' self.config.add_layout('test', view=View, renderer='player:tests/test-layout.pt') self.config.add_view( name='view.html', renderer=player.layout('player:tests/dir1/view.pt', 'test')) from pyramid.view import render_view_to_response res1 = render_view_to_response(Context(), self.request, 'view.html') res2 = render_view_to_response(Context(), self.request, 'view.html') self.assertEqual(res1.text, res2.text) self.assertEqual('<div><h1>Test</h1></div>', res1.text.strip())
def test_layout_renderer(self, m): import player m.choice.return_value = 'red' self.config.add_layout('test', view=View, renderer='player:tests/test-layout.jinja2') self.config.add_view(name='view.html', renderer=player.layout( 'player:tests/dir1/view.jinja2', 'test')) from pyramid.view import render_view_to_response res1 = render_view_to_response(Context(), self.request, 'view.html') res2 = render_view_to_response(Context(), self.request, 'view.html') self.assertEqual(res1.text, res2.text) self.assertEqual('<div><h1>Test</h1></div>', res1.text.strip())
def test_form_render_layout_raise_httpexc_with_template(self): import pform, player request = self.make_request(POST={'form.buttons.test': 'test'}) class CustomForm(pform.Form): fields = pform.Fieldset(pform.TextField('test')) @pform.button('test') def handler(self): raise HTTPFound(location='.') self.config.add_view( name='test', view=CustomForm, renderer=player.layout('pform:tests/test-form.jinja2')) self.config.add_layout( renderer='pform:tests/test-layout.jinja2') resp = render_view_to_response(None, request, 'test', False) self.assertIsInstance(resp, HTTPFound)
def test_layout_preview(self): from ptah.manage.layout import layoutPreview class Context(object): """ """ __name__ = 'test' def View(context, request): request.response.text = text_('test body') return request.response self.init_ptah() self.config.add_view( name='', context=Context, renderer=player.layout(), view=View) self.config.add_layout( '', parent='page', context=Context, renderer='ptah.manage:tests/test_layout.pt') request = DummyRequest() res = layoutPreview(Context(), request).text
raise KeyError(key) class Introspector(object): def __init__(self, name, mod, request): self.__name__ = name self.__parent__ = mod self.name = name self.request = request @view_config( context=IntrospectModule, renderer=player.layout('ptah-manage:introspect.lt')) class MainView(ptah.View): __doc__ = 'Introspection module view.' def update(self): registry = self.request.registry self.categories = registry.introspector.categories() self.manage_url = '{0}/introspect'.format(get_manage_url(self.request)) @view_config( context=Introspector, renderer=player.layout('ptah-manage:introspect-intr.lt')) class IntrospectorView(ptah.View):
self.__parent__ = parent self.pname = None self.pcolumn = None for cl in table.columns: if cl.primary_key: self.pname = cl.name self.pcolumn = cl self.data = Session.query(table).filter( self.pcolumn == pid).one() @view_config( context=SQLAModule, renderer=player.layout('ptah-manage:sqla-index.lt')) class MainView(ptah.View): __doc__ = "sqlalchemy tables listing page." def printTable(self, table): columns = [] for cl in table.columns: kwarg = [] if cl.key != cl.name: kwarg.append('key') # pragma: no cover if cl.primary_key: kwarg.append('primary_key') if not cl.nullable: kwarg.append('nullable') if cl.default:
import ptah import player from ptah.manage import get_manage_url from pyramid.view import view_config @ptah.manage.module('permissions') class PermissionsModule(ptah.manage.PtahModule): __doc__ = 'A listing of all permission sets and their definitions' title = 'Permissions' @view_config( context=PermissionsModule, renderer=player.layout('ptah-manage:permissions.lt')) class PermissionsView(ptah.View): """ Permissions module default view """ def update(self): self.manage = get_manage_url(self.request) self.permissions = sorted(ptah.get_permissions().values(), key = lambda p: p.title) acls = ptah.get_acls() self.acls = sorted([acl for acl in acls.values() if acl.id != ''], key = lambda a: a.title) self.acls.insert(0, ptah.DEFAULT_ACL)
if grp is not None and grp.__ttw__: return SettingsWrapper(grp, self) raise KeyError(key) class SettingsWrapper(object): def __init__(self, grp, mod): self.__name__ = grp.__name__ self.__parent__ = mod self.group = grp @view_config( context=SettingsModule, renderer=player.layout('ptah-manage:settings.lt')) class SettingsView(ptah.View): """ Settings manage module view """ grps = None def update(self): groups = ptah.get_cfg_storage(ID_SETTINGS_GROUP).items() data = [] for name, group in sorted(groups): if self.grps is not None and name not in self.grps: continue title = group.__title__ or name
from pyramid.view import view_config @ptah.manage.module('fields') class FieldsModule(ptah.manage.PtahModule): __doc__ = ('A preview and listing of all form fields in the ' 'application. This is useful to see what fields are available. ' 'You may also interact with the field to see how it works in ' 'display mode.') title = 'Field types' @view_config( context=FieldsModule, renderer=player.layout('ptah-manage:fields.lt')) class FieldsView(ptah.View): """ Fields manage module view """ def update(self): data = [] fields = self.request.registry[ID_FIELD] previews = self.request.registry[ID_PREVIEW] for name, cls in fields.items(): data.append({'name': name, 'doc': cls.__doc__, 'preview': previews.get(cls)})
""" uri resolve """ import inspect import pform import player from pyramid.view import view_config import ptah from ptah import config from ptah.uri import ID_RESOLVER from ptah.manage.manage import PtahManageRoute @view_config( name='uri.html', context=PtahManageRoute, renderer=player.layout('ptah-manage:uri.lt')) class UriResolver(pform.Form): """ Uri resolver form """ fields = pform.Fieldset( pform.LinesField( 'uri', title = 'Uri', description = "List of uri's", klass = 'xxlarge')) uri = None rst_to_html = staticmethod(ptah.rst_to_html) def form_content(self): return {'uri': [self.request.GET.get('uri','')]}