# Path: agora_site/agora_core/models/voting_systems/base.py
# class BaseVotingSystem(object):
#     '''
#     Defines the helper functions that allows agora to manage a voting system.
#     '''
# 
#     @staticmethod
#     def get_id():
#         '''
#         Returns the identifier of the voting system, used internally to
#         discriminate  the voting system used in an election
#         '''
#         return 'base'
# 
#     @staticmethod
#     def get_description():
#         '''
#         Returns the user text description of the voting system
#         '''
#         pass
# 
#     @staticmethod
#     def create_tally(election, question_num):
#         '''
#         Create object that helps to compute the tally
#         '''
#         return BaseTally(election, question_num)
# 
#     @staticmethod
#     def get_question_field(election, question):
#         '''
#         Creates a voting field that can be used to answer a question in a ballot
#         '''
#         pass
# 
#     @staticmethod
#     def validate_question(question):
#         '''
#         Validates the value of a given question in an election. Raises a
#         django_forms.ValidationError exception if validation fails
#         '''
#         pass
# 
# class BaseTally(object):
#     '''
#     Class oser to tally an election
#     '''
#     election = None
#     question_num = None
# 
#     def __init__(self, election, question_num):
#         self.election = election
#         self.question_num = question_num
#         self.init()
# 
#     def init(self):
#         pass
# 
#     def pre_tally(self, result):
#         '''
#         Function called once before the tally begins
#         '''
#         pass
# 
#     def add_vote(self, voter_answers, result, is_delegated):
#         '''
#         Add to the count a vote from a voter
#         '''
#         pass
# 
#     def post_tally(self, result):
#         '''
#         Once all votes have been added, this function is called once
#         '''
#         pass
# 
#     def get_log(self):
#         '''
#         Returns the tally log. Called after post_tally()
#         '''
#         return None


import random
import copy
import sys
        import os
        import uuid
        import codecs
from django import forms as django_forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from .base import BaseVotingSystem, BaseTally
from agora_site.misc.utils import *
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins
        from .json_report import JsonReport

        # find question in election
        question = None
        for q in self.election.questions:
            if q['question'] == self.label:
                question = q

        # gather possible answers
        possible_answers = [answer['value'] for answer in question['answers']]

        # check the answers provided are valid
        for i in value:
            if i not in possible_answers:
                raise error

        # NOTE: in the future, when encryption support is added, this will be
        # handled differently, probably in a more generic way so that
        # BaseSTVField doesn't know anything about plaintext or encryption.
        if len(value) > 0:
            clean_value = super(BaseSTVField, self).clean(value)
            return {
                "a": "plaintext-answer",
                "choices": clean_value,
            }
        else:
            return {
                "a": "plaintext-answer",
                "choices": [],
            }


# Path: agora_site/agora_core/models/voting_systems/base.py
# class BaseVotingSystem(object):
#     '''
#     Defines the helper functions that allows agora to manage a voting system.
#     '''
# 
#     @staticmethod
#     def get_id():
#         '''
#         Returns the identifier of the voting system, used internally to
#         discriminate  the voting system used in an election
#         '''
#         return 'base'
# 
#     @staticmethod
#     def get_description():
#         '''
#         Returns the user text description of the voting system
#         '''
#         pass
# 
#     @staticmethod
#     def create_tally(election, question_num):
#         '''
#         Create object that helps to compute the tally
#         '''
#         return BaseTally(election, question_num)
# 
#     @staticmethod
#     def get_question_field(election, question):
#         '''
#         Creates a voting field that can be used to answer a question in a ballot
#         '''
#         pass
# 
#     @staticmethod
#     def validate_question(question):
#         '''
#         Validates the value of a given question in an election. Raises a
#         django_forms.ValidationError exception if validation fails
#         '''
#         pass
# 
# class BaseTally(object):
#     '''
#     Class oser to tally an election
#     '''
#     election = None
#     question_num = None
# 
#     def __init__(self, election, question_num):
#         self.election = election
#         self.question_num = question_num
#         self.init()
# 
#     def init(self):
#         pass
# 
#     def pre_tally(self, result):
#         '''
#         Function called once before the tally begins
#         '''
#         pass
# 
#     def add_vote(self, voter_answers, result, is_delegated):
#         '''
#         Add to the count a vote from a voter
#         '''
#         pass
# 
#     def post_tally(self, result):
#         '''
#         Once all votes have been added, this function is called once
#         '''
#         pass
# 
#     def get_log(self):
#         '''
#         Returns the tally log. Called after post_tally()
#         '''
#         return None


# Path: agora_site/agora_core/models/voting_systems/base_stv.py
import random
import copy
import sys
        import os
        import uuid
        import codecs
from django import forms as django_forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from .base import BaseVotingSystem, BaseTally
from agora_site.misc.utils import *
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins
        from .json_report import JsonReport


        # find question in election
        question = None
        for q in self.election.questions:
            if q['question'] == self.label:
                question = q

        # gather possible answers
        possible_answers = [answer['value'] for answer in question['answers']]

        # check the answers provided are valid
        for i in value:
            if i not in possible_answers:
                raise error

        # NOTE: in the future, when encryption support is added, this will be
        # handled differently, probably in a more generic way so that
        # BaseSTVField doesn't know anything about plaintext or encryption.
        if len(value) > 0:
            clean_value = super(BaseSTVField, self).clean(value)
            return {
                "a": "plaintext-answer",
                "choices": clean_value,
            }
        else:
            return {
                "a": "plaintext-answer",
                "choices": [],
            }


class BaseSTVTally(BaseTally):