magic-removal: More cleanup due to django.db move
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1638 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
aecff3e245
commit
9f6f675e7b
|
@ -1,17 +1,17 @@
|
||||||
"Daily cleanup file"
|
"Daily cleanup file"
|
||||||
|
|
||||||
from django.core.db import db
|
from django.db import backend, connection
|
||||||
|
|
||||||
DOCUMENTATION_DIRECTORY = '/home/html/documentation/'
|
DOCUMENTATION_DIRECTORY = '/home/html/documentation/'
|
||||||
|
|
||||||
def clean_up():
|
def clean_up():
|
||||||
# Clean up old database records
|
# Clean up old database records
|
||||||
cursor = db.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
|
cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
|
||||||
(db.quote_name('core_sessions'), db.quote_name('expire_date')))
|
(backend.quote_name('core_sessions'), backend.quote_name('expire_date')))
|
||||||
cursor.execute("DELETE FROM %s WHERE %s < NOW() - INTERVAL '1 week'" % \
|
cursor.execute("DELETE FROM %s WHERE %s < NOW() - INTERVAL '1 week'" % \
|
||||||
(db.quote_name('registration_challenges'), db.quote_name('request_date')))
|
(backend.quote_name('registration_challenges'), backend.quote_name('request_date')))
|
||||||
db.commit()
|
connection.commit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
clean_up()
|
clean_up()
|
||||||
|
|
|
@ -41,8 +41,8 @@ class DjangoContext(Context):
|
||||||
self['LANGUAGE_CODE'] = settings.LANGUAGE_CODE
|
self['LANGUAGE_CODE'] = settings.LANGUAGE_CODE
|
||||||
if DEBUG and request.META.get('REMOTE_ADDR') in INTERNAL_IPS:
|
if DEBUG and request.META.get('REMOTE_ADDR') in INTERNAL_IPS:
|
||||||
self['debug'] = True
|
self['debug'] = True
|
||||||
from django.core import db
|
from django.db import connection
|
||||||
self['sql_queries'] = db.db.queries
|
self['sql_queries'] = connection.queries
|
||||||
|
|
||||||
# PermWrapper and PermLookupDict proxy the permissions system into objects that
|
# PermWrapper and PermLookupDict proxy the permissions system into objects that
|
||||||
# the template system can understand.
|
# the template system can understand.
|
||||||
|
|
|
@ -47,12 +47,13 @@ class BaseHandler:
|
||||||
|
|
||||||
def get_response(self, path, request):
|
def get_response(self, path, request):
|
||||||
"Returns an HttpResponse object for the given HttpRequest"
|
"Returns an HttpResponse object for the given HttpRequest"
|
||||||
from django.core import db, exceptions, urlresolvers
|
from django.core import exceptions, urlresolvers
|
||||||
|
from django.db import connection, DatabaseError
|
||||||
from django.core.mail import mail_admins
|
from django.core.mail import mail_admins
|
||||||
from django.conf.settings import DEBUG, INTERNAL_IPS, ROOT_URLCONF
|
from django.conf.settings import DEBUG, INTERNAL_IPS, ROOT_URLCONF
|
||||||
|
|
||||||
# Reset query list per request.
|
# Reset query list per request.
|
||||||
db.db.queries = []
|
connection.queries = []
|
||||||
|
|
||||||
# Apply request middleware
|
# Apply request middleware
|
||||||
for middleware_method in self._request_middleware:
|
for middleware_method in self._request_middleware:
|
||||||
|
@ -93,8 +94,8 @@ class BaseHandler:
|
||||||
else:
|
else:
|
||||||
callback, param_dict = resolver.resolve404()
|
callback, param_dict = resolver.resolve404()
|
||||||
return callback(request, **param_dict)
|
return callback(request, **param_dict)
|
||||||
except db.DatabaseError:
|
except DatabaseError:
|
||||||
db.db.rollback()
|
connection.rollback()
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
return self.get_technical_error_response(request)
|
return self.get_technical_error_response(request)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -128,7 +128,7 @@ class ModPythonHandler(BaseHandler):
|
||||||
# now that the environ works we can see the correct settings, so imports
|
# now that the environ works we can see the correct settings, so imports
|
||||||
# that use settings now can work
|
# that use settings now can work
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import db
|
from django.db import connection
|
||||||
|
|
||||||
# if we need to set up middleware, now that settings works we can do it now.
|
# if we need to set up middleware, now that settings works we can do it now.
|
||||||
if self._request_middleware is None:
|
if self._request_middleware is None:
|
||||||
|
@ -138,7 +138,7 @@ class ModPythonHandler(BaseHandler):
|
||||||
request = ModPythonRequest(req)
|
request = ModPythonRequest(req)
|
||||||
response = self.get_response(req.uri, request)
|
response = self.get_response(req.uri, request)
|
||||||
finally:
|
finally:
|
||||||
db.db.close()
|
connection.close()
|
||||||
|
|
||||||
# Apply response middleware
|
# Apply response middleware
|
||||||
for middleware_method in self._response_middleware:
|
for middleware_method in self._response_middleware:
|
||||||
|
|
|
@ -143,7 +143,7 @@ class WSGIRequest(httpwrappers.HttpRequest):
|
||||||
class WSGIHandler(BaseHandler):
|
class WSGIHandler(BaseHandler):
|
||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import db
|
from django.db import connection
|
||||||
|
|
||||||
# Set up middleware if needed. We couldn't do this earlier, because
|
# Set up middleware if needed. We couldn't do this earlier, because
|
||||||
# settings weren't available.
|
# settings weren't available.
|
||||||
|
@ -154,7 +154,7 @@ class WSGIHandler(BaseHandler):
|
||||||
request = WSGIRequest(environ)
|
request = WSGIRequest(environ)
|
||||||
response = self.get_response(request.path, request)
|
response = self.get_response(request.path, request)
|
||||||
finally:
|
finally:
|
||||||
db.db.close()
|
connection.close()
|
||||||
|
|
||||||
# Apply response middleware
|
# Apply response middleware
|
||||||
for middleware_method in self._response_middleware:
|
for middleware_method in self._response_middleware:
|
||||||
|
|
Loading…
Reference in New Issue