def reset_deform(config=None): """ Reset deform to its original state. Run this in the tearDown part of tests, otherwise deform will still be patched. (This doesn't apply for tests run with nose, but with setuptools.) This will also clear search paths from deform. """ Form.set_default_renderer(_OLD_RENDERER)
def init(): from deform import Form from deform_jinja2 import jinja2_renderer_factory from deform_jinja2.translator import PyramidTranslator renderer = jinja2_renderer_factory(search_paths=SEARCH_PATHS, translator=PyramidTranslator()) Form.set_default_renderer(renderer)
def main(global_config, **settings): '''Main config function''' Form.set_default_renderer(mako_renderer) initializeDb(engine(DbConfig)) config = Configurator(settings=settings, root_factory=SiteModel) config.add_static_view(name='static', path='studentunderground:static') #Includes config.include('pyramid_handlers') config.include('pyramid_tm') #Handler Root Routes config.add_handler('site_root', '/', handler=SiteHandler, action='index') config.add_handler('article_root', '/articles', handler=ArticleHandler, action='index') config.add_handler('assignment_root', '/assignments', handler=AssignmentHandler, action='index') config.add_handler('group_root', '/groups', handler=GroupHandler, action='index') config.add_handler('hw_root', '/hw', handler=HwHandler, action='index') config.add_handler('setting_root', '/settings', handler=SettingHandler, action='index') config.add_handler('user_root', '/user', handler=UserHandler, action='index') #Handler Action Routes config.add_handler('site_action', '/{action}', handler=SiteHandler) config.add_handler('article_action', '/articles/{action}', handler=ArticleHandler) config.add_handler('assignment_action', '/assignments/{action}', handler=AssignmentHandler) config.add_handler('group_action', '/groups/{action}', handler=GroupHandler) config.add_handler('hw_action', '/hw/{action}', handler=HwHandler) config.add_handler('setting_action', '/settings/{action}', handler=SettingHandler) config.add_handler('user_action', '/user/{action}', handler=UserHandler) #Exception Views config.add_view(notFound, context=NotFound, permission='__no_permission_required__', renderer='exceptions/not_found.mako') config.add_view(forbidden, context=Forbidden, permission='__no_permission_required__') return config.make_wsgi_app()
def main(global_config, **settings): '''Main config function''' renderer = mako_renderer_factory('reprap/templates/forms/', translator=translator) Form.set_default_renderer(renderer) engine = engine_from_config(settings, 'sqlalchemy.') initializeBase(engine) # NOTE: A transaction is created by default in postgres, so I have added the # 'autocommit' kwarg so that I don't have to deal with transactions for # the moment. Remove it once I have pyramid_tm & zope.sqlalchemy implemented. maker = sessionmaker(bind=engine, autocommit=True) settings['db.sessionmaker'] = maker config = Configurator(settings=settings, root_factory=SiteModel, request_factory=RepRapRequest) config.add_static_view(name='static', path='reprap:static') #Handler Root Routes config.add_route('issues_root', '/issues') config.add_route('toggle_vote', '/toggle_vote/{user_id}/{comment_id}/{vote}') #Handler Action Routes config.add_route('issues_add', '/issues/add') config.add_route('issues_view', '/issues/view/{id}') #Exception Views config.add_view(notFound, context=NotFound, permission='__no_permission_required__', renderer='exceptions/not_found.mako') config.add_view(forbidden, context=Forbidden, permission='__no_permission_required__') config.scan('reprap') return config.make_wsgi_app()
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')
Session.commit() Session.remove() return flask_app # def log_request_info(): # current_app.logger.debug(u'Headers: %s', request.headers) # current_app.logger.debug(u'Body: %s', request.get_data()) # print 'logging..' if __name__ == '__main__': # bootstrap_widget_templates_path = os.path.join(get_root_path(), 'templates', 'bootstrap_widget_templates') renderer = jinja2_renderer_factory( search_paths=['fakturahr:templates/bootstrap_widget_templates']) Form.set_default_renderer(renderer) init_models() init_db() app = create_app() log_handler = TimedRotatingFileHandler(filename=os.path.join( get_root_path(), config.LOG_FILE_PATH), when='midnight', backupCount=365) formatter = logging.Formatter( u'[%(asctime)s] {%(levelname)s - %(message)s') log_handler.setFormatter(formatter) app.logger.addHandler(log_handler)