@frontend.route('/objects/new', methods=['GET', 'POST'])
@flask_login.login_required
def new_object():
    check_current_user_is_not_readonly()
    action_id = flask.request.args.get('action_id', None)
    previous_object_id = flask.request.args.get('previous_object_id', None)
    if ((not action_id) and (not previous_object_id)):
        return flask.abort(404)
    sample_id = flask.request.args.get('sample_id', None)
    previous_object = None
    action = None
    if previous_object_id:
        try:
            previous_object = get_object(previous_object_id)
        except ObjectDoesNotExistError:
            flask.flash(_('This object does not exist.'), 'error')
            return flask.abort(404)
        if (Permissions.READ not in get_user_object_permissions(user_id=flask_login.current_user.id, object_id=previous_object_id)):
            flask.flash(_('You do not have the required permissions to use this object as a template.'), 'error')
            return flask.abort(403)
        if action_id:
            if (action_id != str(previous_object.action_id)):
                flask.flash(_('This object was created with a different action.'), 'error')
                return flask.abort(400)
            else:
                action_id = previous_object.action_id
    if action_id:
        try:
            action = get_action(action_id)
        except ActionDoesNotExistError:
            flask.flash(_('This action does not exist.'), 'error')
            return flask.abort(404)
        if (Permissions.READ not in get_user_action_permissions(action_id, user_id=flask_login.current_user.id)):
            flask.flash(_('You do not have the required permissions to use this action.'), 'error')
            return flask.abort(403)
    placeholder_data = {}
    if (sample_id is not None):
        try:
            sample_id = int(sample_id)
        except ValueError:
            sample_id = None
        else:
            if (sample_id <= 0):
                sample_id = None
    if (sample_id is not None):
        try:
            logic.objects.get_object(sample_id)
        except logic.errors.ObjectDoesNotExistError:
            sample_id = None
    if (sample_id is not None):
        if (action.schema.get('properties', {}).get('sample', {}).get('type', '') == 'sample'):
            placeholder_data = {('sample',): {'_type': 'sample', 'object_id': sample_id}}
    return show_object_form(None, action, previous_object, placeholder_data=placeholder_data)
@frontend.route('/objects/new', methods=['GET', 'POST'])
@flask_login.login_required
def new_object():
    check_current_user_is_not_readonly()
    action_id = flask.request.args.get('action_id', None)
    previous_object_id = flask.request.args.get('previous_object_id', None)
    if ((not action_id) and (not previous_object_id)):
        return flask.abort(404)
    sample_id = flask.request.args.get('sample_id', None)
    previous_object = None
    action = None
    if previous_object_id:
        try:
            previous_object = get_object(previous_object_id)
        except ObjectDoesNotExistError:
            flask.flash(_('This object does not exist.'), 'error')
            return flask.abort(404)
        if (Permissions.READ not in get_user_object_permissions(user_id=flask_login.current_user.id, object_id=previous_object_id)):
            flask.flash(_('You do not have the required permissions to use this object as a template.'), 'error')
            return flask.abort(403)
        if action_id:
            if (action_id != str(previous_object.action_id)):
                flask.flash(_('This object was created with a different action.'), 'error')
                return flask.abort(400)
            else:
                action_id = previous_object.action_id
    if action_id:
        try:
            action = get_action(action_id)
        except ActionDoesNotExistError:
            flask.flash(_('This action does not exist.'), 'error')
            return flask.abort(404)
        if (Permissions.READ not in get_user_action_permissions(action_id, user_id=flask_login.current_user.id)):
            flask.flash(_('You do not have the required permissions to use this action.'), 'error')
            return flask.abort(403)
    placeholder_data = {}
    if (sample_id is not None):
        try:
            sample_id = int(sample_id)
        except ValueError:
            sample_id = None
        else:
            if (sample_id <= 0):
                sample_id = None
    if (sample_id is not None):
        try:
            logic.objects.get_object(sample_id)
        except logic.errors.ObjectDoesNotExistError:
            sample_id = None
    if (sample_id is not None):
        if (action.schema.get('properties', {}).get('sample', {}).get('type', ) == 'sample'):
            placeholder_data = {('sample',): {'_type': 'sample', 'object_id': sample_id}}
    return show_object_form(None, action, previous_object, placeholder_data=placeholder_data)