Esempio n. 1
0
def return_newest_contributions():
    contributions = Contribution.get_contributions_new(repository)
    for c in contributions:
        aux = Comment.get_number_comments_by_contribution(repository, str(c['id']))
        c['n_comments'] = aux[0]['n_comments']
        aux = UserContributionVoted.get_votes_contribution(repository, str(c['id']))
        contribution_votes = []
        for aux_v in aux:
            contribution_votes.append(aux_v['username'])
        c['contribution_votes'] = contribution_votes
    return Response(json.dumps(contributions), mimetype='application/json')
Esempio n. 2
0
def new():
    contributions = Contribution.get_contributions_new(repository)
    username = decode_auth_token(request.cookies.get('token'))
    for c in contributions:
        aux = Comment.get_number_comments_by_contribution(repository, str(c['id']))
        c['n_comments'] = aux[0]['n_comments']
    if username is not None:
        user = User.get(repository, username)
        contributions_voted = UserContributionVoted.get_voted(repository, username)
        for c in contributions:
            c.voted = c['id'] in [cv['contribution_id'] for cv in contributions_voted]
        return render_template('home.html', contributions=contributions, user=user)
    return render_template('home.html', contributions=contributions)