Modify Objects
+ sort the object list + alter objects + delete objects
This commit is contained in:
parent
32d60f51ac
commit
51c942746b
6 changed files with 249 additions and 27 deletions
|
|
@ -1,6 +1,9 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
import uuid
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.objlist, name='objlist'),
|
||||
path('<str:orderstr>', views.objlist, name='objlist_ordered'),
|
||||
path('<str:uuid_url>/delete', views.delete, name='del_obj')
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
object {{ uuid }} deleted
|
||||
</body>
|
||||
</html>
|
||||
76
invsystem/user_manager/templates/object_lister/details.html
Normal file
76
invsystem/user_manager/templates/object_lister/details.html
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
{% extends 'bases/navbar.html' %}
|
||||
<html>
|
||||
{% block content %}
|
||||
|
||||
<div class="container shadow">
|
||||
|
||||
{% if not message is None %}
|
||||
<div class="alert alert-info alert-dismissible">
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||
Das Objekt <strong>{{ obj.title }}</strong> wurde verändert.
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="alert alert-danger alert-dismissible nodisplay" id="abortalert">
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||
Abbruch.
|
||||
</div>
|
||||
<form method="POST" class="post-form invform">
|
||||
{% csrf_token %}
|
||||
<div class="ammout-wrapper">
|
||||
{{ form.ammout.errors }}
|
||||
<label for="{{ form.ammout.id_for_lable }}">Anzahl:</label>
|
||||
{{ form.ammout }}
|
||||
</div>
|
||||
<div class="title-wrapper">
|
||||
{{ form.title.errors }}
|
||||
<label for="{{ form.title.id_for_lable }}">Objekt:</label>
|
||||
{{ form.title }}
|
||||
</div>
|
||||
<div class="category-wrapper">
|
||||
{{ form.category.errors }}
|
||||
<label for="{{ form.category.id_for_lable }}">Kategorie:</label>
|
||||
{{ form.category }}
|
||||
</div>
|
||||
<div class="img-wrapper">
|
||||
{{ form.img.errors }}
|
||||
<label for="{{ form.img.id_for_lable }}">Bild:</label>
|
||||
{{ form.img }}
|
||||
</div>
|
||||
<div class="description-wrapper">
|
||||
{{ form.description.errors }}
|
||||
<label for="{{ form.description.id_for_lable }}">Beschreibung:</label>
|
||||
{{ form.description }}
|
||||
</div>
|
||||
<div class="btnwrapper">
|
||||
<button type="submit" class="save btn btn-primary">speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
<button type="button" class="delbtn btn btn-danger" onclick="del()">Objekt löschen</button>
|
||||
</div>
|
||||
<script>
|
||||
function del() {
|
||||
if (confirm('Möchten sie das Objekt {{ obj.title }} wirklich löschen?')) {
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.onreadystatechange = function () {
|
||||
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
window.location.href = "./"
|
||||
}
|
||||
|
||||
};
|
||||
xhttp.open("GET", './{{ obj.uuid }}/delete', true);
|
||||
xhttp.send();
|
||||
|
||||
|
||||
} else {
|
||||
abox = document.getElementById('abortalert');
|
||||
abox.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
</html>
|
||||
|
||||
|
|
@ -4,24 +4,57 @@
|
|||
|
||||
<body>
|
||||
<div class="container shadow">
|
||||
<table class="objecttable">
|
||||
<tr class="objecttable-row">
|
||||
<th class="objecttable-head">Name</th>
|
||||
<th class="objecttable-head">Anzahl</th>
|
||||
<form>
|
||||
{% csrf_token %}
|
||||
<table class="objecttable">
|
||||
<tr>
|
||||
<th class="objecttable-head"><a href="./0">Name</a></th>
|
||||
<th class="objecttable-head"><a href="./1">Anzahl</a></th>
|
||||
<th class="objecttable-head"><a href="./2">Kategorie</a></th>
|
||||
<th class="objecttable-head"><a href="./3">Inventarisierungsdatum</a></th>
|
||||
<th class="objecttable-head"><a href="./4">Hinzugefügt von</a></th>
|
||||
</tr>
|
||||
{% for object in objects %}
|
||||
<tr class="objecttable-row">
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">{{ object.title }}</a>
|
||||
</td>
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">{{ object.ammout }}</a>
|
||||
</td>
|
||||
{% if object.category is not None %}
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">{{ object.category }}</a>
|
||||
</td>
|
||||
{% else %}
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">-------</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">{{ object.inventarized_date }}</a>
|
||||
</td>
|
||||
<td class="objecttable-data">
|
||||
<a class="celllink" href="./{{ object.uuid }}">{{ object.user_added }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<p>{{ objammout }} Objekte insgesamt</p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container shadow lower-box">
|
||||
<table class="cattable">
|
||||
<tr>
|
||||
<th class="objecttable-head">Kategorie</th>
|
||||
<th class="objecttable-head">Inventarisierungsdatum</th>
|
||||
<th class="objecttable-head">Hinzugefügt von</th>
|
||||
</tr>
|
||||
{% for object in objects %}
|
||||
{% for category in categories %}
|
||||
<tr class="objecttable-row">
|
||||
<td class="objecttable-data">{{ object.title }}</td>
|
||||
<td class="objecttable-data">{{ object.ammout }}</td>
|
||||
<td class="objecttable-data">{{ object.category }}</td>
|
||||
<td class="objecttable-data">{{ object.inventarized_date }}</td>
|
||||
<td class="objecttable-data">{{ object.user_added }}</td>
|
||||
<td class="objecttable-data">{{ category.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<p>{{ ncats }} Kategorien insgesamt</p>
|
||||
</div>
|
||||
</body>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue