drop python2 support, upgrade to django 3
This commit is contained in:
parent
80390a1f9b
commit
844382b1e8
124 changed files with 413 additions and 563 deletions
|
|
@ -111,10 +111,10 @@ class ApiActions(dict):
|
|||
f = fc[len(fc)-1].cell_contents
|
||||
if PY2:
|
||||
info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:]
|
||||
info = u'%s:%s' % (info, f.func_code.co_firstlineno)
|
||||
info = '%s:%s' % (info, f.func_code.co_firstlineno)
|
||||
else:
|
||||
info = f.__code__.co_filename[len(settings.PROJECT_ROOT)+1:]
|
||||
info = u'%s:%s' % (info, f.__code__.co_firstlineno)
|
||||
info = '%s:%s' % (info, f.__code__.co_firstlineno)
|
||||
return info, trim(inspect.getsource(f))
|
||||
|
||||
def register(self, method, action=None, cache=True, version=None):
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
from . import actions
|
||||
actions.autodiscover()
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.api),
|
||||
urls = [
|
||||
[
|
||||
path(r'', views.api),
|
||||
],
|
||||
'api',
|
||||
'api'
|
||||
]
|
||||
|
|
@ -3,7 +3,7 @@ from __future__ import division, absolute_import
|
|||
|
||||
import json
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.shortcuts import render
|
||||
from django.conf import settings
|
||||
|
||||
from ..shortcuts import render_to_json_response, json_response, HttpErrorJson
|
||||
|
|
@ -31,7 +31,7 @@ def api(request):
|
|||
'settings': settings,
|
||||
'sitename': settings.SITENAME
|
||||
}
|
||||
response = render_to_response('api.html', context)
|
||||
response = render(request, 'api.html', context)
|
||||
response['Access-Control-Allow-Origin'] = '*'
|
||||
return response
|
||||
if request.META.get('CONTENT_TYPE') == 'application/json':
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ def login_required_json(function=None):
|
|||
"""
|
||||
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
return function(request, *args, **kwargs)
|
||||
return render_to_json_response({'status': {'code': 401, 'text': 'login required'}})
|
||||
return wraps(function)(_wrapped_view)
|
||||
|
|
@ -24,7 +24,7 @@ def admin_required_json(function=None):
|
|||
"""
|
||||
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated() and request.user.profile.get_level() == 'admin':
|
||||
if request.user.is_authenticated and request.user.profile.get_level() == 'admin':
|
||||
return function(request, *args, **kwargs)
|
||||
return render_to_json_response({'status': {'code': 403, 'text': 'permission denied'}})
|
||||
return wraps(function)(_wrapped_view)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class DictField(models.TextField):
|
|||
def dumps(cls, obj):
|
||||
return json.dumps(obj, default=to_json, ensure_ascii=False)
|
||||
|
||||
def from_db_value(self, value, expression, connection, context):
|
||||
def from_db_value(self, value, expression, connection, context=None):
|
||||
if value is None:
|
||||
return value
|
||||
if isinstance(value, self._type):
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
from .shortcuts import HttpErrorJson, render_to_json_response
|
||||
|
||||
class ExceptionMiddleware(object):
|
||||
class ExceptionMiddleware(MiddlewareMixin):
|
||||
|
||||
def process_exception(self, request, exception):
|
||||
if isinstance(exception, HttpErrorJson):
|
||||
return render_to_json_response(exception.response)
|
||||
return None
|
||||
|
||||
class ChromeFrameMiddleware(object):
|
||||
class ChromeFrameMiddleware(MiddlewareMixin):
|
||||
|
||||
def process_response(self, request, response):
|
||||
response['X-UA-Compatible'] = 'chrome=1'
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function
|
||||
import datetime
|
||||
from django.utils import datetime_safe
|
||||
from django.http import HttpResponse, Http404
|
||||
|
|
@ -23,7 +22,7 @@ def _to_json(python_object):
|
|||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
if isinstance(python_object, datetime_safe.datetime):
|
||||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
||||
raise TypeError('%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
||||
|
||||
def json_dump(data, fp, indent=4):
|
||||
return json.dump(data, fp, indent=indent, default=_to_json, ensure_ascii=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue