示例#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)
示例#2
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)
示例#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)
示例#4
0
def edit_nominees(n=None, form=None):
    """Called from login(), a convenience method."""
    # Temporary redirect to voting
    if config.STAGE not in ('call', 'select'):
        return redirect(url_for('login'))
    if 'osm_token' not in session:
        return redirect(url_for('login'))
    if 'nomination' not in session:
        session['nomination'] = 0
    if n is not None:
        if len(n) == 1 and n.isdigit() and int(n) < len(config.NOMINATIONS):
            session['nomination'] = int(n)
        elif n in config.NOMINATIONS:
            session['nomination'] = config.NOMINATIONS.index(n)
    nom = session['nomination']

    tmp_obj = None
    if 'tmp_nominee' in session:
        tmp_obj = session['tmp_nominee']
        del session['tmp_nominee']
    form = AddNomineeForm(data=tmp_obj)
    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees = Nominee.select(Nominee, Vote.user.alias('voteuser')).where(Nominee.nomination == nom).join(
        Vote, JOIN.LEFT_OUTER, on=((Vote.nominee == Nominee.id) & (Vote.user == uid) & (Vote.preliminary))).naive()
    canadd = isadmin or (config.STAGE == 'call' and Nominee.select().where(
        (Nominee.proposedby == uid) & (Nominee.nomination == nom)).count() < 10)
    if isteam(uid):
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).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
        # Now for the team votes
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).join(Vote, JOIN.LEFT_OUTER, on=(
                (Vote.nominee == Nominee.id) & (Vote.preliminary) & (Vote.user << list(config.TEAM)))).group_by(Nominee.id)
        teamvotes = {}
        if isadmin:
            for v in votesq:
                teamvotes[v.id] = v.num_votes
    else:
        votes = None
        teamvotes = None
    return render_template('index.html',
                           form=form, nomination=config.NOMINATIONS[nom],
                           nominees=nominees, user=uid, isadmin=isadmin, canvote=canvote(uid),
                           canunvote=config.STAGE == 'call' or isteam(uid),
                           votes=votes, teamvotes=teamvotes,
                           year=date.today().year, stage=config.STAGE, canadd=canadd,
                           nominations=config.NOMINATIONS, lang=g.lang)
示例#5
0
def list_chosen():
    nominees = Nominee.select().where(Nominee.chosen)
    return render_template('list.html',
                           nominees=nominees,
                           year=date.today().year,
                           nominations=config.NOMINATIONS,
                           lang=g.lang)
示例#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)
示例#7
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)
示例#8
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)
示例#9
0
def list_chosen():
    nominees = Nominee.select().where(Nominee.chosen)
    return render_template('list.html',
                           nominees=nominees, year=date.today().year,
                           nominations=config.NOMINATIONS, lang=g.lang)
示例#10
0
def list_chosen():
    uid = session.get('osm_uid', None)
    nominees = Nominee.select().where(Nominee.status == Nominee.Status.CHOSEN)
    return render_template('list.html',
                           nominees=nominees, user=uid,
                           nominations=config.NOMINATIONS, lang=g.lang)
