Skip to content

Commit a160b6b

Browse files
authored
Merge pull request #505 from xchem/m2ms-1294-all-structures
Allow subset of structures in api/download_strucures call (issue 1294)
2 parents d21b5b3 + c03c548 commit a160b6b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

viewer/download_structures.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,13 @@ def create_or_return_download_link(request, target, site_observations):
749749

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

762768
# Remove 'references_' from protein list if present.
763769
site_observations = _protein_garbage_filter(site_observations)
764-
if num_removed := num_given_site_obs - num_given_site_obs:
765-
logger.warning('Removed %d "references_" proteins from download', num_removed)
770+
if num_given_site_obs > site_observations.count():
771+
logger.warning(
772+
'Removed %d "references_" proteins from download',
773+
num_given_site_obs - site_observations.count(),
774+
)
766775

767776
# Save the list of protein codes - this is the ispybsafe set for this user.
768777
proteins_list = list(site_observations.values_list('code', flat=True))

viewer/views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,11 @@ def create(self, request):
14821482
code__contains=code_first_part
14831483
)
14841484
if prot.exists():
1485-
site_obvs = prot[0:1]
1485+
# even more than just django object, I need an
1486+
# unevaluated queryset down the line
1487+
site_obvs = models.SiteObservation.objects.filter(
1488+
pk=prot.first().pk,
1489+
)
14861490
else:
14871491
logger.warning(
14881492
'Could not find SiteObservation record for "%s"',

0 commit comments

Comments
 (0)