Commit d6ec92d8 authored by ibuler's avatar ibuler

[Update] 修改url

parent ad321464
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from django.conf.urls import url, include from django.conf.urls import url, include
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from rest_framework.response import Response
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.utils.encoding import iri_to_uri
from rest_framework.schemas import get_schema_view from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
...@@ -11,30 +16,69 @@ from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer ...@@ -11,30 +16,69 @@ from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
from .views import IndexView, LunaView from .views import IndexView, LunaView
schema_view = get_schema_view(title='Users API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer]) schema_view = get_schema_view(title='Users API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])
urlpatterns = [ api_url_pattern = re.compile(r'^/api/(?P<app>\w+)/(?P<version>\w+)/(?P<extra>.*)$')
url(r'^$', IndexView.as_view(), name='index'),
url(r'^luna/', LunaView.as_view(), name='luna-error'),
class HttpResponseTemporaryRedirect(HttpResponse):
status_code = 307
def __init__(self, redirect_to):
HttpResponse.__init__(self)
self['Location'] = iri_to_uri(redirect_to)
@csrf_exempt
def redirect_old_format_api(request, *args, **kwargs):
path, query = request.path, request.GET.urlencode()
matched = api_url_pattern.match(path)
if matched:
app, version, extra = matched.groups()
path = '/api/{version}/{app}/{extra}?{query}'.format(**{
"app": app, "version": version, "extra": extra,
"query": query
})
return HttpResponseTemporaryRedirect(path)
else:
return Response({"msg": "Redirect url failed: {}".format(path)}, status=404)
v1_api_patterns = [
url(r'^users/', include('users.urls.api_urls', namespace='api-users')),
url(r'^assets/', include('assets.urls.api_urls', namespace='api-assets')),
url(r'^perms/', include('perms.urls.api_urls', namespace='api-perms')),
url(r'^terminal/', include('terminal.urls.api_urls', namespace='api-terminal')),
url(r'^ops/', include('ops.urls.api_urls', namespace='api-ops')),
url(r'^audits/', include('audits.urls.api_urls', namespace='api-audits')),
url(r'^orgs/', include('orgs.urls.api_urls', namespace='api-orgs')),
url(r'^common/', include('common.urls.api_urls', namespace='api-common')),
]
app_view_patterns = [
url(r'^users/', include('users.urls.views_urls', namespace='users')), url(r'^users/', include('users.urls.views_urls', namespace='users')),
url(r'^assets/', include('assets.urls.views_urls', namespace='assets')), url(r'^assets/', include('assets.urls.views_urls', namespace='assets')),
url(r'^perms/', include('perms.urls.views_urls', namespace='perms')), url(r'^perms/', include('perms.urls.views_urls', namespace='perms')),
url(r'^terminal/', include('terminal.urls.views_urls', namespace='terminal')), url(r'^terminal/', include('terminal.urls.views_urls', namespace='terminal')),
url(r'^ops/', include('ops.urls.view_urls', namespace='ops')), url(r'^ops/', include('ops.urls.view_urls', namespace='ops')),
url(r'^audits/', include('audits.urls.view_urls', namespace='audits')), url(r'^audits/', include('audits.urls.view_urls', namespace='audits')),
url(r'^orgs/', include('orgs.urls.views_urls', namespace='orgs')),
]
urlpatterns = [
url(r'^$', IndexView.as_view(), name='index'),
url(r'^luna/', LunaView.as_view(), name='luna-error'),
url(r'^settings/', include('common.urls.view_urls', namespace='settings')), url(r'^settings/', include('common.urls.view_urls', namespace='settings')),
url(r'^common/', include('common.urls.view_urls', namespace='common')), url(r'^common/', include('common.urls.view_urls', namespace='common')),
url(r'^api/v1/', include(v1_api_patterns)),
url(r'^api/(?P<app>.*)/v1/.*', redirect_old_format_api),
# Api url view map # Api url view map
url(r'^api/users/', include('users.urls.api_urls', namespace='api-users')),
url(r'^api/assets/', include('assets.urls.api_urls', namespace='api-assets')),
url(r'^api/perms/', include('perms.urls.api_urls', namespace='api-perms')),
url(r'^api/terminal/', include('terminal.urls.api_urls', namespace='api-terminal')),
url(r'^api/ops/', include('ops.urls.api_urls', namespace='api-ops')),
url(r'^api/audits/', include('audits.urls.api_urls', namespace='api-audits')),
url(r'^api/common/', include('common.urls.api_urls', namespace='api-common')),
# External apps url # External apps url
url(r'^captcha/', include('captcha.urls')), url(r'^captcha/', include('captcha.urls')),
] ]
urlpatterns += app_view_patterns
# urlpatterns = wrapper_patterns_with_org(urlpatterns)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
......
# -*- coding: utf-8 -*-
#
# -*- coding: utf-8 -*-
#
from django.conf.urls import url
from .. import views
app_name = 'orgs'
urlpatterns = [
# url(r'^(?P<pk>[0-9a-zA-Z\-]{36})/$', views.OrgDetailView.as_view(), name='asset-index')
]
\ No newline at end of file
# -*- coding: utf-8 -*-
#
from django.conf.urls import url
from .. import views
app_name = 'orgs'
urlpatterns = [
url(r'^(?P<pk>.*)/switch/$', views.SwitchOrgView.as_view(), name='org-switch')
]
from django.shortcuts import render from django.shortcuts import redirect
# Create your views here. from django.views.generic import DetailView
from .models import Organization
class SwitchOrgView(DetailView):
model = Organization
object = None
def get(self, request, *args, **kwargs):
pk = kwargs.get('pk')
self.object = Organization.get_instance(pk)
request.session['oid'] = self.object.id.__str__()
return redirect('index')
{% load i18n %} {% load i18n %}
{% if ADMIN_ORGS %}
<li id="org">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<i class="fa fa-star" style="width: 14px"></i> <span class="nav-label">{{ CURRENT_ORG.name }}</span>
<span class="fa fa-caret-down arrow"></span>
</a>
<ul class="dropdown-menu">
{% for org in ADMIN_ORGS %}
{% if org.is_default %}
<li><a class="org-dropdown" href="{% url 'orgs:org-switch' pk=org.id %}" data-id="{{ org.id }}">{{ org.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
<hr>
{% endif %}
<li id="index"> <li id="index">
<a href="{% url 'index' %}"> <a href="{% url 'index' %}">
<i class="fa fa-dashboard" style="width: 14px"></i> <span class="nav-label">{% trans 'Dashboard' %}</span><span <i class="fa fa-dashboard" style="width: 14px"></i> <span class="nav-label">{% trans 'Dashboard' %}</span><span
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment