kopia lustrzana https://github.com/wagtail/wagtail
Replaced use of force_text with force_str.
rodzic
b928747e48
commit
5e2f50403b
|
@ -1,7 +1,7 @@
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.html import escape, format_html, format_html_join
|
from django.utils.html import escape, format_html, format_html_join
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
|
@ -52,8 +52,8 @@ class TextFieldComparison(FieldComparison):
|
||||||
class RichTextFieldComparison(TextFieldComparison):
|
class RichTextFieldComparison(TextFieldComparison):
|
||||||
def htmldiff(self):
|
def htmldiff(self):
|
||||||
return diff_text(
|
return diff_text(
|
||||||
BeautifulSoup(force_text(self.val_a), 'html5lib').getText(),
|
BeautifulSoup(force_str(self.val_a), 'html5lib').getText(),
|
||||||
BeautifulSoup(force_text(self.val_b), 'html5lib').getText()
|
BeautifulSoup(force_str(self.val_b), 'html5lib').getText()
|
||||||
).to_html()
|
).to_html()
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,16 +95,16 @@ class BlockComparison:
|
||||||
class CharBlockComparison(BlockComparison):
|
class CharBlockComparison(BlockComparison):
|
||||||
def htmldiff(self):
|
def htmldiff(self):
|
||||||
return diff_text(
|
return diff_text(
|
||||||
force_text(self.val_a),
|
force_str(self.val_a),
|
||||||
force_text(self.val_b)
|
force_str(self.val_b)
|
||||||
).to_html()
|
).to_html()
|
||||||
|
|
||||||
|
|
||||||
class RichTextBlockComparison(BlockComparison):
|
class RichTextBlockComparison(BlockComparison):
|
||||||
def htmldiff(self):
|
def htmldiff(self):
|
||||||
return diff_text(
|
return diff_text(
|
||||||
BeautifulSoup(force_text(self.val_a), 'html5lib').getText(),
|
BeautifulSoup(force_str(self.val_a), 'html5lib').getText(),
|
||||||
BeautifulSoup(force_text(self.val_b), 'html5lib').getText()
|
BeautifulSoup(force_str(self.val_b), 'html5lib').getText()
|
||||||
).to_html()
|
).to_html()
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,15 +219,15 @@ class StreamFieldComparison(FieldComparison):
|
||||||
else:
|
else:
|
||||||
# Fall back to diffing the HTML representation
|
# Fall back to diffing the HTML representation
|
||||||
return diff_text(
|
return diff_text(
|
||||||
BeautifulSoup(force_text(self.val_a), 'html5lib').getText(),
|
BeautifulSoup(force_str(self.val_a), 'html5lib').getText(),
|
||||||
BeautifulSoup(force_text(self.val_b), 'html5lib').getText()
|
BeautifulSoup(force_str(self.val_b), 'html5lib').getText()
|
||||||
).to_html()
|
).to_html()
|
||||||
|
|
||||||
|
|
||||||
class ChoiceFieldComparison(FieldComparison):
|
class ChoiceFieldComparison(FieldComparison):
|
||||||
def htmldiff(self):
|
def htmldiff(self):
|
||||||
val_a = force_text(dict(self.field.flatchoices).get(self.val_a, self.val_a), strings_only=True)
|
val_a = force_str(dict(self.field.flatchoices).get(self.val_a, self.val_a), strings_only=True)
|
||||||
val_b = force_text(dict(self.field.flatchoices).get(self.val_b, self.val_b), strings_only=True)
|
val_b = force_str(dict(self.field.flatchoices).get(self.val_b, self.val_b), strings_only=True)
|
||||||
|
|
||||||
if self.val_a != self.val_b:
|
if self.val_a != self.val_b:
|
||||||
return TextDiff([('deletion', val_a), ('addition', val_b)]).to_html()
|
return TextDiff([('deletion', val_a), ('addition', val_b)]).to_html()
|
||||||
|
@ -291,16 +291,16 @@ class ForeignObjectComparison(FieldComparison):
|
||||||
if obj_a != obj_b:
|
if obj_a != obj_b:
|
||||||
if obj_a and obj_b:
|
if obj_a and obj_b:
|
||||||
# Changed
|
# Changed
|
||||||
return TextDiff([('deletion', force_text(obj_a)), ('addition', force_text(obj_b))]).to_html()
|
return TextDiff([('deletion', force_str(obj_a)), ('addition', force_str(obj_b))]).to_html()
|
||||||
elif obj_b:
|
elif obj_b:
|
||||||
# Added
|
# Added
|
||||||
return TextDiff([('addition', force_text(obj_b))]).to_html()
|
return TextDiff([('addition', force_str(obj_b))]).to_html()
|
||||||
elif obj_a:
|
elif obj_a:
|
||||||
# Removed
|
# Removed
|
||||||
return TextDiff([('deletion', force_text(obj_a))]).to_html()
|
return TextDiff([('deletion', force_str(obj_a))]).to_html()
|
||||||
else:
|
else:
|
||||||
if obj_a:
|
if obj_a:
|
||||||
return escape(force_text(obj_a))
|
return escape(force_str(obj_a))
|
||||||
else:
|
else:
|
||||||
return mark_safe(_("None"))
|
return mark_safe(_("None"))
|
||||||
|
|
||||||
|
|
|
@ -744,7 +744,7 @@ class TestPasswordReset(TestCase, WagtailTestUtils):
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
def setup_password_reset_confirm_tests(self):
|
def setup_password_reset_confirm_tests(self):
|
||||||
from django.utils.encoding import force_bytes, force_text
|
from django.utils.encoding import force_bytes, force_str
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
|
@ -754,7 +754,7 @@ class TestPasswordReset(TestCase, WagtailTestUtils):
|
||||||
self.password_reset_token = PasswordResetTokenGenerator().make_token(self.user)
|
self.password_reset_token = PasswordResetTokenGenerator().make_token(self.user)
|
||||||
|
|
||||||
# Generate a password reset uid
|
# Generate a password reset uid
|
||||||
self.password_reset_uid = force_text(urlsafe_base64_encode(force_bytes(self.user.pk)))
|
self.password_reset_uid = force_str(urlsafe_base64_encode(force_bytes(self.user.pk)))
|
||||||
|
|
||||||
# Create url_args
|
# Create url_args
|
||||||
if DJANGO_VERSION >= (3, 0):
|
if DJANGO_VERSION >= (3, 0):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib.admin.utils import quote
|
from django.contrib.admin.utils import quote
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class ButtonHelper:
|
||||||
self.request = request
|
self.request = request
|
||||||
self.model = view.model
|
self.model = view.model
|
||||||
self.opts = view.model._meta
|
self.opts = view.model._meta
|
||||||
self.verbose_name = force_text(self.opts.verbose_name)
|
self.verbose_name = force_str(self.opts.verbose_name)
|
||||||
self.verbose_name_plural = force_text(self.opts.verbose_name_plural)
|
self.verbose_name_plural = force_str(self.opts.verbose_name_plural)
|
||||||
self.permission_helper = view.permission_helper
|
self.permission_helper = view.permission_helper
|
||||||
self.url_helper = view.url_helper
|
self.url_helper = view.url_helper
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.db import models
|
||||||
from django.forms.utils import flatatt
|
from django.forms.utils import flatatt
|
||||||
from django.template import Library
|
from django.template import Library
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
@ -59,7 +59,7 @@ def items_for_result(view, result):
|
||||||
models.DateField, models.TimeField, models.ForeignKey)
|
models.DateField, models.TimeField, models.ForeignKey)
|
||||||
):
|
):
|
||||||
row_classes.append('nowrap')
|
row_classes.append('nowrap')
|
||||||
if force_text(result_repr) == '':
|
if force_str(result_repr) == '':
|
||||||
result_repr = mark_safe(' ')
|
result_repr = mark_safe(' ')
|
||||||
row_classes.extend(
|
row_classes.extend(
|
||||||
modeladmin.get_extra_class_names_for_field_col(result, field_name)
|
modeladmin.get_extra_class_names_for_field_col(result, field_name)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from django.db.models.fields.related import ManyToManyField, OneToOneRel
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.defaultfilters import filesizeformat
|
from django.template.defaultfilters import filesizeformat
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
@ -53,10 +53,10 @@ class WMABaseView(TemplateView):
|
||||||
self.model_admin = model_admin
|
self.model_admin = model_admin
|
||||||
self.model = model_admin.model
|
self.model = model_admin.model
|
||||||
self.opts = self.model._meta
|
self.opts = self.model._meta
|
||||||
self.app_label = force_text(self.opts.app_label)
|
self.app_label = force_str(self.opts.app_label)
|
||||||
self.model_name = force_text(self.opts.model_name)
|
self.model_name = force_str(self.opts.model_name)
|
||||||
self.verbose_name = force_text(self.opts.verbose_name)
|
self.verbose_name = force_str(self.opts.verbose_name)
|
||||||
self.verbose_name_plural = force_text(self.opts.verbose_name_plural)
|
self.verbose_name_plural = force_str(self.opts.verbose_name_plural)
|
||||||
self.pk_attname = self.opts.pk.attname
|
self.pk_attname = self.opts.pk.attname
|
||||||
self.is_pagemodel = model_admin.is_pagemodel
|
self.is_pagemodel = model_admin.is_pagemodel
|
||||||
self.permission_helper = model_admin.permission_helper
|
self.permission_helper = model_admin.permission_helper
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.db import DEFAULT_DB_ALIAS, NotSupportedError, connections, transact
|
||||||
from django.db.models import Count, F, Manager, Q, TextField, Value
|
from django.db.models import Count, F, Manager, Q, TextField, Value
|
||||||
from django.db.models.constants import LOOKUP_SEP
|
from django.db.models.constants import LOOKUP_SEP
|
||||||
from django.db.models.functions import Cast
|
from django.db.models.functions import Cast
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
|
|
||||||
from wagtail.search.backends.base import (
|
from wagtail.search.backends.base import (
|
||||||
BaseSearchBackend, BaseSearchQueryCompiler, BaseSearchResults, FilterFieldError)
|
BaseSearchBackend, BaseSearchQueryCompiler, BaseSearchResults, FilterFieldError)
|
||||||
|
@ -65,7 +65,7 @@ class Index:
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return ', '.join(self.prepare_value(item)
|
return ', '.join(self.prepare_value(item)
|
||||||
for item in value.values())
|
for item in value.values())
|
||||||
return force_text(value)
|
return force_str(value)
|
||||||
|
|
||||||
def prepare_field(self, obj, field):
|
def prepare_field(self, obj, field):
|
||||||
if isinstance(field, SearchField):
|
if isinstance(field, SearchField):
|
||||||
|
@ -86,7 +86,7 @@ class Index:
|
||||||
yield from self.prepare_field(sub_obj, sub_field)
|
yield from self.prepare_field(sub_obj, sub_field)
|
||||||
|
|
||||||
def prepare_obj(self, obj, search_fields):
|
def prepare_obj(self, obj, search_fields):
|
||||||
obj._object_id_ = force_text(obj.pk)
|
obj._object_id_ = force_str(obj.pk)
|
||||||
obj._autocomplete_ = []
|
obj._autocomplete_ = []
|
||||||
obj._body_ = []
|
obj._body_ = []
|
||||||
for field in search_fields:
|
for field in search_fields:
|
||||||
|
|
|
@ -5,14 +5,10 @@ from django import forms
|
||||||
from django.core import checks
|
from django.core import checks
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
|
|
||||||
# unicode_literals ensures that any render / __str__ methods returning HTML via calls to mark_safe / format_html
|
|
||||||
# return a SafeText, not SafeBytes; necessary so that it doesn't get re-encoded when the template engine
|
|
||||||
# calls force_text, which would cause it to lose its 'safe' flag
|
|
||||||
|
|
||||||
__all__ = ['BaseBlock', 'Block', 'BoundBlock', 'DeclarativeSubBlocksMetaclass', 'BlockWidget', 'BlockField']
|
__all__ = ['BaseBlock', 'Block', 'BoundBlock', 'DeclarativeSubBlocksMetaclass', 'BlockWidget', 'BlockField']
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,7 +97,7 @@ class Block(metaclass=BaseBlock):
|
||||||
def set_name(self, name):
|
def set_name(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
if not self.meta.label:
|
if not self.meta.label:
|
||||||
self.label = capfirst(force_text(name).replace('_', ' '))
|
self.label = capfirst(force_str(name).replace('_', ' '))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media(self):
|
def media(self):
|
||||||
|
@ -256,7 +252,7 @@ class Block(metaclass=BaseBlock):
|
||||||
Return a text rendering of 'value', suitable for display on templates. render() will fall back on
|
Return a text rendering of 'value', suitable for display on templates. render() will fall back on
|
||||||
this if the block does not define a 'template' property.
|
this if the block does not define a 'template' property.
|
||||||
"""
|
"""
|
||||||
return force_text(value)
|
return force_str(value)
|
||||||
|
|
||||||
def get_searchable_content(self, value):
|
def get_searchable_content(self, value):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.db.models.fields import BLANK_CHOICE_DASH
|
||||||
from django.forms.fields import CallableChoiceIterator
|
from django.forms.fields import CallableChoiceIterator
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.dateparse import parse_date, parse_datetime, parse_time
|
from django.utils.dateparse import parse_date, parse_datetime, parse_time
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
@ -109,7 +109,7 @@ class CharBlock(FieldBlock):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def get_searchable_content(self, value):
|
def get_searchable_content(self, value):
|
||||||
return [force_text(value)]
|
return [force_str(value)]
|
||||||
|
|
||||||
|
|
||||||
class TextBlock(FieldBlock):
|
class TextBlock(FieldBlock):
|
||||||
|
@ -133,7 +133,7 @@ class TextBlock(FieldBlock):
|
||||||
return forms.CharField(**field_kwargs)
|
return forms.CharField(**field_kwargs)
|
||||||
|
|
||||||
def get_searchable_content(self, value):
|
def get_searchable_content(self, value):
|
||||||
return [force_text(value)]
|
return [force_str(value)]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
icon = "pilcrow"
|
icon = "pilcrow"
|
||||||
|
@ -453,16 +453,16 @@ class ChoiceBlock(FieldBlock):
|
||||||
|
|
||||||
def get_searchable_content(self, value):
|
def get_searchable_content(self, value):
|
||||||
# Return the display value as the searchable value
|
# Return the display value as the searchable value
|
||||||
text_value = force_text(value)
|
text_value = force_str(value)
|
||||||
for k, v in self.field.choices:
|
for k, v in self.field.choices:
|
||||||
if isinstance(v, (list, tuple)):
|
if isinstance(v, (list, tuple)):
|
||||||
# This is an optgroup, so look inside the group for options
|
# This is an optgroup, so look inside the group for options
|
||||||
for k2, v2 in v:
|
for k2, v2 in v:
|
||||||
if value == k2 or text_value == force_text(k2):
|
if value == k2 or text_value == force_str(k2):
|
||||||
return [force_text(k), force_text(v2)]
|
return [force_str(k), force_str(v2)]
|
||||||
else:
|
else:
|
||||||
if value == k or text_value == force_text(k):
|
if value == k or text_value == force_str(k):
|
||||||
return [force_text(v)]
|
return [force_str(v)]
|
||||||
return [] # Value was not found in the list of choices
|
return [] # Value was not found in the list of choices
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -518,7 +518,7 @@ class RichTextBlock(FieldBlock):
|
||||||
return RichText(value)
|
return RichText(value)
|
||||||
|
|
||||||
def get_searchable_content(self, value):
|
def get_searchable_content(self, value):
|
||||||
return [force_text(value.source)]
|
return [force_str(value.source)]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
icon = "doc-full"
|
icon = "doc-full"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django import template
|
from django import template
|
||||||
from django.shortcuts import reverse
|
from django.shortcuts import reverse
|
||||||
from django.template.defaulttags import token_kwargs
|
from django.template.defaulttags import token_kwargs
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from wagtail import VERSION, __version__
|
from wagtail import VERSION, __version__
|
||||||
|
@ -130,7 +130,7 @@ class IncludeBlockNode(template.Node):
|
||||||
|
|
||||||
return value.render_as_block(context=new_context)
|
return value.render_as_block(context=new_context)
|
||||||
else:
|
else:
|
||||||
return force_text(value)
|
return force_str(value)
|
||||||
|
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
|
|
|
@ -5,7 +5,7 @@ import unicodedata
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
|
||||||
WAGTAIL_APPEND_SLASH = getattr(settings, 'WAGTAIL_APPEND_SLASH', True)
|
WAGTAIL_APPEND_SLASH = getattr(settings, 'WAGTAIL_APPEND_SLASH', True)
|
||||||
|
@ -70,7 +70,7 @@ def cautious_slugify(value):
|
||||||
This ensures that the result of slugifying e.g. Cyrillic text will not be an empty
|
This ensures that the result of slugifying e.g. Cyrillic text will not be an empty
|
||||||
string, and can thus be safely used as an identifier (albeit not a human-readable one).
|
string, and can thus be safely used as an identifier (albeit not a human-readable one).
|
||||||
"""
|
"""
|
||||||
value = force_text(value)
|
value = force_str(value)
|
||||||
|
|
||||||
# Normalize the string to decomposed unicode form. This causes accented Latin
|
# Normalize the string to decomposed unicode form. This causes accented Latin
|
||||||
# characters to be split into 'base character' + 'accent modifier'; the latter will
|
# characters to be split into 'base character' + 'accent modifier'; the latter will
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.core.exceptions import PermissionDenied
|
||||||
from django.http import HttpResponseBadRequest, JsonResponse
|
from django.http import HttpResponseBadRequest, JsonResponse
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.views.decorators.vary import vary_on_headers
|
from django.views.decorators.vary import vary_on_headers
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ def add(request):
|
||||||
'success': False,
|
'success': False,
|
||||||
|
|
||||||
# https://github.com/django/django/blob/stable/1.6.x/django/forms/util.py#L45
|
# https://github.com/django/django/blob/stable/1.6.x/django/forms/util.py#L45
|
||||||
'error_message': '\n'.join(['\n'.join([force_text(i) for i in v]) for k, v in form.errors.items()]),
|
'error_message': '\n'.join(['\n'.join([force_str(i) for i in v]) for k, v in form.errors.items()]),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
form = DocumentForm(user=request.user)
|
form = DocumentForm(user=request.user)
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.core.exceptions import PermissionDenied
|
||||||
from django.http import HttpResponseBadRequest, JsonResponse
|
from django.http import HttpResponseBadRequest, JsonResponse
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.views.decorators.vary import vary_on_headers
|
from django.views.decorators.vary import vary_on_headers
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ def add(request):
|
||||||
'success': False,
|
'success': False,
|
||||||
|
|
||||||
# https://github.com/django/django/blob/stable/1.6.x/django/forms/util.py#L45
|
# https://github.com/django/django/blob/stable/1.6.x/django/forms/util.py#L45
|
||||||
'error_message': '\n'.join(['\n'.join([force_text(i) for i in v]) for k, v in form.errors.items()]),
|
'error_message': '\n'.join(['\n'.join([force_str(i) for i in v]) for k, v in form.errors.items()]),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
# Instantiate a dummy copy of the form that we can retrieve validation messages and media from;
|
# Instantiate a dummy copy of the form that we can retrieve validation messages and media from;
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.http import HttpResponse, HttpResponsePermanentRedirect, StreamingHt
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.decorators import classonlymethod
|
from django.utils.decorators import classonlymethod
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
from wagtail.images import get_image_model
|
from wagtail.images import get_image_model
|
||||||
|
@ -30,11 +30,11 @@ def generate_signature(image_id, filter_spec, key=None):
|
||||||
# Based on libthumbor hmac generation
|
# Based on libthumbor hmac generation
|
||||||
# https://github.com/thumbor/libthumbor/blob/b19dc58cf84787e08c8e397ab322e86268bb4345/libthumbor/crypto.py#L50
|
# https://github.com/thumbor/libthumbor/blob/b19dc58cf84787e08c8e397ab322e86268bb4345/libthumbor/crypto.py#L50
|
||||||
url = '{}/{}/'.format(image_id, filter_spec)
|
url = '{}/{}/'.format(image_id, filter_spec)
|
||||||
return force_text(base64.urlsafe_b64encode(hmac.new(key, url.encode(), hashlib.sha1).digest()))
|
return force_str(base64.urlsafe_b64encode(hmac.new(key, url.encode(), hashlib.sha1).digest()))
|
||||||
|
|
||||||
|
|
||||||
def verify_signature(signature, image_id, filter_spec, key=None):
|
def verify_signature(signature, image_id, filter_spec, key=None):
|
||||||
return force_text(signature) == generate_signature(image_id, filter_spec, key=key)
|
return force_str(signature) == generate_signature(image_id, filter_spec, key=key)
|
||||||
|
|
||||||
|
|
||||||
def generate_image_url(image, filter_spec, viewname='wagtailimages_serve', key=None):
|
def generate_image_url(image, filter_spec, viewname='wagtailimages_serve', key=None):
|
||||||
|
|
|
@ -72,8 +72,8 @@ def sendfile(request, filename, attachment=False, attachment_filename=None, mime
|
||||||
parts = ['attachment']
|
parts = ['attachment']
|
||||||
if attachment_filename:
|
if attachment_filename:
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str
|
||||||
attachment_filename = force_text(attachment_filename)
|
attachment_filename = force_str(attachment_filename)
|
||||||
ascii_filename = unidecode(attachment_filename)
|
ascii_filename = unidecode(attachment_filename)
|
||||||
parts.append('filename="%s"' % ascii_filename)
|
parts.append('filename="%s"' % ascii_filename)
|
||||||
if ascii_filename != attachment_filename:
|
if ascii_filename != attachment_filename:
|
||||||
|
|
Ładowanie…
Reference in New Issue