Skip to content

Commit

Permalink
Proxito: save one queryset (#9980)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Feb 7, 2023
1 parent 5cea411 commit e85ee7d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions readthedocs/proxito/views/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import structlog
from functools import wraps

import structlog
from django.db.models import Q
from django.http import Http404

from readthedocs.projects.models import Project, ProjectRelationship
Expand All @@ -25,26 +26,20 @@ def inner_view( # noqa
# Try to fetch by subproject alias first, otherwise we might end up
# redirected to an unrelated project.
# Depends on a project passed into kwargs
rel = ProjectRelationship.objects.filter(
parent=kwargs['project'],
alias=subproject_slug,
).first()
rel = (
ProjectRelationship.objects.filter(parent=kwargs["project"])
.filter(Q(alias=subproject_slug) | Q(child__slug=subproject_slug))
.first()
)
if rel:
subproject = rel.child
else:
rel = ProjectRelationship.objects.filter(
parent=kwargs['project'],
child__slug=subproject_slug,
).first()
if rel:
subproject = rel.child
else:
log.warning(
'The slug is not subproject of project.',
subproject_slug=subproject_slug,
project_slug=kwargs['project'].slug,
)
raise Http404('Invalid subproject slug')
log.warning(
"The slug is not subproject of project.",
subproject_slug=subproject_slug,
project_slug=kwargs["project"].slug,
)
raise Http404("Invalid subproject slug")
return view_func(request, subproject=subproject, *args, **kwargs)

return inner_view
Expand Down

0 comments on commit e85ee7d

Please sign in to comment.