Skip to content

Commit

Permalink
Merge pull request #56 from emre/fix-choice-order
Browse files Browse the repository at this point in the history
Fix choice order
  • Loading branch information
emre committed Nov 27, 2018
2 parents 75a04a9 + 16e5d47 commit 659d5c1
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 659d5c1

Please sign in to comment.