Example #1
0
def actions():
    user = flask.ext.security.current_user
    if flask.request.method == 'POST':
        commit = False
        name = flask.session.get('method_name')
        method = models.Method.query.filter_by(name=name).first()
        if user.method != method:
            user.method = method
            flask.flash('Method saved.', 'success')
            commit = True
        if flask.request.form.getlist('action'):
            actions = []
            for action_id in flask.request.form.getlist('action', type=int):
                actions.append(models.Action.query.get(action_id))
            if {str(x) for x in user.actions} != {str(x) for x in actions}:
                flask.flash('Actions saved.', 'success')
                commit = True
        elif not commit:
            message = 'Uh oh. You need to pick at least one action.'
            flask.flash(message, 'error')
        if commit:
            models.db.session.add(user)
            models.db.session.commit()
    form = utils.get_actions_for_method(user.method, header='manage')
    modal = flask.render_template('snippets/methods_dialog.html',
                                  methods=models.approved_methods(),
                                  method_name=user.method)
    return flask.render_template('actions.html', form=form, modal=modal)
Example #2
0
def actions():
    user = flask_security.current_user
    if flask.request.method == "POST":
        commit = False
        name = flask.session.get("method_name")
        method = models.Method.query.filter_by(name=name).first()
        if user.method != method:
            user.method = method
            flask.flash("Method saved.", "success")
            commit = True
        if flask.request.form.getlist("action"):
            actions = []
            for action_id in flask.request.form.getlist("action", type=int):
                actions.append(models.Action.query.get(action_id))
            if {str(x) for x in user.actions} != {str(x) for x in actions}:
                flask.flash("Actions saved.", "success")
                commit = True
        elif not commit:
            message = "Uh oh. You need to pick at least one action."
            flask.flash(message, "error")
        if commit:
            models.db.session.add(user)
            models.db.session.commit()
    form = utils.get_actions_for_method(user.method, header="manage")
    modal = flask.render_template(
        "snippets/methods_dialog.html",
        methods=models.approved_methods(),
        method_name=user.method,
    )
    return flask.render_template("actions.html", form=form, modal=modal)
Example #3
0
def _get_actions():
    method_name = flask.request.args.get('method_name')
    flask.session['method_name'] = method_name
    header = flask.request.args.get('header')
    back = flask.request.args.get('back')
    actions = utils.get_actions_for_method(method_name, header=header,
                                           back=back)
    modal = flask.render_template('snippets/methods_dialog.html',
                                  methods=models.approved_methods(),
                                  method_name=method_name)
    return flask.jsonify(actions=actions, modal=modal)
Example #4
0
def _get_actions():
    method_name = flask.request.args.get("method_name")
    flask.session["method_name"] = method_name
    header = flask.request.args.get("header")
    back = flask.request.args.get("back")
    actions = utils.get_actions_for_method(method_name, header=header, back=back)
    modal = flask.render_template(
        "snippets/methods_dialog.html",
        methods=models.approved_methods(),
        method_name=method_name,
    )
    return flask.jsonify(actions=actions, modal=modal)