|
1 |
| -"""Define routes between URL paths and views/endpoints.""" |
| 1 | +# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
| -from __future__ import absolute_import |
| 3 | +"""Define routes between URL paths and views/endpoints.""" |
4 | 4 |
|
5 |
| -from django.conf.urls import url, include |
| 5 | +from __future__ import ( |
| 6 | + absolute_import, |
| 7 | + division, |
| 8 | + print_function, |
| 9 | + unicode_literals, |
| 10 | +) |
6 | 11 |
|
| 12 | +from django.conf import settings |
| 13 | +from django.conf.urls import include, url |
7 | 14 | from rest_framework import routers
|
8 | 15 |
|
9 | 16 | from readthedocs.constants import pattern_opts
|
10 | 17 | from readthedocs.restapi import views
|
11 | 18 | from readthedocs.restapi.views import (
|
12 |
| - core_views, footer_views, search_views, task_views, integrations |
| 19 | + core_views, |
| 20 | + footer_views, |
| 21 | + integrations, |
| 22 | + search_views, |
| 23 | + task_views, |
13 | 24 | )
|
14 | 25 |
|
15 |
| -from .views.model_views import (BuildViewSet, BuildCommandViewSet, |
16 |
| - ProjectViewSet, NotificationViewSet, |
17 |
| - VersionViewSet, DomainViewSet, |
18 |
| - RemoteOrganizationViewSet, |
19 |
| - RemoteRepositoryViewSet, |
20 |
| - SocialAccountViewSet) |
| 26 | +from .views.model_views import ( |
| 27 | + BuildCommandViewSet, |
| 28 | + BuildViewSet, |
| 29 | + DomainViewSet, |
| 30 | + NotificationViewSet, |
| 31 | + ProjectViewSet, |
| 32 | + RemoteOrganizationViewSet, |
| 33 | + RemoteRepositoryViewSet, |
| 34 | + SocialAccountViewSet, |
| 35 | + VersionViewSet, |
| 36 | +) |
21 | 37 |
|
22 | 38 | router = routers.DefaultRouter()
|
23 | 39 | router.register(r'build', BuildViewSet, base_name='build')
|
|
27 | 43 | router.register(r'notification', NotificationViewSet, base_name='emailhook')
|
28 | 44 | router.register(r'domain', DomainViewSet, base_name='domain')
|
29 | 45 | router.register(
|
30 |
| - r'remote/org', RemoteOrganizationViewSet, base_name='remoteorganization') |
| 46 | + r'remote/org', |
| 47 | + RemoteOrganizationViewSet, |
| 48 | + base_name='remoteorganization', |
| 49 | +) |
31 | 50 | router.register(
|
32 |
| - r'remote/repo', RemoteRepositoryViewSet, base_name='remoterepository') |
| 51 | + r'remote/repo', |
| 52 | + RemoteRepositoryViewSet, |
| 53 | + base_name='remoterepository', |
| 54 | +) |
33 | 55 | router.register(
|
34 |
| - r'remote/account', SocialAccountViewSet, base_name='remoteaccount') |
| 56 | + r'remote/account', |
| 57 | + SocialAccountViewSet, |
| 58 | + base_name='remoteaccount', |
| 59 | +) |
35 | 60 |
|
36 | 61 | urlpatterns = [
|
37 | 62 | url(r'^', include(router.urls)),
|
|
45 | 70 | ]
|
46 | 71 |
|
47 | 72 | search_urls = [
|
48 |
| - url(r'index_search/', |
| 73 | + url( |
| 74 | + r'index_search/', |
49 | 75 | search_views.index_search,
|
50 |
| - name='index_search'), |
| 76 | + name='index_search', |
| 77 | + ), |
51 | 78 | url(r'search/$', views.search_views.search, name='api_search'),
|
52 |
| - url(r'search/project/$', |
| 79 | + url( |
| 80 | + r'search/project/$', |
53 | 81 | search_views.project_search,
|
54 |
| - name='api_project_search'), |
55 |
| - url(r'search/section/$', |
| 82 | + name='api_project_search', |
| 83 | + ), |
| 84 | + url( |
| 85 | + r'search/section/$', |
56 | 86 | search_views.section_search,
|
57 |
| - name='api_section_search'), |
| 87 | + name='api_section_search', |
| 88 | + ), |
58 | 89 | ]
|
59 | 90 |
|
60 | 91 | task_urls = [
|
61 |
| - url(r'jobs/status/(?P<task_id>[^/]+)/', |
| 92 | + url( |
| 93 | + r'jobs/status/(?P<task_id>[^/]+)/', |
62 | 94 | task_views.job_status,
|
63 |
| - name='api_job_status'), |
64 |
| - url(r'jobs/sync-remote-repositories/', |
| 95 | + name='api_job_status', |
| 96 | + ), |
| 97 | + url( |
| 98 | + r'jobs/sync-remote-repositories/', |
65 | 99 | task_views.sync_remote_repositories,
|
66 |
| - name='api_sync_remote_repositories'), |
| 100 | + name='api_sync_remote_repositories', |
| 101 | + ), |
67 | 102 | ]
|
68 | 103 |
|
69 | 104 | integration_urls = [
|
70 |
| - url(r'webhook/github/(?P<project_slug>{project_slug})/$'.format(**pattern_opts), |
| 105 | + url( |
| 106 | + r'webhook/github/(?P<project_slug>{project_slug})/$' |
| 107 | + .format(**pattern_opts), |
71 | 108 | integrations.GitHubWebhookView.as_view(),
|
72 |
| - name='api_webhook_github'), |
73 |
| - url(r'webhook/gitlab/(?P<project_slug>{project_slug})/$'.format(**pattern_opts), |
| 109 | + name='api_webhook_github', |
| 110 | + ), |
| 111 | + url( |
| 112 | + r'webhook/gitlab/(?P<project_slug>{project_slug})/$' |
| 113 | + .format(**pattern_opts), |
74 | 114 | integrations.GitLabWebhookView.as_view(),
|
75 |
| - name='api_webhook_gitlab'), |
76 |
| - url(r'webhook/bitbucket/(?P<project_slug>{project_slug})/$'.format(**pattern_opts), |
| 115 | + name='api_webhook_gitlab', |
| 116 | + ), |
| 117 | + url( |
| 118 | + r'webhook/bitbucket/(?P<project_slug>{project_slug})/$' |
| 119 | + .format(**pattern_opts), |
77 | 120 | integrations.BitbucketWebhookView.as_view(),
|
78 |
| - name='api_webhook_bitbucket'), |
79 |
| - url(r'webhook/generic/(?P<project_slug>{project_slug})/$'.format(**pattern_opts), |
| 121 | + name='api_webhook_bitbucket', |
| 122 | + ), |
| 123 | + url( |
| 124 | + r'webhook/generic/(?P<project_slug>{project_slug})/$' |
| 125 | + .format(**pattern_opts), |
80 | 126 | integrations.APIWebhookView.as_view(),
|
81 |
| - name='api_webhook_generic'), |
82 |
| - url((r'webhook/(?P<project_slug>{project_slug})/' |
83 |
| - r'(?P<integration_pk>{integer_pk})/$'.format(**pattern_opts)), |
| 127 | + name='api_webhook_generic', |
| 128 | + ), |
| 129 | + url( |
| 130 | + ( |
| 131 | + r'webhook/(?P<project_slug>{project_slug})/' |
| 132 | + r'(?P<integration_pk>{integer_pk})/$'.format(**pattern_opts) |
| 133 | + ), |
84 | 134 | integrations.WebhookView.as_view(),
|
85 |
| - name='api_webhook'), |
| 135 | + name='api_webhook', |
| 136 | + ), |
86 | 137 | ]
|
87 | 138 |
|
88 | 139 | urlpatterns += function_urls
|
89 | 140 | urlpatterns += search_urls
|
90 | 141 | urlpatterns += task_urls
|
91 | 142 | urlpatterns += integration_urls
|
92 | 143 |
|
93 |
| -try: |
| 144 | +if 'readthedocsext.search' in settings.INSTALLED_APPS: |
| 145 | + # pylint: disable=import-error |
94 | 146 | from readthedocsext.search.docsearch import DocSearch
|
95 | 147 | api_search_urls = [
|
96 | 148 | url(r'^docsearch/$', DocSearch.as_view(), name='doc_search'),
|
97 | 149 | ]
|
98 | 150 | urlpatterns += api_search_urls
|
99 |
| -except ImportError: |
100 |
| - pass |
101 | 151 |
|
102 |
| -try: |
103 |
| - from readthedocsext.donate.restapi.urls import urlpatterns as sustainability_urls |
| 152 | +if 'readthedocsext.donate' in settings.INSTALLED_APPS: |
| 153 | + # pylint: disable=import-error |
| 154 | + from readthedocsext.donate.restapi.urls import urlpatterns \ |
| 155 | + as sustainability_urls |
104 | 156 |
|
105 | 157 | urlpatterns += [
|
106 | 158 | url(r'^sustainability/', include(sustainability_urls)),
|
107 | 159 | ]
|
108 |
| -except ImportError: |
109 |
| - pass |
|
0 commit comments