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 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/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. diff --git a/docs/core_components/pages/creating_pages.rst b/docs/core_components/pages/creating_pages.rst index e6fb9a14b..40dfa6439 100644 --- a/docs/core_components/pages/creating_pages.rst +++ b/docs/core_components/pages/creating_pages.rst @@ -147,3 +147,50 @@ 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 internal ``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 + +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``: + +.. 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 option to the model ``Meta`` class + + +.. code-block:: python + + class HomePage(Page): + ... + + 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). 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:: 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 ====================== diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 04ae37ad0..404cc7210 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: 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') +