Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
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
OpenEdx
django-pipeline
Commits
f33292d8
Commit
f33292d8
authored
Oct 26, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix jinja tag
parent
3cf8257f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
41 deletions
+7
-41
pipeline/jinja2/ext.py
+6
-40
tests/tests/test_compressor.py
+1
-1
No files found.
pipeline/jinja2/ext.py
View file @
f33292d8
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
inspect
from
django.utils
import
six
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
django.conf
import
settings
as
django_settings
from
django.conf
import
settings
from
jinja2
import
Environment
,
FileSystemLoader
from
jinja2
import
Environment
,
FileSystemLoader
from
pipeline.conf
import
settings
as
pipeline_settings
from
pipeline.packager
import
Packager
,
PackageNotFound
from
pipeline.packager
import
Packager
,
PackageNotFound
from
pipeline.utils
import
guess_type
from
pipeline.utils
import
guess_type
...
@@ -18,45 +16,13 @@ class Jinja2Compressed(object):
...
@@ -18,45 +16,13 @@ class Jinja2Compressed(object):
raise
PackageNotFound
(
"Package type must be css or js, supplied
%
s"
%
package_type
)
raise
PackageNotFound
(
"Package type must be css or js, supplied
%
s"
%
package_type
)
self
.
package_type
=
package_type
self
.
package_type
=
package_type
self
.
loader
=
FileSystemLoader
((
app_directories
.
app_template_dirs
+
self
.
loader
=
FileSystemLoader
((
app_directories
.
app_template_dirs
+
django_settings
.
TEMPLATE_DIRS
))
settings
.
TEMPLATE_DIRS
))
self
.
get_pipeline_settings
()
def
get_pipeline_settings
(
self
):
"""
Because extra Jinja2 functions have to be declared
at creation time the new functions have to be declared before
django settings evaluation so when pipeline tries to import django
settings it will get the default globals rather than user defined
settings. This function attempts to fudge back in user defined
settings into pipeline settings as django.conf.settings is lazy
loaded and pipeline settings are not.
No harm intended :)
I guess a better more robust solution would be to make pipeline
settings lazy loaded also.
"""
members
=
inspect
.
getmembers
(
pipeline_settings
)
for
setting
,
val
in
members
:
if
setting
.
startswith
(
'PIPELINE'
):
if
hasattr
(
django_settings
,
setting
):
val
=
getattr
(
django_settings
,
setting
)
else
:
if
type
(
getattr
(
pipeline_settings
,
setting
))
==
str
:
val
=
"'
%
s'"
%
val
val
=
val
if
val
else
"''"
expr
=
"pipeline_settings.
%
s =
%
s"
%
(
setting
,
val
)
exec
(
expr
)
pipeline_settings
.
PIPELINE
=
getattr
(
django_settings
,
'PIPELINE'
,
not
django_settings
.
DEBUG
)
self
.
settings
=
pipeline_settings
def
get_package
(
self
,
name
):
def
get_package
(
self
,
name
):
"""Get the js or css package."""
"""Get the js or css package."""
package
=
{
package
=
{
'js'
:
se
lf
.
se
ttings
.
PIPELINE_JS
.
get
(
name
,
{}),
'js'
:
settings
.
PIPELINE_JS
.
get
(
name
,
{}),
'css'
:
se
lf
.
se
ttings
.
PIPELINE_CSS
.
get
(
name
,
{}),
'css'
:
settings
.
PIPELINE_CSS
.
get
(
name
,
{}),
}[
self
.
package_type
]
}[
self
.
package_type
]
if
package
:
if
package
:
...
@@ -101,7 +67,7 @@ class Jinja2Compressed(object):
...
@@ -101,7 +67,7 @@ class Jinja2Compressed(object):
"""Render the HTML Snippet"""
"""Render the HTML Snippet"""
self
.
get_package
(
name
)
self
.
get_package
(
name
)
if
self
.
package
:
if
self
.
package
:
if
se
lf
.
se
ttings
.
PIPELINE
:
if
settings
.
PIPELINE
:
return
self
.
render
(
self
.
package
.
output_filename
)
return
self
.
render
(
self
.
package
.
output_filename
)
else
:
else
:
paths
=
self
.
packager
.
compile
(
self
.
package
.
paths
)
paths
=
self
.
packager
.
compile
(
self
.
package
.
paths
)
...
...
tests/tests/test_compressor.py
View file @
f33292d8
...
@@ -5,7 +5,7 @@ import base64
...
@@ -5,7 +5,7 @@ import base64
try
:
try
:
from
mock
import
patch
from
mock
import
patch
except
:
except
ImportError
:
from
unittest.mock
import
patch
# noqa
from
unittest.mock
import
patch
# noqa
from
django.test
import
TestCase
from
django.test
import
TestCase
...
...
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