Skip to content

Migrate v1 to v2 #3051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/comments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DocumentNodeAdmin(admin.ModelAdmin):
search_fields = ('id', 'document')
list_filter = ('project__name',)
raw_id_fields = ('project', 'version')
list_display = ('__unicode__', 'latest_hash', 'latest_commit')
list_display = ('__str__', 'latest_hash', 'latest_commit')
inlines = (SnapshotAdmin,)


Expand Down
3 changes: 1 addition & 2 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from readthedocs.builds.constants import BUILD_STATE_FINISHED
from readthedocs.builds.models import BuildCommandResultMixin
from readthedocs.projects.constants import LOG_TEMPLATE
from readthedocs.api.client import api as api_v1
from readthedocs.restapi.client import api as api_v2

from .exceptions import (BuildEnvironmentException, BuildEnvironmentError,
Expand All @@ -37,7 +36,7 @@


__all__ = (
'api_v1', 'api_v2',
'api_v2',
'BuildCommand', 'DockerBuildCommand',
'BuildEnvironment', 'LocalEnvironment', 'DockerEnvironment',
)
Expand Down
10 changes: 4 additions & 6 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
from guardian.shortcuts import assign
from taggit.managers import TaggableManager

from readthedocs.api.client import api
from readthedocs.core.utils import broadcast, slugify
from readthedocs.restapi.client import api as apiv2
from readthedocs.restapi.client import api
from readthedocs.builds.constants import LATEST, LATEST_VERBOSE_NAME, STABLE
from readthedocs.projects import constants
from readthedocs.projects.exceptions import ProjectImportError
Expand Down Expand Up @@ -358,7 +357,7 @@ def get_builds_url(self):

def get_canonical_url(self):
if getattr(settings, 'DONT_HIT_DB', True):
return apiv2.project(self.pk).canonical_url().get()['url']
return api.project(self.pk).canonical_url().get()['url']
return self.get_docs_url()

def get_subproject_urls(self):
Expand All @@ -369,7 +368,7 @@ def get_subproject_urls(self):
if getattr(settings, 'DONT_HIT_DB', True):
return [(proj['slug'], proj['canonical_url'])
for proj in (
apiv2.project(self.pk)
api.project(self.pk)
.subprojects()
.get()['subprojects'])]
return [(proj.child.slug, proj.child.get_docs_url())
Expand Down Expand Up @@ -642,8 +641,7 @@ def get_latest_build(self, finished=True):

def api_versions(self):
ret = []
for version_data in api.version.get(project=self.pk,
active=True)['objects']:
for version_data in api.project(self.pk).active_versions.get()['versions']:
version = make_api_version(version_data)
ret.append(version)
return sort_version_aware(ret)
Expand Down
9 changes: 4 additions & 5 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
from readthedocs.search.utils import process_mkdocs_json
from readthedocs.restapi.utils import index_search_request
from readthedocs.vcs_support import utils as vcs_support_utils
from readthedocs.api.client import api as api_v1
from readthedocs.restapi.client import api as api_v2
from readthedocs.core.resolver import resolve_path

Expand Down Expand Up @@ -236,17 +235,17 @@ def run_build(self, docker=False, record=True):
@staticmethod
def get_project(project_pk):
"""Get project from API"""
project_data = api_v1.project(project_pk).get()
project_data = api_v2.project(project_pk).get()
project = make_api_project(project_data)
return project

@staticmethod
def get_version(project, version_pk):
"""Ensure we're using a sane version"""
if version_pk:
version_data = api_v1.version(version_pk).get()
version_data = api_v2.version(version_pk).get()
else:
version_data = (api_v1
version_data = (api_v2
.version(project.slug)
.get(slug=LATEST)['objects'][0])
return make_api_version(version_data)
Expand Down Expand Up @@ -466,7 +465,7 @@ def update_imported_docs(version_pk):

:param version_pk: Version id to update
"""
version_data = api_v1.version(version_pk).get()
version_data = api_v2.version(version_pk).get()
version = make_api_version(version_data)
project = version.project
ret_dict = {}
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/restapi/views/footer_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def footer_html(request):
'theme': theme,
}

request_context = RequestContext(request, context)
html = template_loader.get_template('restapi/footer.html').render(request_context)
html = template_loader.get_template('restapi/footer.html').render(context,
request)
resp_data = {
'html': html,
'version_active': version.active,
Expand Down
9 changes: 9 additions & 0 deletions readthedocs/restapi/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def subprojects(self, request, **kwargs):
'subprojects': ProjectSerializer(children, many=True).data
})

@detail_route()
def active_versions(self, request, **kwargs):
project = get_object_or_404(
Project.objects.api(request.user), pk=kwargs['pk'])
versions = project.versions.filter(active=True)
return Response({
'versions': VersionSerializer(versions, many=True).data
})

@decorators.detail_route(permission_classes=[permissions.IsAdminUser])
def token(self, request, **kwargs):
project = get_object_or_404(
Expand Down
2 changes: 0 additions & 2 deletions readthedocs/rtd_tests/mocks/mock_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,5 @@ def mock_api(repo):
with mock.patch('readthedocs.restapi.client.api', api_mock), \
mock.patch('readthedocs.api.client.api', api_mock), \
mock.patch('readthedocs.projects.tasks.api_v2', api_mock), \
mock.patch('readthedocs.projects.tasks.api_v1', api_mock), \
mock.patch('readthedocs.doc_builder.environments.api_v1', api_mock), \
mock.patch('readthedocs.doc_builder.environments.api_v2', api_mock):
yield api_mock
1 change: 1 addition & 0 deletions readthedocs/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def DATABASES(self): # noqa
SLUMBER_USERNAME = 'test'
SLUMBER_PASSWORD = 'test' # noqa: ignore dodgy check
SLUMBER_API_HOST = 'http://localhost:8000'
PUBLIC_API_URL = 'http://localhost:8000'

BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/vcs_support/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def run(self, *args):
except UnicodeDecodeError:
# >:x
pass
return (process.returncode, stdout, stderr)
return (
process.returncode,
stdout.decode('utf-8'),
stderr.decode('utf-8'))

@property
def env(self):
Expand Down