Skip to content

Commit

Permalink
remove subtag field from knowledge domain lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
elichad committed Nov 6, 2023
1 parent c6a87a1 commit 20ad9fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
11 changes: 1 addition & 10 deletions amy/workshops/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,11 @@ def get_queryset(self):


class KnowledgeDomainLookupView(OnlyForAdminsNoRedirectMixin, AutoResponseView):
def dispatch(self, request, *args, **kwargs):
self.subtag = "subtag" in request.GET.keys()
return super().dispatch(request, *args, **kwargs)

def get_queryset(self):
results = models.KnowledgeDomain.objects.all()

if self.term:
results = results.filter(
Q(name__icontains=self.term) | Q(subtag__icontains=self.term)
)

if self.subtag:
return results.filter(subtag__iexact=self.term)
results = results.filter(Q(name__icontains=self.term))

results = results.annotate(person_count=Count("person")).order_by(
"-person_count"
Expand Down
31 changes: 31 additions & 0 deletions amy/workshops/tests/test_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
EventLookupForAwardsView,
EventLookupView,
GenericObjectLookupView,
KnowledgeDomainLookupView,
TTTEventLookupView,
urlpatterns,
)
from workshops.models import (
Award,
Badge,
Event,
KnowledgeDomain,
Lesson,
Person,
Role,
Expand Down Expand Up @@ -56,6 +58,35 @@ def test_login_regression(self):
self.assertEqual(rv.status_code, 200, pattern.name) # OK


class TestKnowledgeDomainLookupView(TestBase):
def setUpView(self, term: str = "") -> KnowledgeDomainLookupView:
# path doesn't matter
request = RequestFactory().get("/")
view = KnowledgeDomainLookupView(request=request, term=term)
return view

def test_get_queryset_no_term(self):
# Arrange
view = self.setUpView()
# Act
queryset = view.get_queryset()
# Assert
self.assertQuerysetEqual(queryset, KnowledgeDomain.objects.all(), ordered=False)

def test_get_queryset_simple_term(self):
# Arrange
term = "ed"
view = self.setUpView(term=term)
# Act
queryset = view.get_queryset()
# Assert
self.assertQuerysetEqual(
queryset,
KnowledgeDomain.objects.filter(name__icontains=term),
ordered=False,
)


class TestAwardLookupView(TestBase):
def setUpView(self, term: str = "", badge: Optional[int] = None) -> AwardLookupView:
# path doesn't matter
Expand Down

0 comments on commit 20ad9fe

Please sign in to comment.