diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-20 00:28:16 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-20 00:28:16 +0200 |
commit | ffb9b4111a891fda9e9e1ddf19de936bdbd664f8 (patch) | |
tree | cbd563acbfb97d2cad4f7da425de412aad00e5dd /server | |
parent | More data for users (diff) | |
download | scout-subs-ffb9b4111a891fda9e9e1ddf19de936bdbd664f8.tar.gz scout-subs-ffb9b4111a891fda9e9e1ddf19de936bdbd664f8.zip |
Document support
Diffstat (limited to 'server')
-rw-r--r-- | server/templates/server/doc_edit.html | 79 | ||||
-rw-r--r-- | server/templates/server/doc_list.html | 70 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 70 | ||||
-rw-r--r-- | server/templates/server/index.html | 3 | ||||
-rw-r--r-- | server/urls.py | 3 | ||||
-rw-r--r-- | server/views.py | 96 |
6 files changed, 319 insertions, 2 deletions
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 %} + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> + <a href="{% url 'doctype' %}" class="breadcrumb hide-on-med-and-down">Tipo Doc</a> + <a href="#!" class="breadcrumb hide-on-med-and-down">Modifica Doc</a> +{% endblock %} + +{% block content %} +<div class="row"> + <div class="col l8 offset-l2 s12"> + <div class="card-panel"> + <div class="row"> + <form id="form" action="{% url 'docedit'%}" method="post" class="col s12"> + {% csrf_token %} + <div class="row"> + <div class="input-field col s12"> + <input name="name" value="{{name}}" id="name" type="text" class="validate"> + <label for="name">Nome</label> + </div> + </div> + <div class="row"> + <div class="switch col s3"> + <label> + Disabilitato + <input name="enabled" type="checkbox" {{enabled_check}}> + <span class="lever"></span> + Abilitato + </label> + </div> + <div class="switch col s3"> + <label> + Publico + <input name="group_private" type="checkbox" {{private_check}}> + <span class="lever"></span> + Privato + </label> + </div> + </div> + <div class="row"> + <div class="input-field col s3"> + <label> + <input name="personal_data" type="checkbox" class="filled-in" {{personal_check}}/> + <span>Dati personali</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="medical_data" type="checkbox" class="filled-in" {{medical_check}} /> + <span>Dati medici</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="custom_data" type="checkbox" class="filled-in" {{custom_check}}/> + <span>Parametri personalizzati</span> + </label> + </div> + </div> + <div class="row"> + <div class="input-field col s12"> + <textarea name="custom" id="textarea" class="materialize-textarea"></textarea> + <label for="textarea">Lista parametri personalizzati, uno per riga</label> + </div> + </div> + <div class="fixed-action-btn"> + <a class="btn-floating btn-large red lighten-1" onclick="document.getElementById('form').submit()"> + <i class="large material-icons">save</i> + </a> + </div> + </form> + </div> + </div> + </div> +</div> +{% 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 %} + <nav> + <div class="nav-wrapper red lighten-1"> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> + <a href="{% url 'doctype' %}" class="breadcrumb hide-on-med-and-down">Documenti</a> + <ul class="right"> + {% if user.is_staff %} + <li><a onclick="document.getElementById('selection').submit()">Elimina selezionati</a></li> + <li><a href="{% url 'server' %}">Pannello Admin</a></li> + {% endif %} + {% if user.is_authenticated %} + <li><a href="{% url 'personal' %}">{{ user.username }}</a></li> + {% endif %} + {% if user.username != "" %} + <li> + <a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a> + </li> + {% else %} + <li><a href="{% url 'signup' %}">Registrazione</a></li> + <li><a href="{% url 'login' %}">Login</a></li> + {% endif %} + </ul> + </div> + </nav> +{% endblock %} + +{% block content %} +<form id="selection" action="{% url 'doctype' %}" method="post"> +{% csrf_token %} +<ul class="collapsible"> + {% for doc in docs %} + <li> + <div class="collapsible-header"> + <label> + <input name={{doc.id}} type="checkbox" class="filled-in"/> + <span></span> + </label> + {% if doc.enabled %} + <i class="material-icons">visibility_on</i> + {% else %} + <i class="material-icons">visibility_off</i> + {% endif %} + {{doc.document_type.name}} + </div> + <div class="collapsible-body"><span> + {% for key in keys %} + {{key}}<br> + {% endfor %} + </span></div> + </li> + {% endfor %} +</ul> +</form> +<div class="fixed-action-btn"> + <a class="btn-floating btn-large red lightend-1" href="{% url 'docedit'%}"> + <i class="large material-icons">add</i> + </a> +</div> +{% 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 %} + <nav> + <div class="nav-wrapper red lighten-1"> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> + <a href="{% url 'doctype' %}" class="breadcrumb hide-on-med-and-down">Tipo Doc</a> + <ul class="right"> + {% if user.is_staff %} + <li><a onclick="document.getElementById('selection').submit()">Elimina selezionati</a></li> + <li><a href="{% url 'server' %}">Pannello Admin</a></li> + {% endif %} + {% if user.is_authenticated %} + <li><a href="{% url 'personal' %}">{{ user.username }}</a></li> + {% endif %} + {% if user.username != "" %} + <li> + <a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a> + </li> + {% else %} + <li><a href="{% url 'signup' %}">Registrazione</a></li> + <li><a href="{% url 'login' %}">Login</a></li> + {% endif %} + </ul> + </div> + </nav> +{% endblock %} + +{% block content %} +<form id="selection" action="{% url 'doctype' %}" method="post"> +{% csrf_token %} +<ul class="collapsible"> + {% for doctype in docs %} + <li> + <div class="collapsible-header"> + <label> + <input name={{doctype.id}} type="checkbox" class="filled-in"/> + <span></span> + </label> + {% if doctype.enabled %} + <i class="material-icons">visibility_on</i> + {% else %} + <i class="material-icons">visibility_off</i> + {% endif %} + {{doctype.name}} + </div> + <div class="collapsible-body"><span> + {% for key in keys %} + {{key}}<br> + {% endfor %} + </span></div> + </li> + {% endfor %} +</ul> +</form> +<div class="fixed-action-btn"> + <a class="btn-floating btn-large red lightend-1" href="{% url 'docedit'%}"> + <i class="large material-icons">add</i> + </a> +</div> +{% 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.</p> </div> <div class="card-action"> - <a href="{% url 'ulist' %}">Lista documenti</a> + <a href="{% url 'doctype' %}">Lista tipo doc</a> + <a href="{% url 'doclist' %}">Lista documenti</a> <a href="{% url 'uapprove' %}">Approva documento</a> </div> </div> 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) |