Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/django-3.1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
alixedi authored Dec 16, 2021
2 parents a83ae7b + 3df2bad commit fe8f580
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
18 changes: 14 additions & 4 deletions api/cases/libraries/get_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
from lite_content.lite_api import strings


def get_case(pk, include_draft=False):
def get_case(pk, include_draft=False, prefetch_related=None):
"""
Returns a case or returns a 404 on failure
Returns a case or returns a 404 on failure.
Lookups for related objects can be passed via prefetch_related
as a list of strings.
"""
try:
if include_draft:
return Case.objects.all().get(pk=pk)
qs = Case.objects.all()
else:
return Case.objects.submitted().get(pk=pk)
qs = Case.objects.submitted()

if prefetch_related:
for lookup in prefetch_related:
qs = qs.prefetch_related(lookup)

return qs.get(pk=pk)

except Case.DoesNotExist:
raise NotFoundError({"case": strings.Cases.CASE_NOT_FOUND})

Expand Down
2 changes: 1 addition & 1 deletion api/cases/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get(self, request, pk):
Retrieve a case instance
"""
gov_user = request.user.govuser
case = get_case(pk)
case = get_case(pk, prefetch_related=["advice__countersigned_by", "advice__denial_reasons", "advice__user",])
data = CaseDetailSerializer(case, user=gov_user, team=gov_user.team).data

if case.case_type.sub_type == CaseTypeSubTypeEnum.OPEN:
Expand Down
2 changes: 1 addition & 1 deletion api/licences/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def serialize_goods_on_licence(licence):

if licence.goods.exists():
# Standard Application
return GoodOnLicenceViewSerializer(licence.goods.filter(good__is_good_controlled=True), many=True).data
return GoodOnLicenceViewSerializer(licence.goods, many=True).data
elif licence.case.baseapplication.goods_type.exists():
# Open Application
approved_goods_types = get_approved_goods_types(licence.case.baseapplication)
Expand Down
2 changes: 0 additions & 2 deletions api/licences/tests/test_get_licences.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def setUp(self):

for application, licence in self.licences.items():
for good in application.goods.all():
good.is_good_controlled = True
good.save()
FinalAdviceFactory(user=self.gov_user, good=good.good, case=application)
GoodOnLicenceFactory(licence=licence, good=good, quantity=good.quantity, value=good.value)
for goods_type in application.goods_type.all():
Expand Down

0 comments on commit fe8f580

Please sign in to comment.