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 __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 render(self, items): values = {} values['request'] = self._request values['items'] = items values['body'] = self._render_body() values['modul'] = get_item_modul(self._request, self._item).get_label(plural=True) values['action'] = self._action.capitalize() values['ok_url'] = self._request.current_route_path() values['_'] = self._request.translate values['cancel_url'] = self._request.referrer values['evalurl'] = self._request.application_url+get_eval_url() return literal(self.template.render(**values))
def __init__(self, request, clazz): """@todo: to be defined """ DialogRenderer.__init__(self, request, clazz, "evaluate") self.template = template_lookup.get_template("internal/evaluation.mako") config = Config(load(get_path_to_form_config('evaluations.xml', 'ringo_evaluation', location="."))) form_config = config.get_form('dialog') url_prefix = request.application_url self.form = Form(form_config, csrf_token=self._request.session.get_csrf_token(), translate=request.translate, eval_url=get_eval_url(), url_prefix=url_prefix)
def render(self, items): _ = self._request.translate values = {} values['request'] = self._request values['items'] = items values['body'] = self._render_body() values['modul'] = get_item_modul(self._request, self._item).get_label(plural=True) values['action'] = _(self._action.capitalize()) values['ok_url'] = self._request.current_route_path() values['_'] = self._request.translate values['cancel_url'] = self._request.referrer values['eval_url'] = self._request.application_url+get_eval_url() return literal(self.template.render(**values))
def render(self, url=None): values = {} values['icon'] = self.icon values['header'] = self._title values['body'] = self._body history = self._request.ringo.history if url: values['ok_url'] = url elif history and history.last(): values['ok_url'] = history.last() else: values['ok_url'] = self._request.route_path('home') values['eval_url'] = self._request.application_url+get_eval_url() return literal(self.template.render(**values))
def render(self, url=None): values = {} values['icon'] = self.icon values['header'] = self._title values['body'] = self._body history = self._request.session.get('history') if url: values['ok_url'] = url elif history: values['ok_url'] = self._request.session['history'].pop() else: values['ok_url'] = self._request.route_path('home') values['eval_url'] = self._request.application_url+get_eval_url() return literal(self.template.render(**values))
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 render(self, items): _ = self._request.translate mapping = {'Action': _(self._action.capitalize())} values = {} values['request'] = self._request values['icon'] = self.icon if self._title: values['header'] = self._title else: values['header'] = _("Confirm ${Action}", mapping=mapping) if self._body: values['body'] = self._body else: values['body'] = self._render_body(items) values['action'] = self.ok_label or _(self._action.capitalize()) values['ok_url'] = self._request.current_route_path() values['_'] = self._request.translate values['cancel_url'] = self._request.referrer values['eval_url'] = self._request.application_url+get_eval_url() return literal(self.template.render(**values))
def trainable_index_view(request): values = index_view(request) if request.user: client = Client() client_id = request.user.profile[0].strava_client_id redirect_uri = request.route_url("authstrava") url = client.authorization_url(client_id=client_id, redirect_uri=redirect_uri, scope="view_private") _ = request.translate config = Config(load(get_path_to_form_config('strava.xml'))) form_config = config.get_form('syncform') form = Form(form_config, csrf_token=request.session.get_csrf_token(), translate=_, locale="de", eval_url=get_eval_url()) if request.POST and form.validate(request.params): sync(request, form.data.get("sport"), form.data.get("start"), form.data.get("end"), form.data.get("commute")) values["fitness"] = get_fitness(0, 0, get_activities_for_user(request)) values["strava_auth_url"] = url values["strava_syncform"] = form.render() return values
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)