Commit 59a472a0 by Brian Mesick Committed by GitHub

Move model import down into methods (#11)

Work around import issues in Django 1.11 when djpyfs is imported early.
parent 9cb3dde2
...@@ -5,8 +5,8 @@ functionality: ...@@ -5,8 +5,8 @@ functionality:
1) Django configuration. This can go to Amazon S3 or a static 1) Django configuration. This can go to Amazon S3 or a static
filesystem. filesystem.
2) The ability to get URLs for objects stored on the filesystem. 2) The ability to get URLs for objects stored on the filesystem.
3) The ability to create objects with a limited lifetime. A 3) The ability to create objects with a limited lifetime. A
task can garbage-collect those objects. task can garbage-collect those objects.
""" """
from __future__ import absolute_import from __future__ import absolute_import
...@@ -20,14 +20,12 @@ from django.conf import settings ...@@ -20,14 +20,12 @@ from django.conf import settings
from fs.osfs import OSFS from fs.osfs import OSFS
from fs.s3fs import S3FS from fs.s3fs import S3FS
from .models import FSExpirations
if hasattr(settings, 'DJFS'): if hasattr(settings, 'DJFS'):
DJFS_SETTINGS = settings.DJFS # pragma: no cover DJFS_SETTINGS = settings.DJFS # pragma: no cover
else: else:
DJFS_SETTINGS = {'type': 'osfs', DJFS_SETTINGS = {'type': 'osfs',
'directory_root': 'django-pyfs/static/django-pyfs', 'directory_root': 'django-pyfs/static/django-pyfs',
'url_root': '/static/django-pyfs'} 'url_root': '/static/django-pyfs'}
# Global to hold the active S3 connection. Prevents needing to reconnect # Global to hold the active S3 connection. Prevents needing to reconnect
...@@ -56,6 +54,7 @@ def expire_objects(): ...@@ -56,6 +54,7 @@ def expire_objects():
""" """
Remove all obsolete objects from the file systems. Remove all obsolete objects from the file systems.
""" """
from .models import FSExpirations
objects = sorted(FSExpirations.expired(), key=lambda x: x.module) objects = sorted(FSExpirations.expired(), key=lambda x: x.module)
fs = None fs = None
module = None module = None
...@@ -97,6 +96,7 @@ def patch_fs(fs, namespace, url_method): ...@@ -97,6 +96,7 @@ def patch_fs(fs, namespace, url_method):
Returns: Returns:
None None
""" """
from .models import FSExpirations
FSExpirations.create_expiration(namespace, filename, seconds, days=days, expires=expires) FSExpirations.create_expiration(namespace, filename, seconds, days=days, expires=expires)
fs.expire = types.MethodType(expire, fs) fs.expire = types.MethodType(expire, fs)
...@@ -153,7 +153,7 @@ def get_s3fs(namespace): ...@@ -153,7 +153,7 @@ def get_s3fs(namespace):
""" """
global S3CONN global S3CONN
try: try:
if not S3CONN: if not S3CONN:
S3CONN = S3Connection(aws_access_key_id=key_id, aws_secret_access_key=key_secret) S3CONN = S3Connection(aws_access_key_id=key_id, aws_secret_access_key=key_secret)
return S3CONN.generate_url( return S3CONN.generate_url(
......
...@@ -12,7 +12,7 @@ else: ...@@ -12,7 +12,7 @@ else:
setup( setup(
name='django-pyfs', name='django-pyfs',
version='1.0.6', version='1.0.7',
description='Django pyfilesystem integration', description='Django pyfilesystem integration',
author='Piotr Mitros', author='Piotr Mitros',
author_email='pmitros@edx.org', author_email='pmitros@edx.org',
......
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