def __init__(self, *args, **kwargs): search_path = (resource_filename( 'kottisnippets', 'templates/forms'), ) + Form.default_renderer.loader.search_path renderer = ZPTRendererFactory(search_path) kwargs['renderer'] = renderer super(Form, self).__init__(*args, **kwargs)
def includeme(config): config.add_static_view('static-deform', 'deform:static') config.add_static_view('static-kotti', 'kotti:static') # deform stuff config.include('deform_bootstrap') search_path = (resource_filename( 'kotti', 'templates/edit/widgets'), ) + Form.default_renderer.loader.search_path Form.default_renderer = ZPTRendererFactory(search_path, translator=translator)
def includeme(config): """ Patch deform to use zpt_renderer as default with Pyramids translation mechanism activated. Also a good pluggable point for patching templates or other things. WARNING! This method patches global variables, which means that it will affect ALL tests after this method is included. """ settings = config.registry.settings auto_reload = settings['pyramid.reload_templates'] debug_templates = settings['pyramid.debug_templates'] zpt_renderer = ZPTRendererFactory(DEFORM_TEMPLATE_DIR, translator = deform_translator, auto_reload = auto_reload, debug = debug_templates) Form.set_default_renderer(zpt_renderer) append_search_path(WIDGETS_PATH) #Patches for widget templates, so they actually display sane readonly templates RadioChoiceWidget.readonly_template = join(WIDGETS_PATH, 'readonly', 'radio_choice') #Patches for RichTextWidget templates to display a better editor RichTextWidget.template = join(WIDGETS_PATH, 'richtext')
# sqlalchemy setup DBSession = scoped_session( sessionmaker(extension=ZopeTransactionExtension(), expire_on_commit=False)) sess = DBSession() # view flash session info req_session_factory = SignedCookieSessionFactory('itsaseekreet') config = Configurator() config.set_session_factory(req_session_factory) # deform retail form additions resource_registry = widget.ResourceRegistry() deform_templates = resource_filename('deform', 'templates') tpath = os.getcwd() search_path = (tpath + '/nportal/templates', deform_templates) drenderer = ZPTRendererFactory(search_path) # Form.set_zpt_renderer(search_path) # import htmllaundry # from htmllaundry import sanitize def site_layout(): renderer = get_renderer("../templates/_layout.pt") layout = renderer.implementation().macros['layout'] return layout def add_base_template(event): base = get_renderer('templates/_layout.pt').implementation() event.update({'base': base})
# Code here exists solely to allow the running of deformdemo. Use the # 'includeme' from the __init__.py or similar in your production code, # not code from here: search_path = ( resource_filename('deform_bootstrap', 'templates'), resource_filename('deform', 'templates'), ) def translator(term): return get_localizer(get_current_request()).translate(term) zpt_renderer = ZPTRendererFactory(search_path, translator=translator) def includeme(config): base_includeme(config) config.override_asset( to_override='deformdemo:templates/main.pt', override_with='deform_bootstrap:demo/main.pt', ) def onerror(*arg): pass config.scan('deform_bootstrap.demo', onerror=onerror)
def _get_renderer(search_paths): if search_paths is None: return None else: from c2cgeoform import translator return ZPTRendererFactory(search_paths, translator=translator)