Skip to content

Commit

Permalink
WIP | Fix more django2.0 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hipek8 committed Jun 20, 2024
1 parent f2129e8 commit 4df1479
Show file tree
Hide file tree
Showing 50 changed files with 116 additions and 77 deletions.
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ django-cryptography==0.3
django-extensions==2.2.9
django-filter==1.0.4
django-import-export==1.2.0
django-money==0.12
django-money==0.12.3
django-mptt==0.8.7
django-reversion==3.0.5
django-rq==2.0
django-sitetree==1.13.0
django-taggit-serializer==0.1.7
django-taggit==0.22.2
django-threadlocals==0.8
djangorestframework==3.4.1
djangorestframework==3.5.4
djangorestframework_xml==1.2.0
drf-nested-routers==0.11.1
factory-boy==2.11.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r test.txt
django-debug-toolbar==1.8
django-debug-toolbar==1.11
werkzeug==0.16.1
pudb
ipython
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def users_list(self, obj):

def formfield_for_manytomany(self, db_field, request=None, **kwargs):
if db_field.name == 'permissions':
qs = kwargs.get('queryset', db_field.rel.to.objects)
qs = kwargs.get('queryset', db_field.remote_field.model.objects)
if qs:
qs = self._simplify_permissions(qs)
kwargs['queryset'] = qs
Expand Down
1 change: 1 addition & 0 deletions src/ralph/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RalphUserViewSet(RalphAPIViewSet):
class RegionSerializer(RalphAPISerializer):
class Meta:
model = Region
fields = "__all__"


class RegionViewSet(RalphAPIViewSet):
Expand Down
4 changes: 2 additions & 2 deletions src/ralph/accounts/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_tag_asset(self):
}, follow=True
)

self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
for t in self.tags:
self.assertIn(t, self.asset.tags.names())

Expand All @@ -229,7 +229,7 @@ def test_ownership_verification(self):
'answer': 'yes'
}, follow=True
)
self.assertEquals(response.status_code, 403)
self.assertEqual(response.status_code, 403)


class RalphUserAdminTests(TestCase, ClientMixin):
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/admin/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def dispatch(self, request, *args, **kwargs):
return HttpResponseBadRequest('Model not found')

self.field = model._meta.get_field(kwargs['field'])
self.model = self.field.rel.to
self.model = self.field.remote_field.model
self.query = request.GET.get(QUERY_PARAM, None)
if not self.query:
return HttpResponseBadRequest()
Expand Down
8 changes: 4 additions & 4 deletions src/ralph/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ def queryset(self, request, queryset):
"""
if self.value():
try:
root = self.field.rel.to.objects.get(pk=self.value())
except self.field.rel.to.DoesNotExist:
root = self.field.remote_field.model.objects.get(pk=self.value())
except self.field.remote_field.model.DoesNotExist:
_add_incorrect_value_message(request, self.title)
raise IncorrectLookupParameters()
else:
Expand All @@ -483,8 +483,8 @@ class TreeRelatedAutocompleteFilterWithDescendants(
"""
def _get_descendants(self, request, root_id):
try:
root = self.field.rel.to.objects.get(pk=root_id)
except self.field.rel.to.DoesNotExist:
root = self.field.remote_field.model.objects.get(pk=root_id)
except self.field.remote_field.model.DoesNotExist:
_add_incorrect_value_message(request, self.title)
raise IncorrectLookupParameters()
return root.get_descendants(include_self=True)
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/admin/m2m.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def save_new(self, form, commit=True):

@classmethod
def get_default_prefix(cls):
return cls.m2m.rel.get_accessor_name(model=cls.model).replace("+", "")
return cls.m2m.remote_field.get_accessor_name(model=cls.model).replace("+", "")

def save_existing_objects(self, commit=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/admin/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def get_context_data(self, **kwargs):
context['site_header'] = settings.ADMIN_SITE_HEADER
context['site_title'] = settings.ADMIN_SITE_TITLE
# checks if user is allowed to see elements in template
context['has_permission'] = self.request.user.is_authenticated()
context['has_permission'] = self.request.user.is_authenticated
return context


Expand Down
2 changes: 1 addition & 1 deletion src/ralph/admin/tests/tests_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_tree_related_field_with_descendants(self):
field=(
DataCenterAsset._meta.get_field(
'configuration_path'
).rel.to._meta.get_field('module')
).remote_field.model._meta.get_field('module')
),
request=None,
params={
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/admin/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_ordering_from_related_model_admin(self, prefix, field_name):
if not field:
return fields
try:
model_admin = admin_site._registry[field.field.rel.to]
model_admin = admin_site._registry[field.field.remote_field.model]
except (AttributeError, KeyError):
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __new__(cls, name, bases, attrs):

if model and issubclass(model, AdminAbsoluteUrlMixin):
attrs['ui_url'] = AbsoluteUrlField()
if fields:
if fields and isinstance(fields, (list, tuple)):
meta.fields += ('ui_url',)
return super().__new__(cls, name, bases, attrs)

Expand Down
1 change: 1 addition & 0 deletions src/ralph/api/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Meta:
'view_name': 'test-ralph-api:foo-detail'
}
}
fields = "__all__"


