Beispiel #1
0
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
Beispiel #2
0
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)
Beispiel #3
0
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
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
 def locale(self):
     """Cached property of the locale setting."""
     return locale_negotiator(self.request)