in pysteve/lib/backends/es.py [0:0]
def voter_ballots(self, UID):
"""Find all elections (and ballots) this user has participated in"""
# First, get all elections
elections = {}
res = self.DB.ES.search(index=self.index, doc_type="elections", sort = "id", q = "*", size = 9999)
results = len(res['hits']['hits'])
if results > 0:
for entry in res['hits']['hits']:
election = entry['_source']
# Mark election open or closed
elections[election['id']] = {
'title': election['title'],
'open': False if election['closed'] else True
}
# Then, get all ballots and note whether they still apply or not
ballots = {}
res = self.DB.ES.search(index=self.index, doc_type="voters", body = {
"query": {
"match": {
"uid": UID
}
}
}, size = 999)
results = len(res['hits']['hits'])
if results > 0:
for entry in res['hits']['hits']:
ballot = entry['_source']
ballots[ballot['election']] = {
'ballot': entry['_id'],
'metadata': elections[ballot['election']]
}
return ballots