mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-20 23:00:58 +00:00
Look up Filter objects on first call to an image tag, instead of on compilation.
This should make it possible to run ./manage.py compress without a database configured. Also, the module-level cache of filter objects is removed, which was breaking tests on mysql - the filter objects were persisting beyond the teardown/recreation of the database.
This commit is contained in:
parent
3d2a9ce18f
commit
a712c79c6b
1 changed files with 6 additions and 6 deletions
|
|
@ -1,12 +1,10 @@
|
|||
from django import template
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from wagtail.wagtailimages.models import Filter, SourceImageIOError
|
||||
|
||||
register = template.Library()
|
||||
|
||||
# Local cache of filters, avoid hitting the DB
|
||||
filters = {}
|
||||
|
||||
|
||||
@register.tag(name="image")
|
||||
def image(parser, token):
|
||||
|
|
@ -37,10 +35,12 @@ class ImageNode(template.Node):
|
|||
self.image_var = template.Variable(image_var_name)
|
||||
self.output_var_name = output_var_name
|
||||
self.attrs = attrs
|
||||
self.filter_spec = filter_spec
|
||||
|
||||
if filter_spec not in filters:
|
||||
filters[filter_spec], _ = Filter.objects.get_or_create(spec=filter_spec)
|
||||
self.filter = filters[filter_spec]
|
||||
@cached_property
|
||||
def filter(self):
|
||||
_filter, _ = Filter.objects.get_or_create(spec=self.filter_spec)
|
||||
return _filter
|
||||
|
||||
def render(self, context):
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in a new issue