Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
94700a6c
Commit
94700a6c
authored
Feb 07, 2017
by
Diederik van der Boor
Browse files
Replace remaining `import_symbol()` with Django 1.7's `import_string()`
parent
317e92ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
private_storage/servers.py
View file @
94700a6c
...
...
@@ -7,15 +7,14 @@ from django.conf import settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.http
import
HttpResponse
from
django.utils.lru_cache
import
lru_cache
from
django.utils.module_loading
import
import_string
from
django.views.static
import
serve
from
.utils
import
import_symbol
@
lru_cache
()
def
get_server_class
(
path
):
if
'.'
in
path
:
return
import_s
ymbol
(
path
)
return
import_s
tring
(
path
)
elif
path
==
'django'
:
return
DjangoServer
elif
path
==
'apache'
:
...
...
private_storage/utils.py
deleted
100644 → 0
View file @
317e92ff
from
django.core.exceptions
import
ImproperlyConfigured
try
:
from
importlib
import
import_module
# Python 2.7+
except
ImportError
:
from
django.utils.importlib
import
import_module
def
import_symbol
(
import_path
):
"""
Import a class or attribute by name.
"""
try
:
dot
=
import_path
.
rindex
(
'.'
)
except
ValueError
:
raise
ImproperlyConfigured
(
"{0} isn't a Python path."
.
format
(
import_path
))
module
,
classname
=
import_path
[:
dot
],
import_path
[
dot
+
1
:]
try
:
mod
=
import_module
(
module
)
except
ImportError
as
e
:
raise
ImproperlyConfigured
(
'Error importing module {0}: "{1}"'
.
format
(
module
,
e
))
try
:
return
getattr
(
mod
,
classname
)
except
AttributeError
:
raise
ImproperlyConfigured
(
'Module "{0}" does not define a "{1}" class.'
.
format
(
module
,
classname
))
private_storage/views.py
View file @
94700a6c
...
...
@@ -2,13 +2,13 @@
Views to send private files.
"""
from
django.http
import
HttpResponseForbidden
,
Http404
from
django.utils.module_loading
import
import_string
from
django.views.generic
import
View
from
.
import
appconfig
from
.models
import
PrivateFile
from
.servers
import
get_server_class
from
.storage
import
private_storage
from
.utils
import
import_symbol
class
PrivateStorageView
(
View
):
...
...
@@ -20,7 +20,7 @@ class PrivateStorageView(View):
storage
=
private_storage
#: The authorisation rule for accessing
can_access_file
=
staticmethod
(
import_s
ymbol
(
appconfig
.
PRIVATE_STORAGE_AUTH_FUNCTION
))
can_access_file
=
staticmethod
(
import_s
tring
(
appconfig
.
PRIVATE_STORAGE_AUTH_FUNCTION
))
#: Import the server class once
server_class
=
get_server_class
(
appconfig
.
PRIVATE_STORAGE_SERVER
)
...
...
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