Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fdw-forks
django-database-files
Commits
5ee5ef59
Commit
5ee5ef59
authored
May 09, 2013
by
chris
Browse files
Added configurable file URL constructor.
parent
40195f0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
database_files/models.py
View file @
5ee5ef59
import
base64
import
settings
as
_settings
from
django.conf
import
settings
from
django.db
import
models
from
django.utils
import
timezone
...
...
database_files/settings.py
0 → 100644
View file @
5ee5ef59
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
)
database_files/storage.py
View file @
5ee5ef59
...
...
@@ -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
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment