Ejemplo n.º 1
0
def make_decision():

    email = session.get('email')
    if not email:
        return redirect(url_for('login'))
    if request.method == 'POST':

        decision = request.form['decision']
        pair_id = request.form['pair_id']

        context.stats_client.incr('{}.decision.{}'.format(config.METRICS_ENV, decision))

        if decision.lower() == "skip":
            util.skip_title(pair_id, email)
        else:
            util.update_decision(decision=decision, pair_id=pair_id, user=email)
            session['total_attempted'] += 1

        session['session_count'] += 1
        return get_titles()

    if session.get('session_count') % C.DECISION_REFRESH_RATE == 0:
        user = util.get_user(user_email=email)
        set_session_data(session, user)
    titles = util.get_titles(email)
    return render_template('make_decision.html', titles=titles, total_attempted=session['total_attempted'], email=email)
Ejemplo n.º 2
0
def past_decisions(user_email, admin_token):
    if session.get("email") != user_email and admin_token != config.ADMIN_TOKEN:
        flash('You can only view your own decisions')
        return redirect(url_for('make_decision'))

    user = util.get_user(user_email=user_email)
    if session.get("email") == user_email:
        set_session_data(session, user)

    results = util.get_attempted_titles(user_email=user_email)
    titles = [{"decision": decision['decision'], "title_1": title["title_1"], "title_2": title["title_2"],
               P.FINAL_DECISION: title[P.FINAL_DECISION] if P.FINAL_DECISION in title else ""} for title in results for
              decision in title['decisions'] if decision['email'] == session['email']]

    return render_template('past_decisions.html', titles=titles)
Ejemplo n.º 3
0
def login():
    app.logger.info("in login")
    error = None
    if request.method == 'POST':

        user_email = request.form['email'].lower()

        if util.check_valid_user(user_email):
            user = util.get_user(user_email=user_email)
            set_session_data(session, user)

            if user[U.FREEZE_ACCOUNT]:
                flash('Account Frozen')
                return redirect(url_for('login'))

            flash('You were logged in')

            return redirect(url_for('make_decision'))
        else:

            flash('User not registered. Please register.')
            return redirect(url_for('register'))

    return render_template('login.html', error=error)