remove python 2 style codes

This commit is contained in:
Asif Saif Uddin 2021-10-17 17:01:51 +06:00
parent 2a5156005b
commit 933489a491
7 changed files with 16 additions and 16 deletions

View file

@ -49,7 +49,7 @@ class BaseListAction(Admin2ModelMixin, TemplateView):
objects_name = options.verbose_name_plural
self.objects_name = force_str(objects_name)
super(BaseListAction, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def get_queryset(self):
""" Replaced `get_queryset` from `Admin2ModelMixin`"""
@ -85,7 +85,7 @@ class BaseListAction(Admin2ModelMixin, TemplateView):
""" Utility method when you want to display nested objects
(such as during a bulk update/delete)
"""
context = super(BaseListAction, self).get_context_data()
context = super().get_context_data()
def _format_callback(obj):
opts = utils.model_options(obj)
@ -108,7 +108,7 @@ class BaseListAction(Admin2ModelMixin, TemplateView):
def get(self, request):
if self.item_count > 0:
return super(BaseListAction, self).get(request)
return super().get(request)
message = _(self.empty_message)
messages.add_message(request, messages.INFO, message)
@ -160,7 +160,7 @@ class DeleteSelectedAction(BaseListAction):
def post(self, request):
if request.POST.get('confirmed'):
super(DeleteSelectedAction, self).post(request)
super().post(request)
else:
# The user has not confirmed that they want to delete the
# objects, so render a template asking for their confirmation.

View file

@ -17,7 +17,7 @@ class Admin2APISerializer(serializers.HyperlinkedModelSerializer):
__unicode__ = fields.ReadOnlyField(source='__str__')
def get_extra_kwargs(self):
extra_kwargs = super(Admin2APISerializer, self).get_extra_kwargs()
extra_kwargs = super().get_extra_kwargs()
extra_kwargs.update({
'url': {'view_name': self._get_default_view_name(self.Meta.model)}
})
@ -56,7 +56,7 @@ class Admin2APIMixin(Admin2Mixin):
fields = '__all__'
return ModelAPISerilizer
return super(Admin2APIMixin, self).get_serializer_class()
return super().get_serializer_class()
class IndexAPIView(Admin2APIMixin, APIView):

View file

@ -14,7 +14,7 @@ from . import utils
from . import views
class Admin2(object):
class Admin2:
"""
The base Admin2 object.
It keeps a registry of all registered Models and collects the urls of their
@ -137,7 +137,7 @@ class Admin2(object):
for object_admin in self.registry.values():
if object_admin.name == name:
return object_admin
raise ValueError(u"No object admin found with name {}".format(repr(name)))
raise ValueError("No object admin found with name {}".format(repr(name)))
def get_index_kwargs(self):
return {

View file

@ -5,7 +5,7 @@ from ..actions import get_description
from .models import Thing
class TestAction(object):
class TestAction:
description = "Test Action Class"

View file

@ -73,12 +73,12 @@ class TagsTests(TestCase):
formset = TagsTestFormSet()
self.assertEqual(
admin2_tags.formset_visible_fieldlist(formset),
[u'Visible 1', u'Visible 2']
['Visible 1', 'Visible 2']
)
def test_verbose_name_for(self):
app_verbose_names = {
u'app_one_label': 'App One Verbose Name',
'app_one_label': 'App One Verbose Name',
}
self.assertEqual(
"App One Verbose Name",

View file

@ -6,7 +6,7 @@ from ..core import Admin2
from .models import BigThing
class ModelAdmin(object):
class ModelAdmin:
model_admin_attributes = ['a', 'b', 'c']
a = 1 # covered
b = 2 # covered
@ -73,7 +73,7 @@ class ModelAdminTest(TestCase):
admin_instance.get_urls()
except TypeError as e:
message = u"Cannot instantiate admin view " \
message = "Cannot instantiate admin view " \
'"ModelAdmin2.None". The error that got raised was: ' \
"'NoneType' object has no attribute 'as_view'"
self.assertEqual(e.args[0], message)

View file

@ -119,7 +119,7 @@ class UtilsTest(TestCase):
)
def test_get_attr_callable(self):
class Klass(object):
class Klass:
def hello(self):
return "hello"
@ -129,7 +129,7 @@ class UtilsTest(TestCase):
)
def test_get_attr_str(self):
class Klass(object):
class Klass:
def __str__(self):
return "str"
@ -142,7 +142,7 @@ class UtilsTest(TestCase):
)
def test_get_attr(self):
class Klass(object):
class Klass:
attr = "value"
self.assertEqual(