Commit 43bb8fc9 by muhammad-ammar Committed by muzaffaryousaf

Fix RemovedInDjango19Warning warnings

TNL-3450
parent 4573317d
...@@ -37,5 +37,7 @@ script: ...@@ -37,5 +37,7 @@ script:
branches: branches:
only: only:
- master - master
- ora-staff-grading
- ned/django-upgrade-1.8
after_success: after_success:
coveralls coveralls
...@@ -5,8 +5,9 @@ from uuid import uuid4 ...@@ -5,8 +5,9 @@ from uuid import uuid4
import json import json
import logging import logging
from django.conf import settings from django.conf import settings
from django.core import signals
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.core.cache import cache, get_cache from django.core.cache import cache, _create_cache
from django.db import models, transaction, DatabaseError from django.db import models, transaction, DatabaseError
from django.utils.timezone import now from django.utils.timezone import now
from django_extensions.db.fields import UUIDField from django_extensions.db.fields import UUIDField
...@@ -21,11 +22,23 @@ AI_ASSESSMENT_TYPE = "AI" ...@@ -21,11 +22,23 @@ AI_ASSESSMENT_TYPE = "AI"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def create_cache(backend, **kwargs):
"""
Create cache backend. Using this custom function to avoid deprecation warnings.
"""
cache = _create_cache(backend, **kwargs)
# Some caches -- python-memcached in particular -- need to do a cleanup at the
# end of a request cycle. If not implemented in a particular backend
# cache.close is a no-op
signals.request_finished.connect(cache.close)
return cache
# Use an in-memory cache to hold classifier data, but allow settings to override this. # Use an in-memory cache to hold classifier data, but allow settings to override this.
# The classifier data will generally be larger than memcached's default max size # The classifier data will generally be larger than memcached's default max size
CLASSIFIERS_CACHE_IN_MEM = getattr( CLASSIFIERS_CACHE_IN_MEM = getattr(
settings, 'ORA2_CLASSIFIERS_CACHE_IN_MEM', settings, 'ORA2_CLASSIFIERS_CACHE_IN_MEM',
get_cache( create_cache(
'django.core.cache.backends.locmem.LocMemCache', 'django.core.cache.backends.locmem.LocMemCache',
LOCATION='openassessment.ai.classifiers_dict' LOCATION='openassessment.ai.classifiers_dict'
) )
...@@ -33,7 +46,7 @@ CLASSIFIERS_CACHE_IN_MEM = getattr( ...@@ -33,7 +46,7 @@ CLASSIFIERS_CACHE_IN_MEM = getattr(
CLASSIFIERS_CACHE_IN_FILE = getattr( CLASSIFIERS_CACHE_IN_FILE = getattr(
settings, 'ORA2_CLASSIFIERS_CACHE_IN_FILE', settings, 'ORA2_CLASSIFIERS_CACHE_IN_FILE',
get_cache( create_cache(
'django.core.cache.backends.filebased.FileBasedCache', 'django.core.cache.backends.filebased.FileBasedCache',
LOCATION='/tmp/ora2_classifier_cache' LOCATION='/tmp/ora2_classifier_cache'
) )
......
...@@ -61,7 +61,7 @@ def get_cache(): ...@@ -61,7 +61,7 @@ def get_cache():
cache_name = getattr(settings, "ORA2_FILEUPLOAD_CACHE_NAME", None) cache_name = getattr(settings, "ORA2_FILEUPLOAD_CACHE_NAME", None)
if cache_name is None: if cache_name is None:
raise exceptions.FileUploadInternalError("Undefined cache backend for file upload") raise exceptions.FileUploadInternalError("Undefined cache backend for file upload")
return django.core.cache.get_cache(cache_name) return django.core.cache.caches[cache_name]
def make_upload_url_available(url_key_name, timeout): def make_upload_url_available(url_key_name, timeout):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment