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
840bf27a
Commit
840bf27a
authored
Apr 08, 2015
by
Allard Stijnman
Committed by
Timothée Peignier
Jun 06, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent collecting all static multiple times per request
parent
9717de7a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
pipeline/collector.py
+6
-1
pipeline/templatetags/pipeline.py
+21
-1
No files found.
pipeline/collector.py
View file @
840bf27a
...
@@ -11,6 +11,8 @@ from pipeline.finders import PipelineFinder
...
@@ -11,6 +11,8 @@ from pipeline.finders import PipelineFinder
class
Collector
(
object
):
class
Collector
(
object
):
request
=
None
def
__init__
(
self
,
storage
=
None
):
def
__init__
(
self
,
storage
=
None
):
if
storage
is
None
:
if
storage
is
None
:
storage
=
staticfiles_storage
storage
=
staticfiles_storage
...
@@ -24,7 +26,10 @@ class Collector(object):
...
@@ -24,7 +26,10 @@ class Collector(object):
for
d
in
dirs
:
for
d
in
dirs
:
self
.
clear
(
os
.
path
.
join
(
path
,
d
))
self
.
clear
(
os
.
path
.
join
(
path
,
d
))
def
collect
(
self
):
def
collect
(
self
,
request
=
None
):
if
self
.
request
and
self
.
request
is
request
:
return
self
.
request
=
request
found_files
=
OrderedDict
()
found_files
=
OrderedDict
()
for
finder
in
finders
.
get_finders
():
for
finder
in
finders
.
get_finders
():
# Ignore our finder to avoid looping
# Ignore our finder to avoid looping
...
...
pipeline/templatetags/pipeline.py
View file @
840bf27a
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
django
import
template
from
django
import
template
from
django.template.base
import
VariableDoesNotExist
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
...
@@ -16,6 +17,15 @@ register = template.Library()
...
@@ -16,6 +17,15 @@ register = template.Library()
class
PipelineMixin
(
object
):
class
PipelineMixin
(
object
):
request
=
None
_request_var
=
None
@property
def
request_var
(
self
):
if
not
self
.
_request_var
:
self
.
_request_var
=
template
.
Variable
(
'request'
)
return
self
.
_request_var
def
package_for
(
self
,
package_name
,
package_type
):
def
package_for
(
self
,
package_name
,
package_type
):
package
=
{
package
=
{
'js'
:
getattr
(
settings
,
'PIPELINE_JS'
,
{})
.
get
(
package_name
,
{}),
'js'
:
getattr
(
settings
,
'PIPELINE_JS'
,
{})
.
get
(
package_name
,
{}),
...
@@ -32,12 +42,18 @@ class PipelineMixin(object):
...
@@ -32,12 +42,18 @@ class PipelineMixin(object):
return
packager
.
package_for
(
package_type
,
package_name
)
return
packager
.
package_for
(
package_type
,
package_name
)
def
render
(
self
,
context
):
try
:
self
.
request
=
self
.
request_var
.
resolve
(
context
)
except
VariableDoesNotExist
:
pass
def
render_compressed
(
self
,
package
,
package_type
):
def
render_compressed
(
self
,
package
,
package_type
):
if
settings
.
PIPELINE_ENABLED
:
if
settings
.
PIPELINE_ENABLED
:
method
=
getattr
(
self
,
"render_{0}"
.
format
(
package_type
))
method
=
getattr
(
self
,
"render_{0}"
.
format
(
package_type
))
return
method
(
package
,
package
.
output_filename
)
return
method
(
package
,
package
.
output_filename
)
else
:
else
:
default_collector
.
collect
()
default_collector
.
collect
(
self
.
request
)
packager
=
Packager
()
packager
=
Packager
()
method
=
getattr
(
self
,
"render_individual_{0}"
.
format
(
package_type
))
method
=
getattr
(
self
,
"render_individual_{0}"
.
format
(
package_type
))
...
@@ -51,7 +67,9 @@ class StylesheetNode(PipelineMixin, template.Node):
...
@@ -51,7 +67,9 @@ class StylesheetNode(PipelineMixin, template.Node):
self
.
name
=
name
self
.
name
=
name
def
render
(
self
,
context
):
def
render
(
self
,
context
):
super
(
StylesheetNode
,
self
)
.
render
(
context
)
package_name
=
template
.
Variable
(
self
.
name
)
.
resolve
(
context
)
package_name
=
template
.
Variable
(
self
.
name
)
.
resolve
(
context
)
try
:
try
:
package
=
self
.
package_for
(
package_name
,
'css'
)
package
=
self
.
package_for
(
package_name
,
'css'
)
except
PackageNotFound
:
except
PackageNotFound
:
...
@@ -77,7 +95,9 @@ class JavascriptNode(PipelineMixin, template.Node):
...
@@ -77,7 +95,9 @@ class JavascriptNode(PipelineMixin, template.Node):
self
.
name
=
name
self
.
name
=
name
def
render
(
self
,
context
):
def
render
(
self
,
context
):
super
(
JavascriptNode
,
self
)
.
render
(
context
)
package_name
=
template
.
Variable
(
self
.
name
)
.
resolve
(
context
)
package_name
=
template
.
Variable
(
self
.
name
)
.
resolve
(
context
)
try
:
try
:
package
=
self
.
package_for
(
package_name
,
'js'
)
package
=
self
.
package_for
(
package_name
,
'js'
)
except
PackageNotFound
:
except
PackageNotFound
:
...
...
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