1
- import structlog
2
1
from functools import wraps
3
2
3
+ import structlog
4
+ from django .db .models import Q
4
5
from django .http import Http404
5
6
6
7
from readthedocs .projects .models import Project , ProjectRelationship
@@ -25,26 +26,20 @@ def inner_view( # noqa
25
26
# Try to fetch by subproject alias first, otherwise we might end up
26
27
# redirected to an unrelated project.
27
28
# Depends on a project passed into kwargs
28
- rel = ProjectRelationship .objects .filter (
29
- parent = kwargs ['project' ],
30
- alias = subproject_slug ,
31
- ).first ()
29
+ rel = (
30
+ ProjectRelationship .objects .filter (parent = kwargs ["project" ])
31
+ .filter (Q (alias = subproject_slug ) | Q (child__slug = subproject_slug ))
32
+ .first ()
33
+ )
32
34
if rel :
33
35
subproject = rel .child
34
36
else :
35
- rel = ProjectRelationship .objects .filter (
36
- parent = kwargs ['project' ],
37
- child__slug = subproject_slug ,
38
- ).first ()
39
- if rel :
40
- subproject = rel .child
41
- else :
42
- log .warning (
43
- 'The slug is not subproject of project.' ,
44
- subproject_slug = subproject_slug ,
45
- project_slug = kwargs ['project' ].slug ,
46
- )
47
- raise Http404 ('Invalid subproject slug' )
37
+ log .warning (
38
+ "The slug is not subproject of project." ,
39
+ subproject_slug = subproject_slug ,
40
+ project_slug = kwargs ["project" ].slug ,
41
+ )
42
+ raise Http404 ("Invalid subproject slug" )
48
43
return view_func (request , subproject = subproject , * args , ** kwargs )
49
44
50
45
return inner_view
0 commit comments