@frontend.route('/objects/referencable')
@flask_login.login_required
def referencable_objects():
    required_perm = Permissions.READ
    if ('required_perm' in flask.request.args):
        try:
            required_perm = Permissions.from_name(flask.request.args['required_perm'])
        except ValueError:
            try:
                required_perm = Permissions(int(flask.request.args['required_perm']))
            except ValueError:
                return ({'message': 'argument {} is not a valid permission.'.format(flask.request.args['required_perm'])}, 400)
    referencable_objects = get_object_info_with_permissions(user_id=flask_login.current_user.id, permissions=required_perm)

    def dictify(x):
        return {'id': x.object_id, 'text': flask.escape('{} (#{})'.format(get_translated_text(x.name_json), x.object_id)), 'action_id': x.action_id, 'max_permission': x.max_permission, 'tags': ([flask.escape(tag) for tag in x.tags['tags']] if (x.tags and isinstance(x.tags, dict) and (x.tags.get('_type') == 'tags') and x.tags.get('tags')) else [])}
    return {'referencable_objects': [dictify(x) for x in referencable_objects]}
@frontend.route('/objects/referencable')
@flask_login.login_required
def referencable_objects():
    required_perm = Permissions.READ
    if ('required_perm' in flask.request.args):
        try:
            required_perm = Permissions.from_name(flask.request.args['required_perm'])
        except ValueError:
            try:
                required_perm = Permissions(int(flask.request.args['required_perm']))
            except ValueError:
                return ({'message': 'argument {} is not a valid permission.'.format(flask.request.args['required_perm'])}, 400)
    referencable_objects = get_object_info_with_permissions(user_id=flask_login.current_user.id, permissions=required_perm)

    def dictify(x):
        return {'id': x.object_id, 'text': flask.escape('{} (#{})'.format(get_translated_text(x.name_json), x.object_id)), 'action_id': x.action_id, 'max_permission': x.max_permission, 'tags': ([flask.escape(tag) for tag in x.tags['tags']] if (x.tags and isinstance(x.tags, dict) and (x.tags.get('_type') == 'tags') and x.tags.get('tags')) else [])}
    return {'referencable_objects': [dictify(x) for x in referencable_objects]}