From 52d7f2c6faf3672da0e6b9079d622698f4b88371 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 27 Aug 2014 12:12:03 +0100 Subject: [PATCH 01/14] Added failing test for #573 --- wagtail/wagtailimages/tests.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailimages/tests.py b/wagtail/wagtailimages/tests.py index dabd5e0e8..d040a922d 100644 --- a/wagtail/wagtailimages/tests.py +++ b/wagtail/wagtailimages/tests.py @@ -32,7 +32,7 @@ from wagtail.tests.models import EventPage, EventPageCarouselItem from wagtail.wagtailcore.models import Page -def get_test_image_file(): +def get_test_image_file(filename='test.png'): from six import BytesIO from PIL import Image from django.core.files.images import ImageFile @@ -40,7 +40,7 @@ def get_test_image_file(): f = BytesIO() image = Image.new('RGB', (640, 480), 'white') image.save(f, 'PNG') - return ImageFile(f, name='test.png') + return ImageFile(f, name=filename) Image = get_image_model() @@ -1016,3 +1016,24 @@ class TestCropToPoint(TestCase): CropBox(125, 25, 275, 175), ) + +class TestIssue573(TestCase): + """ + This tests for a bug which causes filename limit on Renditions to be reached + when the Image has a long original filename and a big focal point key + """ + def test_issue_573(self): + # Create an image with a big filename and focal point + image = Image.objects.create( + title="Test image", + file=get_test_image_file('thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexpialidocious.png'), + focal_point_x=1000, + focal_point_y=1000, + focal_point_width=1000, + focal_point_height=1000, + ) + + # Try creating a rendition from that image + # This would crash if the bug is present + image.get_rendition('fill-800x600') + From 01daf3fb74974429a733e8014e52d0733ae30f22 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 27 Aug 2014 12:28:08 +0100 Subject: [PATCH 02/14] Prevent rendition filenames going over 60 chars even with large focal point key. Fixes #573 --- wagtail/wagtailimages/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 63151b602..88aa1ee1c 100644 --- a/wagtail/wagtailimages/models.py +++ b/wagtail/wagtailimages/models.py @@ -161,10 +161,9 @@ class AbstractImage(models.Model, TagSearchable): input_filename_parts = os.path.basename(file_field.file.name).split('.') filename_without_extension = '.'.join(input_filename_parts[:-1]) - filename_without_extension = filename_without_extension[:60] # trim filename base so that we're well under 100 chars - output_filename_parts = [filename_without_extension, focal_point_key, filter.spec] + input_filename_parts[-1:] - output_filename = '.'.join(output_filename_parts) - + extension = '.'.join([focal_point_key, filter.spec] + input_filename_parts[-1:]) + filename_without_extension = filename_without_extension[:(59-len(extension))] # Truncate filename to prevent it going over 60 chars + output_filename = filename_without_extension + '.' + extension generated_image_file = File(generated_image, name=output_filename) if self.focal_point: From f75ec76b3aa71b99111ea47134dacd44ef2c76e1 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 27 Aug 2014 17:10:30 +0100 Subject: [PATCH 03/14] fix more documentation links in the readme --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a2c11cb16..77d153f26 100644 --- a/README.rst +++ b/README.rst @@ -53,8 +53,8 @@ Contributing ~~~~~~~~~~~~ If you're a Python or Django developer, fork the repo and get stuck in! -We suggest you start by checking the `Help develop me! `_ label and the `coding guidelines `_. +We suggest you start by checking the `Help develop me! `_ label and the `coding guidelines `_. Send us a useful pull request and we'll post you a `t-shirt `_. -We also welcome `translations `_ for Wagtail's interface. +We also welcome `translations `_ for Wagtail's interface. From 0aee07fd5a204cbbafab3092c69e88d62644ff83 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 28 Aug 2014 10:33:42 +0100 Subject: [PATCH 04/14] Exclude south_migrations from test coverage --- .coveragerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 7f6f849cd..b49e59cd5 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,6 +5,7 @@ branch = True source = wagtail omit = + */south_migrations/* */migrations/* wagtail/vendor/* @@ -31,4 +32,4 @@ exclude_lines = ignore_errors = True [html] -directory = coverage_html_report \ No newline at end of file +directory = coverage_html_report From b0e97c954a1342c3092c015467e1979fc83ed8be Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 1 Sep 2014 10:44:42 +0100 Subject: [PATCH 05/14] release notes / changelog for #574 --- CHANGELOG.txt | 1 + docs/releases/0.6.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5122b8d1d..88d221100 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -9,6 +9,7 @@ Changelog * Renamed wagtailsearch.indexed to wagtailsearch.index * Fix: Page URL generation now returns correct URLs for sites that have the main 'serve' view rooted somewhere other than '/' * Fix: Search results in the page chooser now respect the page_type parameter on PageChooserPanel + * Fix: Rendition filenames are now prevented from going over 60 chars, even with a large focal_point_key 0.5 (01.08.2014) ~~~~~~~~~~~~~~~~ diff --git a/docs/releases/0.6.rst b/docs/releases/0.6.rst index a5fbad591..ebd97fc05 100644 --- a/docs/releases/0.6.rst +++ b/docs/releases/0.6.rst @@ -26,6 +26,7 @@ Bug fixes * Page URL generation now returns correct URLs for sites that have the main 'serve' view rooted somewhere other than '/'. * Search results in the page chooser now respect the page_type parameter on PageChooserPanel. + * Rendition filenames are now prevented from going over 60 chars, even with a large focal_point_key. Upgrade considerations ====================== From f0db8082c830a7c075390996bb53fe4f5151cac5 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:09:22 +0100 Subject: [PATCH 06/14] Better description of purpose --- docs/core_components/pages/editing_api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core_components/pages/editing_api.rst b/docs/core_components/pages/editing_api.rst index f1025cbcb..aa1db2efe 100644 --- a/docs/core_components/pages/editing_api.rst +++ b/docs/core_components/pages/editing_api.rst @@ -1,6 +1,6 @@ .. _editing-api: -Defining models with the Editing API +Displaying fields with the Editing API ==================================== .. note:: From 0b3515a91669f229469ea80c0a77f810760afb29 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:16:15 +0100 Subject: [PATCH 07/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index e6fb9a14b..e5e4d740d 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -147,3 +147,26 @@ In addition to the model fields provided, ``Page`` has many properties and metho Defines which template file should be used to render the login form for Protected pages using this model. This overrides the default, defined using ``PASSWORD_REQUIRED_TEMPLATE`` in your settings. See :ref:`private_pages` +Tips +~~~~ + +Friendly model names +-------------------- + +Make your model names more friendly to users of Wagtail using Django's ``Meta`` class with a ``verbose_name`` e.g + +.. code-block:: python + + class HomePage(Page): + ... + + class Meta: + verbose_name = "Homepage" + +When users are given a choice of pages to create, the list of page types is generated by splitting your model names on each of their capital letters. Thus a ``HomePage`` model would be named "Home Page" which is a little clumsy. ``verbose_name`` as in the example above, would change this to read "Homepage" which is slightly more conventional. + +The above example also ensures the name of the + +Describing your models +---------------------- + From e2a3d549f875bdb0d0aa62b362c52c8f1a2a173d Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:30:43 +0100 Subject: [PATCH 08/14] Added how to add model descriptions --- docs/core_components/pages/creating_pages.rst | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index e5e4d740d..5d98581a9 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -167,6 +167,23 @@ When users are given a choice of pages to create, the list of page types is gene The above example also ensures the name of the -Describing your models ----------------------- +Helpful model descriptions +-------------------------- +As your site becomes more complex users may require some prompting in deciding which content type to use when creating a new page. Developers can add a description to their Models by extending Django's in-built model meta class. + +Insert the following once at the top of your models.py: + +.. code-block:: python + import django.db.models.options as options + options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('description',) + +Then for each model as necessary, add a description attribute to the model ``Meta``: + +.. code-block:: python + class HomePage(Page): + ... + + class Meta: + description = "The top level homepage for your site" + verbose_name = "Homepage" From 04c65833f01981c75ef53455bc383b1abe257824 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:31:41 +0100 Subject: [PATCH 09/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index 5d98581a9..c65ad2e6b 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -160,8 +160,8 @@ Make your model names more friendly to users of Wagtail using Django's ``Meta`` class HomePage(Page): ... - class Meta: - verbose_name = "Homepage" + class Meta: + verbose_name = "Homepage" When users are given a choice of pages to create, the list of page types is generated by splitting your model names on each of their capital letters. Thus a ``HomePage`` model would be named "Home Page" which is a little clumsy. ``verbose_name`` as in the example above, would change this to read "Homepage" which is slightly more conventional. @@ -184,6 +184,6 @@ Then for each model as necessary, add a description attribute to the model ``Met class HomePage(Page): ... - class Meta: - description = "The top level homepage for your site" - verbose_name = "Homepage" + class Meta: + description = "The top level homepage for your site" + verbose_name = "Homepage" From 98fd81e910927455dfb971c11d011cb6e1f35396 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:33:15 +0100 Subject: [PATCH 10/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index c65ad2e6b..b55edb281 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -178,7 +178,9 @@ Insert the following once at the top of your models.py: import django.db.models.options as options options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('description',) -Then for each model as necessary, add a description attribute to the model ``Meta``: + +Then for each model as necessary, add a description attribute to the model ``Meta`` class + .. code-block:: python class HomePage(Page): From 84aa8a18872539540f05bf50dee7f9f564e7b14e Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:34:32 +0100 Subject: [PATCH 11/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index b55edb281..a8c5e7bf0 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -183,9 +183,10 @@ Then for each model as necessary, add a description attribute to the model ``Met .. code-block:: python + class HomePage(Page): ... - + class Meta: description = "The top level homepage for your site" verbose_name = "Homepage" From 6c159bee59202839e63937e9314e92e79a4c97f5 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:39:07 +0100 Subject: [PATCH 12/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index a8c5e7bf0..b859f16f6 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -153,7 +153,7 @@ Tips Friendly model names -------------------- -Make your model names more friendly to users of Wagtail using Django's ``Meta`` class with a ``verbose_name`` e.g +Make your model names more friendly to users of Wagtail using Django's internal ``Meta`` class with a ``verbose_name`` e.g .. code-block:: python @@ -170,7 +170,7 @@ The above example also ensures the name of the Helpful model descriptions -------------------------- -As your site becomes more complex users may require some prompting in deciding which content type to use when creating a new page. Developers can add a description to their Models by extending Django's in-built model meta class. +As your site becomes more complex users may require some prompting in deciding which content type to use when creating a new page. Developers can add a description to their Models by extending Django's internal model ``Meta`` class. Insert the following once at the top of your models.py: @@ -179,7 +179,7 @@ Insert the following once at the top of your models.py: options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('description',) -Then for each model as necessary, add a description attribute to the model ``Meta`` class +Then for each model as necessary, add a description option to the model ``Meta`` class .. code-block:: python @@ -190,3 +190,6 @@ Then for each model as necessary, add a description attribute to the model ``Met class Meta: description = "The top level homepage for your site" verbose_name = "Homepage" + + +(This method can be used to extend the Model Meta class in various ways however Wagtail only supports the addition of a ``description`` option). From 22f81498b5c96949f48a315fac1e90cc8c88cad9 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:39:33 +0100 Subject: [PATCH 13/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index b859f16f6..a8038f36b 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -175,6 +175,7 @@ As your site becomes more complex users may require some prompting in deciding w Insert the following once at the top of your models.py: .. code-block:: python + import django.db.models.options as options options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('description',) From 95d249918bc06956e1c9259fdeb7158e06cba6e1 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Mon, 1 Sep 2014 16:39:48 +0100 Subject: [PATCH 14/14] Update creating_pages.rst --- docs/core_components/pages/creating_pages.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index a8038f36b..40dfa6439 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -172,7 +172,7 @@ Helpful model descriptions As your site becomes more complex users may require some prompting in deciding which content type to use when creating a new page. Developers can add a description to their Models by extending Django's internal model ``Meta`` class. -Insert the following once at the top of your models.py: +Insert the following once at the top of your ``models.py``: .. code-block:: python