From ccc5d1f1b2cb4b5e2a95b97bbd1a5760ce585f08 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sat, 20 Jun 2020 15:55:28 +0200 Subject: Document custom field --- server/templates/server/approve_doc.html | 43 ++++++++++++ server/templates/server/approve_user.html | 51 ++++++++++----- server/templates/server/doc_edit.html | 19 +++++- server/templates/server/doc_list.html | 65 +++++++++++++----- server/templates/server/doc_type.html | 52 ++++++++++++--- server/templates/server/index.html | 2 +- server/urls.py | 1 + server/views.py | 105 ++++++++++++++++++++++++++---- 8 files changed, 278 insertions(+), 60 deletions(-) create mode 100644 server/templates/server/approve_doc.html (limited to 'server') diff --git a/server/templates/server/approve_doc.html b/server/templates/server/approve_doc.html new file mode 100644 index 0000000..82ecf2a --- /dev/null +++ b/server/templates/server/approve_doc.html @@ -0,0 +1,43 @@ +{% extends 'registration/base.html' %} + +{% block title %}Admin - Approva Utente{% endblock %} + +{% block nav %} + Home + Admin + Approva Documento +{% endblock %} + +{% block content %} + +{% if not empty %} +
+
+
+
    + {% for i in messages %} +
  • {{ i }}
  • + {% endfor %} +
+
+
+
+{% endif %} + +
+
+
+
+ {% csrf_token %} +
+

Inserire un codice per riga

+ +
+
+ Invia +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/server/templates/server/approve_user.html b/server/templates/server/approve_user.html index 126c0b9..9d4b36c 100644 --- a/server/templates/server/approve_user.html +++ b/server/templates/server/approve_user.html @@ -3,24 +3,41 @@ {% block title %}Admin - Approva Utente{% endblock %} {% block nav %} - Home - Admin - Approva Utente + Home + Admin + Approva Utente {% endblock %} {% block content %} -

Inserire un codice per riga

- -
- {% csrf_token %} - -

- -
+ +{% if not empty %} +
+
+
+
    + {% for i in messages %} +
  • {{ i }}
  • + {% endfor %} +
+
+
+
+{% endif %} + +
+
+
+
+ {% csrf_token %} +
+

Inserire un codice per riga

