Skip to content

Commit 5faa516

Browse files
authored
Merge pull request #5496 from saadmk11/make-random-path-work
Make /random/ path work
2 parents 700b83d + a14d541 commit 5faa516

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

readthedocs/core/views/__init__.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
from readthedocs.core.utils.general import wipe_version_via_slugs
2121
from readthedocs.core.resolver import resolve_path
2222
from readthedocs.core.symlink import PrivateSymlink, PublicSymlink
23-
from readthedocs.core.utils import broadcast
2423
from readthedocs.core.views.serve import _serve_file
2524
from readthedocs.projects.constants import PRIVATE
26-
from readthedocs.projects.models import Project, ImportedFile
27-
from readthedocs.projects.tasks import remove_dirs
28-
from readthedocs.redirects.utils import get_redirect_response, project_and_path_from_request, language_and_version_from_path
25+
from readthedocs.projects.models import HTMLFile, Project
26+
from readthedocs.redirects.utils import (
27+
get_redirect_response,
28+
project_and_path_from_request,
29+
language_and_version_from_path
30+
)
2931

3032
log = logging.getLogger(__name__)
3133

@@ -66,13 +68,13 @@ def get_context_data(self, **kwargs):
6668

6769

6870
def random_page(request, project_slug=None): # pylint: disable=unused-argument
69-
imported_file = ImportedFile.objects.order_by('?')
71+
html_file = HTMLFile.objects.order_by('?')
7072
if project_slug:
71-
imported_file = imported_file.filter(project__slug=project_slug)
72-
imported_file = imported_file.first()
73-
if imported_file is None:
73+
html_file = html_file.filter(project__slug=project_slug)
74+
html_file = html_file.first()
75+
if html_file is None:
7476
raise Http404
75-
url = imported_file.get_absolute_url()
77+
url = html_file.get_absolute_url()
7678
return HttpResponseRedirect(url)
7779

7880

readthedocs/rtd_tests/tests/test_views.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from readthedocs.builds.models import Build
1212
from readthedocs.core.permissions import AdminPermission
1313
from readthedocs.projects.forms import UpdateProjectForm
14-
from readthedocs.projects.models import ImportedFile, Project
14+
from readthedocs.projects.models import HTMLFile, Project
1515

1616

1717
class Testmaker(TestCase):
@@ -170,10 +170,10 @@ class RandomPageTests(TestCase):
170170
def setUp(self):
171171
self.pip = Project.objects.get(slug='pip')
172172
self.pip_version = self.pip.versions.all()[0]
173-
ImportedFile.objects.create(
173+
HTMLFile.objects.create(
174174
project=self.pip,
175175
version=self.pip_version,
176-
name='File',
176+
name='file.html',
177177
slug='file',
178178
path='file.html',
179179
md5='abcdef',
@@ -193,8 +193,8 @@ def test_404_for_unknown_project(self):
193193
response = self.client.get('/random/not-existent/')
194194
self.assertEqual(response.status_code, 404)
195195

196-
def test_404_for_with_no_imported_files(self):
197-
ImportedFile.objects.all().delete()
196+
def test_404_for_with_no_html_files(self):
197+
HTMLFile.objects.all().delete()
198198
response = self.client.get('/random/pip/')
199199
self.assertEqual(response.status_code, 404)
200200

0 commit comments

Comments
 (0)