Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix /candidate-urls-api endpoint to add include patterns above exclude patterns in URLs list #1044

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions sde_collections/models/candidate_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@

from .collection import Collection
from .collection_choice_fields import Divisions, DocumentTypes
from .pattern import ExcludePattern, TitlePattern
from .pattern import ExcludePattern, IncludePattern, TitlePattern


class CandidateURLQuerySet(models.QuerySet):
def with_exclusion_status(self):
def with_exclusion_and_inclusion_status(self):
return self.annotate(
excluded=models.Exists(
ExcludePattern.candidate_urls.through.objects.filter(candidateurl=models.OuterRef("pk"))
)
),
included=models.Exists(
IncludePattern.candidate_urls.through.objects.filter(candidateurl=models.OuterRef("pk"))
),
)


class CandidateURLManager(models.Manager):
def get_queryset(self):
return CandidateURLQuerySet(self.model, using=self._db).with_exclusion_status()
return CandidateURLQuerySet(self.model, using=self._db).with_exclusion_and_inclusion_status()


class CandidateURL(models.Model):
Expand Down
5 changes: 3 additions & 2 deletions sde_collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ def get(self, request, *args, **kwargs):
self.config_folder = config_folder
return super().get(request, *args, **kwargs)

# return the urls that are either not excluded or specifically included
def get_queryset(self):
queryset = (
CandidateURL.objects.filter(collection__config_folder=self.config_folder)
.with_exclusion_status()
.filter(excluded=False)
.with_exclusion_and_inclusion_status()
.filter(models.Q(excluded=False) | models.Q(included=True))
)
return queryset

Expand Down