Ejemplo n.º 1
0
    def __func():
        form = forms.EditTriggerForm(request.form)
        trigger = running_context.Triggers.query.filter_by(
            name=trigger_name).first()
        if trigger is not None:
            # Ensures new name is unique
            if form.name.data:
                if len(
                        running_context.Triggers.query.filter_by(
                            name=form.name.data).all()) > 0:
                    return {
                        "error": "Trigger could not be edited."
                    }, OBJECT_EXISTS_ERROR

            result = trigger.edit_trigger(form)

            if result:
                running_context.db.session.commit()
                current_app.logger.info('Edited trigger {0}'.format(trigger))
                return SUCCESS
            else:
                current_app.logger.error(
                    'Could not edit trigger {0}. Malformed JSON in conditional'
                    .format(trigger))
                return {
                    "error": "Invalid json in conditional field"
                }, INVALID_INPUT_ERROR
        else:
            current_app.logger.error(
                'Could not edit trigger {0}. Trigger does not exist'.format(
                    trigger))
            return {"error": "Trigger does not exist."}, OBJECT_DNE_ERROR
Ejemplo n.º 2
0
def update_trigger(name):
    form = forms.EditTriggerForm(request.form)
    trigger = running_context.Triggers.query.filter_by(name=name).first()
    if form.validate() and trigger is not None:
        # Ensures new name is unique
        if form.name.data:
            if len(
                    running_context.Triggers.query.filter_by(
                        name=form.name.data).all()) > 0:
                return json.dumps({
                    "status":
                    "error: duplicate names found. Trigger could not be edited"
                })

        result = trigger.edit_trigger(form)

        if result:
            running_context.db.session.commit()
            return json.dumps({"status": "success"})
        else:
            return json.dumps(
                {"status": "error: invalid json in conditional field"})
    return json.dumps({"status": "trigger could not be edited"})
Ejemplo n.º 3
0
def triggers():
    return {
        "form": forms.AddNewTriggerForm(),
        "editForm": forms.EditTriggerForm()
    }