Fixing python style errors
This commit is contained in:
Oliver 2018-04-16 01:02:17 +10:00
parent 1027e812bc
commit a91ff58d84
24 changed files with 74 additions and 97 deletions

View File

@ -7,6 +7,7 @@ from rest_framework.exceptions import ValidationError
from django.db.models.signals import pre_delete
from django.dispatch import receiver
class Company(models.Model):
""" Abstract model representing an external company
"""
@ -185,7 +186,7 @@ class InvenTreeTree(models.Model):
@receiver(pre_delete, sender=InvenTreeTree, dispatch_uid='tree_pre_delete_log')
def before_delete_tree_item(sender, intance, using, **kwargs):
def before_delete_tree_item(sender, instance, using, **kwargs):
# Update each tree item below this one
for child in instance.children.all():

View File

@ -1,17 +1,14 @@
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework.documentation import include_docs_urls
from part.urls import part_api_urls, part_cat_api_urls
from part.urls import bom_api_urls
from part.urls import part_urls
from stock.urls import stock_api_urls, stock_api_loc_urls
from stock.urls import stock_urls
#from supplier.urls import supplier_api_urls, supplier_api_part_urls
# from supplier.urls import supplier_api_urls, supplier_api_part_urls
from supplier.urls import supplier_urls
from django.conf import settings
@ -21,8 +18,8 @@ from django.views.generic.base import RedirectView
from track.urls import tracking_urls
#from project.urls import prj_urls, prj_part_urls, prj_cat_urls, prj_run_urls
#from track.urls import unique_urls, part_track_urls
# from project.urls import prj_urls, prj_part_urls, prj_cat_urls, prj_run_urls
# from track.urls import unique_urls, part_track_urls
from users.urls import user_urls
@ -37,28 +34,28 @@ apipatterns = [
# Part URLs
url(r'^part/', include(part_api_urls)),
url(r'^part-category/', include(part_cat_api_urls)),
#url(r'^part-param/', include(part_param_urls)),
#url(r'^part-param-template/', include(part_param_template_urls)),
# url(r'^part-param/', include(part_param_urls)),
# url(r'^part-param-template/', include(part_param_template_urls)),
# Part BOM URLs
url(r'^bom/', include(bom_api_urls)),
# Supplier URLs
#url(r'^supplier/', include(supplier_api_urls)),
#url(r'^supplier-part/', include(supplier_api_part_urls)),
#url(r'^price-break/', include(price_break_urls)),
#url(r'^manufacturer/', include(manu_urls)),
#url(r'^customer/', include(cust_urls)),
# url(r'^supplier/', include(supplier_api_urls)),
# url(r'^supplier-part/', include(supplier_api_part_urls)),
# url(r'^price-break/', include(price_break_urls)),
# url(r'^manufacturer/', include(manu_urls)),
# url(r'^customer/', include(cust_urls)),
# Tracking URLs
#url(r'^track/', include(part_track_urls)),
#url(r'^unique-part/', include(unique_urls)),
# url(r'^track/', include(part_track_urls)),
# url(r'^unique-part/', include(unique_urls)),
# Project URLs
#url(r'^project/', include(prj_urls)),
#url(r'^project-category/', include(prj_cat_urls)),
#url(r'^project-part/', include(prj_part_urls)),
#url(r'^project-run/', include(prj_run_urls)),
# url(r'^project/', include(prj_urls)),
# url(r'^project-category/', include(prj_cat_urls)),
# url(r'^project-part/', include(prj_part_urls)),
# url(r'^project-run/', include(prj_run_urls)),
# User URLs
url(r'^user/', include(user_urls)),
@ -67,8 +64,8 @@ apipatterns = [
urlpatterns = [
# API URL
#url(r'^api/', include(apipatterns)),
#url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
# url(r'^api/', include(apipatterns)),
# url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
url(r'^part/', include(part_urls)),
url(r'^stock/', include(stock_urls)),
@ -87,4 +84,4 @@ if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# Send any unknown URLs to the parts page
urlpatterns += [url(r'^.*$', RedirectView.as_view(url='part/', permanent=False), name='part-index')]
urlpatterns += [url(r'^.*$', RedirectView.as_view(url='part/', permanent=False), name='part-index')]

View File

@ -5,7 +5,7 @@ from .models import PartCategory, Part
from .models import BomItem
from .models import PartAttachment
#class PartAdmin(admin.ModelAdmin):
class PartAdmin(ImportExportModelAdmin):
list_display = ('name', 'IPN', 'description', 'stock', 'category')
@ -15,13 +15,15 @@ class PartCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'pathstring', 'description')
#class BomItemAdmin(admin.ModelAdmin):
class BomItemAdmin(ImportExportModelAdmin):
list_display=('part', 'sub_part', 'quantity')
list_display = ('part', 'sub_part', 'quantity')
class PartAttachmentAdmin(admin.ModelAdmin):
list_display = ('part', 'attachment')
"""
class ParameterTemplateAdmin(admin.ModelAdmin):
list_display = ('name', 'units', 'format')
@ -36,6 +38,6 @@ admin.site.register(PartCategory, PartCategoryAdmin)
admin.site.register(BomItem, BomItemAdmin)
admin.site.register(PartAttachment, PartAttachmentAdmin)
#admin.site.register(PartParameter, ParameterAdmin)
#admin.site.register(PartParameterTemplate, ParameterTemplateAdmin)
#admin.site.register(CategoryParameterLink)
# admin.site.register(PartParameter, ParameterAdmin)
# admin.site.register(PartParameterTemplate, ParameterTemplateAdmin)
# admin.site.register(CategoryParameterLink)

View File

@ -8,6 +8,9 @@ from django_filters.rest_framework import FilterSet, DjangoFilterBackend
from .models import PartCategory, Part, BomItem
from InvenTree.models import FilterChildren
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
"""
@ -69,6 +72,7 @@ class PartParamDetail(generics.RetrieveUpdateDestroyAPIView):
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
"""
class PartFilter(FilterSet):
class Meta:
@ -174,6 +178,7 @@ class PartTemplateList(generics.ListCreateAPIView):
"""
class BomItemDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = BomItem.objects.all()
@ -190,9 +195,6 @@ class BomItemFilter(FilterSet):
class BomItemList(generics.ListCreateAPIView):
#def get_queryset(self):
# params = self.request.
queryset = BomItem.objects.all()
serializer_class = BomItemSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

View File

@ -12,9 +12,7 @@ class EditPartForm(forms.ModelForm):
self.helper = FormHelper()
self.helper.form_id = 'id-edit-part-form'
#self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -39,9 +37,7 @@ class EditCategoryForm(forms.ModelForm):
self.helper = FormHelper()
self.helper.form_id = 'id-edit-part-form'
#self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -61,10 +57,8 @@ class EditBomItemForm(forms.ModelForm):
self.helper = FormHelper()
self.helper.form_id = 'id-edit-part-form'
#self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
@ -73,4 +67,4 @@ class EditBomItemForm(forms.ModelForm):
'part',
'sub_part',
'quantity'
]
]

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext as _
from django.db import models
from django.db.models import Sum
from django.core.validators import MinValueValidator
@ -42,6 +41,7 @@ class PartCategory(InvenTreeTree):
return self.part_set.all()
"""
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
def before_delete_part_category(sender, instance, using, **kwargs):
@ -129,7 +129,6 @@ class Part(models.Model):
class Meta:
verbose_name = "Part"
verbose_name_plural = "Parts"
#unique_together = (("name", "category"),)
@property
def tracked_parts(self):
@ -152,7 +151,6 @@ class Part(models.Model):
def bomItemCount(self):
return self.bom_items.all().count()
@property
def usedInCount(self):
return self.used_in.all().count()
@ -177,9 +175,10 @@ class Part(models.Model):
return projects
"""
def attach_file(instance, filename):
base='part_files'
base = 'part_files'
# TODO - For a new PartAttachment object, PK is NULL!!
@ -188,19 +187,18 @@ def attach_file(instance, filename):
return os.path.join(base, fn)
class PartAttachment(models.Model):
""" A PartAttachment links a file to a part
Parts can have multiple files such as datasheets, etc
"""
part = models.ForeignKey(Part, on_delete=models.CASCADE,
related_name='attachments')
attachment = models.FileField(upload_to=attach_file, null=True, blank=True)
class BomItem(models.Model):
""" A BomItem links a part to its component items.
A part can have a BOM (bill of materials) which defines
@ -221,7 +219,6 @@ class BomItem(models.Model):
# Quantity required
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
class Meta:
verbose_name = "BOM Item"

View File

@ -3,6 +3,7 @@ from rest_framework import serializers
from .models import Part, PartCategory
from .models import BomItem
class BomItemSerializer(serializers.ModelSerializer):
class Meta:
@ -12,6 +13,7 @@ class BomItemSerializer(serializers.ModelSerializer):
'sub_part',
'quantity')
"""
class PartParameterSerializer(serializers.HyperlinkedModelSerializer):
" Serializer for a PartParameter
@ -27,7 +29,7 @@ class PartParameterSerializer(serializers.HyperlinkedModelSerializer):
'units')
"""
#class PartSerializer(serializers.HyperlinkedModelSerializer):
class PartSerializer(serializers.ModelSerializer):
""" Serializer for complete detail information of a part.
Used when displaying all details of a single component.
@ -56,6 +58,7 @@ class PartCategorySerializer(serializers.HyperlinkedModelSerializer):
'parent',
'pathstring')
"""
class PartTemplateSerializer(serializers.HyperlinkedModelSerializer):
@ -65,4 +68,4 @@ class PartTemplateSerializer(serializers.HyperlinkedModelSerializer):
'name',
'units',
'format')
"""
"""

View File

@ -46,7 +46,6 @@ part_detail_urls = [
url(r'^suppliers/?', views.PartDetail.as_view(template_name='part/supplier.html'), name='part-suppliers'),
# Any other URLs go to the part detail page
#url(r'^.*$', views.detail, name='part-detail'),
url(r'^.*$', views.PartDetail.as_view(), name='part-detail'),
]
@ -87,11 +86,9 @@ part_urls = [
# Top level part list (display top level parts and categories)
url('', views.PartIndex.as_view(), name='part-index'),
url(r'^.*$', RedirectView.as_view(url='', permanent=False), name='part-index'),
url(r'^.*$', RedirectView.as_view(url='', permanent=False), name='part-index'),
]
"""
part_param_urls = [
# Detail of a single part parameter
@ -111,5 +108,3 @@ part_param_template_urls = [
url(r'^$', views.PartTemplateList.as_view())
]
"""

View File

@ -1,15 +1,13 @@
from InvenTree.models import FilterChildren
from .models import PartCategory, Part, BomItem
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from .forms import EditPartForm, EditCategoryForm, EditBomItemForm
from .models import PartCategory, Part, BomItem
class PartIndex(ListView):
model = Part
@ -114,7 +112,7 @@ class CategoryDelete(DeleteView):
model = PartCategory
template_name = 'part/category_delete.html'
context_object_name = 'category'
success_url ='/part/'
success_url = '/part/'
def post(self, request, *args, **kwargs):
if 'confirm' in request.POST:
@ -150,7 +148,7 @@ class CategoryCreate(CreateView):
class BomItemDetail(DetailView):
context_object_name ='item'
context_object_name = 'item'
queryset = BomItem.objects.all()
template_name = 'part/bom-detail.html'

View File

@ -3,9 +3,6 @@ from django_filters import NumberFilter
from rest_framework import generics, permissions, response
# from InvenTree.models import FilterChildren
from .models import StockLocation, StockItem
from .serializers import StockItemSerializer, StockQuantitySerializer

View File

@ -14,7 +14,6 @@ class EditStockLocationForm(forms.ModelForm):
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -36,11 +35,9 @@ class EditStockItemForm(forms.ModelForm):
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = StockItem
fields = [
@ -49,4 +46,4 @@ class EditStockItemForm(forms.ModelForm):
'location',
'quantity',
'status'
]
]

View File

@ -14,6 +14,7 @@ from datetime import datetime
from django.db.models.signals import pre_delete
from django.dispatch import receiver
class StockLocation(InvenTreeTree):
""" Organization tree for StockItem objects
A "StockLocation" can be considered a warehouse, or storage location
@ -47,6 +48,7 @@ def before_delete_stock_location(sender, instance, using, **kwargs):
child.parent = instance.parent
child.save()
class StockItem(models.Model):
def get_absolute_url(self):

View File

@ -1,5 +1,4 @@
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
from . import api
@ -58,4 +57,4 @@ stock_urls = [
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
url(r'^.*$', views.StockIndex.as_view(), name='stock-index'),
]
]

