# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView

#from rest_framework.routers import DefaultRouter
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework.urlpatterns import format_suffix_patterns

from commonrepo.api.routers import DefaultRouter
from commonrepo.snippets_api.views import SnippetViewSet
from commonrepo.users_api.views import UserViewSet, UserViewSetV2
from commonrepo.elos_api.views import ELOViewSet, ELOViewSetV2, ELOTypeViewSet, ELOFileUploadViewSet
from commonrepo.groups_api.views import GroupViewSet, GroupViewSetV2

router_api = DefaultRouter()
# API v1
router_api.register(r'api/v1/snippets', SnippetViewSet)
router_api.register(r'api/v1/users', UserViewSet)
router_api.register(r'api/v1/elos', ELOViewSet)
router_api.register(r'api/v1/elotypes', ELOTypeViewSet)
router_api.register(r'api/v1/groups', GroupViewSet)
# API v2
router_api.register(r'api/v2/elos', ELOViewSetV2)
router_api.register(r'api/v2/groups', GroupViewSetV2)
router_api.register(r'api/v2/users', UserViewSetV2)

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
    url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name="about"),

    # Django Admin
    url(r'^admin/', include(admin.site.urls)),

    # User management
    url(r'^users/', include("commonrepo.users.urls", namespace="users")),
    url(r'^accounts/', include('allauth.urls')),

    # Your stuff: custom urls includes go here
    url(r'^elos/', include("commonrepo.elos.urls", namespace="elos")),
    url(r'^groups/', include("commonrepo.groups.urls", namespace="groups")),

    # API endpoints
    url(r'^', include(router_api.urls)),
    url(r'^api/v0/auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^api/v1/auth/', include('djoser.urls')),
    url(r'^api/v1/auth/token', obtain_auth_token),

    url(r'^api/v1/elos-upload', ELOFileUploadViewSet),


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    # This allows the error pages to be debugged during development, just visit
    # these url in browser to see how these error pages look like.
    urlpatterns += [
        url(r'^400/$', 'django.views.defaults.bad_request'),
        url(r'^403/$', 'django.views.defaults.permission_denied'),
        url(r'^404/$', 'django.views.defaults.page_not_found'),
        url(r'^500/$', 'django.views.defaults.server_error'),
    ]

@@ -495,23 +495,19 @@
 monrepo.
-snippet
+elo
 s_api.vi
@@ -517,23 +517,71 @@
  import 
-Snippet
+ELOViewSet, ELOViewSetV2, ELOTypeViewSet, ELOFileUpload
 ViewSet%0A
@@ -596,20 +596,21 @@
 monrepo.
-user
+group
 s_api.vi
@@ -620,20 +620,21 @@
  import 
-User
+Group
 ViewSet,
@@ -634,20 +634,21 @@
 iewSet, 
-User
+Group
 ViewSetV
@@ -657,35 +657,39 @@
 from commonrepo.
-elo
+snippet
 s_api.views impo
@@ -695,63 +695,15 @@
 ort 
-ELOViewSet, ELOViewSetV2, ELOTypeViewSet, ELOFileUpload
+Snippet
 View
@@ -714,37 +714,36 @@
 from commonrepo.
-group
+user
 s_api.views impo
@@ -737,37 +737,36 @@
 pi.views import 
-Group
+User
 ViewSet, GroupVi
@@ -750,37 +750,36 @@
 rt UserViewSet, 
-Group
+User
 ViewSetV2%0A%0Aroute
@@ -844,26 +844,18 @@
 /v1/
-snippets', Snippet
+elos', ELO
 View
@@ -888,28 +888,34 @@
 'api/v1/
-users', User
+elotypes', ELOType
 ViewSet)
@@ -940,34 +940,38 @@
 er(r'api/v1/
-elos', ELO
+groups', Group
 ViewSet)%0Arou
@@ -996,34 +996,34 @@
 'api/v1/
-eloty
+snip
 pe
+t
 s', 
-ELOTy
+Snip
 pe
+t
 ViewSet)
@@ -1048,38 +1048,36 @@
 er(r'api/v1/
-groups', Group
+users', User
 ViewSet)%0A# A

更新 config/settings/urls.py, 調整程式碼排序以提升可讀性