2+3 ox.django
This commit is contained in:
parent
a1ed41f96d
commit
4b8aad5b38
4 changed files with 15 additions and 13 deletions
|
@ -5,6 +5,7 @@ import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import datetime_safe
|
from django.utils import datetime_safe
|
||||||
|
from six import string_types
|
||||||
|
|
||||||
from ox.utils import json
|
from ox.utils import json
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ class DictField(models.TextField):
|
||||||
"""Convert our JSON object to a string before we save"""
|
"""Convert our JSON object to a string before we save"""
|
||||||
if value == None:
|
if value == None:
|
||||||
return value
|
return value
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, string_types):
|
||||||
value = eval(value)
|
value = eval(value)
|
||||||
assert isinstance(value, dict)
|
assert isinstance(value, dict)
|
||||||
value = json.dumps(value, default=to_json)
|
value = json.dumps(value, default=to_json)
|
||||||
|
@ -92,7 +93,7 @@ class TupleField(models.TextField):
|
||||||
|
|
||||||
def get_db_prep_save(self, value, connection):
|
def get_db_prep_save(self, value, connection):
|
||||||
"""Convert our JSON object to a string before we save"""
|
"""Convert our JSON object to a string before we save"""
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, string_types):
|
||||||
value = eval(value)
|
value = eval(value)
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = tuple(value)
|
value = tuple(value)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from urllib import quote
|
from six.movies.urllib.parse import quote
|
||||||
|
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -26,14 +26,14 @@ def HttpFileResponse(path, content_type=None, filename=None):
|
||||||
url = getattr(settings, PREFIX+'_URL', '')
|
url = getattr(settings, PREFIX+'_URL', '')
|
||||||
if root and path.startswith(root):
|
if root and path.startswith(root):
|
||||||
path = url + path[len(root)+1:]
|
path = url + path[len(root)+1:]
|
||||||
if isinstance(path, unicode):
|
if not isinstance(path, bytes):
|
||||||
path = path.encode('utf-8')
|
path = path.encode('utf-8')
|
||||||
response['X-Accel-Redirect'] = path
|
response['X-Accel-Redirect'] = path
|
||||||
if content_type:
|
if content_type:
|
||||||
response['Content-Type'] = content_type
|
response['Content-Type'] = content_type
|
||||||
elif getattr(settings, 'XSENDFILE', False):
|
elif getattr(settings, 'XSENDFILE', False):
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
if isinstance(path, unicode):
|
if not isinstance(path, bytes):
|
||||||
path = path.encode('utf-8')
|
path = path.encode('utf-8')
|
||||||
response['X-Sendfile'] = path
|
response['X-Sendfile'] = path
|
||||||
if content_type:
|
if content_type:
|
||||||
|
@ -42,7 +42,7 @@ def HttpFileResponse(path, content_type=None, filename=None):
|
||||||
else:
|
else:
|
||||||
response = HttpResponse(open(path), content_type=content_type)
|
response = HttpResponse(open(path), content_type=content_type)
|
||||||
if filename:
|
if filename:
|
||||||
if isinstance(filename, unicode):
|
if not isinstance(filename, bytes):
|
||||||
filename = filename.encode('utf-8')
|
filename = filename.encode('utf-8')
|
||||||
response['Content-Disposition'] = "attachment; filename*=UTF=8''%s" % quote(filename)
|
response['Content-Disposition'] = "attachment; filename*=UTF=8''%s" % quote(filename)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
|
||||||
from shortcuts import HttpErrorJson, render_to_json_response
|
from .shortcuts import HttpErrorJson, render_to_json_response
|
||||||
|
|
||||||
class ExceptionMiddleware(object):
|
class ExceptionMiddleware(object):
|
||||||
def process_exception(self, request, exception):
|
def process_exception(self, request, exception):
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import signal
|
import signal
|
||||||
import threading
|
import threading
|
||||||
import atexit
|
import atexit
|
||||||
import Queue
|
from six.moves.queue import Queue
|
||||||
|
|
||||||
_interval = 1.0
|
_interval = 1.0
|
||||||
_times = {}
|
_times = {}
|
||||||
_files = []
|
_files = []
|
||||||
|
|
||||||
_running = False
|
_running = False
|
||||||
_queue = Queue.Queue()
|
_queue = Queue()
|
||||||
_lock = threading.Lock()
|
_lock = threading.Lock()
|
||||||
|
|
||||||
def _restart(path):
|
def _restart(path):
|
||||||
_queue.put(True)
|
_queue.put(True)
|
||||||
prefix = 'monitor (pid=%d):' % os.getpid()
|
prefix = 'monitor (pid=%d):' % os.getpid()
|
||||||
print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path)
|
print('%s Change detected to \'%s\'.' % (prefix, path), file=sys.stderr)
|
||||||
print >> sys.stderr, '%s Triggering process restart.' % prefix
|
print('%s Triggering process restart.' % prefix, file=sys.stderr)
|
||||||
os.kill(os.getpid(), signal.SIGINT)
|
os.kill(os.getpid(), signal.SIGINT)
|
||||||
|
|
||||||
def _modified(path):
|
def _modified(path):
|
||||||
|
@ -59,7 +60,7 @@ def _monitor():
|
||||||
while 1:
|
while 1:
|
||||||
# Check modification times on all files in sys.modules.
|
# Check modification times on all files in sys.modules.
|
||||||
|
|
||||||
for module in sys.modules.values():
|
for module in list(sys.modules.values()):
|
||||||
if not hasattr(module, '__file__'):
|
if not hasattr(module, '__file__'):
|
||||||
continue
|
continue
|
||||||
path = getattr(module, '__file__')
|
path = getattr(module, '__file__')
|
||||||
|
|
Loading…
Reference in a new issue