Merge branch 'mayapurmedia-set_multipart'

pull/1838/head
Matt Westcott 2015-10-16 12:12:13 +01:00
commit 5c1abe3a86
8 zmienionych plików z 86 dodań i 3 usunięć

Wyświetl plik

@ -23,6 +23,7 @@ Changelog
* Wagtail admin now standardises on a single thumbnail image size, to reduce the overhead of creating multiple renditions
* The `first_published_at` and `latest_revision_created_at` fields on page models are now available as filter fields on search queries
* Rich text fields now strip out HTML comments
* Page editor form now sets enctype="multipart/form-data" as appropriate, allowing FileField to be used on page models (Petr Vacha)
* Fix: Deleting a page permission from the groups admin UI does not immediately submit the form
* Fix: Wagtail userbar is shown on pages that do not pass a `page` variable to the template (e.g. because they override the `serve` method)
* Fix: request.site now set correctly on page preview when the page is not in the default site

Wyświetl plik

@ -71,6 +71,7 @@ Contributors
* Salvador Faria
* Alex Gleason
* Ryan Pineo
* Petr Vacha
Translators

Wyświetl plik

@ -55,6 +55,7 @@ Minor features
* The ``first_published_at`` and ``latest_revision_created_at`` fields on page models are now available as filter fields on search queries
* Wagtail admin now standardises on a single thumbnail image size, to reduce the overhead of creating multiple renditions
* Rich text fields now strip out HTML comments
* Page editor form now sets ``enctype="multipart/form-data"`` as appropriate, allowing FileField to be used on page models (Petr Vacha)
Bug fixes
~~~~~~~~~

Wyświetl plik

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0019_verbose_names_cleanup'),
('tests', '0011_auto_20151006_2141'),
]
operations = [
migrations.CreateModel(
name='FilePage',
fields=[
('page_ptr', models.OneToOneField(to='wagtailcore.Page', serialize=False, auto_created=True, primary_key=True, parent_link=True)),
('file_field', models.FileField(upload_to='')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]

Wyświetl plik

@ -131,6 +131,17 @@ class PageWithOldStyleRouteMethod(Page):
return self.serve(request)
# File page
class FilePage(Page):
file_field = models.FileField()
FilePage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('file_field'),
]
# Event page
class EventPageCarouselItem(Orderable, CarouselItem):

Wyświetl plik

@ -17,7 +17,7 @@
</div>
</header>
<form id="page-edit-form" action="{% url 'wagtailadmin_pages:add' content_type.app_label content_type.model parent_page.id %}" method="POST">
<form id="page-edit-form" action="{% url 'wagtailadmin_pages:add' content_type.app_label content_type.model parent_page.id %}" method="POST"{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>
{% csrf_token %}
{{ edit_handler.render_form_content }}

Wyświetl plik

@ -24,7 +24,7 @@
</div>
</header>
<form id="page-edit-form" action="{% url 'wagtailadmin_pages:edit' page.id %}" method="POST">
<form id="page-edit-form" action="{% url 'wagtailadmin_pages:edit' page.id %}" method="POST"{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>
{% csrf_token %}
{{ edit_handler.render_form_content }}

Wyświetl plik

@ -6,11 +6,12 @@ from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.core import mail, paginator
from django.core.files.base import ContentFile
from django.db.models.signals import pre_delete, post_delete
from django.utils import timezone
from wagtail.tests.testapp.models import (
SimplePage, EventPage, EventPageCarouselItem,
SimplePage, FilePage, EventPage, EventPageCarouselItem,
StandardIndex, StandardChild,
BusinessIndex, BusinessChild, BusinessSubIndex,
TaggedPage, Advert, AdvertPlacement)
@ -225,6 +226,21 @@ class TestPageCreation(TestCase, WagtailTestUtils):
self.assertContains(response, '<a href="#content" class="active">Content</a>')
self.assertContains(response, '<a href="#promote" class="">Promote</a>')
def test_create_multipart(self):
"""
Test checks if 'enctype="multipart/form-data"' is added and only to forms that require multipart encoding.
"""
# check for SimplePage where is no file field
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'enctype="multipart/form-data"')
self.assertTemplateUsed(response, 'wagtailadmin/pages/create.html')
# check for FilePage which has file field
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'filepage', self.root_page.id)))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'enctype="multipart/form-data"')
def test_create_page_without_promote_tab(self):
"""
Test that the Promote tab is not rendered for page classes that define it as empty
@ -528,6 +544,18 @@ class TestPageEdit(TestCase, WagtailTestUtils):
child_page.save_revision().publish()
self.child_page = SimplePage.objects.get(id=child_page.id)
# Add file page
fake_file = ContentFile("File for testing multipart")
fake_file.name = 'test.txt'
file_page = FilePage(
title="File Page",
slug="file-page",
file_field=fake_file,
)
self.root_page.add_child(instance=file_page)
file_page.save_revision().publish()
self.file_page = FilePage.objects.get(id=file_page.id)
# Add event page (to test edit handlers)
self.event_page = EventPage()
self.event_page.title = "Event page"
@ -542,6 +570,21 @@ class TestPageEdit(TestCase, WagtailTestUtils):
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.event_page.id, )))
self.assertEqual(response.status_code, 200)
def test_edit_multipart(self):
"""
Test checks if 'enctype="multipart/form-data"' is added and only to forms that require multipart encoding.
"""
# check for SimplePage where is no file field
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.event_page.id, )))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'enctype="multipart/form-data"')
self.assertTemplateUsed(response, 'wagtailadmin/pages/edit.html')
# check for FilePage which has file field
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.file_page.id, )))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'enctype="multipart/form-data"')
def test_page_edit_bad_permissions(self):
# Remove privileges from user
self.user.is_superuser = False