py3: use @six.python_2_unicode_compatible
Put the @six.python_2_unicode_compatible decorator on classes defining a __unicode__() method to support Python 3, and rename __unicode__() to __str__(). Partial-Implements: blueprint porting-python3 Change-Id: I0be33e1a777c98e02140ef9eafaf0c1068a7f408
This commit is contained in:
parent
3b67a817c8
commit
c25d76646d
@ -306,6 +306,7 @@ class Panel(HorizonComponent):
|
||||
return urlpatterns, self.slug, self.slug
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class PanelGroup(object):
|
||||
"""A container for a set of :class:`~horizon.Panel` classes.
|
||||
|
||||
@ -336,7 +337,7 @@ class PanelGroup(object):
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def __iter__(self):
|
||||
|
@ -154,6 +154,7 @@ class ServiceCatalogException(HorizonException):
|
||||
super(ServiceCatalogException, self).__init__(message)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class AlreadyExists(HorizonException):
|
||||
"""Exception to be raised when trying to create an API resource which
|
||||
already exists.
|
||||
@ -168,9 +169,6 @@ class AlreadyExists(HorizonException):
|
||||
def __str__(self):
|
||||
return self.msg % self.attrs
|
||||
|
||||
def __unicode__(self):
|
||||
return self.msg % self.attrs
|
||||
|
||||
|
||||
class ConfigurationError(HorizonException):
|
||||
"""Exception to be raised when invalid settings have been provided."""
|
||||
|
@ -49,6 +49,7 @@ PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
|
||||
STRING_SEPARATOR = "__"
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Column(html.HTMLElement):
|
||||
"""A class which represents a single column in a :class:`.DataTable`.
|
||||
|
||||
@ -335,7 +336,7 @@ class Column(html.HTMLElement):
|
||||
if self.link is not None:
|
||||
self.classes.append('anchor')
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return six.text_type(self.verbose_name)
|
||||
|
||||
def __repr__(self):
|
||||
@ -1124,6 +1125,7 @@ class DataTableMetaclass(type):
|
||||
return type.__new__(mcs, name, bases, dt_attrs)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
@six.add_metaclass(DataTableMetaclass)
|
||||
class DataTable(object):
|
||||
"""A class which defines a table with all data and associated actions.
|
||||
@ -1176,7 +1178,7 @@ class DataTable(object):
|
||||
self.needs_summary_row = any([col.summation
|
||||
for col in self.columns.values()])
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return six.text_type(self._meta.verbose_name)
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -74,6 +74,7 @@ class ActionMetaclass(forms.forms.DeclarativeFieldsMetaclass):
|
||||
return cls
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
@six.add_metaclass(ActionMetaclass)
|
||||
class Action(forms.Form):
|
||||
"""An ``Action`` represents an atomic logical interaction you can have with
|
||||
@ -138,7 +139,7 @@ class Action(forms.Form):
|
||||
self._populate_choices(request, context)
|
||||
self.required_css_class = 'required'
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return force_text(self.name)
|
||||
|
||||
def __repr__(self):
|
||||
@ -189,6 +190,7 @@ class MembershipAction(Action):
|
||||
return self.slug + "_role_" + role_id
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Step(object):
|
||||
"""A step is a wrapper around an action which defines its context in a
|
||||
workflow. It knows about details such as:
|
||||
@ -284,7 +286,7 @@ class Step(object):
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return force_text(self.name)
|
||||
|
||||
def __init__(self, workflow):
|
||||
@ -484,6 +486,7 @@ class UpdateMembersStep(Step):
|
||||
return self.slug + "_role_" + role_id
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
@six.add_metaclass(WorkflowMetaclass)
|
||||
class Workflow(html.HTMLElement):
|
||||
"""A Workflow is a collection of Steps. Its interface is very
|
||||
@ -600,7 +603,7 @@ class Workflow(html.HTMLElement):
|
||||
fullscreen = False
|
||||
_registerable_class = Step
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -22,6 +22,7 @@ import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
@ -76,6 +77,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Service(base.APIDictWrapper):
|
||||
"""Wrapper for a dict based on the service data from keystone."""
|
||||
_attrs = ['id', 'type', 'name']
|
||||
@ -92,7 +94,7 @@ class Service(base.APIDictWrapper):
|
||||
self.disabled = None
|
||||
self.region = region
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
if(self.type == "identity"):
|
||||
return _("%(type)s (%(backend)s backend)") \
|
||||
% {"type": self.type, "backend": keystone_backend_name()}
|
||||
|
@ -29,6 +29,7 @@ from django.utils.datastructures import SortedDict
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from neutronclient.common import exceptions as neutron_exc
|
||||
from neutronclient.v2_0 import client as neutron_client
|
||||
import six
|
||||
|
||||
from horizon import messages
|
||||
from horizon.utils.memoized import memoized # noqa
|
||||
@ -175,6 +176,7 @@ class SecurityGroup(NeutronAPIDictWrapper):
|
||||
return {k: self._apidict[k] for k in self._apidict if k != 'rules'}
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class SecurityGroupRule(NeutronAPIDictWrapper):
|
||||
# Required attributes:
|
||||
# id, parent_group_id
|
||||
@ -215,7 +217,7 @@ class SecurityGroupRule(NeutronAPIDictWrapper):
|
||||
rule['group'] = {'name': group} if group else {}
|
||||
super(SecurityGroupRule, self).__init__(rule)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
if 'name' in self.group:
|
||||
remote = self.group['name']
|
||||
elif 'cidr' in self.ip_range:
|
||||
|
@ -25,6 +25,7 @@ import logging
|
||||
from django.conf import settings
|
||||
from django.utils.functional import cached_property # noqa
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import six
|
||||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from novaclient.v2 import client as nova_client
|
||||
@ -218,12 +219,13 @@ class SecurityGroup(base.APIResourceWrapper):
|
||||
return self._apiresource.to_dict()
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class SecurityGroupRule(base.APIResourceWrapper):
|
||||
"""Wrapper for individual rules in a SecurityGroup."""
|
||||
|
||||
_attrs = ['id', 'ip_protocol', 'from_port', 'to_port', 'ip_range', 'group']
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
if 'name' in self.group:
|
||||
vals = {'from': self.from_port,
|
||||
'to': self.to_port,
|
||||
|
@ -13,6 +13,7 @@
|
||||
from django.contrib.humanize.templatetags import humanize
|
||||
from django.utils import text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import six
|
||||
|
||||
from horizon import tables
|
||||
|
||||
@ -58,6 +59,7 @@ class ReportTable(tables.DataTable):
|
||||
multi_select = False
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class UsageTable(tables.DataTable):
|
||||
service = tables.Column('service', verbose_name=_('Service'))
|
||||
meter = tables.Column('meter', verbose_name=_('Meter'))
|
||||
@ -83,7 +85,7 @@ class UsageTable(tables.DataTable):
|
||||
else:
|
||||
return self.title
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user