Skip to content

Commit

Permalink
fix: allow subset instead of all api/download_strucures call
Browse files Browse the repository at this point in the history
Also fixes 1286 (Cannot filter a query once a slice has been taken)
  • Loading branch information
kaliif committed Jan 26, 2024
1 parent a17e238 commit c03c548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,13 @@ def create_or_return_download_link(request, target, site_observations):

# Log the provided SiteObservations
num_given_site_obs = site_observations.count()
site_ob_repr = "".join("%r " % site_ob for site_ob in site_observations)
site_ob_repr = "".join(
# & syntax copies the queryset without evaluating it. this way
# I have an unsliced queryset for later for protein_garbage
# filter method (this is what gave sliced queryset error)
"%r " % site_ob
for site_ob in site_observations & site_observations
)
logger.debug(
'Given %s SiteObservation records: %r', num_given_site_obs, site_ob_repr
)
Expand All @@ -761,8 +767,11 @@ def create_or_return_download_link(request, target, site_observations):

# Remove 'references_' from protein list if present.
site_observations = _protein_garbage_filter(site_observations)
if num_removed := num_given_site_obs - num_given_site_obs:
logger.warning('Removed %d "references_" proteins from download', num_removed)
if num_given_site_obs > site_observations.count():
logger.warning(
'Removed %d "references_" proteins from download',
num_given_site_obs - site_observations.count(),
)

# Save the list of protein codes - this is the ispybsafe set for this user.
proteins_list = list(site_observations.values_list('code', flat=True))
Expand Down
6 changes: 5 additions & 1 deletion viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,11 @@ def create(self, request):
code__contains=code_first_part
)
if prot.exists():
site_obvs = prot[0:1]
# even more than just django object, I need an
# unevaluated queryset down the line
site_obvs = models.SiteObservation.objects.filter(
pk=prot.first().pk,
)
else:
logger.warning(
'Could not find SiteObservation record for "%s"',
Expand Down

0 comments on commit c03c548

Please sign in to comment.