Skip to content

Commit

Permalink
glamr/views: Use ChainedQuerySet to export sample-based readabundance
Browse files Browse the repository at this point in the history
Closes #56.
  • Loading branch information
robert102 committed Nov 22, 2024
1 parent 4c824e1 commit 0132f58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mibios/glamr/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ class Meta:
exclude = ['id']

def customize_queryset(self, qs):
if not self.is_for_export():
if self.is_for_export():
if isinstance(qs, ChainedQuerySet):
if qs.fk_field is self._meta.model._meta.get_field('sample'):
# use sample+ref uniq constraint index, so existing order
# by ref_id
qs.iterate_sortkey = 'ref_id'
else:
# For normal HTML table get the function names, don't need or want
# those for export
qs = qs.prefetch_related('ref__function_names')
Expand Down
6 changes: 6 additions & 0 deletions mibios/glamr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def get_export_queryset(self, export_option):
# more intricate options would need to be implemented by inheriting
# views.
remote_field = self.get_export_remote_field(export_option)
if self.model is Sample:
return remote_field.model.objects.all().split_by_fk(
remote_field,
self.get_queryset(),
)

f = {remote_field.name + '__in': self.get_queryset()}
return remote_field.model.objects.filter(**f)

Expand Down

0 comments on commit 0132f58

Please sign in to comment.