def get_item_form(name, request, renderers=None, validators=None, values=None): """Will return a form for the given item :name: Name of the form :request: Current request :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :values: Dictionary with external values to prefill the form or add addional values for rule evaluation. :returns: Form """ if renderers is None: renderers = {} if validators is None: validators = [] if values is None: values = {} item = get_item_from_request(request) renderers = add_renderers(renderers) clazz = request.context.__model__ name = request.session.get("%s.form" % clazz) or name # handle blobforms if isinstance(item, Blobform): # TODO: Why not use the get_form_config method here. This can # handle Blobforms and usual form configs. () <2014-08-26 22:21> item, formconfig = get_blobform_config(request, item, name) else: formconfig = get_form_config(item, name) form = Form(formconfig, item, request.db, translate=request.translate, renderers=renderers, change_page_callback={ 'url': 'set_current_form_page', 'item': clazz.__tablename__, 'itemid': item.id }, request=request, csrf_token=request.session.get_csrf_token(), eval_url=get_eval_url(), url_prefix=get_app_url(request), locale=locale_negotiator(request), values=values, timezone=get_timezone(request), dependencies=create_dependencies(request)) # Add validators for validator in validators: form.add_validator(validator) return form
def add_renderer_globals(event): request = event['request'] event['h'] = helpers event['s'] = security event['_'] = request.translate event['N_'] = request.translate event['formbar_css_filenames'] = formbar_css_filenames event['formbar_js_filenames'] = formbar_js_filenames event['localizer'] = request.localizer event['client_language'] = locale_negotiator(request) event['application_path'] = helpers.get_app_url(request)
def __init__(self, request, clazz): """@todo: to be defined """ DialogRenderer.__init__(self, request, clazz, "import") self.template = template_lookup.get_template("internal/import.mako") config = Config(load(get_path_to_form_config('import.xml', 'ringo'))) form_config = config.get_form('default') self.form = Form(form_config, csrf_token=self._request.session.get_csrf_token(), dbsession=request.db, eval_url=get_eval_url(), url_prefix=get_app_url(request))
def add_renderer_globals(event): request = event['request'] default_locale = request.registry.settings.get("pyramid.default_locale_name", "en") event['h'] = helpers event['s'] = security event['_'] = request.translate event['N_'] = request.translate event['formbar_css_filenames'] = formbar_css_filenames event['formbar_js_filenames'] = formbar_js_filenames event['localizer'] = request.localizer event['client_language'] = getattr(request, "_LOCALE_", default_locale) event['application_path'] = helpers.get_app_url(request)
def get_item_form(name, request, renderers=None, validators=None, values=None): """Will return a form for the given item :name: Name of the form :request: Current request :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :values: Dictionary with external values to prefill the form or add addional values for rule evaluation. :returns: Form """ if renderers is None: renderers = {} if validators is None: validators = [] if values is None: values = {} item = get_item_from_request(request) renderers = add_renderers(renderers) clazz = request.context.__model__ name = request.session.get("%s.form" % clazz) or name ## handle blobforms if isinstance(item, Blobform): # TODO: Why not use the get_form_config method here. This can # handle Blobforms and usual form configs. () <2014-08-26 22:21> item, formconfig = get_blobform_config(request, item, name) else: formconfig = get_form_config(item, name) form = Form(formconfig, item, request.db, translate=request.translate, renderers=renderers, change_page_callback={'url': 'set_current_form_page', 'item': clazz.__tablename__, 'itemid': item.id}, request=request, csrf_token=request.session.get_csrf_token(), eval_url=get_eval_url(), url_prefix=get_app_url(request), locale=locale_negotiator(request), values=values) # Add validators for validator in validators: form.add_validator(validator) return form
def get_ownership_form(request): item = get_item_from_request(request) db = request.db csrf_token = request.session.get_csrf_token() url_prefix = get_app_url(request) # Check if the form is rendered as readonly form. if has_role(request.user, "admin"): readonly = False elif isinstance(item, Owned) and item.is_owner(request.user): readonly = False else: readonly = True return _get_ownership_form(item, db, csrf_token, get_eval_url(), readonly, url_prefix, locale=locale_negotiator(request), translate=request.translate)
def __init__(self, request, clazz): """@todo: to be defined """ DialogRenderer.__init__(self, request, clazz, "print") self.template = template_lookup.get_template("internal/print.mako") config = Config( load( get_path_to_form_config('print.xml', 'ringo_printtemplate', '.'))) form_config = config.get_form('default') # Load available_printtemplates and put them into the form as # external data. This than later used to render the available # printtemplates. mid = clazz._modul_id values = {} values['printtemplates'] = [(p, p.id) for p in self._item.printtemplates] self.form = Form(form_config, item=clazz, csrf_token=self._request.session.get_csrf_token(), dbsession=request.db, translate=request.translate, url_prefix=get_app_url(request), eval_url=get_eval_url(), values=values)