From ffb9b4111a891fda9e9e1ddf19de936bdbd664f8 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sat, 20 Jun 2020 00:28:16 +0200 Subject: Document support --- server/templates/server/doc_edit.html | 79 ++++++++++++++++++++++++++++ server/templates/server/doc_list.html | 70 +++++++++++++++++++++++++ server/templates/server/doc_type.html | 70 +++++++++++++++++++++++++ server/templates/server/index.html | 3 +- server/urls.py | 3 ++ server/views.py | 96 ++++++++++++++++++++++++++++++++++- 6 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 server/templates/server/doc_edit.html create mode 100644 server/templates/server/doc_list.html create mode 100644 server/templates/server/doc_type.html (limited to 'server') diff --git a/server/templates/server/doc_edit.html b/server/templates/server/doc_edit.html new file mode 100644 index 0000000..cca0607 --- /dev/null +++ b/server/templates/server/doc_edit.html @@ -0,0 +1,79 @@ +{% extends 'registration/base.html' %} + +{% block title %}Admin - Modifica Tipo{% endblock %} + +{% block nav %} + Home + Admin + Tipo Doc + Modifica Doc +{% endblock %} + +{% block content %} +
+
+
+
+
+ {% csrf_token %} +
+
+ + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ + +
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html new file mode 100644 index 0000000..cf98010 --- /dev/null +++ b/server/templates/server/doc_list.html @@ -0,0 +1,70 @@ +{% extends 'registration/base_custom.html' %} + +{% block title %}Admin - Documenti{% endblock %} + +{% block nav %} + +{% endblock %} + +{% block content %} +
+{% csrf_token %} + +
+
+ + add + +
+{% endblock %} + +{%block script%} +$(document).ready(function(){ + $('.collapsible').collapsible(); +}); +{% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html new file mode 100644 index 0000000..75bb79a --- /dev/null +++ b/server/templates/server/doc_type.html @@ -0,0 +1,70 @@ +{% extends 'registration/base_custom.html' %} + +{% block title %}Admin - Tipo Documenti{% endblock %} + +{% block nav %} + +{% endblock %} + +{% block content %} +
+{% csrf_token %} + +
+
+ + add + +
+{% endblock %} + +{%block script%} +$(document).ready(function(){ + $('.collapsible').collapsible(); +}); +{% endblock %} \ No newline at end of file diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 37a553b..4095d4a 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -44,7 +44,8 @@ I am convenient because I require little markup to use effectively.

- Lista documenti + Lista tipo doc + Lista documenti Approva documento
diff --git a/server/urls.py b/server/urls.py index a41b346..de94d50 100644 --- a/server/urls.py +++ b/server/urls.py @@ -6,4 +6,7 @@ urlpatterns = [ path('', views.index, name='server'), path('uapprove', views.uapprove, name='uapprove'), path('ulist', views.ulist, name='ulist'), + path('doctype', views.doctype, name='doctype'), + path('docedit', views.docedit, name='docedit'), + path('doclist', views.doclist, name='doclist'), ] diff --git a/server/views.py b/server/views.py index aa2dc3a..aed1fb6 100644 --- a/server/views.py +++ b/server/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render -from client.models import UserCode +from client.models import UserCode, Keys, DocumentType, Document from django.contrib.auth.models import Group, Permission, User +from django.db.models import Q +from django.http import HttpResponseRedirect # Create your views here. @@ -136,3 +138,95 @@ def ulist(request): return render(request, 'server/user_list.html', context) else: return render(request, 'client/index.html', context) + + +def doctype(request): + context = {} + if request.user.is_staff: + if request.method == "POST": + selected = [] + for i in request.POST.keys(): + if i == "csrfmiddlewaretoken": + continue + selected.append(DocumentType.objects.get(id=i)) + + for i in selected: + i.delete() + + parent_group = request.user.groups.values_list('name', flat=True)[ + 0] + group = Group.objects.get(name=parent_group) + public_types = DocumentType.objects.filter( + Q(group_private=False) | Q(group=group)) + out = [] + for doc in public_types: + out.append(doc) + + context = {'docs': out} + return render(request, 'server/doc_type.html', context) + else: + return render(request, 'client/index.html', context) + + +def docedit(request): + context = {} + if request.user.is_staff: + parent_group = request.user.groups.values_list('name', flat=True)[ + 0] + group = Group.objects.get(name=parent_group) + enabled = False + group_private = False + personal_data = False + medical_data = False + custom_data = False + name = "" + + enabled_check = "" + private_check = 'checked="checked"' + personal_check = 'checked="checked"' + medical_check = "" + custom_check = "" + context = { + "enabled_check": enabled_check, + "private_check": private_check, + "personal_check": personal_check, + "medical_check": medical_check, + "custom_check": custom_check, + } + if request.method == "POST": + enabled = "enabled" in request.POST.keys() + group_private = "group_private" in request.POST.keys() + personal_data = "personal_data" in request.POST.keys() + medical_data = "medical_data" in request.POST.keys() + custom_data = "custom_data" in request.POST.keys() + 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) + doctype.save() + for i in custom: + key = Keys(key=i[:-1], container=doctype) + key.save() + return HttpResponseRedirect('doctype') + + return render(request, 'server/doc_edit.html', context) + else: + return render(request, 'client/index.html', context) + + +def doclist(request): + context = {} + if request.user.is_staff: + 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) + context = {"docs": out} + return render(request, 'server/doc_list.html', context) + else: + return render(request, 'client/index.html', context) -- cgit v1.2.1