Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Chris Rogers 2015-06-24 17:56:32 +01:00
commit 6c80a42e45
11 changed files with 111 additions and 19 deletions

View file

@ -1,6 +1,12 @@
Changelog
=========
1.1 (xx.xx.xxxx)
~~~~~~~~~~~~~~~~
* The `{% image %}` tag now supports filters on the image variable, e.g. `{% image primary_img|default:secondary_img width-500 %}`
1.0 (xx.xx.xxxx)
~~~~~~~~~~~~~~~~

View file

@ -41,13 +41,61 @@ Here's an example of an ``EventPage`` with three views:
"""
...
# Multiple routes!
@route(r'^year/(\d+)/$')
@route(r'^year/current/$')
def events_for_year(self, request, year=None):
"""
View function for the events for year page
"""
...
Reversing URLs
==============
:class:`~models.RoutablePageMixin` adds a :meth:`~models.RoutablePageMixin.reverse_subpage` method to your page model which you can use for reversing URLs. For example:
.. code-block:: python
# The URL name defaults to the view method name.
>>> event_page.reverse_subpage('events_for_year', args=(2015, ))
'year/2015/'
This method only returns the part of the URL within the page. To get the full URL, you must append it to the values of either the :attr:`~wagtail.wagtailcore.models.Page.url` or the :attr:`~wagtail.wagtailcore.models.Page.full_url` attribute on your page:
.. code-block:: python
>>> event_page.url + event_page.reverse_subpage('events_for_year', args=(2015, ))
'/events/year/2015/'
>>> event_page.full_url + event_page.reverse_subpage('events_for_year', args=(2015, ))
'http://example.com/events/year/2015/'
Changing route names
--------------------
The route name defaults to the name of the view. You can override this name with the ``name`` keyword argument on ``@route``:
.. code-block:: python
from wagtail.wagtailcore.models import Page
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
class EventPage(RoutablePageMixin, Page):
...
@route(r'^year/(\d+)/$', name='year')
def events_for_year(self, request, year):
"""
View function for the events for year page
"""
...
.. code-block:: python
>>> event_page.reverse_subpage('year', args=(2015, ))
'/events/year/2015/'
The ``RoutablePageMixin`` class
===============================

View file

@ -1,6 +1,6 @@
==========================================
Wagtail 1.0 release notes - IN DEVELOPMENT
==========================================
=========================
Wagtail 1.0 release notes
=========================
.. contents::
:local:
@ -318,3 +318,9 @@ Previously you could customize the Wagtail userbar using the ``construct_wagtail
The hook has been renamed to ``construct_wagtail_userbar``.
The old hook is now deprecated; all existing ``construct_wagtail_edit_bird`` declarations should be updated to the new hook.
``IMAGE_COMPRESSION_QUALITY`` setting has been renamed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``IMAGE_COMPRESSION_QUALITY`` setting, which determines the quality of saved JPEG images as a value from 1 to 100, has been renamed to ``WAGTAILIMAGES_JPEG_QUALITY``. If you have used this setting, please update your settings file accordingly.

17
docs/releases/1.1.rst Normal file
View file

@ -0,0 +1,17 @@
==========================================
Wagtail 1.1 release notes - IN DEVELOPMENT
==========================================
.. contents::
:local:
:depth: 1
What's new
==========
Minor features
~~~~~~~~~~~~~~
* The ``{% image %}`` tag now supports filters on the image variable, e.g. ``{% image primary_img|default:secondary_img width-500 %}``

View file

@ -4,6 +4,7 @@ Release notes
.. toctree::
:maxdepth: 1
1.1
1.0
0.8.8
0.8.7

View file

@ -1,6 +1,6 @@
class RemovedInWagtail11Warning(DeprecationWarning):
class RemovedInWagtail12Warning(DeprecationWarning):
pass
class RemovedInWagtail12Warning(PendingDeprecationWarning):
class RemovedInWagtail13Warning(PendingDeprecationWarning):
pass

View file

@ -7,7 +7,7 @@ from wagtail.wagtailadmin.userbar import EditPageItem, AddPageItem, ApproveModer
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page, PageRevision
from wagtail.utils.deprecation import RemovedInWagtail11Warning
from wagtail.utils.deprecation import RemovedInWagtail12Warning
@permission_required('wagtailadmin.access_admin', raise_exception=True)
@ -17,7 +17,7 @@ def for_frontend(request, page_id):
AddPageItem(Page.objects.get(id=page_id)),
]
# TODO: Remove in 1.1 release
# TODO: Remove in 1.2 release
run_deprecated_edit_bird_hook(request, items)
for fn in hooks.get_hooks('construct_wagtail_userbar'):
@ -44,7 +44,7 @@ def for_moderation(request, revision_id):
RejectModerationEditPageItem(PageRevision.objects.get(id=revision_id)),
]
# TODO: Remove in 1.1 release
# TODO: Remove in 1.2 release
run_deprecated_edit_bird_hook(request, items)
for fn in hooks.get_hooks('construct_wagtail_userbar'):
@ -68,5 +68,5 @@ def run_deprecated_edit_bird_hook(request, items):
warnings.warn(
"The 'construct_wagtail_edit_bird' hook has been renamed to 'construct_wagtail_userbar'."
"Please update function '%s' in '%s'." % (fn.__name__, fn.__module__), RemovedInWagtail11Warning
"Please update function '%s' in '%s'." % (fn.__name__, fn.__module__), RemovedInWagtail12Warning
)

View file

@ -1,2 +1,2 @@
__version__ = '1.0rc1'
__version__ = '1.1a0'
default_app_config = 'wagtail.wagtailcore.apps.WagtailCoreAppConfig'

View file

@ -31,7 +31,7 @@ from wagtail.wagtailsearch import index
from wagtail.wagtailimages.rect import Rect
from wagtail.wagtailimages.exceptions import InvalidFilterSpecError
from wagtail.wagtailadmin.utils import get_object_usage
from wagtail.utils.deprecation import RemovedInWagtail11Warning
from wagtail.utils.deprecation import RemovedInWagtail12Warning
class SourceImageIOError(IOError):
@ -336,7 +336,7 @@ class Filter(models.Model):
warnings.warn(
"The IMAGE_COMPRESSION_QUALITY setting has been renamed to "
"WAGTAILIMAGES_JPEG_QUALITY. Please update your settings.",
RemovedInWagtail11Warning)
RemovedInWagtail12Warning)
else:
quality = 85

View file

@ -9,13 +9,13 @@ register = template.Library()
@register.tag(name="image")
def image(parser, token):
bits = token.split_contents()[1:]
image_var = bits[0]
image_expr = parser.compile_filter(bits[0])
filter_spec = bits[1]
bits = bits[2:]
if len(bits) == 2 and bits[0] == 'as':
# token is of the form {% image self.photo max-320x200 as img %}
return ImageNode(image_var, filter_spec, output_var_name=bits[1])
return ImageNode(image_expr, filter_spec, output_var_name=bits[1])
else:
# token is of the form {% image self.photo max-320x200 %} - all additional tokens
# should be kwargs, which become attributes
@ -25,14 +25,14 @@ def image(parser, token):
name, value = bit.split('=')
except ValueError:
raise template.TemplateSyntaxError("'image' tag should be of the form {% image self.photo max-320x200 [ custom-attr=\"value\" ... ] %} or {% image self.photo max-320x200 as img %}")
attrs[name] = parser.compile_filter(value) # setup to resolve context variables as value
attrs[name] = parser.compile_filter(value) # setup to resolve context variables as value
return ImageNode(image_var, filter_spec, attrs=attrs)
return ImageNode(image_expr, filter_spec, attrs=attrs)
class ImageNode(template.Node):
def __init__(self, image_var_name, filter_spec, output_var_name=None, attrs={}):
self.image_var = template.Variable(image_var_name)
def __init__(self, image_expr, filter_spec, output_var_name=None, attrs={}):
self.image_expr = image_expr
self.output_var_name = output_var_name
self.attrs = attrs
self.filter_spec = filter_spec
@ -44,7 +44,7 @@ class ImageNode(template.Node):
def render(self, context):
try:
image = self.image_var.resolve(context)
image = self.image_expr.resolve(context)
except template.VariableDoesNotExist:
return ''

View file

@ -43,6 +43,10 @@ class TestImageTag(TestCase):
self.assertTrue('height="300"' in result)
self.assertTrue('alt="Test image"' in result)
def test_image_tag_none(self):
result = self.render_image_tag(None, "width-500")
self.assertEqual(result, '')
def render_image_tag_as(self, image, filter_spec):
temp = template.Template('{% load wagtailimages_tags %}{% image image_obj ' + filter_spec + ' as test_img %}<img {{ test_img.attrs }} />')
context = template.Context({'image_obj': image})
@ -70,6 +74,16 @@ class TestImageTag(TestCase):
self.assertTrue('class="photo"' in result)
self.assertTrue('title="my wonderful title"' in result)
def render_image_tag_with_filters(self, image):
temp = template.Template('{% load wagtailimages_tags %}{% image image_primary|default:image_alternate width-400 %}')
context = template.Context({'image_primary': None, 'image_alternate': image})
return temp.render(context)
def test_image_tag_with_filters(self):
result = self.render_image_tag_with_filters(self.image)
self.assertTrue('width="400"' in result)
self.assertTrue('height="300"' in result)
class TestMissingImage(TestCase):
"""