From 5877b8342459537b7b2e44dda572c2862e21aefd Mon Sep 17 00:00:00 2001 From: Clemens-Dautermann Date: Wed, 19 Dec 2018 22:03:01 +0100 Subject: [PATCH] + Implemented inventarization + minor translation fixes --- invsystem/object_adder/admin.py | 2 +- invsystem/object_adder/forms.py | 12 ++ invsystem/object_adder/models.py | 13 +- invsystem/object_adder/views.py | 26 ++- .../static/user_manager/style.css | 181 ++---------------- .../user_manager/templates/bases/navbar.html | 5 +- .../templates/object_adder/error.html | 8 + .../templates/object_adder/index.html | 42 +++- .../templates/registration/login.html | 4 +- .../templates/user_manager/index.html | 13 +- 10 files changed, 121 insertions(+), 185 deletions(-) create mode 100644 invsystem/object_adder/forms.py create mode 100644 invsystem/user_manager/templates/object_adder/error.html diff --git a/invsystem/object_adder/admin.py b/invsystem/object_adder/admin.py index edd57bb..f9bb2db 100644 --- a/invsystem/object_adder/admin.py +++ b/invsystem/object_adder/admin.py @@ -3,7 +3,7 @@ from .models import Object class ObjectAdmin(admin.ModelAdmin): - pass + list_display = ('title', 'ammout', 'uuid', 'img') # Register your models here. diff --git a/invsystem/object_adder/forms.py b/invsystem/object_adder/forms.py new file mode 100644 index 0000000..fcae523 --- /dev/null +++ b/invsystem/object_adder/forms.py @@ -0,0 +1,12 @@ +from django.forms import ModelForm, TextInput + +from .models import Object + + +class ObjectForm(ModelForm): + class Meta: + model = Object + fields = ('ammout', 'title', 'img', 'description') + widgets = { + 'title': TextInput(), + } diff --git a/invsystem/object_adder/models.py b/invsystem/object_adder/models.py index 4bc9330..286f681 100644 --- a/invsystem/object_adder/models.py +++ b/invsystem/object_adder/models.py @@ -6,10 +6,11 @@ from django.contrib.auth.models import User # Create your models here. class Object(models.Model): - title = models.TextField(max_length=100, default=None) - img = models.ImageField(default=None) + ammout = models.PositiveIntegerField(default=1, blank=False) + title = models.TextField(max_length=100, default=None, blank=False) + img = models.ImageField(default=None, blank=True) uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - inventarized_date = models.DateTimeField() - description = models.TextField(max_length=500) - removed_date = models.DateTimeField() - user_added = models.ForeignKey(User, on_delete=models.CASCADE) + inventarized_date = models.DateTimeField(blank=False, null=True) + description = models.TextField(max_length=500, blank=True) + removed_date = models.DateTimeField(blank=True, default=None, null=True) + user_added = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=True) diff --git a/invsystem/object_adder/views.py b/invsystem/object_adder/views.py index af99baf..a284689 100644 --- a/invsystem/object_adder/views.py +++ b/invsystem/object_adder/views.py @@ -1,11 +1,33 @@ from django.shortcuts import render from django.contrib.auth.decorators import login_required +from .forms import ObjectForm +from django.utils import timezone # Create your views here. @login_required def add(request): - context = {'title': 'Objekt inventarisieren'} + if request.method == 'POST': + form = ObjectForm(request.POST) - return render(request, 'object_adder/index.html', context) + if form.is_valid(): + try: + obj = form.save(commit=True) + except OverflowError: + context = {'title': 'Fehler!', + 'error': 'Weder in den Chemieraum noch in eine Variable des Datentypes SQLite INTEGER passen mehr als 9223372036854775807 Objekte. Bitte inventarisieren sie das Objekt neu.'} + return render(request, 'object_adder/error.html', context) + + obj.inventarized_date = timezone.now() + obj.removed_date = None + obj.user_added = request.user + obj.save() + + context = {'title': 'Objekt inventarisieren', 'form': ObjectForm, + 'obj_name': form.cleaned_data.get('title')} + return render(request, 'object_adder/index.html', context) + + else: + context = {'title': 'Objekt inventarisieren', 'form': ObjectForm} + return render(request, 'object_adder/index.html', context) diff --git a/invsystem/user_manager/static/user_manager/style.css b/invsystem/user_manager/static/user_manager/style.css index 292254a..a84d5ce 100644 --- a/invsystem/user_manager/static/user_manager/style.css +++ b/invsystem/user_manager/static/user_manager/style.css @@ -36,75 +36,12 @@ position: relative; } -.error { - color: red; -} - -.userlist { - list-style-type: none; -} - -.profilecontainer { - height: 60px; - margin: 20px; - padding: 10px; - -} - -.profilecontainer:hover { - height: 60px; - margin: 20px; - -webkit-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.64); - -moz-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.64); - box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.64); - border-radius: 10px; - transition: 0.3s; - -} - -.profilepic { - height: 50px; - float: left; - border-radius: 50%; - margin-top: -5px; -} - -.profilename { - position: relative; - top: 16%; - margin-left: 10px; - font-size: 1.3em; -} .heading { font-size: 1.6em; font-weight: bold; } -.btn-info { - margin-left: 3%; -} - -.imgcontainer { - float: left; -} - -.profilepic-big { - border-radius: 50%; - margin-left: 70px; - -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); - transition: 0.3s; - margin-top: 15px; -} - -.info { - font-size: 1.3em; - margin: 20px; - padding-top: 20px; - padding-bottom: 20px; -} .shadow { -webkit-box-shadow: 3px 3px 28px -3px rgba(0, 0, 0, 0.1); @@ -114,118 +51,32 @@ transition: 0.3s; } -.verified { - height: 23px; - width: 23px; -} - -.search { - width: 210px; - box-sizing: border-box; - border: 2px solid #ccc; - border-radius: 4px; - font-size: 16px; - background-color: white; - background-position: 10px 10px; - background-size: 24px 24px; - background-repeat: no-repeat; - padding: 12px 20px 12px 40px; - -webkit-transition: width 0.4s ease-in-out; - transition: width 0.4s ease-in-out; - margin-bottom: 20px; -} - -.search:focus { - width: 50%; -} - -.btn-del { - margin-left: 30px; -} - -.profilepic-1 { - height: 50px; - float: left; - border-radius: 50%; - margin-top: -11px; - margin-right: 10px; - -} - -.bot { - font-size: 1.3em; - margin-top: 1em; -} - -bot: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.3s; -} - -.botheading { - margin-left: 0.5em; - font-weight: bold; -} - -.nodec { - list-style-type: none; -} - -.description { - margin-left: 1em; -} - -.detaillist { - margin-top: 20px; - margin-bottom: 20px; - font-size: 1.3em; -} - -.startbutton { - margin-left: 1em; - margin-top: 1em; - float: left; - order: 1; - -} - -.notrunning { - color: red; - margin-left: 1em; -} - -.running { - color: greenyellow; - margin-left: 1em; -} .red { color: red; } -.yellowgreen { - color: yellowgreen; + + +.title-wrapper *{ + vertical-align: middle; } -.btn-reload { - margin-top: 1em; +#id_img{ + display: inline-block; + margin-left: 1.2em; + } -.uilink { - margin-left: 1.1em; - font-size: 1.3em; - order: 2; +.description-wrapper *{ + vertical-align: middle; } -.bot-btn-cont { - height: 3em; - display: flex; - flex-direction: row; - align-items: center; +.invform *{ + margin-top: 1.5em; } -.stop-api-button{ - margin-top: 2em; + +#id_description{ + width: 18em; + height: 5em; } \ No newline at end of file diff --git a/invsystem/user_manager/templates/bases/navbar.html b/invsystem/user_manager/templates/bases/navbar.html index 0ddd6ec..e7ae547 100644 --- a/invsystem/user_manager/templates/bases/navbar.html +++ b/invsystem/user_manager/templates/bases/navbar.html @@ -11,6 +11,9 @@ integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous"> + + + {{ title }} @@ -24,7 +27,7 @@ - Welcome {{ user.username }}! + Wilkommen {{ user.username }}! {% else %}