Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Added urn sorter by index
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Dec 19, 2018
1 parent db645f9 commit d534ae5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import string
import csv
from datetime import datetime

Expand Down Expand Up @@ -191,6 +192,13 @@ def format_csv_rows(variants, columns, dtype):
return rowdicts


def urn_number(variant):
number = variant.urn.split('#')[-1]
if not str.isdigit(number):
return 0
return int(number)


def format_response(response, scoreset, dtype):
"""
Writes the CSV response by formatting each variant into a row including
Expand All @@ -217,7 +225,7 @@ def format_response(response, scoreset, dtype):
])

variants = sorted(
scoreset.children.all(), key=lambda v: int(v.urn.split('#')[-1]))
scoreset.children.all(), key=lambda v: urn_number(v))

if dtype == 'scores':
columns = ['urn', ] + scoreset.score_columns
Expand Down

0 comments on commit d534ae5

Please sign in to comment.