class BarSerializer(RalphAPISerializer):
Expand Down
8 changes: 8 additions & 0 deletions src/ralph/assets/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class OwnersFromServiceEnvSerializerMixin(RalphAPISerializer):
class BusinessSegmentSerializer(RalphAPISerializer):
class Meta:
model = BusinessSegment
fields = "__all__"


class BudgetInfoSerializer(RalphAPISerializer):
Expand All @@ -78,6 +79,7 @@ class Meta:
class EnvironmentSerializer(RalphAPISerializer):
class Meta:
model = Environment
fields = "__all__"


class SaveServiceSerializer(
Expand Down Expand Up @@ -115,6 +117,7 @@ class SaveServiceSerializer(

class Meta:
model = Service
fields = "__all__"

@transaction.atomic
def _save_environments(self, instance, environments):
Expand Down Expand Up @@ -161,6 +164,7 @@ class ServiceSerializer(RalphAPISerializer):
class Meta:
model = Service
depth = 1
fields = "__all__"


class ServiceEnvironmentSimpleSerializer(RalphAPISerializer):
Expand Down Expand Up @@ -200,6 +204,7 @@ class Meta:
class ManufacturerSerializer(RalphAPISerializer):
class Meta:
model = Manufacturer
fields = "__all__"


class ManufacturerKindSerializer(RalphAPISerializer):
Expand All @@ -215,6 +220,7 @@ class CategorySerializer(RalphAPISerializer):

class Meta:
model = Category
fields = "__all__"


class AssetModelSerializer(WithCustomFieldsSerializerMixin, RalphAPISerializer):
Expand All @@ -237,6 +243,7 @@ class AssetModelSaveSerializer(RalphAPISaveSerializer):

class Meta:
model = AssetModel
fields = "__all__"


class BaseObjectPolymorphicSerializer(
Expand Down Expand Up @@ -351,6 +358,7 @@ class EthernetSerializer(EthernetSimpleSerializer):
class Meta:
model = Ethernet
depth = 1
fields = "__all__"


class MemorySimpleSerializer(RalphAPISerializer):
Expand Down
4 changes: 2 additions & 2 deletions src/ralph/assets/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _update_service_owners(service, business_owners, technical_owners):
username__in=[i['username'] for i in technical_owners]
)

service.business_owners = business_owners
service.technical_owners = technical_owners
service.business_owners.set([business_owners])
service.technical_owners.set([technical_owners])


def _update_service_environments(service, environments):
Expand Down
3 changes: 2 additions & 1 deletion src/ralph/back_office/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django import forms
from django.apps import apps
from django.conf import settings
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

from ralph.admin.decorators import register
Expand Down Expand Up @@ -283,6 +284,7 @@ def get_multiadd_fields(self, obj=None):
)
return multi_add_fields

@mark_safe
def get_user(self, obj):
if not obj.user_id:
return '-'
Expand All @@ -294,7 +296,6 @@ def get_user(self, obj):
)
get_user.short_description = _('User')
get_user.admin_order_field = 'get_user'
get_user.allow_tags = True


@register(Warehouse)
Expand Down
10 changes: 5 additions & 5 deletions src/ralph/back_office/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def test_try_assign_hostname_category_without_code(self):

def test_get_autocomplete_queryset(self):
queryset = BackOfficeAsset.get_autocomplete_queryset()
self.assertEquals(1, queryset.count())
self.assertEqual(1, queryset.count())

def test_buyout_date(self):
self.assertEqual(
Expand Down Expand Up @@ -490,7 +490,7 @@ def test_assign_hostname_doesnt_assign_hostname_when_its_empty(self):
target=BackOfficeAssetStatus.used.id,
actions=['assign_hostname_if_empty_or_country_not_match']
)
self.assertEquals(self.bo_asset.hostname, hostname)
self.assertEqual(self.bo_asset.hostname, hostname)

run_field_transition(
[self.bo_asset],
Expand All @@ -517,7 +517,7 @@ def test_assign_hostname_assigns_hostname_when_its_empty(self):
target=BackOfficeAssetStatus.used.id,
actions=['assign_hostname_if_empty_or_country_not_match']
)
self.assertEquals(self.bo_asset.hostname, hostname)
self.assertEqual(self.bo_asset.hostname, hostname)

