def resolve_ballots_with_metadata(self, info): ballots_with_metadata = {} meta = {} meta['election_id'] = str(self.election.id) meta['election_name'] = self.election.name meta['election_type'] = self.election.type_str meta['start'] = self.election.start.astimezone( pytz.timezone('Europe/Oslo')).strftime('%Y-%m-%d %H:%M:%S') meta['end'] = self.election.end.astimezone( pytz.timezone('Europe/Oslo')).strftime('%Y-%m-%d %H:%M:%S') if self.election.type_str == 'uio_stv': meta['num_regular'] = self.election.num_choosable meta['num_substitutes'] = self.election.num_substitutes ballots_with_metadata['meta'] = meta pollbook_names = {} for pbook in self.election.pollbooks: pollbook_names[str(pbook.id)] = pbook.name ballots_with_metadata['pollbook_names'] = pollbook_names if (self.election.meta['candidate_type'] == "single" or self.election.meta['candidate_type'] == "single_team"): candidate_names = {} for candidate in self.election.lists[0].candidates: candidate_names[str(candidate.id)] = candidate.name ballots_with_metadata['candidate_names'] = candidate_names if self.election.meta['candidate_type'] == "party_list": # TODO after implementing list elections: # Handle this case according to how list and candidate names are # stored, and according to what is needed to "decode" UUIDs in # party_list ballots. # This might work: list_names = {} candidate_names = {} for election_list in self.election.lists: list_names[str(election_list.id)] = election_list.name for candidate in election_list.candidates: candidate_names[str(candidate.id)] = candidate.name ballots_with_metadata['list_names'] = list_names ballots_with_metadata['candidate_names'] = candidate_names quotas = [] for quota_group in self.election.quotas: quotas.append({ 'name': quota_group.name, 'members': [str(m.id) for m in quota_group.members] }) ballots_with_metadata['quotas'] = quotas ballots_with_metadata['ballots'] = self.ballots return convert_json(ballots_with_metadata)
def resolve_meta(self, info): return convert_json(self.meta)
def resolve_election_template(_, info, **kwargs): template = election_template_builder() return convert_json(template)
def resolve_meta(self, info): if self.meta is None: return None return convert_json(self.meta)