Example #1
0
def wait():
    uid = session['osm_uid'] if 'osm_uid' in session else 0
    isadmin = uid in config.ADMINS
    nominees = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.chosen).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (~Vote.preliminary))).naive()
    # For admin, populate the dict of votes
    winners = [[0, 0] for x in range(len(config.NOMINATIONS))]
    if isadmin or config.STAGE == 'results':
        votesq = Nominee.select(Nominee.id, Nominee.nomination, fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.chosen).join(
            Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
            if v.num_votes > winners[v.nomination][1]:
                winners[v.nomination] = (v.id, v.num_votes)
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    # Update a link in the description
    desc = g.lang['stages'][config.STAGE]['description']
    desc = desc.replace('{', '<a href="{}">'.format(url_for('static', filename='osmawards2016.txt'))).replace('}', '</a>')
    # Yay, done
    return render_template('wait.html',
                           nominees=nominees, year=date.today().year,
                           description=desc,
                           isadmin=isadmin, votes=votes, stage=config.STAGE,
                           total=total, winners=winners, isresults=config.STAGE == 'results',
                           nominations=config.NOMINATIONS, lang=g.lang)
Example #2
0
def canvote(uid):
    if session['osm_uid'] in config.ADMINS:
        return True
    if config.STAGE != 'call' and not isteam(uid):
        return False
    return Vote.select().join(Nominee).where(
        (Vote.user == uid) & (Vote.preliminary) & (Nominee.nomination == session['nomination'])).count() < 5
Example #3
0
def voting():
    """Called from login(), a convenience method."""
    if 'osm_token' not in session:
        return redirect(url_for('login'))
    if config.STAGE != 'voting':
        return redirect(url_for('login'))

    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees_list = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.chosen).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (~Vote.preliminary))).naive()
    # Shuffle the nominees
    nominees = [n for n in nominees_list]
    rnd = Random()
    rnd.seed(uid)
    rnd.shuffle(nominees)
    # For admin, populate the dict of votes
    if isadmin:
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.chosen).join(
            Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    # Yay, done
    return render_template('voting.html',
                           nominees=nominees, year=date.today().year,
                           isadmin=isadmin, votes=votes, stage=config.STAGE,
                           total=total,
                           nominations=config.NOMINATIONS, lang=g.lang)
Example #4
0
def wait():
    uid = session['osm_uid'] if 'osm_uid' in session else 0
    isadmin = uid in config.ADMINS
    nominees = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.status == Nominee.Status.CHOSEN).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (~Vote.preliminary))).naive()
    # For admin, populate the dict of votes
    winners = {x: [0, 0] for x in config.NOMINATIONS}
    if isadmin or config.STAGE == 'results':
        votesq = Nominee.select(Nominee.id, Nominee.category, fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.status == Nominee.Status.CHOSEN).join(
            Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
            if v.num_votes > winners[v.category][1]:
                winners[v.category] = (v.id, v.num_votes)
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    # Update a link in the description
    desc = g.lang['stages'][config.STAGE]['description']
    desc = desc.replace('{', '<a href="{}">'.format(
        url_for('static', filename='osmawards2020.txt'))).replace('}', '</a>')
    # Yay, done
    return render_template('wait.html',
                           nominees=nominees,
                           description=desc,
                           isadmin=isadmin, votes=votes, stage=config.STAGE,
                           total=total, winners=winners, isresults=config.STAGE == 'results',
                           nominations=config.NOMINATIONS, lang=g.lang)
Example #5
0
def canvote(uid):
    if session['osm_uid'] in config.ADMINS:
        return True
    if config.STAGE != 'call' and not isteam(uid):
        return False
    return Vote.select().join(Nominee).where(
        (Vote.user == uid) & (Vote.preliminary)
        & (Nominee.nomination == session['nomination'])).count() < 5
Example #6
0
def voting():
    """Called from login(), a convenience method."""
    if 'osm_token' not in session:
        return redirect(url_for('login'))
    if config.STAGE != 'voting':
        return redirect(url_for('login'))

    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees_list = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(
        Nominee.chosen).join(
            Vote,
            JOIN.LEFT_OUTER,
            on=((Vote.nominee == Nominee.id) & (Vote.user == uid) &
                (~Vote.preliminary))).naive()
    # Shuffle the nominees
    nominees = [n for n in nominees_list]
    rnd = Random()
    rnd.seed(uid)
    rnd.shuffle(nominees)
    # For admin, populate the dict of votes
    if isadmin:
        votesq = Nominee.select(
            Nominee.id,
            fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.chosen).join(
                Vote,
                JOIN.LEFT_OUTER,
                on=((Vote.nominee == Nominee.id) &
                    (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(
        Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    # Yay, done
    return render_template('voting.html',
                           nominees=nominees,
                           year=date.today().year,
                           isadmin=isadmin,
                           votes=votes,
                           stage=config.STAGE,
                           total=total,
                           nominations=config.NOMINATIONS,
                           lang=g.lang)
Example #7
0
def vote(nid):
    if 'osm_token' not in session or config.STAGE != 'voting':
        return redirect(url_for('login'))
    uid = session['osm_uid']
    n = Nominee.get(Nominee.id == nid)
    try:
        # Delete votes from the same category by this voter
        v = Vote.select().where((Vote.user == uid) & (~Vote.preliminary)).join(Nominee).where(
            Nominee.nomination == n.nomination).get()
        v.delete_instance()
    except Vote.DoesNotExist:
        pass
    v = Vote()
    v.nominee = n
    v.user = uid
    v.preliminary = False
    v.save()
    return redirect(url_for('voting'))
Example #8
0
def vote(nid):
    if 'osm_token' not in session or config.STAGE != 'voting':
        return redirect(url_for('login'))
    uid = session['osm_uid']
    n = Nominee.get(Nominee.id == nid)
    try:
        # Delete votes from the same category by this voter
        v = Vote.select().where((Vote.user == uid) & (~Vote.preliminary)).join(Nominee).where(
            Nominee.category == n.category).get()
        v.delete_instance()
    except Vote.DoesNotExist:
        pass
    v = Vote()
    v.nominee = n
    v.user = uid
    v.preliminary = False
    v.save()
    return redirect(url_for('voting'))
Example #9
0
def voting():
    """Called from login(), a convenience method."""
    if 'osm_token' not in session:
        return redirect(url_for('list_chosen'))
    if config.STAGE != 'voting':
        return redirect(url_for('login'))

    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees_list = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.status == Nominee.Status.CHOSEN).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (~Vote.preliminary))).naive()
    # Shuffle the nominees
    nominees = [n for n in nominees_list]
    rnd = Random()
    rnd.seed(uid)
    rnd.shuffle(nominees)
    # Make a dict of categories user voted in
    cats = set([x.category for x in Nominee.select(Nominee.category).join(Vote, JOIN.INNER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary) & (Vote.user == uid))).distinct()])
    # For admin, populate the dict of votes
    if isadmin:
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.status == Nominee.Status.CHOSEN).join(
            Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    readmore = (g.lang['stages']['voting']['readmore']
                .replace('{', '<a href="{}">'.format(
                    g.lang['stages']['voting']['readmore_link']))
                .replace('}', '</a>'))
    # Yay, done
    return render_template('voting.html',
                           nominees=nominees,
                           isadmin=isadmin, votes=votes, stage=config.STAGE,
                           total=total, voted_cats=cats, readmore=readmore,
                           nominations=config.NOMINATIONS, lang=g.lang)
Example #10
0
def voting():
    """Called from login(), a convenience method."""
    if 'osm_token' not in session:
        return redirect(url_for('list_chosen'))
    if config.STAGE != 'voting':
        return redirect(url_for('login'))

    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees_list = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.status == Nominee.Status.CHOSEN).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (~Vote.preliminary))).naive()
    # Shuffle the nominees
    nominees = [n for n in nominees_list]
    rnd = Random()
    rnd.seed(uid)
    rnd.shuffle(nominees)
    # Make a dict of categories user voted in
    cats = set([x.category for x in Nominee.select(Nominee.category).join(Vote, JOIN.INNER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary) & (Vote.user == uid))).distinct()])
    # For admin, populate the dict of votes
    if isadmin:
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).where(Nominee.status == Nominee.Status.CHOSEN).join(
            Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (~Vote.preliminary))).group_by(Nominee.id)
        votes = {}
        for v in votesq:
            votes[v.id] = v.num_votes
    else:
        votes = None
    # Count total number of voters
    total = Vote.select(fn.Distinct(Vote.user)).where(~Vote.preliminary).group_by(Vote.user).count()
    readmore = (g.lang['stages']['voting']['readmore']
                .replace('{', '<a href="{}">'.format(
                    g.lang['stages']['voting']['readmore_link']))
                .replace('}', '</a>'))
    # Yay, done
    return render_template('voting.html',
                           nominees=nominees,
                           isadmin=isadmin, votes=votes, stage=config.STAGE,
                           total=total, voted_cats=cats, readmore=readmore,
                           nominations=config.NOMINATIONS, lang=g.lang)
