Skip to content

Commit

Permalink
Change force_text to force_str for django
Browse files Browse the repository at this point in the history
  • Loading branch information
oleast committed Mar 29, 2020
1 parent 3876c5c commit a4025dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions apps/dashboard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.forms.utils import format_html
from django.forms.widgets import TextInput
from django.utils.encoding import force_text
from django.utils.encoding import force_str

DATEPICKER_WIDGET_STRING = """
<div class="input-group dp">\r\n
Expand Down Expand Up @@ -105,7 +105,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = format_html(
'value="{}"', force_text(self.format_value(value))
'value="{}"', force_str(self.format_value(value))
)
else:
final_attrs["value"] = ""
Expand All @@ -114,13 +114,13 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs["placeholder"] = "Vennligst velg en dato ..."
if attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(attrs.get("placeholder"))

return format_html(
DATEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)

Expand Down Expand Up @@ -149,21 +149,21 @@ def render(self, name, value, attrs=None, renderer=None):
attrs = self.build_attrs(self.attrs, attrs)
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = force_text(self.format_value(value))
final_attrs["value"] = force_str(self.format_value(value))
else:
final_attrs["value"] = ""

# Kept for backwards compatibility with existing forms.
final_attrs["placeholder"] = "Vennligst velg dato og klokkeslett ..."
if self.attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(self.attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(self.attrs.get("placeholder"))

return format_html(
DATETIMEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)

Expand Down Expand Up @@ -193,7 +193,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = format_html(
'value="{}"', force_text(self.format_value(value))
'value="{}"', force_str(self.format_value(value))
)
else:
final_attrs["value"] = ""
Expand All @@ -202,12 +202,12 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs["placeholder"] = "Vennligst velg klokkeslett ..."
if attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(attrs.get("placeholder"))

return format_html(
TIMEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)
4 changes: 2 additions & 2 deletions apps/gallery/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.forms import HiddenInput, TextInput
from django.forms.utils import flatatt, format_html
from django.urls import reverse_lazy
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from apps.gallery.models import ResponsiveImage

Expand Down Expand Up @@ -62,7 +62,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
# Only add the value attribute if the value is non-empty
final_attrs["value"] = force_text(self.format_value(value))
final_attrs["value"] = force_str(self.format_value(value))
img = ResponsiveImage.objects.get(pk=value)
img_thumb = format_html(
'<img src="{}" alt title="{}"/>',
Expand Down

0 comments on commit a4025dc

Please sign in to comment.