Skip to content
Snippets Groups Projects
Commit 4f38afb3 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

An unification of presentation for find_votes/list_votes

parent c42963fe
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!138Small typos fixed,!129The calls 'list_votes'/'find_votes' work
This commit is part of merge request !129. Comments created here will be created in the context of that merge request.
......@@ -167,6 +167,25 @@ class VotesPresentation(Enum):
CondenserApi = 3
BridgeApi = 4
def result_presentation(rows, votes_presentation):
ret = []
for row in rows:
if votes_presentation == VotesPresentation.DatabaseApi:
ret.append(dict(voter=row.voter, author=row.author, permlink=row.permlink,
weight=row.weight, rshares=row.rshares, vote_percent=row.percent,
last_update=str(row.time), num_changes=row.num_changes))
elif votes_presentation == VotesPresentation.CondenserApi:
ret.append(dict(percent=str(row.percent), reputation=rep_to_raw(row.reputation),
rshares=str(row.rshares), voter=row.voter))
elif votes_presentation == VotesPresentation.BridgeApi:
ret.append(dict(rshares=str(row.rshares), voter=row.voter))
else:
ret.append(dict(percent=row.percent, reputation=rep_to_raw(row.reputation),
rshares=number_to_json_value(row.rshares), time=time_string_with_t(row.time),
voter=row.voter, weight=number_to_json_value(row.weight)
))
return ret
@return_error_info
async def find_votes(context, author: str, permlink: str, votes_presentation = VotesPresentation.DatabaseApi):
""" Returns all votes for the given post """
......@@ -192,25 +211,8 @@ async def find_votes(context, author: str, permlink: str, votes_presentation = V
voter_id
"""
ret = []
rows = await db.query_all(sql, author=author, permlink=permlink)
for row in rows:
if votes_presentation == VotesPresentation.DatabaseApi:
ret.append(dict(voter=row.voter, author=row.author, permlink=row.permlink,
weight=row.weight, rshares=row.rshares, vote_percent=row.percent,
last_update=str(row.time), num_changes=row.num_changes))
elif votes_presentation == VotesPresentation.CondenserApi:
ret.append(dict(percent=str(row.percent), reputation=rep_to_raw(row.reputation),
rshares=str(row.rshares), voter=row.voter))
elif votes_presentation == VotesPresentation.BridgeApi:
ret.append(dict(rshares=str(row.rshares), voter=row.voter))
else:
ret.append(dict(percent=row.percent, reputation=rep_to_raw(row.reputation),
rshares=number_to_json_value(row.rshares), time=time_string_with_t(row.time),
voter=row.voter, weight=number_to_json_value(row.weight)
))
return ret
return result_presentation(rows, votes_presentation)
@return_error_info
async def list_votes(context, start: list, limit: int, order: str, votes_presentation = VotesPresentation.DatabaseApi):
......@@ -221,8 +223,6 @@ async def list_votes(context, start: list, limit: int, order: str, votes_present
assert len(start) == 3, "Expecting 3 elements in start array"
db = context['db']
ret = []
sql = """
SELECT
voter,
......@@ -266,20 +266,4 @@ async def list_votes(context, start: list, limit: int, order: str, votes_present
"""
rows = await db.query_all(sql, author=start[1], permlink=start[2], voter=start[0], limit=limit)
for row in rows:
if votes_presentation == VotesPresentation.DatabaseApi:
ret.append(dict(voter=row.voter, author=row.author, permlink=row.permlink,
weight=row.weight, rshares=row.rshares, vote_percent=row.percent,
last_update=str(row.time), num_changes=row.num_changes))
elif votes_presentation == VotesPresentation.CondenserApi:
ret.append(dict(percent=str(row.percent), reputation=rep_to_raw(row.reputation),
rshares=str(row.rshares), voter=row.voter))
elif votes_presentation == VotesPresentation.BridgeApi:
ret.append(dict(rshares=str(row.rshares), voter=row.voter))
else:
ret.append(dict(percent=row.percent, reputation=rep_to_raw(row.reputation),
rshares=number_to_json_value(row.rshares), time=time_string_with_t(row.time),
voter=row.voter, weight=number_to_json_value(row.weight)
))
return ret
return result_presentation(rows, votes_presentation)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment