Commit 5ee5ef59 authored by chris's avatar chris
Browse files

Added configurable file URL constructor.

parent 40195f0b
import base64
import settings as _settings
from django.conf import settings
from django.db import models
from django.utils import timezone
......
import os
from django.conf import settings
from django.core.urlresolvers import reverse
def URL_METHOD_1(name):
"""
Construct file URL based on media URL.
"""
return os.path.join(settings.MEDIA_URL, name)
def URL_METHOD_2(name):
"""
Construct file URL based on configured URL pattern.
"""
return reverse('database_file', kwargs={'name': name})
URL_METHODS = (
('URL_METHOD_1', URL_METHOD_1),
('URL_METHOD_2', URL_METHOD_2),
)
DATABASE_FILES_URL_METHOD_NAME = getattr(
settings,
'DATABASE_FILES_URL_METHOD',
'URL_METHOD_1')
if callable(DATABASE_FILES_URL_METHOD_NAME):
method = DATABASE_FILES_URL_METHOD_NAME
else:
method = dict(URL_METHODS)[DATABASE_FILES_URL_METHOD_NAME]
DATABASE_FILES_URL_METHOD = setattr(
settings,
'DATABASE_FILES_URL_METHOD',
method)
......@@ -108,8 +108,7 @@ class DatabaseStorage(FileSystemStorage):
"""
Returns the web-accessible URL for the file with filename `name`.
"""
return os.path.join(settings.MEDIA_URL, name)
#return reverse('database_file', kwargs={'name': name})
return settings.DATABASE_FILES_URL_METHOD(name)
def size(self, name):
"""
......
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