From 9a5954607d4ddc232991e493d61484e3fb2fbdcb Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 10:28:56 +0100 Subject: [PATCH 1/8] Renamed pageurl tags to wagtailcore_tags --- wagtail/wagtailcore/templatetags/pageurl.py | 26 ++++--------------- .../templatetags/wagtailcore_tags.py | 25 ++++++++++++++++++ 2 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 wagtail/wagtailcore/templatetags/wagtailcore_tags.py diff --git a/wagtail/wagtailcore/templatetags/pageurl.py b/wagtail/wagtailcore/templatetags/pageurl.py index d3488d9b45..fe64a302f6 100644 --- a/wagtail/wagtailcore/templatetags/pageurl.py +++ b/wagtail/wagtailcore/templatetags/pageurl.py @@ -1,24 +1,8 @@ -from django import template +import warnings -from wagtail.wagtailcore.models import Page - -register = template.Library() +warnings.warn( + "The pageurl tags has been renamed. " + "Use wagtailcore_tags instead.", DeprecationWarning) -@register.simple_tag(takes_context=True) -def pageurl(context, page): - """ - Outputs a page's URL as relative (/foo/bar/) if it's within the same site as the - current page, or absolute (http://example.com/foo/bar/) if not. - """ - return page.relative_url(context['request'].site) - -@register.simple_tag(takes_context=True) -def slugurl(context, slug): - """Returns the URL for the page that has the given slug.""" - page = Page.objects.filter(slug=slug).first() - - if page: - return page.relative_url(context['request'].site) - else: - return None +from wagtail.wagtailcore.templatetags.wagtailcore_tags import register diff --git a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py new file mode 100644 index 0000000000..d91c05742d --- /dev/null +++ b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py @@ -0,0 +1,25 @@ +from django import template + +from wagtail.wagtailcore.models import Page + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def pageurl(context, page): + """ + Outputs a page's URL as relative (/foo/bar/) if it's within the same site as the + current page, or absolute (http://example.com/foo/bar/) if not. + """ + return page.relative_url(context['request'].site) + + +@register.simple_tag(takes_context=True) +def slugurl(context, slug): + """Returns the URL for the page that has the given slug.""" + page = Page.objects.filter(slug=slug).first() + + if page: + return page.relative_url(context['request'].site) + else: + return None From 122abc9a8c7a332b623b86e7a5c6d9bdb28ac4b4 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 10:30:09 +0100 Subject: [PATCH 2/8] renamed rich_text tags to wagtailrichtext_tags --- wagtail/wagtailcore/templatetags/rich_text.py | 13 +++++-------- .../templatetags/wagtailrichtext_tags.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py diff --git a/wagtail/wagtailcore/templatetags/rich_text.py b/wagtail/wagtailcore/templatetags/rich_text.py index d3bc64fddc..d7d1626450 100644 --- a/wagtail/wagtailcore/templatetags/rich_text.py +++ b/wagtail/wagtailcore/templatetags/rich_text.py @@ -1,11 +1,8 @@ -from django import template -from django.utils.safestring import mark_safe +import warnings -from wagtail.wagtailcore.rich_text import expand_db_html - -register = template.Library() +warnings.warn( + "The rich_text tags has been renamed. " + "Use wagtailrichtext_tags instead.", DeprecationWarning) -@register.filter -def richtext(value): - return mark_safe('
' + expand_db_html(value) + '
') +from wagtail.wagtailcore.templatetags.wagtailrichtext_tags import register diff --git a/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py b/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py new file mode 100644 index 0000000000..d3bc64fddc --- /dev/null +++ b/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py @@ -0,0 +1,11 @@ +from django import template +from django.utils.safestring import mark_safe + +from wagtail.wagtailcore.rich_text import expand_db_html + +register = template.Library() + + +@register.filter +def richtext(value): + return mark_safe('
' + expand_db_html(value) + '
') From 65ec6d77e8effdf54aefcb6d5b42f65ba2089436 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 10:36:03 +0100 Subject: [PATCH 3/8] Merged richtext tags into wagtailcore_tags --- wagtail/wagtailcore/templatetags/rich_text.py | 4 ++-- wagtail/wagtailcore/templatetags/wagtailcore_tags.py | 7 +++++++ .../wagtailcore/templatetags/wagtailrichtext_tags.py | 11 ----------- 3 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py diff --git a/wagtail/wagtailcore/templatetags/rich_text.py b/wagtail/wagtailcore/templatetags/rich_text.py index d7d1626450..94c2d176c1 100644 --- a/wagtail/wagtailcore/templatetags/rich_text.py +++ b/wagtail/wagtailcore/templatetags/rich_text.py @@ -2,7 +2,7 @@ import warnings warnings.warn( "The rich_text tags has been renamed. " - "Use wagtailrichtext_tags instead.", DeprecationWarning) + "Use wagtailcore_tags instead.", DeprecationWarning) -from wagtail.wagtailcore.templatetags.wagtailrichtext_tags import register +from wagtail.wagtailcore.templatetags.wagtailcore_tags import register diff --git a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py index d91c05742d..5e137c7a2e 100644 --- a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py +++ b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py @@ -1,6 +1,8 @@ from django import template +from django.utils.safestring import mark_safe from wagtail.wagtailcore.models import Page +from wagtail.wagtailcore.rich_text import expand_db_html register = template.Library() @@ -23,3 +25,8 @@ def slugurl(context, slug): return page.relative_url(context['request'].site) else: return None + + +@register.filter +def richtext(value): + return mark_safe('
' + expand_db_html(value) + '
') diff --git a/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py b/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py deleted file mode 100644 index d3bc64fddc..0000000000 --- a/wagtail/wagtailcore/templatetags/wagtailrichtext_tags.py +++ /dev/null @@ -1,11 +0,0 @@ -from django import template -from django.utils.safestring import mark_safe - -from wagtail.wagtailcore.rich_text import expand_db_html - -register = template.Library() - - -@register.filter -def richtext(value): - return mark_safe('
' + expand_db_html(value) + '
') From b3e79519329dc9f2b3ebd94405b3e84024dc8353 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 10:39:50 +0100 Subject: [PATCH 4/8] Moved embed_filters to wagtailembeds_tags --- .../templatetags/embed_filters.py | 26 ++++------------- .../templatetags/wagtailembeds_tags.py | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py diff --git a/wagtail/wagtailembeds/templatetags/embed_filters.py b/wagtail/wagtailembeds/templatetags/embed_filters.py index d916c0ffba..25326fec60 100644 --- a/wagtail/wagtailembeds/templatetags/embed_filters.py +++ b/wagtail/wagtailembeds/templatetags/embed_filters.py @@ -1,24 +1,8 @@ -from django import template -from django.utils.safestring import mark_safe +import warnings -from wagtail.wagtailembeds import get_embed +warnings.warn( + "The embed_filters tags has been renamed. " + "Use wagtailembeds_tags instead.", DeprecationWarning) -register = template.Library() - - -@register.filter -def embed(url, max_width=None): - embed = get_embed(url, max_width=max_width) - try: - if embed is not None: - return mark_safe(embed.html) - else: - return '' - except: - return '' - - -@register.filter -def embedly(url, max_width=None): - return embed(url, max_width) +from wagtail.wagtailembeds.templatetags.wagtailembeds_tags import register diff --git a/wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py b/wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py new file mode 100644 index 0000000000..aad751c6a6 --- /dev/null +++ b/wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py @@ -0,0 +1,28 @@ +from django import template +from django.utils.safestring import mark_safe + +from wagtail.wagtailembeds import get_embed + + +register = template.Library() + + +@register.filter +def embed(url, max_width=None): + embed = get_embed(url, max_width=max_width) + try: + if embed is not None: + return mark_safe(embed.html) + else: + return '' + except: + return '' + + +@register.filter +def embedly(url, max_width=None): + warnings.warn( + "The 'embedly' filter has been renamed. " + "Use 'embed' instead.", DeprecationWarning) + + return embed(url, max_width) From 008b3238abfb874e520c7cad0349fc55441aca6f Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 10:41:53 +0100 Subject: [PATCH 5/8] Moved image_tags to wagtailimages_tags --- .../wagtailimages/templatetags/image_tags.py | 71 ++----------------- .../templatetags/wagtailimages_tags.py | 69 ++++++++++++++++++ 2 files changed, 74 insertions(+), 66 deletions(-) create mode 100644 wagtail/wagtailimages/templatetags/wagtailimages_tags.py diff --git a/wagtail/wagtailimages/templatetags/image_tags.py b/wagtail/wagtailimages/templatetags/image_tags.py index e59d9cd148..7eba192d46 100644 --- a/wagtail/wagtailimages/templatetags/image_tags.py +++ b/wagtail/wagtailimages/templatetags/image_tags.py @@ -1,69 +1,8 @@ -from django import template +import warnings -from wagtail.wagtailimages.models import Filter - -register = template.Library() - -# Local cache of filters, avoid hitting the DB -filters = {} - -@register.tag(name="image") -def image(parser, token): - args = token.split_contents() - - if len(args) == 3: - # token is of the form {% image self.photo max-320x200 %} - tag_name, image_var, filter_spec = args - return ImageNode(image_var, filter_spec) - - elif len(args) == 5: - # token is of the form {% image self.photo max-320x200 as img %} - tag_name, image_var, filter_spec, as_token, out_var = args - - if as_token != 'as': - raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 %%} or {%% image self.photo max-320x200 as img %%}") - - return ImageNode(image_var, filter_spec, out_var) - - else: - raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 %%} or {%% image self.photo max-320x200 as img %%}") +warnings.warn( + "The image_tags tags has been renamed. " + "Use wagtailimages_tags instead.", DeprecationWarning) -class ImageNode(template.Node): - def __init__(self, image_var_name, filter_spec, output_var_name=None): - self.image_var = template.Variable(image_var_name) - self.output_var_name = output_var_name - - if filter_spec not in filters: - filters[filter_spec], _ = Filter.objects.get_or_create(spec=filter_spec) - self.filter = filters[filter_spec] - - def render(self, context): - try: - image = self.image_var.resolve(context) - except template.VariableDoesNotExist: - return '' - - if not image: - return '' - - try: - rendition = image.get_rendition(self.filter) - except IOError: - # It's fairly routine for people to pull down remote databases to their - # local dev versions without retrieving the corresponding image files. - # In such a case, we would get an IOError at the point where we try to - # create the resized version of a non-existent image. Since this is a - # bit catastrophic for a missing image, we'll substitute a dummy - # Rendition object so that we just output a broken link instead. - Rendition = image.renditions.model # pick up any custom Image / Rendition classes that may be in use - rendition = Rendition(image=image, width=0, height=0) - rendition.file.name = 'not-found' - - if self.output_var_name: - # return the rendition object in the given variable - context[self.output_var_name] = rendition - return '' - else: - # render the rendition's image tag now - return rendition.img_tag() +from wagtail.wagtailimages.templatetags.wagtailimages_tags import register diff --git a/wagtail/wagtailimages/templatetags/wagtailimages_tags.py b/wagtail/wagtailimages/templatetags/wagtailimages_tags.py new file mode 100644 index 0000000000..e59d9cd148 --- /dev/null +++ b/wagtail/wagtailimages/templatetags/wagtailimages_tags.py @@ -0,0 +1,69 @@ +from django import template + +from wagtail.wagtailimages.models import Filter + +register = template.Library() + +# Local cache of filters, avoid hitting the DB +filters = {} + +@register.tag(name="image") +def image(parser, token): + args = token.split_contents() + + if len(args) == 3: + # token is of the form {% image self.photo max-320x200 %} + tag_name, image_var, filter_spec = args + return ImageNode(image_var, filter_spec) + + elif len(args) == 5: + # token is of the form {% image self.photo max-320x200 as img %} + tag_name, image_var, filter_spec, as_token, out_var = args + + if as_token != 'as': + raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 %%} or {%% image self.photo max-320x200 as img %%}") + + return ImageNode(image_var, filter_spec, out_var) + + else: + raise template.TemplateSyntaxError("'image' tag should be of the form {%% image self.photo max-320x200 %%} or {%% image self.photo max-320x200 as img %%}") + + +class ImageNode(template.Node): + def __init__(self, image_var_name, filter_spec, output_var_name=None): + self.image_var = template.Variable(image_var_name) + self.output_var_name = output_var_name + + if filter_spec not in filters: + filters[filter_spec], _ = Filter.objects.get_or_create(spec=filter_spec) + self.filter = filters[filter_spec] + + def render(self, context): + try: + image = self.image_var.resolve(context) + except template.VariableDoesNotExist: + return '' + + if not image: + return '' + + try: + rendition = image.get_rendition(self.filter) + except IOError: + # It's fairly routine for people to pull down remote databases to their + # local dev versions without retrieving the corresponding image files. + # In such a case, we would get an IOError at the point where we try to + # create the resized version of a non-existent image. Since this is a + # bit catastrophic for a missing image, we'll substitute a dummy + # Rendition object so that we just output a broken link instead. + Rendition = image.renditions.model # pick up any custom Image / Rendition classes that may be in use + rendition = Rendition(image=image, width=0, height=0) + rendition.file.name = 'not-found' + + if self.output_var_name: + # return the rendition object in the given variable + context[self.output_var_name] = rendition + return '' + else: + # render the rendition's image tag now + return rendition.img_tag() From f73c7da7728f92cd07702de89cd31544db5fff7f Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 11:17:32 +0100 Subject: [PATCH 6/8] Update docs to import tags from correct tags module --- docs/building_your_site/frontenddevelopers.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/building_your_site/frontenddevelopers.rst b/docs/building_your_site/frontenddevelopers.rst index f0054eaab5..704708e0cd 100644 --- a/docs/building_your_site/frontenddevelopers.rst +++ b/docs/building_your_site/frontenddevelopers.rst @@ -100,7 +100,7 @@ For example: .. code-block:: django - {% load image %} + {% load wagtailimages_tags %} ... {% image self.photo width-400 %} @@ -190,7 +190,7 @@ In some cases greater control over the ``img`` tag is required, for example to a .. code-block:: django - {% load image %} + {% load wagtailimages_tags %} ... {% image self.photo width-400 as tmp_photo %} @@ -209,7 +209,7 @@ Only fields using ``RichTextField`` need this applied in the template. .. code-block:: django - {% load rich_text %} + {% load wagtailcore_tags %} ... {{ self.body|richtext }} @@ -252,7 +252,7 @@ Takes a Page object and returns a relative URL (``/foo/bar/``) if within the sam .. code-block:: django - {% load pageurl %} + {% load wagtailcore_tags %} ... @@ -263,7 +263,7 @@ Takes any ``slug`` as defined in a page's "Promote" tab and returns the URL for .. code-block:: django - {% load slugurl %} + {% load wagtailcore_tags %} ... From 879269ab20e69894c8e947892101f9eba3669471 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 19 Jun 2014 11:22:58 +0100 Subject: [PATCH 7/8] Added versionchanged notes to docs --- docs/building_your_site/frontenddevelopers.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/building_your_site/frontenddevelopers.rst b/docs/building_your_site/frontenddevelopers.rst index 704708e0cd..0ef918582d 100644 --- a/docs/building_your_site/frontenddevelopers.rst +++ b/docs/building_your_site/frontenddevelopers.rst @@ -90,6 +90,9 @@ In addition to Django's standard tags and filters, Wagtail provides some of its Images (tag) ~~~~~~~~~~~~ +.. versionchanged:: 0.4 + The 'image_tags' tags library was renamed to 'wagtailimages_tags' + The ``image`` tag inserts an XHTML-compatible ``img`` element into the page, setting its ``src``, ``width``, ``height`` and ``alt``. See also :ref:`image_tag_alt`. The syntax for the tag is thus:: @@ -203,6 +206,9 @@ In some cases greater control over the ``img`` tag is required, for example to a Rich text (filter) ~~~~~~~~~~~~~~~~~~ +.. versionchanged:: 0.4 + The 'rich_text' tags library was renamed to 'wagtailcore_tags' + This filter takes a chunk of HTML content and renders it as safe HTML in the page. Importantly it also expands internal shorthand references to embedded images and links made in the Wagtail editor into fully-baked HTML ready for display. Only fields using ``RichTextField`` need this applied in the template. @@ -245,6 +251,9 @@ Wagtail embeds and images are included at their full width, which may overflow t Internal links (tag) ~~~~~~~~~~~~~~~~~~~~ +.. versionchanged:: 0.4 + The 'pageurl' tags library was renamed to 'wagtailcore_tags' + pageurl -------- From bdbcf3cd99d5b44ca275e38da5e6bab0ab181609 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 24 Jun 2014 09:53:41 +0100 Subject: [PATCH 8/8] Updated deprecation warning messages of moved template tags libraries --- wagtail/wagtailcore/templatetags/pageurl.py | 4 ++-- wagtail/wagtailcore/templatetags/rich_text.py | 4 ++-- wagtail/wagtailembeds/templatetags/embed_filters.py | 4 ++-- wagtail/wagtailimages/templatetags/image_tags.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailcore/templatetags/pageurl.py b/wagtail/wagtailcore/templatetags/pageurl.py index fe64a302f6..b31756c308 100644 --- a/wagtail/wagtailcore/templatetags/pageurl.py +++ b/wagtail/wagtailcore/templatetags/pageurl.py @@ -1,8 +1,8 @@ import warnings warnings.warn( - "The pageurl tags has been renamed. " - "Use wagtailcore_tags instead.", DeprecationWarning) + "The pageurl tag library has been moved to wagtailcore_tags. " + "Use {% load wagtailcore_tags %} instead.", DeprecationWarning) from wagtail.wagtailcore.templatetags.wagtailcore_tags import register diff --git a/wagtail/wagtailcore/templatetags/rich_text.py b/wagtail/wagtailcore/templatetags/rich_text.py index 94c2d176c1..ed8ac6f0f0 100644 --- a/wagtail/wagtailcore/templatetags/rich_text.py +++ b/wagtail/wagtailcore/templatetags/rich_text.py @@ -1,8 +1,8 @@ import warnings warnings.warn( - "The rich_text tags has been renamed. " - "Use wagtailcore_tags instead.", DeprecationWarning) + "The rich_text tag library has been moved to wagtailcore_tags. " + "Use {% load wagtailcore_tags %} instead.", DeprecationWarning) from wagtail.wagtailcore.templatetags.wagtailcore_tags import register diff --git a/wagtail/wagtailembeds/templatetags/embed_filters.py b/wagtail/wagtailembeds/templatetags/embed_filters.py index 25326fec60..7d3500e581 100644 --- a/wagtail/wagtailembeds/templatetags/embed_filters.py +++ b/wagtail/wagtailembeds/templatetags/embed_filters.py @@ -1,8 +1,8 @@ import warnings warnings.warn( - "The embed_filters tags has been renamed. " - "Use wagtailembeds_tags instead.", DeprecationWarning) + "The embed_filters tag library has been moved to wagtailcore_tags. " + "Use {% load wagtailembeds_tags %} instead.", DeprecationWarning) from wagtail.wagtailembeds.templatetags.wagtailembeds_tags import register diff --git a/wagtail/wagtailimages/templatetags/image_tags.py b/wagtail/wagtailimages/templatetags/image_tags.py index 7eba192d46..9a96356c9a 100644 --- a/wagtail/wagtailimages/templatetags/image_tags.py +++ b/wagtail/wagtailimages/templatetags/image_tags.py @@ -1,8 +1,8 @@ import warnings warnings.warn( - "The image_tags tags has been renamed. " - "Use wagtailimages_tags instead.", DeprecationWarning) + "The image_tags tag library has been moved to wagtailcore_tags. " + "Use {% load wagtailimages_tags %} instead.", DeprecationWarning) from wagtail.wagtailimages.templatetags.wagtailimages_tags import register