Compare commits

...

3 Commits

Author SHA1 Message Date
agp8x 8304f30cb6 fix migrate_postgres 2019-12-05 23:32:03 +01:00
agp8x 72d50bf545 Merge branch 'master' of git.clkl.de:agp8x/partdoc 2019-12-04 23:53:14 +01:00
agp8x d55ff39cd6 add part view, use url patterns 2019-12-04 23:29:15 +01:00
8 changed files with 50 additions and 14 deletions

View File

@ -1,11 +1,11 @@
# start old postgres, dump data
sed -i 's/postgres:12-alpine/postgres:10-alpine/' docker-compose.yml
docker-compose exec db pg_dumpall -U partdoc > pgdump.tmp
docker-compose exec web python3 manage.py dumpdata -o /app/djangodump0.json --natural-foreign --exclude auth.permission --exclude contenttypes --indent 1
# migrate to new postgres, import data
docker-compose stop db
docker-compose down
mv pgdata __pgdata__10
sed -i 's/postgres:10-alpine/postgres:12-alpine/' docker-compose.yml
docker-compose up -d
docker-compose exec -T db psql -U partdoc < pgdump.tmp
docker-compose down
docker-compose up -d
rm pgdump.tmp
docker-compose exec web python3 manage.py migrate
docker-compose exec web python3 manage.py loaddata /app/djangodump0.json
docker-compose exec web rm /app/djangodump0.json

View File

@ -0,0 +1,20 @@
<h1>part {{part.number}}</h1>
<h3>{{part.name}}</h3>
<table>
<tr>
<th>Produkt</th>
<th>Zeichnung</th>
<th>Pos.</th>
<th>Anzahl</th>
</tr>
{% for s in sketches %}
<tr>
<td><a href="{% url 'parts:product' s.sketch__product__id %}">{{s.sketch__product__name}}</a></td>
<td><a href="{% url 'parts:sketch' s.sketch %}">{{s.sketch__name}}</a></td>
<td>{{s.sketch_number}}</td>
<td>{{s.qty}}</td>
</tr>
{% endfor %}
</table>

View File

@ -12,7 +12,7 @@
{% for part in quantities %}
<tr>
<td>{{part.number}}</td>
<td><a href="{% url 'parts:part' part.id %}">{{part.number}}</a></td>
<td>{{part.name}}</td>
{% for product in part.quantities %}
<td>{{product}}</td>

View File

@ -3,13 +3,13 @@
<h3>explicit sketches</h3>
<ul>
{% for sketch in product.sketch_set.all %}
<li><a href="/parts/sketch/{{sketch.id}}/">{{sketch.name}}</a></li>
<li><a href="{% url 'parts:sketch' sketch.id %}">{{sketch.name}}</a></li>
{% endfor %}
</ul>
<h3>implicit sketches</h3>
<ul>
{% for sketch in sketches %}
<li><a href="/parts/sketch/{{sketch.id}}/">{{sketch.name}}</a></li>
<li><a href="{% url 'parts:sketch' sketch.id %}">{{sketch.name}}</a></li>
{% endfor %}
</ul>
</ul>

View File

@ -1,6 +1,6 @@
<h1>Available products:</h1>
<ul>
{% for product in product_list %}
<li><a href="/parts/product/{{product.id}}/">{{product.name}}</a></li>
<li><a href="{% url 'parts:product' product.id %}">{{product.name}}</a></li>
{% endfor %}
</ul>
</ul>

View File

@ -3,9 +3,10 @@
<ul>
{% for usage in sketch.usage_set.all %}
<li><a href="/parts/usage/{{usage.id}}/">{{usage}}</a></li>
<li><a href="% url 'parts:usage' usage.id %">{usage}</a></li><!--TODO!-->
{% endfor %}
</ul>
<p>{{sketch.get_brand}}</p>
<p>{{sketch.get_brand.name.foo}}</p>
<a href="{% url "parts:continue_sketch" sketch.product_id sketch.id %}">Edit</a>
<a href="{% url "parts:continue_sketch" sketch.product_id sketch.id %}">Edit</a>

View File

@ -5,9 +5,11 @@ from . import views
app_name = "parts"
urlpatterns = [
path('', views.index, name="index"),
path('product/<int:product_id>/', views.product, name="detail"),
path('product/<int:product_id>/', views.product, name="product"),
path('sketch/<int:sketch_id>/', views.sketch, name="sketch"),
path('parts', views.parts, name="parts"),
path('part/by_number/<part_number>', views.part_by_number, name="part_num"),
path('part/<int:part_id>', views.part, name="part"),
path('add/<int:product_id>/sketch/<int:sketch_id>', views.sketch_add, name="continue_sketch"),
path('add/<int:product_id>/sketch', views.sketch_add, name="new_sketch"),
path('search/part/', views.part_search, name="part_search"),

View File

@ -28,6 +28,18 @@ def sketch(request, sketch_id):
context = {'sketch': sketch}
return render(request, 'parts/sketch.html', context)
def __part_view(request, part):
sketches = part.usage_set.values('sketch', 'sketch_number', 'sketch__name', 'sketch__product__name', 'sketch__product__id').annotate(qty=Sum('productusage__quantity'))
context = {'part': part, 'sketches': sketches}
return render(request, 'parts/part.html', context)
def part(request, part_id):
part = BrandedPart.objects.get(id=part_id)
return __part_view(request, part)
def part_by_number(request, part_number):
part = BrandedPart.objects.get(number=part_number)
return __part_view(request, part)
def parts(request):
products = Product.objects.order_by('name')
@ -49,6 +61,7 @@ def parts(request):
"number": part.number,
"quantities": prod_qtys,
"sum": sum(prod_qtys),
"id": part.id,
})
context = {'products': products, 'parts': parts, 'quantities': quantities, 'len': len(quantities)}