示例#11
0
def edit_nominees(cat=None, edit_id=None):
    """Called from login(), a convenience method."""
    uid = session.get('osm_uid', None)
    isadmin = uid in config.ADMINS
    if config.STAGE not in ('call', 'callvote', 'select') and not isadmin:
        return redirect(url_for('login'))
    if cat is None:
        cat = session.get('nomination', 'core')
    if cat == 'all':
        cat = None if isadmin else 'mine'
    if cat == 'mine' and not uid:
        cat = 'core'
    if cat in config.NOMINATIONS or cat is None or cat == 'mine':
        session['nomination'] = cat
    nom = session.get('nomination', cat)

    # Prepare editing form
    edit_obj = None
    if edit_id and uid and (isadmin or config.STAGE in ('call', 'callvote')):
        edit_nom = Nominee.get(Nominee.id == edit_id)
        if (edit_nom.status == Nominee.Status.SUBMITTED and edit_nom.proposedby == uid) or isadmin:
            edit_obj = model_to_dict(edit_nom)
            edit_obj['nomid'] = edit_id
    form = AddNomineeForm(data=edit_obj)
    form.category.choices = g.category_choices

    # Select nominees from the database
    nominees = Nominee.select(Nominee, Vote.user.alias('voteuser')).join(
        Vote, JOIN.LEFT_OUTER, on=(
            (Vote.nominee == Nominee.id) & (Vote.user == uid) & (Vote.preliminary)
        )).order_by(Nominee.id.desc())

    if nom in config.NOMINATIONS:
        nominees = nominees.where(Nominee.category == nom)
    elif nom == 'mine':
        nominees = nominees.where(Nominee.proposedby == uid)
    if nom != 'mine' and not isadmin:
        min_status = (Nominee.Status.SUBMITTED
                      if config.STAGE in ('call', 'callvote', 'select')
                      else Nominee.Status.ACCEPTED)
        nominees = nominees.where(Nominee.status >= min_status)

    # Calculate the number of votes for the selection team
    if isteam(uid):
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).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

    # Prepare a list of categories
    filterables = list(config.NOMINATIONS)
    if uid:
        filterables.insert(0, 'mine')
    if isadmin:
        filterables.insert(0, 'all')

    # All done, return the template
    canadd = isadmin or (uid and config.STAGE.startswith('call') and Nominee.select().where(
        Nominee.proposedby == uid).count() < config.MAX_NOMINEES_PER_USER)
    return render_template('index.html',
                           form=form, nomination=nom or 'all',
                           nominees=nominees.naive(), user=uid, isadmin=isadmin,
                           canvote=canvote(uid),
                           canunvote=config.STAGE == 'callvote' or isteam(uid),
                           votes=votes, statuses={k: v for k, v in Nominee.status.choices},
                           stage=config.STAGE, canadd=canadd,
                           nominations=filterables, lang=g.lang)
示例#12
0
def list_chosen():
    uid = session.get('osm_uid', None)
    nominees = Nominee.select().where(Nominee.status == Nominee.Status.CHOSEN)
    return render_template('list.html',
                           nominees=nominees, user=uid,
                           nominations=config.NOMINATIONS, lang=g.lang)
示例#13
0
def edit_nominees(cat=None, edit_id=None):
    """Called from login(), a convenience method."""
    uid = session.get('osm_uid', None)
    isadmin = uid in config.ADMINS
    if config.STAGE not in ('call', 'callvote', 'select') and not isadmin:
        return redirect(url_for('login'))
    if cat is None:
        cat = session.get('nomination', 'core')
    if cat == 'all':
        cat = None if isadmin else 'mine'
    if cat == 'mine' and not uid:
        cat = 'core'
    if cat in config.NOMINATIONS or cat is None or cat == 'mine':
        session['nomination'] = cat
    nom = session.get('nomination', cat)

    # Prepare editing form
    edit_obj = None
    if edit_id and uid and (isadmin or config.STAGE in ('call', 'callvote')):
        edit_nom = Nominee.get(Nominee.id == edit_id)
        if (edit_nom.status == Nominee.Status.SUBMITTED and edit_nom.proposedby == uid) or isadmin:
            edit_obj = model_to_dict(edit_nom)
            edit_obj['nomid'] = edit_id
    form = AddNomineeForm(data=edit_obj)
    form.category.choices = g.category_choices

    # Select nominees from the database
    nominees = Nominee.select(Nominee, Vote.user.alias('voteuser')).join(
        Vote, JOIN.LEFT_OUTER, on=(
            (Vote.nominee == Nominee.id) & (Vote.user == uid) & (Vote.preliminary)
        )).order_by(Nominee.id.desc())

    if nom in config.NOMINATIONS:
        nominees = nominees.where(Nominee.category == nom)
    elif nom == 'mine':
        nominees = nominees.where(Nominee.proposedby == uid)
    if nom != 'mine' and not isadmin:
        min_status = (Nominee.Status.SUBMITTED
                      if config.STAGE in ('call', 'callvote', 'select')
                      else Nominee.Status.ACCEPTED)
        nominees = nominees.where(Nominee.status >= min_status)

    # Calculate the number of votes for the selection team
    if isteam(uid):
        votesq = Nominee.select(Nominee.id, fn.COUNT(Vote.id).alias('num_votes')).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

    # Prepare a list of categories
    filterables = list(config.NOMINATIONS)
    if uid:
        filterables.insert(0, 'mine')
    if isadmin:
        filterables.insert(0, 'all')

    # All done, return the template
    canadd = isadmin or (uid and config.STAGE.startswith('call') and Nominee.select().where(
        Nominee.proposedby == uid).count() < config.MAX_NOMINEES_PER_USER)
    return render_template('index.html',
                           form=form, nomination=nom or 'all',
                           nominees=nominees.naive(), user=uid, isadmin=isadmin,
                           canvote=canvote(uid),
                           canunvote=config.STAGE == 'callvote' or isteam(uid),
                           votes=votes, statuses={k: v for k, v in Nominee.status.choices},
                           stage=config.STAGE, canadd=canadd,
                           nominations=filterables, lang=g.lang)
示例#14
0
def edit_nominees(n=None, form=None):
    """Called from login(), a convenience method."""
    # Temporary redirect to voting
    if config.STAGE not in ('call', 'select'):
        return redirect(url_for('login'))
    if 'osm_token' not in session:
        return redirect(url_for('login'))
    if 'nomination' not in session:
        session['nomination'] = 0
    if n is not None:
        if len(n) == 1 and n.isdigit() and int(n) < len(config.NOMINATIONS):
            session['nomination'] = int(n)
        elif n in config.NOMINATIONS:
            session['nomination'] = config.NOMINATIONS.index(n)
    nom = session['nomination']

    tmp_obj = None
    if 'tmp_nominee' in session:
        tmp_obj = session['tmp_nominee']
        del session['tmp_nominee']
    form = AddNomineeForm(data=tmp_obj)
    uid = session['osm_uid']
    isadmin = uid in config.ADMINS
    nominees = Nominee.select(
        Nominee,
        Vote.user.alias('voteuser')).where(Nominee.nomination == nom).join(
            Vote,
            JOIN.LEFT_OUTER,
            on=((Vote.nominee == Nominee.id) & (Vote.user == uid) &
                (Vote.preliminary))).naive()
    canadd = isadmin or (config.STAGE == 'call' and Nominee.select().where(
        (Nominee.proposedby == uid) &
        (Nominee.nomination == nom)).count() < 10)
    if isteam(uid):
        votesq = Nominee.select(Nominee.id,
                                fn.COUNT(Vote.id).alias('num_votes')).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
        # Now for the team votes
        votesq = Nominee.select(
            Nominee.id,
            fn.COUNT(Vote.id).alias('num_votes')).join(
                Vote,
                JOIN.LEFT_OUTER,
                on=((Vote.nominee == Nominee.id) & (Vote.preliminary) &
                    (Vote.user << list(config.TEAM)))).group_by(Nominee.id)
        teamvotes = {}
        if isadmin:
            for v in votesq:
                teamvotes[v.id] = v.num_votes
    else:
        votes = None
        teamvotes = None
    return render_template('index.html',
                           form=form,
                           nomination=config.NOMINATIONS[nom],
                           nominees=nominees,
                           user=uid,
                           isadmin=isadmin,
                           canvote=canvote(uid),
                           canunvote=config.STAGE == 'call' or isteam(uid),
                           votes=votes,
                           teamvotes=teamvotes,
                           year=date.today().year,
                           stage=config.STAGE,
                           canadd=canadd,
                           nominations=config.NOMINATIONS,
                           lang=g.lang)