<commit_before>from django.http.response import HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, render, redirect
from shultze.models import IssuesGraph
from issues.models import Issue, IssueRankingVote
from ocd.base_views import json_response
import json


def user_vote(community_id, current_vote, prev_vote):
    try:
        g = IssuesGraph.objects.get(community_id=community_id)
    except IssuesGraph.DoesNotExist:
        g = IssuesGraph.objects.create(community_id=community_id)
        g.initialize_graph()
    if prev_vote:
        g.add_ballots(prev_vote,reverse=True)
    g.add_ballots(current_vote)


def set_issues_order_by_votes(community_id):
    Issue.objects.filter(community_id=community_id).update( \
        order_by_votes=9999)
    try:
        g = IssuesGraph.objects.get(community_id=community_id)
    except IssuesGraph.DoesNotExist:
        raise
    res = g.get_schulze_npr_results()
    issues = Issue.objects.in_bulk(res['order'])
    for idx, id in enumerate(res['order']):
        issues[id].order_by_votes = idx
        print '[', idx, '] ', issues[id]
        issues[id].save()
        <commit_msg>added default value to prev_vote parameter in  issues.shultze_vote.user_vote<commit_after>from django.http.response import HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, render, redirect
from shultze.models import IssuesGraph
from issues.models import Issue, IssueRankingVote
from ocd.base_views import json_response
import json


def user_vote(community_id, current_vote, prev_vote=[]):
    try:
        g = IssuesGraph.objects.get(community_id=community_id)
    except IssuesGraph.DoesNotExist:
        g = IssuesGraph.objects.create(community_id=community_id)
        g.initialize_graph()
    if prev_vote:
        g.add_ballots(prev_vote,reverse=True)
    g.add_ballots(current_vote)


def set_issues_order_by_votes(community_id):
    Issue.objects.filter(community_id=community_id).update( \
        order_by_votes=9999)
    try:
        g = IssuesGraph.objects.get(community_id=community_id)
    except IssuesGraph.DoesNotExist:
        raise
    res = g.get_schulze_npr_results()
    issues = Issue.objects.in_bulk(res['order'])
    for idx, id in enumerate(res['order']):
        issues[id].order_by_votes = idx
        print '[', idx, '] ', issues[id]
        issues[id].save()
        
{'fraction_non_alphanumeric': 0.09208333333333334, 'fraction_numerical': 0.005833333333333334, 'mean_word_length': 3.991683991683992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7028317', 'n_tokens_mistral': 805, 'n_tokens_neox': 754, 'n_words': 141}