mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Code style improvements (#4683)
* fix list comps * mopre comp fixes * reduce computing cost on any() calls * add bugbear * check for clean imports * only allow limited relative imports * fix notification method lookup * fix notification method assigement * rewrite assigment * fix upstream changes to new style * fix upstream change to new coding style
This commit is contained in:
@ -3,13 +3,13 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import import_export.widgets as widgets
|
||||
from import_export import widgets
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from import_export.fields import Field
|
||||
|
||||
import part.models as models
|
||||
from company.models import SupplierPart
|
||||
from InvenTree.admin import InvenTreeResource
|
||||
from part import models
|
||||
from stock.models import StockLocation
|
||||
|
||||
|
||||
|
@ -1140,10 +1140,10 @@ class PartList(PartMixin, APIDownloadMixin, ListCreateAPI):
|
||||
|
||||
if related is not None:
|
||||
# Only return related results
|
||||
queryset = queryset.filter(pk__in=[pk for pk in part_ids])
|
||||
queryset = queryset.filter(pk__in=list(part_ids))
|
||||
elif exclude_related is not None:
|
||||
# Exclude related results
|
||||
queryset = queryset.exclude(pk__in=[pk for pk in part_ids])
|
||||
queryset = queryset.exclude(pk__in=list(part_ids))
|
||||
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
@ -89,14 +89,15 @@ class PartCategory(MetadataMixin, InvenTreeTree):
|
||||
|
||||
for child_category in self.children.all():
|
||||
if kwargs.get('delete_child_categories', False):
|
||||
child_category.delete_recursive(**dict(delete_child_categories=True,
|
||||
delete_parts=delete_parts,
|
||||
parent_category=parent_category))
|
||||
child_category.delete_recursive(**{
|
||||
"delete_child_categories": True,
|
||||
"delete_parts": delete_parts,
|
||||
"parent_category": parent_category})
|
||||
else:
|
||||
child_category.parent = parent_category
|
||||
child_category.save()
|
||||
|
||||
super().delete(*args, **dict())
|
||||
super().delete(*args, **{})
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""Custom model deletion routine, which updates any child categories or parts.
|
||||
@ -104,9 +105,10 @@ class PartCategory(MetadataMixin, InvenTreeTree):
|
||||
This must be handled within a transaction.atomic(), otherwise the tree structure is damaged
|
||||
"""
|
||||
with transaction.atomic():
|
||||
self.delete_recursive(**dict(delete_parts=kwargs.get('delete_parts', False),
|
||||
delete_child_categories=kwargs.get('delete_child_categories', False),
|
||||
parent_category=self.parent))
|
||||
self.delete_recursive(**{
|
||||
"delete_parts": kwargs.get('delete_parts', False),
|
||||
"delete_child_categories": kwargs.get('delete_child_categories', False),
|
||||
"parent_category": self.parent})
|
||||
|
||||
if self.parent is not None:
|
||||
# Partially rebuild the tree (cheaper than a complete rebuild)
|
||||
@ -275,7 +277,7 @@ class PartCategory(MetadataMixin, InvenTreeTree):
|
||||
for result in queryset:
|
||||
subscribers.add(result.user)
|
||||
|
||||
return [s for s in subscribers]
|
||||
return list(subscribers)
|
||||
|
||||
def is_starred_by(self, user, **kwargs):
|
||||
"""Returns True if the specified user subscribes to this category."""
|
||||
@ -1195,7 +1197,7 @@ class Part(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, MPTTModel)
|
||||
for sub in self.category.get_subscribers():
|
||||
subscribers.add(sub)
|
||||
|
||||
return [s for s in subscribers]
|
||||
return list(subscribers)
|
||||
|
||||
def is_starred_by(self, user, **kwargs):
|
||||
"""Return True if the specified user subscribes to this part."""
|
||||
|
@ -1340,7 +1340,7 @@ class BomImportExtractSerializer(DataFileExtractSerializer):
|
||||
|
||||
part_columns = ['part', 'part_name', 'part_ipn', 'part_id']
|
||||
|
||||
if not any([col in self.columns for col in part_columns]):
|
||||
if not any(col in self.columns for col in part_columns):
|
||||
# At least one part column is required!
|
||||
raise serializers.ValidationError(_("No part column specified"))
|
||||
|
||||
|
@ -208,7 +208,7 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
url,
|
||||
{
|
||||
'columns': dataset.headers,
|
||||
'rows': [row for row in dataset],
|
||||
'rows': list(dataset),
|
||||
},
|
||||
)
|
||||
|
||||
@ -249,7 +249,7 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
url,
|
||||
{
|
||||
'columns': dataset.headers,
|
||||
'rows': [row for row in dataset],
|
||||
'rows': list(dataset),
|
||||
},
|
||||
expected_code=201,
|
||||
)
|
||||
@ -276,7 +276,7 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
url,
|
||||
{
|
||||
'columns': dataset.headers,
|
||||
'rows': [row for row in dataset],
|
||||
'rows': list(dataset),
|
||||
},
|
||||
expected_code=201,
|
||||
)
|
||||
@ -308,7 +308,7 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
response = self.post(
|
||||
url,
|
||||
{
|
||||
'rows': [row for row in dataset],
|
||||
'rows': list(dataset),
|
||||
'columns': dataset.headers,
|
||||
},
|
||||
expected_code=201,
|
||||
|
Reference in New Issue
Block a user