View File

@ -1,6 +1,5 @@
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
@ -11,6 +10,7 @@ from .models import StockItem, StockLocation
from .forms import EditStockLocationForm
from .forms import EditStockItemForm
class StockIndex(ListView):
model = StockItem
template_name = 'stock/index.html'
@ -29,6 +29,7 @@ class StockIndex(ListView):
return context
class StockLocationDetail(DetailView):
context_object_name = 'location'
template_name = 'stock/location.html'
@ -118,4 +119,4 @@ class StockItemDelete(DeleteView):
if 'confirm' in request.POST:
return super(StockItemDelete, self).post(request, *args, **kwargs)
else:
return HttpResponseRedirect(self.get_object().get_absolute_url())
return HttpResponseRedirect(self.get_object().get_absolute_url())

View File

@ -14,7 +14,6 @@ class EditSupplierForm(forms.ModelForm):
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -40,7 +39,6 @@ class EditSupplierPartForm(forms.ModelForm):
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -54,4 +52,4 @@ class EditSupplierPartForm(forms.ModelForm):
'URL',
'manufacturer',
'MPN',
]
]

View File

@ -46,8 +46,7 @@ class SupplierPart(models.Model):
related_name='supplier_parts')
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE,
related_name = 'parts')
related_name='parts')
SKU = models.CharField(max_length=100)

