Improved list and detail views for supplier

Huzzah for bootstrap
This commit is contained in:
Oliver 2018-04-15 13:49:47 +10:00
parent 9e6c7350f9
commit 8232baeed7
17 changed files with 201 additions and 84 deletions

View File

@ -15,7 +15,7 @@ class Company(models.Model):
abstract = True
name = models.CharField(max_length=100, unique=True)
description = models.CharField(max_length=500, blank=True)
description = models.CharField(max_length=500)
website = models.URLField(blank=True)
address = models.CharField(max_length=200,
blank=True)
@ -43,7 +43,7 @@ class InvenTreeTree(models.Model):
name = models.CharField(max_length=100, unique=True)
description = models.CharField(max_length=250, blank=True)
description = models.CharField(max_length=250)
# When a category is deleted, graft the children onto its parent
parent = models.ForeignKey('self',

View File

@ -11,7 +11,7 @@ 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
@ -46,8 +46,8 @@ apipatterns = [
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'^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)),
@ -69,15 +69,14 @@ apipatterns = [
urlpatterns = [
# API URL
url(r'^api/', include(apipatterns)),
#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)),
url(r'^supplier/', include(supplier_urls)),
url(r'^track/', include(tracking_urls)),
url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
url(r'^admin/', admin.site.urls),
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-15 03:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0014_auto_20180415_0107'),
]
operations = [
migrations.AlterField(
model_name='partcategory',
name='description',
field=models.CharField(max_length=250),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-15 03:16
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0015_auto_20180415_0302'),
]
operations = [
migrations.AlterField(
model_name='part',
name='description',
field=models.CharField(max_length=250),
),
]

View File

@ -88,7 +88,7 @@ class Part(models.Model):
name = models.CharField(max_length=100, unique=True)
# Longer description of the part (optional)
description = models.CharField(max_length=250, blank=True)
description = models.CharField(max_length=250)
# Internal Part Number (optional)
# Potentially multiple parts map to the same internal IPN (variants?)

View File

@ -6,7 +6,7 @@
<a class="navbar-brand" href="/"><img src="{% static 'img/inventree.png' %}" width="40" height="40"/></a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="/part/">Parts</a></li>
<li><a href="/part/">Parts</a></li>
<li><a href="/stock/">Stock</a></li>
<li><a href="/supplier/">Suppliers</a></li>
<li><a href="/track/">Tracking</a></li>

View File

@ -6,6 +6,11 @@
{% include "part/cat_link.html" with category=category %}
<p>
<b>{{ category.name }}</b><br>
<i>{{ category.description }}</i>
</p>
{% include "part/category_subcategories.html" with children=category.children.all %}
{% include "part/category_parts.html" with parts=category.parts.all %}

View File

@ -1,10 +1,15 @@
{% if parts|length > 0 %}
Parts:
<ul class="list-group">
<table class="table table-striped">
<tr>
<th>Part</th>
<th>Description</th>
</tr>
{% for part in parts %}
<li class="list-group-item">
<a href="{% url 'part-detail' part.id %}">{{ part.name }}</a> - {{ part.description }}
</li>
<tr>
<td><a href="{% url 'part-detail' part.id %}">{{ part.name }}</a></td>
<td>{{ part.description }}</td>
</tr>
{% endfor %}
</ul>
</table>
{% endif %}

View File

@ -3,7 +3,10 @@ Subcategories:
<ul class="list-group">
{% for child in children %}
<li class="list-group-item">
<a href="{% url 'category-detail' child.id %}">{{ child.name }}</a> - {{ child.description }}
<b><a href="{% url 'category-detail' child.id %}">{{ child.name }}</a></b>
{% if child.description %}
<i> - {{ child.description }}</i>
{% endif %}
<span class='badge'>{{ child.partcount }}</span>
</li>
{% endfor %}

View File

@ -16,7 +16,7 @@
{% endif %}/>
</div>
<div class="media-body">
<h5>{{ part.name }}</h5>
<h4>{{ part.name }}</h4>
{% if part.description %}
<p><i>{{ part.description }}</i></p>
{% endif %}

View File

@ -1,30 +1,3 @@
table, th, td {
border: 1px solid black;
border-collapse: collapse;
margin-left: 5px;
margin-right: 5px;
margin-top: 10px;
margin-bottom: 10px;
}
th, td {
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
}
th {
text-align: left;
}
table tr:nth-child(even) {
background-color: #eee;
}
table tr:nth-child(odd) {
background-color: #fff;
}
.navbar-brand {
float: left;
}

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-15 03:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0005_auto_20180415_0107'),
]
operations = [
migrations.AlterField(
model_name='stocklocation',
name='description',
field=models.CharField(max_length=250),
),
]

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-15 02:55
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('supplier', '0004_auto_20180414_0624'),
]
operations = [
migrations.AlterField(
model_name='customer',
name='description',
field=models.CharField(max_length=500),
),
migrations.AlterField(
model_name='manufacturer',
name='description',
field=models.CharField(max_length=500),
),
migrations.AlterField(
model_name='supplier',
name='description',
field=models.CharField(max_length=500),
),
]

View File

@ -2,26 +2,55 @@
{% block content %}
<ul>
<li>Name: {{ supplier.name }}</li>
<li>Description: {{ supplier.description }}</li>
<li>Website: {{ supplier.website }}</li>
<li>Contact: {{ supplier.contact }}</li>
</li>
<div class="row">
<div class="col-sm-6">
<h3>{{ supplier.name }}</h3>
<p>{{ supplier.description }}</p>
</div>
<div class="col-sm-6">
<table class="table">
{% if supplier.website %}
<tr>
<td>Website</td><td><a href="{{ supplier.website }}">{{ supplier.website }}</a></td>
</tr>
{% endif %}
{% if supplier.address %}
<tr>
<td>Address</td><td>{{ supplier.address }}</td>
</tr>
{% endif %}
{% if supplier.phone %}
<tr>
<td>Phone</td><td>{{ supplier.phone }}</td>
</tr>
{% endif %}
{% if supplier.email %}
<tr>
<td>Email</td><td>{{ supplier.email }}</td>
</tr>
{% endif %}
{% if supplier.contact %}
<tr>
<td>Contact</td><td>{{ supplier.contact }}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% if supplier.parts.all|length > 0 %}
<table>
<table class="table table-striped">
<tr>
<th>Part</th>
<th>SKU</th>
<th>Part</th>
<th>Manufacturer</th>
<th>MPN</th>
<th>URL</th>
</tr>
{% for part in supplier.parts.all %}
<tr>
<td><a href="{% url 'part-detail' part.part.id %}">{{ part.part.name }}</a></td>
<td><a href="{% url 'supplier-part-detail' part.id %}">{{ part.SKU }}</a></td>
<td><a href="{% url 'part-detail' part.part.id %}">{{ part.part.name }}</a></td>
<td>Manufacturer name goes here</td>
<td>MPN goes here</td>
<td>{{ part.URL }}</td>

View File

@ -2,18 +2,21 @@
{% block content %}
<table>
<tr>
<th>Supplier</th>
<th>Description</th>
<th>URL</th>
</tr>
<h3>Suppliers</h3>
<ul class='list-group'>
{% for supplier in suppliers %}
<tr>
<td><a href="{% url 'supplier-detail' supplier.id %}">{{ supplier.name }}</a></td>
<td>{{ supplier.description }}</td>
<td>{{ supplier.website }}</td>
</tr>
<li class='list-group-item'>
<b><a href="{% url 'supplier-detail' supplier.id %}">{{ supplier.name }}</a></b>
<br>
{{ supplier.description }}
{% if supplier.website %}
<a href="{{ supplier.website }}">- {{ supplier.website }}</a>
{% endif %}
<span class="badge">
{{ supplier.parts.all|length }}
</span>
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -1,9 +1,10 @@
from django.conf.urls import url
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
from . import api
"""
cust_urls = [
# Customer detail
url(r'^(?P<pk>[0-9]+)/?$', api.CustomerDetail.as_view(), name='customer-detail'),
@ -45,11 +46,21 @@ supplier_api_urls = [
url(r'^\?.*/?$', api.SupplierList.as_view()),
url(r'^$', api.SupplierList.as_view())
]
"""
supplier_detail_urls = [
#url(r'edit/?', views.SupplierEdit.as_view(), name='supplier-edit'),
#url(r'delete/?', views.SupplierDelete.as_view(), name='supplier-delete'),
url(r'^.*$', views.SupplierDetail.as_view(), name='supplier-detail'),
]
supplier_urls = [
url(r'^(?P<pk>\d+)/', views.detail, name='supplier-detail'),
url(r'^part/(?P<pk>\d+)/', views.partDetail, name='supplier-part-detail'),
url(r'', views.index, name='supplier-index'),
url(r'^(?P<pk>\d+)/', include(supplier_detail_urls)),
url(r'', views.SupplierIndex.as_view(), name='supplier-index'),
# Redirect any other patterns
url(r'^.*$', RedirectView.as_view(url='', permanent=False), name='supplier-index'),

View File

@ -1,27 +1,26 @@
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404, render
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 .models import Supplier, SupplierPart
def index(request):
""" The supplier index page simply displays all the suppliers
"""
class SupplierIndex(ListView):
model = Supplier
template_name = 'supplier/index.html'
context_object_name = 'suppliers'
paginate_by = 50
suppliers = Supplier.objects.order_by('name')
return render(request, 'supplier/index.html', {'suppliers' : suppliers})
def get_queryset(self):
return Supplier.objects.order_by('name')
def detail(request, pk):
""" The supplier detail page shown detailed information
on a particular supplier
"""
supplier = get_object_or_404(Supplier, pk=pk)
return render(request, 'supplier/detail.html', {'supplier' : supplier})
class SupplierDetail(DetailView):
context_obect = 'supplier'
template_name = 'supplier/detail.html'
queryset = Supplier.objects.all()
def partDetail(request, pk):