run_field_transition(
[self.bo_asset],
Expand All @@ -544,7 +544,7 @@ def test_assign_hostname_skips_hostname_when_its_already_set(self):
target=BackOfficeAssetStatus.used.id,
actions=['assign_hostname_if_empty_or_country_not_match']
)
self.assertEquals(self.bo_asset.hostname, hostname)
self.assertEqual(self.bo_asset.hostname, hostname)

run_field_transition(
[self.bo_asset],
Expand All @@ -554,7 +554,7 @@ def test_assign_hostname_skips_hostname_when_its_already_set(self):
requester=self.request.user
)

self.assertEquals(self.bo_asset.hostname, hostname)
self.assertEqual(self.bo_asset.hostname, hostname)

def test_return_report_when_user_not_assigned(self):
_, transition, _ = self._create_transition(
Expand Down
1 change: 1 addition & 0 deletions src/ralph/configuration_management/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class SCMInfoSerializer(RalphAPISerializer):
class Meta:
model = SCMStatusCheck
fields = "__all__"


class SCMInfoSaveSerializer(RalphAPISaveSerializer):
Expand Down
3 changes: 1 addition & 2 deletions src/ralph/dashboards/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import logging
from urllib.parse import urlencode

from django.urls import NoReverseMatch, reverse
from django.template.loader import render_to_string
from django.urls import NoReverseMatch, reverse
from django.utils.safestring import mark_safe

from ralph.dashboards.helpers import encode_params, normalize_value


logger = logging.getLogger(__name__)
GRAPH_QUERY_SEP = '|'

Expand Down
3 changes: 2 additions & 1 deletion src/ralph/data_center/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import Prefetch, Q
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

from ralph.admin import filters
Expand Down Expand Up @@ -727,12 +728,12 @@ def __init__(self, model, *args, **kwargs):
def _initialize_search_form(self, extra_context, fields_from_model=True):
return super()._initialize_search_form(extra_context)

@mark_safe
def show_location(self, obj):
if hasattr(obj, 'get_location'):
return ' / '.join(obj.get_location())
return ''
show_location.short_description = _('Location')
show_location.allow_tags = True

def get_queryset(self, request):
qs = super().get_queryset(request)
Expand Down
6 changes: 5 additions & 1 deletion src/ralph/data_center/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ class Meta:
class AccessorySerializer(RalphAPISerializer):
class Meta:
model = Accessory
fields = "__all__"


class RackAccessorySerializer(RalphAPISerializer):
name = serializers.ReadOnlyField(source='accessory.name')

class Meta:
model = RackAccessory
fields = "__all__"


class SimpleRackSerializer(RalphAPISerializer):
Expand All @@ -119,6 +121,7 @@ class Meta:
model = DataCenterAsset
fields = ['hostname', 'url']
_skip_tags_field = True
fields = "__all__"


class DataCenterAssetSerializer(ComponentSerializerMixin, AssetSerializer):
Expand Down Expand Up @@ -177,8 +180,9 @@ class DataCenterAssetSaveSerializer(RalphAPISaveSerializer):
queryset=Rack.objects.all()
)

class Meta(object):
class Meta:
model = DataCenterAsset
fields = "__all__"


class DatabaseSerializer(BaseObjectSerializer):
Expand Down
10 changes: 4 additions & 6 deletions src/ralph/data_center/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ def setUp(self):
model=self.model,
service_env__environment__name='some_env'
)
self.dc_asset.service_env.service.business_owners = [self.user1]
self.dc_asset.service_env.service.technical_owners = [self.user2]
self.dc_asset.service_env.save()
self.dc_asset.service_env.service.business_owners.set([self.user1])
self.dc_asset.service_env.service.technical_owners.set([self.user2])
self.ip = IPAddressFactory(
ethernet=EthernetFactory(base_object=self.dc_asset)
)
Expand Down Expand Up @@ -509,9 +508,8 @@ def setUp(self):
is_master=True
)
self.cluster_2 = ClusterFactory()
self.cluster_1.service_env.service.business_owners = [self.user1]
self.cluster_1.service_env.service.technical_owners = [self.user2]
self.cluster_1.service_env.save()
self.cluster_1.service_env.service.business_owners.set([self.user1])
self.cluster_1.service_env.service.technical_owners.set([self.user2])
self.cluster_1.management_ip = '10.20.30.40'

def test_create_cluster(self):
Expand Down
Loading

0 comments on commit 4df1479

Please sign in to comment.