# Path: mysite/upload.py
# @csrf_exempt
# def upload_image(request, dir_name):
#     """
#      kindeditor图片上传返回数据格式说明：
#     "error": 1, "message": "出错信息"}
#     "error": 0, "url": "图片地址"}
#     """
#     result = {"error": 1, "message": "上传出错"}
#     files = request.FILES.get("imgFile", None)
#     if files:
#         result = image_upload(files, dir_name)
#     return HttpResponse(json.dumps(result), content_type="application/json")


from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from rest_framework_jwt.views import obtain_jwt_token
from mysite.upload import upload_image
"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""


admin.site.site_header = '视频点播管理系统'
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^admin_resumable/', include('admin_resumable.urls')),
    url(r'^api/auth/token/', obtain_jwt_token),
    url(r'^tv/api/', include("epg.api.urls", namespace='tv-api')),
    url(r'^vod/api/', include("vodmanagement.api.urls", namespace='vod-api')),

# Path: mysite/upload.py
# @csrf_exempt
# def upload_image(request, dir_name):
#     """
#      kindeditor图片上传返回数据格式说明：
#     "error": 1, "message": "出错信息"}
#     "error": 0, "url": "图片地址"}
#     """
#     result = {"error": 1, "message": "上传出错"}
#     files = request.FILES.get("imgFile", None)
#     if files:
#         result = image_upload(files, dir_name)
#     return HttpResponse(json.dumps(result), content_type="application/json")


# Path: mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from rest_framework_jwt.views import obtain_jwt_token
from mysite.upload import upload_image

"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""


admin.site.site_header = '视频点播管理系统'
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^admin_resumable/', include('admin_resumable.urls')),
    url(r'^api/auth/token/', obtain_jwt_token),
    url(r'^tv/api/', include("epg.api.urls", namespace='tv-api')),
    url(r'^vod/api/', include("vodmanagement.api.urls", namespace='vod-api')),

    url(r'^uploads/(?P<dir_name>[^/]+)$', upload_image, name='upload_image')