Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
def step_one():
    user = flask_security.current_user
    if user.has_role("admin"):
        return flask.redirect(flask.url_for("admin.index"))
    if not user.is_anonymous:
        return flask.redirect(flask.url_for("manage.actions"))
    if flask.request.method == "POST":
        if flask.request.form.getlist("action"):
            actions = flask.request.form.getlist("action", type=int)
            flask.session["actions"] = actions
            return flask.redirect(utils.get_redirect(".step_two"))
        else:
            message = "Uh oh. You need to pick at least one action."
            flask.flash(message, "error")
    return flask.render_template("step_one.html", methods=models.approved_methods())
Ejemplo n.º 6
0
def step_one():
    user = flask.ext.security.current_user
    if user.has_role('admin'):
        return flask.redirect(flask.url_for('admin.index'))
    if not user.is_anonymous():
        return flask.redirect(flask.url_for('manage.actions'))
    if flask.request.method == 'POST':
        if flask.request.form.getlist('action'):
            actions = flask.request.form.getlist('action', type=int)
            flask.session['actions'] = actions
            return flask.redirect(utils.get_redirect('.step_two'))
        else:
            message = 'Uh oh. You need to pick at least one action.'
            flask.flash(message, 'error')
    return flask.render_template('step_one.html',
                                 methods=models.approved_methods())