PEP fixes (not all yet)

This commit is contained in:
Oliver 2018-04-18 00:03:42 +10:00
parent 3f33a921ae
commit 192f823b1a
11 changed files with 25 additions and 37 deletions

View File

@ -1,18 +0,0 @@
import inspect
from enum import Enum
class ChoiceEnum(Enum):
""" Helper class to provide enumerated choice values for integer fields
"""
# http://blog.richard.do/index.php/2014/02/how-to-use-enums-for-django-field-choices/
@classmethod
def choices(cls):
# get all members of the class
members = inspect.getmembers(cls, lambda m: not(inspect.isroutine(m)))
# filter down to just properties
props = [m for m in members if not(m[0][:2] == '__')]
# format into django choice tuple
choices = tuple([(str(p[1].value), p[0]) for p in props])
return choices

View File

@ -18,4 +18,5 @@ class BuildAdmin(admin.ModelAdmin):
'notes',
)
admin.site.register(Build, BuildAdmin)

View File

@ -30,4 +30,4 @@ class EditBuildForm(forms.ModelForm):
'quantity',
'status',
'completion_date',
]
]

View File

@ -8,6 +8,7 @@ from django.core.validators import MinValueValidator
from part.models import Part
class Build(models.Model):
""" A Build object organises the creation of new parts from the component parts
It uses the part BOM to generate new parts.
@ -19,26 +20,24 @@ class Build(models.Model):
# Build status codes
PENDING = 10 # Build is pending / active
HOLDING = 20 # Build is currently being held
CANCELLED = 30 # Build was cancelled
COMPLETE = 40 # Build is complete
HOLDING = 20 # Build is currently being held
CANCELLED = 30 # Build was cancelled
COMPLETE = 40 # Build is complete
BUILD_STATUS_CODES = {
PENDING : _("Pending"),
HOLDING : _("Holding"),
CANCELLED : _("Cancelled"),
COMPLETE : _("Complete"),
}
BUILD_STATUS_CODES = {PENDING: _("Pending"),
HOLDING: _("Holding"),
CANCELLED: _("Cancelled"),
COMPLETE: _("Complete"),
}
batch = models.CharField(max_length=100, blank=True, null=True,
help_text='Batch code for this build output')
help_text='Batch code for this build output')
# Status of the build
status = models.PositiveIntegerField(default=PENDING,
choices=BUILD_STATUS_CODES.items(),
validators=[MinValueValidator(0)])
# Date the build model was 'created'
creation_date = models.DateField(auto_now=True, editable=False)

View File

@ -15,4 +15,4 @@ build_urls = [
url(r'^(?P<pk>\d+)/', include(build_detail_urls)),
url(r'.*$', views.BuildIndex.as_view(), name='build-index'),
]
]

View File

@ -12,6 +12,7 @@ from .models import Build
from .forms import EditBuildForm
class BuildIndex(ListView):
model = Build
template_name = 'build/index.html'

View File

@ -18,4 +18,4 @@ class CustomerOrderLineAdmin(admin.ModelAdmin):
admin.site.register(Customer, CustomerAdmin)
admin.site.register(CustomerOrder, CustomerOrderAdmin)
admin.site.register(CustomerOrderLine, CustomerOrderLineAdmin)
admin.site.register(CustomerOrderLine, CustomerOrderLineAdmin)

View File

@ -64,7 +64,7 @@ class CustomerOrderLine(models.Model):
# TODO: for now, each line corresponds to some quantity of some part, but in future we might want more flexibility
# Only 'salable' items should be allowed in a CSO
part = models.ForeignKey(Part, blank=True, help_text="Part",
limit_choices_to={'salable' : True}
limit_choices_to={'salable': True}
)
# TODO: should quantity field here somehow related to quantity field of related part? Views will handle this, right?
@ -72,4 +72,3 @@ class CustomerOrderLine(models.Model):
# Line notes
notes = models.TextField(blank=True, help_text="Line notes")

View File

@ -1,3 +1,7 @@
{% extends "base.html" %}
{% block contents %}
<table class="table table-striped">
<tr>
<th>Internal Ref</th>
@ -11,4 +15,6 @@
<td>{{ order.customer_ref }}</td>
</tr>
{% endfor %}
</table>
</table>
{% endblock %}

View File

@ -1,3 +1,3 @@
from django.test import TestCase
# from django.test import TestCase
# Create your tests here.

View File

@ -30,4 +30,4 @@ class CustomerOrderDetail(DetailView):
model = CustomerOrder
template_name = 'customer/order_detail.html'
queryset = CustomerOrder.objects.all()
context_object_name = 'order'
context_object_name = 'order'