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