Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
insights
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
insights
Commits
e256f23c
Commit
e256f23c
authored
Mar 31, 2013
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test case for static file storage
parent
60865231
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
src/djanalytics/core/render.py
+19
-0
src/djanalytics/modules/tests.py
+7
-0
No files found.
src/djanalytics/core/render.py
View file @
e256f23c
...
@@ -87,11 +87,24 @@ from django.contrib.staticfiles import utils
...
@@ -87,11 +87,24 @@ from django.contrib.staticfiles import utils
from
django.core.files.storage
import
FileSystemStorage
from
django.core.files.storage
import
FileSystemStorage
class
ModuleStorage
(
FileSystemStorage
):
class
ModuleStorage
(
FileSystemStorage
):
''' Storage which allows static files to live with prefixes in the
static directory which do not exist in the filesystem. A file can
exist as /modules/foo/static/bar.html in the source filesystem,
but as /djmodules/foo/bar.html in the static_files directory.
'''
def
path
(
self
,
name
):
def
path
(
self
,
name
):
''' Returns the absolute path to a file, stripping out
/djmodules/[module] from the beginning. If the system requests
/djmodules/testmodule/hello.html, this will return
/home/user/djanalytics/src/modules/testmodule/static/hello.html
'''
rootpath
=
os
.
path
.
relpath
(
os
.
path
.
join
(
name
),
self
.
base_url
)
rootpath
=
os
.
path
.
relpath
(
os
.
path
.
join
(
name
),
self
.
base_url
)
return
FileSystemStorage
.
path
(
self
,
rootpath
)
return
FileSystemStorage
.
path
(
self
,
rootpath
)
def
listdir
(
self
,
path
):
def
listdir
(
self
,
path
):
''' Lists a directory, stripping out /djmodules/static from
the directory (and allowing / and /djmodules to work)
'''
if
path
==
""
or
path
==
"/"
:
if
path
==
""
or
path
==
"/"
:
return
[
"djmodules"
],
[]
return
[
"djmodules"
],
[]
elif
path
in
[
"djmodules"
,
"djmodules/"
,
"/djmodules"
,
"/djmodules/"
]:
elif
path
in
[
"djmodules"
,
"djmodules/"
,
"/djmodules"
,
"/djmodules/"
]:
...
@@ -100,11 +113,17 @@ class ModuleStorage(FileSystemStorage):
...
@@ -100,11 +113,17 @@ class ModuleStorage(FileSystemStorage):
return
FileSystemStorage
.
listdir
(
self
,
path
)
return
FileSystemStorage
.
listdir
(
self
,
path
)
class
ModuleFileFinder
(
BaseFinder
):
class
ModuleFileFinder
(
BaseFinder
):
''' Finds the static files for all installed analytics
modules. Does magic to put them in the right place in the URL
space.
'''
def
__init__
(
self
,
apps
=
None
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
apps
=
None
,
*
args
,
**
kwargs
):
self
.
static_paths
=
None
self
.
static_paths
=
None
self
.
load_static
()
self
.
load_static
()
def
load_static
(
self
):
def
load_static
(
self
):
''' Walk all modules. Find paths. Create Django storages for them (Django's poorman's pyfs).
'''
self
.
module_paths
=
[(
module
.
split
(
'.'
)[
-
1
],
os
.
path
.
abspath
(
resource_filename
(
module
,
"static"
)))
for
module
in
settings
.
INSTALLED_ANALYTICS_MODULES
]
self
.
module_paths
=
[(
module
.
split
(
'.'
)[
-
1
],
os
.
path
.
abspath
(
resource_filename
(
module
,
"static"
)))
for
module
in
settings
.
INSTALLED_ANALYTICS_MODULES
]
self
.
static_paths
=
[(
module
,
path
,
ModuleStorage
(
path
,
os
.
path
.
join
(
"djmodules"
,
module
)))
for
module
,
path
in
self
.
module_paths
]
self
.
static_paths
=
[(
module
,
path
,
ModuleStorage
(
path
,
os
.
path
.
join
(
"djmodules"
,
module
)))
for
module
,
path
in
self
.
module_paths
]
...
...
src/djanalytics/modules/tests.py
View file @
e256f23c
...
@@ -97,3 +97,10 @@ class SimpleTest(TestCase):
...
@@ -97,3 +97,10 @@ class SimpleTest(TestCase):
def
test_render
(
self
):
def
test_render
(
self
):
c
=
Client
()
c
=
Client
()
self
.
assertEqual
(
c
.
get
(
'/view/global/hello_template'
)
.
content
,
open
(
'modules/testmodule/templates/hello.html'
)
.
read
())
self
.
assertEqual
(
c
.
get
(
'/view/global/hello_template'
)
.
content
,
open
(
'modules/testmodule/templates/hello.html'
)
.
read
())
def
test_storage
(
self
):
from
django.contrib.staticfiles
import
finders
import
os.path
absolute_path
=
finders
.
find
(
'djmodules/testmodule/hello.html'
)
assert
os
.
path
.
exists
(
absolute_path
)
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