Example #11
0
def vote_all():
    if 'osm_token' not in session or config.STAGE != 'voting':
        return redirect(url_for('login'))
    uid = session['osm_uid']
    for nom in range(len(config.NOMINATIONS)):
        vote = request.form.get('vote{}'.format(nom), -1, type=int)
        if vote < 0:
            continue
        try:
            # Delete votes from the same category by this voter
            v = Vote.select().where((Vote.user == uid) & (~Vote.preliminary)).join(Nominee).where(
                Nominee.nomination == nom).get()
            v.delete_instance()
        except Vote.DoesNotExist:
            pass
        if vote > 0:
            v = Vote()
            v.nominee = Nominee.get(Nominee.id == vote)
            v.user = uid
            v.preliminary = False
            v.save()
    flash(g.lang['thanksvoted'])
    return redirect(url_for('voting'))
Example #12
0
def vote_all():
    if 'osm_token' not in session or config.STAGE != 'voting':
        return redirect(url_for('login'))
    uid = session['osm_uid']
    for nom in range(len(config.NOMINATIONS)):
        vote = request.form.get('vote{}'.format(nom), -1, type=int)
        if vote < 0:
            continue
        try:
            # Delete votes from the same category by this voter
            v = Vote.select().where((Vote.user == uid)
                                    & (~Vote.preliminary)).join(Nominee).where(
                                        Nominee.nomination == nom).get()
            v.delete_instance()
        except Vote.DoesNotExist:
            pass
        if vote > 0:
            v = Vote()
            v.nominee = Nominee.get(Nominee.id == vote)
            v.user = uid
            v.preliminary = False
            v.save()
    flash(g.lang['thanksvoted'])
    return redirect(url_for('voting'))