Replace __unicode__ functions by python_2_unicode_compatible decorator

This commit is contained in:
Floréal Cabanettes
2017-07-24 14:49:42 +02:00
parent 908faba24a
commit 54a8dc6aab
3 changed files with 4 additions and 20 deletions
+1 -3
View File
@@ -315,6 +315,7 @@ class MXQuerySet(models.QuerySet):
return self.exists()
@python_2_unicode_compatible
class MXRecord(models.Model):
"""A model used to store MX records for Domain."""
@@ -331,9 +332,6 @@ class MXRecord(models.Model):
return False
return bool(param_tools.get_global_parameter("valid_mxs").strip())
def __unicode__(self):
return u"{0.name} ({0.address}) for {0.domain} ".format(self)
def __str__(self):
return "{0.name} ({0.address}) for {0.domain} ".format(self)
+1 -5
View File
@@ -405,6 +405,7 @@ def populate_callback(user, group="SimpleUsers"):
sender="populate_callback", user=user)
@python_2_unicode_compatible
class ObjectAccess(models.Model):
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType)
@@ -415,11 +416,6 @@ class ObjectAccess(models.Model):
class Meta(object):
unique_together = (("user", "content_type", "object_id"),)
def __unicode__(self):
return "%s => %s (%s)" % (
self.user, self.content_object, self.content_type
)
def __str__(self):
return "%s => %s (%s)" % (
self.user, self.content_object, self.content_type
+2 -12
View File
@@ -13,7 +13,7 @@ from django.forms.fields import Field
from django.forms.widgets import RadioSelect
from django.forms.widgets import RadioChoiceInput
from django.shortcuts import render
from django.utils.encoding import force_text, force_str
from django.utils.encoding import python_2_unicode_compatible, force_text, force_str
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _, ugettext_lazy
@@ -370,20 +370,10 @@ class TabForms(object):
#
@python_2_unicode_compatible
class CustomRadioInput(RadioChoiceInput):
"""Custom radio input."""
def __unicode__(self):
if "id" in self.attrs:
label_for = ' for="%s"' % self.attrs["id"]
else:
label_for = ""
choice_label = conditional_escape(force_text(self.choice_label))
return mark_safe(
u"<label class='radio-inline' %s>%s %s</label>"
% (label_for, self.tag(), choice_label)
)
def __str__(self):
if "id" in self.attrs:
label_for = ' for="%s"' % self.attrs["id"]