View File

@ -2,7 +2,6 @@ from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
from . import api
"""
cust_urls = [
@ -75,4 +74,4 @@ supplier_urls = [
# Redirect any other patterns
url(r'^.*$', RedirectView.as_view(url='', permanent=False), name='supplier-index'),
]
]

View File

@ -1,6 +1,5 @@
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
@ -11,6 +10,7 @@ from .models import Supplier, SupplierPart
from .forms import EditSupplierForm
from .forms import EditSupplierPartForm
class SupplierIndex(ListView):
model = Supplier
template_name = 'supplier/index.html'

View File

@ -7,10 +7,9 @@ class UniquePartAdmin(admin.ModelAdmin):
list_display = ('part', 'serial', 'status', 'creation_date')
class PartTrackingAdmin(admin.ModelAdmin):
list_display = ('part', 'date', 'title')
admin.site.register(UniquePart, UniquePartAdmin)
admin.site.register(PartTrackingInfo, PartTrackingAdmin)
admin.site.register(PartTrackingInfo, PartTrackingAdmin)

View File

@ -14,7 +14,6 @@ class EditTrackedPartForm(forms.ModelForm):
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
#self.helper.form_action = 'submit'
self.helper.add_input(Submit('submit', 'Submit'))
@ -25,4 +24,4 @@ class EditTrackedPartForm(forms.ModelForm):
'serial',
'customer',
'status'
]
]

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals
from rest_framework.exceptions import ValidationError
from django.utils.translation import ugettext as _
from django.db import models
@ -55,8 +54,8 @@ class UniquePart(models.Model):
status = models.IntegerField(default=PART_IN_PROGRESS, choices=PART_STATUS_CODES.items())
def __str__(self):
return "{pn} - # {sn}".format(pn = self.part.name,
sn = self.serial)
return "{pn} - # {sn}".format(pn=self.part.name,
sn=self.serial)
class PartTrackingInfo(models.Model):

View File

@ -1,5 +1,4 @@
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
@ -39,4 +38,4 @@ tracking_urls = [
# List ALL tracked items
url(r'^.*$', views.TrackIndex.as_view(), name='track-index'),
]
]

View File

@ -1,15 +1,15 @@
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from part.models import Part
from .models import UniquePart, PartTrackingInfo
from .models import UniquePart
from .forms import EditTrackedPartForm
class TrackIndex(ListView):
model = UniquePart
template_name = 'track/index.html'
@ -23,7 +23,7 @@ class TrackIndex(ListView):
class TrackDetail(DetailView):
queryset = UniquePart.objects.all()
template_name = 'track/detail.html'
context_object_name='part'
context_object_name = 'part'
class TrackCreate(CreateView):
@ -60,4 +60,4 @@ class TrackDelete(DeleteView):
if 'confirm' in request.POST:
return super(TrackDelete, self).post(request, *args, **kwargs)
else:
return HttpResponseRedirect(self.get_object().get_absolute_url())
return HttpResponseRedirect(self.get_object().get_absolute_url())