Пример #1
0
def votes_constructor():
    votes = Votes(president=Counter(),
                  gobernor=Counter(),
                  diputado=Counter(),
                  senador=Counter(),
                  intendente=Counter(),
                  general=Counter())
    votes.save()
    return votes
Пример #2
0
def load_votes_matrix(box):
    parties = []
    parties_matrix = zip(PARTIES, VOTES_MATRIX)
    for party, flags in dict(parties_matrix).items():
        kwargs = {}
        for i, flag in enumerate(flags):
            counter = Counter(enabled=bool(flag))
            kwargs[CANDIDATES[i]] = counter
        _votes = Votes(**kwargs)
        _votes.save()
        _party = Party(name=party, votes=_votes)
        _party.save()
        parties.append(_party)
    box.parties = parties
    box.save()
    other_votes = OtherVotes(blank=votes_constructor(),
                             nulled=votes_constructor(),
                             recurrent=votes_constructor(),
                             refuted=votes_constructor()).save()
    box.other_votes = other_votes
    box.save()