diff --git a/invsystem/object_lister/urls.py b/invsystem/object_lister/urls.py index c63fc43..7482103 100644 --- a/invsystem/object_lister/urls.py +++ b/invsystem/object_lister/urls.py @@ -1,6 +1,9 @@ from django.urls import path from . import views +import uuid urlpatterns = [ path('', views.objlist, name='objlist'), + path('', views.objlist, name='objlist_ordered'), + path('/delete', views.delete, name='del_obj') ] diff --git a/invsystem/object_lister/views.py b/invsystem/object_lister/views.py index fd3469b..2e1817e 100644 --- a/invsystem/object_lister/views.py +++ b/invsystem/object_lister/views.py @@ -1,13 +1,80 @@ -from django.shortcuts import render -from object_adder.models import Object +from django.shortcuts import render, get_object_or_404 +from object_adder.models import Object, Category +from object_adder.forms import ObjectForm from django.contrib.auth.decorators import login_required +import re # Create your views here. @login_required -def objlist(request): +def objlist(request, orderstr=None): + uuidv4pattern = r"(\d|[a-z]){8}-(\d|[a-z]){4}-4(\d|[a-z]){3}-(\d|[a-z]){4}-(\d|[a-z]){12}" - objects = Object.objects.all() + if request.method == 'GET': - context = {'title': 'Inventar', 'objects': objects} - return render(request, 'object_lister/index.html', context) + if orderstr is None: + objects = Object.objects.all() + elif orderstr == '0': + objects = Object.objects.all().order_by('title') + elif orderstr == '1': + objects = Object.objects.all().order_by('ammout') + elif orderstr == '2': + objects = Object.objects.all().order_by('category') + elif orderstr == '3': + objects = Object.objects.all().order_by('inventarized_date') + elif orderstr == '4': + objects = Object.objects.all().order_by('user_added') + else: + result = re.fullmatch(uuidv4pattern, orderstr) + if result is None: + objects = Object.objects.all() + else: + uuid = result.group(0) + obj = get_object_or_404(Object, pk=uuid) + + form = ObjectForm( + initial={'ammout': obj.ammout, 'title': obj.title, 'description': obj.description, + 'category': obj.category} + ) + + context = {'title': 'Details', 'obj': obj, 'form': form} + + return render(request, 'object_lister/details.html', context) + + categories = Category.categories.all() + + context = {'title': 'Inventar', 'objects': objects, 'objammout': len(objects), 'categories': categories, + 'ncats': len(categories)} + return render(request, 'object_lister/index.html', context) + + elif request.method == 'POST': + form = ObjectForm(request.POST) + + if form.is_valid(): + result = re.fullmatch(uuidv4pattern, orderstr) + + uuid = result.group(0) + obj = get_object_or_404(Object, pk=uuid) + + obj.ammout = form.cleaned_data['ammout'] + obj.title = form.cleaned_data['title'] + obj.description = form.cleaned_data['description'] + obj.category = form.cleaned_data['category'] + + obj.save() + + form = ObjectForm( + initial={'ammout': obj.ammout, 'title': obj.title, 'description': obj.description, + 'category': obj.category} + ) + + context = {'title': 'Details', 'obj': obj, 'form': form, 'message': 'changed'} + + return render(request, 'object_lister/details.html', context) + + +@login_required +def delete(request, uuid_url): + obj = get_object_or_404(Object, pk=uuid_url) + obj.delete() + return render(request, 'object_lister/delete.html', {'uuid': uuid_url}) diff --git a/invsystem/user_manager/static/user_manager/style.css b/invsystem/user_manager/static/user_manager/style.css index 65066c3..b2fc083 100644 --- a/invsystem/user_manager/static/user_manager/style.css +++ b/invsystem/user_manager/static/user_manager/style.css @@ -100,19 +100,53 @@ } .objecttable-data, .objecttable-head { - border: 1px solid #dddddd; + border-bottom: 1px solid #dddddd; text-align: center; padding: 0.4em; } -.objecttable-row:nth-child(even) { - background-color: #dddddd; +.objecttable-row:hover { + background-color: #f8f8f8; } -.objecttable-row:hover { - -webkit-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1); - box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1); - border-radius: 10px; - transition: 0.1s; +.cattable { + border-collapse: collapse; + width: 50%; + margin-top: 2em; + margin-bottom: 2em; +} + +.cattable * { + text-align: left; +} + +.lower-box { + margin-top: 2em; + width: 50%; +} + +.celllink, .celllink:hover, .celllink:visited, .celllink:active { + width: 100%; + height: 100%; + display: block; + padding: 0.4em; + text-decoration: none; + color: #333333; + cursor: default; +} + +.alert { + margin-top: 1em; +} + +.nodisplay { + display: none; +} + +.delaleret { + display: none; +} + +.delbtn{ + margin-bottom: 1em !important; } \ No newline at end of file diff --git a/invsystem/user_manager/templates/object_lister/delete.html b/invsystem/user_manager/templates/object_lister/delete.html new file mode 100644 index 0000000..eee5e86 --- /dev/null +++ b/invsystem/user_manager/templates/object_lister/delete.html @@ -0,0 +1,9 @@ + + + + + + +object {{ uuid }} deleted + + \ No newline at end of file diff --git a/invsystem/user_manager/templates/object_lister/details.html b/invsystem/user_manager/templates/object_lister/details.html new file mode 100644 index 0000000..d9a8266 --- /dev/null +++ b/invsystem/user_manager/templates/object_lister/details.html @@ -0,0 +1,76 @@ +{% extends 'bases/navbar.html' %} + +{% block content %} + +
+ + {% if not message is None %} +
+ × + Das Objekt {{ obj.title }} wurde verändert. +
+ {% endif %} +
+ × + Abbruch. +
+
+ {% csrf_token %} +
+ {{ form.ammout.errors }} + + {{ form.ammout }} +
+
+ {{ form.title.errors }} + + {{ form.title }} +
+
+ {{ form.category.errors }} + + {{ form.category }} +
+
+ {{ form.img.errors }} + + {{ form.img }} +
+
+ {{ form.description.errors }} + + {{ form.description }} +
+
+ +
+
+ +
+ +{% endblock %} + + diff --git a/invsystem/user_manager/templates/object_lister/index.html b/invsystem/user_manager/templates/object_lister/index.html index c536e2f..cfd32ce 100644 --- a/invsystem/user_manager/templates/object_lister/index.html +++ b/invsystem/user_manager/templates/object_lister/index.html @@ -4,24 +4,57 @@
- - - - + + {% csrf_token %} +
NameAnzahl
+ + + + + + + + {% for object in objects %} + + + + {% if object.category is not None %} + + {% else %} + + {% endif %} + + + + {% endfor %} +
NameAnzahlKategorieInventarisierungsdatumHinzugefügt von
+ {{ object.title }} + + {{ object.ammout }} + + {{ object.category }} + + ------- + + {{ object.inventarized_date }} + + {{ object.user_added }} +
+

{{ objammout }} Objekte insgesamt

+ +
+
+ + - - - {% for object in objects %} + {% for category in categories %} - - - - - + {% endfor %}
KategorieInventarisierungsdatumHinzugefügt von
{{ object.title }}{{ object.ammout }}{{ object.category }}{{ object.inventarized_date }}{{ object.user_added }}{{ category.name }}
+

{{ ncats }} Kategorien insgesamt

{% endblock %}