+ +
+
+ Invia +
+
+
+
+
{% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_edit.html b/server/templates/server/doc_edit.html index cca0607..8b01c35 100644 --- a/server/templates/server/doc_edit.html +++ b/server/templates/server/doc_edit.html @@ -41,31 +41,44 @@
-
+
-
+
-
+
+
+ +
+
+
+
+ + +
+
save diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index cf98010..c5978b1 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -7,10 +7,12 @@
- {% for key in keys %} - {{key}}
- {% endfor %} + {{doc.0.code}}
+ {{doc.0.compilation_date}}
+ {% if doc.0.document_type.personal_data %} + person + {% endif %} + {% if doc.0.document_type.medical_data %} + healing + {% endif %} + {% if doc.0.document_type.custom_message %} + message + {% endif %} + {% if doc.0.document_type.custom_data %} + add_circle_outline + {% endif %} + {% if doc.0.document_type.custom_data %} +
+ + + {% for key in doc.1 %} + + + + + {% endfor %} + +
{{key.key}}{{key.value}}
+ {% endif %}
{% endfor %} - {% endblock %} {%block script%} $(document).ready(function(){ $('.collapsible').collapsible(); }); +function send(id) { + var form = document.getElementById('selection') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index 75bb79a..fecfc9d 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -10,7 +10,8 @@ Tipo Doc
    {% if user.is_staff %} -
  • Elimina selezionati
  • +
  • Nascondi/mostra selezionati
  • +
  • Elimina selezionati
  • Pannello Admin
  • {% endif %} {% if user.is_authenticated %} @@ -32,32 +33,56 @@ {% block content %}
    {% csrf_token %} +
      {% for doctype in docs %}
    • - {% if doctype.enabled %} - visibility_on - {% else %} + {% if not doctype.0.enabled %} visibility_off {% endif %} - {{doctype.name}} + {% if not doctype.0.group_private %} + public + {% endif %} + {{doctype.0.name}} + {{doctype.2}}
- {% for key in keys %} - {{key}}
- {% endfor %} + {% if doctype.0.personal_data %} + person + {% endif %} + {% if doctype.0.medical_data %} + healing + {% endif %} + {% if doctype.0.custom_data %} + add_circle_outline + {% endif %} + {% if doctype.0.custom_message %} + message + {% endif %} + {% if doctype.0.custom_data %} +
+
    + {% for key in doctype.1 %} +
  • {{key.key}}
  • + {% endfor %} +
+ {% endif %} + {% if doctype.0.custom_message %} +
+ {{doctype.0.custom_message_text}} + {% endif %}
{% endfor %} @@ -67,4 +92,11 @@ $(document).ready(function(){ $('.collapsible').collapsible(); }); + +function send(id) { + var form = document.getElementById('selection') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %} \ No newline at end of file diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 4095d4a..d88454f 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -46,7 +46,7 @@
diff --git a/server/urls.py b/server/urls.py index de94d50..fb2c2f2 100644 --- a/server/urls.py +++ b/server/urls.py @@ -9,4 +9,5 @@ urlpatterns = [ path('doctype', views.doctype, name='doctype'), path('docedit', views.docedit, name='docedit'), path('doclist', views.doclist, name='doclist'), + path('docapprove', views.docapprove, name='docapprove'), ] diff --git a/server/views.py b/server/views.py index aed1fb6..b59dfb8 100644 --- a/server/views.py +++ b/server/views.py @@ -1,8 +1,9 @@ from django.shortcuts import render -from client.models import UserCode, Keys, DocumentType, Document +from client.models import UserCode, Keys, DocumentType, Document, KeyVal from django.contrib.auth.models import Group, Permission, User from django.db.models import Q from django.http import HttpResponseRedirect +from django.db.models.deletion import ProtectedError # Create your views here. @@ -36,25 +37,27 @@ def index(request): def uapprove(request): context = {} if (request.user.is_staff): + data = [] if request.method == "POST": parent_group = request.user.groups.values_list('name', flat=True)[ 0] group = Group.objects.get(name=parent_group) permission = Permission.objects.get(codename='approved') data = request.POST["codes"] - data += " " + data = "".join(data.split()) + data.replace("\r", "") data = data.split("\n") for i in range(len(data)): if not data[i].startswith("U"): data[i] = data[i] + " - Formato errato" - elif not data[i][1:-1].isdigit(): + elif not data[i][1:].isdigit(): data[i] = data[i] + " - Formato errato" - elif int(data[i][1:-1]) < 100000 or int(data[i][1:-1]) > 999999: + elif int(data[i][1:]) < 100000 or int(data[i][1:]) > 999999: data[i] = data[i] + " - Formato errato" - elif len(UserCode.objects.filter(code=data[i][1:-1])) == 0: + elif len(UserCode.objects.filter(code=data[i][1:])) == 0: data[i] = data[i] + " - Invalido" else: - user = UserCode.objects.filter(code=data[i][1:-1])[0].user + user = UserCode.objects.filter(code=data[i][1:])[0].user if len(user.groups.values_list('name', flat=True)) == 0: user.groups.add(group) user.user_permissions.add(permission) @@ -62,20 +65,58 @@ def uapprove(request): else: if user.groups.values_list('name', flat=True)[0] == parent_group: user.user_permissions.add(permission) - data[i] = data[i] + " - Gia` aggiunto" + data[i] = data[i] + " - Ok" else: user.groups.clear() user.groups.add(group) user.user_permissions.add(permission) data[i] = data[i] + " - Ok, cambio branca" - context = {'messages': data} + context = { + 'messages': data, + 'empty': len(data) == 0, + } return render(request, 'server/approve_user.html', context) else: return render(request, 'client/index.html', context) +def docapprove(request): + context = {} + if (request.user.is_staff): + data = [] + if request.method == "POST": + data = request.POST["codes"] + data = "".join(data.split()) + data.replace("\r", "") + data = data.split("\n") + for i in range(len(data)): + if not data[i].isdigit(): + data[i] = data[i] + " - Formato errato" + elif int(data[i]) < 100000 or int(data[i]) > 999999: + data[i] = data[i] + " - Formato errato" + elif len(Document.objects.filter(code=data[i])) == 0: + data[i] = data[i] + " - Invalido" + else: + document = Document.objects.filter(code=data[i])[0] + if document.status == 'ok': + data[i] = data[i] + " - Gia` approvato" + else: + document.status = 'ok' + document.save() + data[i] = data[i] + " - Ok" + + context = { + 'messages': data, + 'empty': len(data) == 0, + } + + return render(request, 'server/approve_doc.html', context) + else: + return render(request, 'client/index.html', context) + + def ulist(request): context = {} if (request.user.is_staff): @@ -148,10 +189,20 @@ def doctype(request): for i in request.POST.keys(): if i == "csrfmiddlewaretoken": continue + if i == "action": + continue + selected.append(DocumentType.objects.get(id=i)) for i in selected: - i.delete() + if request.POST["action"] == 'delete': + try: + i.delete() + except ProtectedError: + print("nope") + elif request.POST["action"] == 'hide': + i.enabled = not i.enabled + i.save() parent_group = request.user.groups.values_list('name', flat=True)[ 0] @@ -160,7 +211,9 @@ def doctype(request): Q(group_private=False) | Q(group=group)) out = [] for doc in public_types: - out.append(doc) + custom_keys = Keys.objects.filter(container=doc) + ref_docs = Document.objects.filter(document_type=doc) + out.append([doc, custom_keys, len(ref_docs)]) context = {'docs': out} return render(request, 'server/doc_type.html', context) @@ -186,12 +239,14 @@ def docedit(request): personal_check = 'checked="checked"' medical_check = "" custom_check = "" + custom_message_check = "" context = { "enabled_check": enabled_check, "private_check": private_check, "personal_check": personal_check, "medical_check": medical_check, "custom_check": custom_check, + "custom_message_check": custom_message_check, } if request.method == "POST": enabled = "enabled" in request.POST.keys() @@ -199,12 +254,14 @@ def docedit(request): personal_data = "personal_data" in request.POST.keys() medical_data = "medical_data" in request.POST.keys() custom_data = "custom_data" in request.POST.keys() + custom_message = "custom_message" in request.POST.keys() + custom_message_text = request.POST["custom_message_text"] name = request.POST["name"] custom = request.POST["custom"] custom += " " custom = custom.split("\n") doctype = DocumentType( - name=request.POST["name"], enabled=enabled, group_private=group_private, group=group, personal_data=personal_data, medical_data=medical_data, custom_data=custom_data) + custom_message=custom_message, custom_message_text=custom_message_text, name=request.POST["name"], enabled=enabled, group_private=group_private, group=group, personal_data=personal_data, medical_data=medical_data, custom_data=custom_data) doctype.save() for i in custom: key = Keys(key=i[:-1], container=doctype) @@ -219,13 +276,37 @@ def docedit(request): def doclist(request): context = {} if request.user.is_staff: + if request.method == "POST": + selected = [] + for i in request.POST.keys(): + if i == "csrfmiddlewaretoken": + continue + if i == "action": + continue + + selected.append(Document.objects.get(id=i)) + + for i in selected: + if request.POST["action"] == 'delete': + try: + i.delete() + except ProtectedError: + print("nope") + elif request.POST["action"] == 'approve': + i.status = 'ok' + i.save() + elif request.POST["action"] == 'archive': + i.status = 'archive' + i.save() + parent_group = request.user.groups.values_list('name', flat=True)[ 0] group = Group.objects.get(name=parent_group) documents = Document.objects.filter(group=group) out = [] for i in documents: - out.append(i) + custom_keys = KeyVal.objects.filter(container=i) + out.append([i, custom_keys]) context = {"docs": out} return render(request, 'server/doc_list.html', context) else: -- cgit v1.2.1