Skip to content

Commit

Permalink
Merge pull request #366 from RTIInternational/fix_category_sorting_bug
Browse files Browse the repository at this point in the history
fix category sorting when one of the category possibilities is null
  • Loading branch information
AstridKery authored Nov 14, 2024
2 parents b458904 + d58030c commit 995f140
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions backend/django/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,12 @@ def __str__(self):
return self.field_name

def get_unique_options(self):
unique_list = list(
set(self.labelmetadata_set.all().values_list("value", flat=True))
unique_list = (
self.labelmetadata_set.all()
.order_by("value")
.values_list("value", flat=True)
.distinct()
)
unique_list.sort()
return unique_list


Expand Down
2 changes: 1 addition & 1 deletion backend/django/core/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def download_irr_log(request, project_pk):
for log in logs:
label_name = log.label.name if log.label else ""
writer.writerow(
[log.data.pk, log.data.text, label_name, log.profile.user, log.timestamp]
[log.data.upload_id, log.data.text, label_name, log.profile.user, log.timestamp]
)

return response
Expand Down
17 changes: 11 additions & 6 deletions backend/django/core/views/api_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,17 @@ def get_queryset(self):
filter_text = self.request.GET.get("searchString")

label_category = self.request.GET.get("category")
if label_category and label_category != "all":
if label_category == "None":
category_label_list = LabelMetaData.objects.filter(
label_metadata_field=project.category.label_metadata_field,
value="nan",
).values_list("label__pk", flat=True)
if hasattr(project, "category") and label_category != "all":
if label_category == "None" or label_category == "":
category_label_list = (
LabelMetaData.objects.filter(
label_metadata_field=project.category.label_metadata_field
)
.filter(
Q(value__isnull=True) | Q(value="nan"),
)
.values_list("label__pk", flat=True)
)
else:
category_label_list = LabelMetaData.objects.filter(
label_metadata_field=project.category.label_metadata_field,
Expand Down

0 comments on commit 995f140

Please sign in to comment.