Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(poll): Always retain sequence of poll options in result #854

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions raven/api/raven_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ def get_all_votes(poll_id):
if not frappe.has_permission(doctype="Raven Poll", doc=poll_id, ptype="read"):
frappe.throw(_("You do not have permission to access this poll"), frappe.PermissionError)

# Check if the poll is anonymous
is_anonymous = frappe.get_cached_value("Raven Poll", poll_id, "is_anonymous")
poll_doc = frappe.get_cached_doc("Raven Poll", poll_id)

if is_anonymous:
if poll_doc.is_anonymous:
frappe.throw(_("This poll is anonymous. You do not have permission to access the votes."), frappe.PermissionError)
else:
# Get all votes for this poll
Expand All @@ -150,19 +149,12 @@ def get_all_votes(poll_id):
)

# Initialize results dictionary
results = {}
results = {option.name: { 'users': [], 'count': option.votes } for option in poll_doc.options if option.votes}

# Process votes
for vote in votes:
option = vote['option']
if option not in results:
results[option] = {
'users': [vote['user_id']],
'count': 1
}
else:
results[option]['users'].append(vote['user_id'])
results[option]['count'] += 1
results[option]['users'].append(vote['user_id'])

# Calculate total votes
total_votes = sum(result['count'] for result in results.values())
Expand Down
Loading