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 choice order #56

Merged
merged 1 commit into from Nov 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion dpoll/polls/utils.py
Expand Up @@ -28,6 +28,19 @@ def get_sc_client():
return _sc_client


def remove_duplicates(_list):
"""
A helper function to remove duplicate
elements from a list and keeps the list order.
list(set(list... usage loses the order.
"""
new_list = []
for element in _list:
if element not in new_list:
new_list.append(element)
return new_list


def get_comment(request, question, choices, permlink, tags=None):
post_tags = copy.copy(settings.DEFAULT_TAGS)
if tags:
Expand Down Expand Up @@ -119,7 +132,7 @@ def validate_input(request):
"Question text should be between 6-256 chars."
)
error = True
choices = list(set(choices))
choices = remove_duplicates(choices)
choices = [c for c in choices if c]
if len(choices) < 2:
messages.add_message(
Expand Down