Merge branch 'set_multipart' of https://github.com/mayapurmedia/wagtail into mayapurmedia-set_multipart

pull/1838/head
Matt Westcott 2015-10-16 11:42:05 +01:00
commit 6310c906ee
5 zmienionych plików z 83 dodań i 3 usunięć

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