diff options
-rw-r--r-- | accounts/templates/accounts/index.html | 33 | ||||
-rw-r--r-- | client/migrations/0007_auto_20200619_1508.py | 26 | ||||
-rw-r--r-- | client/migrations/0008_auto_20200619_1538.py | 74 | ||||
-rw-r--r-- | client/migrations/0009_auto_20200619_1546.py | 32 | ||||
-rw-r--r-- | client/migrations/0010_documenttype_enabled.py | 18 | ||||
-rw-r--r-- | client/migrations/0011_keys.py | 22 | ||||
-rw-r--r-- | client/migrations/0012_document_group.py | 20 | ||||
-rw-r--r-- | client/models.py | 57 | ||||
-rw-r--r-- | client/templates/client/doc_create.html | 42 | ||||
-rw-r--r-- | client/templates/client/index.html | 51 | ||||
-rw-r--r-- | client/urls.py | 3 | ||||
-rw-r--r-- | client/views.py | 51 | ||||
-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 | ||||
-rw-r--r-- | templates/registration/base.html | 4 | ||||
-rw-r--r-- | templates/registration/base_custom.html | 32 |
20 files changed, 735 insertions, 51 deletions
diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index c01878c..5ba2dc1 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -143,4 +143,37 @@ </div> </div> <div id="medic" class="col s12">Tabella medica</div> +{% endblock %} + +{% block script %} + var elem = $('.tabs') + var options = { + yearRange:100, + format:'dd.mm.yyyy', + i18n: { + months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ], + monthsShort: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic' ], + weekdays: [ 'domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato' ], + weekdaysShort: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ], + weekdaysAbbrev: [ 'D', 'L', 'M', 'M', 'G', 'V', 'S' ], + today: 'Oggi', + clear: 'Cancella', + close: 'Chiudi', + firstDay: 1, + format: 'dddd d mmmm yyyy', + formatSubmit: 'yyyy/mm/dd', + labelMonthNext: 'Mese successivo', + labelMonthPrev: 'Mese precedente', + labelMonthSelect: 'Seleziona un mese', + labelYearSelect: 'Seleziona un anno' + }} + var instance = M.Tabs.init(elem, options); + document.addEventListener('DOMContentLoaded', function() { + var elems = document.querySelectorAll('.datepicker'); + var instances = M.Datepicker.init(elems, options); + }); + document.addEventListener('DOMContentLoaded', function() { + var elems = document.querySelectorAll('select'); + var instances = M.FormSelect.init(elems, options); + }); {% endblock %}
\ No newline at end of file diff --git a/client/migrations/0007_auto_20200619_1508.py b/client/migrations/0007_auto_20200619_1508.py new file mode 100644 index 0000000..a5f2669 --- /dev/null +++ b/client/migrations/0007_auto_20200619_1508.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.7 on 2020-06-19 13:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0006_auto_20200619_1049'), + ] + + operations = [ + migrations.RemoveField( + model_name='yearsubscription', + name='group', + ), + migrations.RemoveField( + model_name='yearsubscription', + name='school', + ), + migrations.AlterField( + model_name='yearsubscription', + name='year', + field=models.CharField(default='', max_length=250), + ), + ] diff --git a/client/migrations/0008_auto_20200619_1538.py b/client/migrations/0008_auto_20200619_1538.py new file mode 100644 index 0000000..c890cd1 --- /dev/null +++ b/client/migrations/0008_auto_20200619_1538.py @@ -0,0 +1,74 @@ +# Generated by Django 3.0.7 on 2020-06-19 13:38 + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('client', '0007_auto_20200619_1508'), + ] + + operations = [ + migrations.CreateModel( + name='KeyVal', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('key', models.CharField(db_index=True, max_length=240)), + ('value', models.CharField(db_index=True, max_length=240)), + ], + ), + migrations.CreateModel( + name='PersonalData', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('parent_name', models.CharField(default='', max_length=250)), + ('via', models.CharField(default='', max_length=250)), + ('cap', models.CharField(default='', max_length=250)), + ('country', models.CharField(default='', max_length=250)), + ('nationality', models.CharField(default='', max_length=250)), + ('born_date', models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0), null=True)), + ('home_phone', models.CharField(default='', max_length=250)), + ('phone', models.CharField(default='', max_length=250)), + ], + ), + migrations.AddField( + model_name='document', + name='compilation_date', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='document', + name='document_type', + field=models.CharField(default='', max_length=50), + ), + migrations.AddField( + model_name='document', + name='status', + field=models.CharField(default='', max_length=50), + ), + migrations.AddField( + model_name='document', + name='user', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.DeleteModel( + name='YearSubscription', + ), + migrations.AddField( + model_name='keyval', + name='container', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='client.Document'), + ), + migrations.AddField( + model_name='document', + name='personal_data', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, to='client.PersonalData'), + ), + ] diff --git a/client/migrations/0009_auto_20200619_1546.py b/client/migrations/0009_auto_20200619_1546.py new file mode 100644 index 0000000..88961d2 --- /dev/null +++ b/client/migrations/0009_auto_20200619_1546.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.7 on 2020-06-19 13:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0011_update_proxy_permissions'), + ('client', '0008_auto_20200619_1538'), + ] + + operations = [ + migrations.CreateModel( + name='DocumentType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('group_private', models.BooleanField(default=False)), + ('personal_data', models.BooleanField(default=False)), + ('medical_data', models.BooleanField(default=False)), + ('custom_data', models.BooleanField(default=False)), + ('name', models.CharField(default='', max_length=250)), + ('group', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auth.Group')), + ], + ), + migrations.AlterField( + model_name='document', + name='document_type', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, to='client.DocumentType'), + ), + ] diff --git a/client/migrations/0010_documenttype_enabled.py b/client/migrations/0010_documenttype_enabled.py new file mode 100644 index 0000000..24928b0 --- /dev/null +++ b/client/migrations/0010_documenttype_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-19 16:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0009_auto_20200619_1546'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='enabled', + field=models.BooleanField(default=False), + ), + ] diff --git a/client/migrations/0011_keys.py b/client/migrations/0011_keys.py new file mode 100644 index 0000000..8739908 --- /dev/null +++ b/client/migrations/0011_keys.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.7 on 2020-06-19 20:36 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0010_documenttype_enabled'), + ] + + operations = [ + migrations.CreateModel( + name='Keys', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('key', models.CharField(db_index=True, max_length=240)), + ('container', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='client.DocumentType')), + ], + ), + ] diff --git a/client/migrations/0012_document_group.py b/client/migrations/0012_document_group.py new file mode 100644 index 0000000..a1fbabc --- /dev/null +++ b/client/migrations/0012_document_group.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.7 on 2020-06-19 21:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0011_update_proxy_permissions'), + ('client', '0011_keys'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='group', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auth.Group'), + ), + ] diff --git a/client/models.py b/client/models.py index d6e8578..01d5f4c 100644 --- a/client/models.py +++ b/client/models.py @@ -1,25 +1,21 @@ from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from datetime import datetime # Create your models here. -class Document(models.Model): - code = models.IntegerField(default=0) - - class Meta: - permissions = [ - ("approved", "The user is approved") - ] +class DocumentType(models.Model): + enabled = models.BooleanField(default=False) + group_private = models.BooleanField(default=False) + group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE) + personal_data = models.BooleanField(default=False) + medical_data = models.BooleanField(default=False) + custom_data = models.BooleanField(default=False) + name = models.CharField(default="", max_length=250) -class YearSubscription(models.Model): - user = models.ForeignKey(User, default=None, on_delete=models.CASCADE) - group = models.CharField(default="", max_length=50) - compilation_date = models.DateTimeField(auto_now_add=True) - status = models.CharField(default="", max_length=50) - code = models.IntegerField(default=0) +class PersonalData(models.Model): parent_name = models.CharField(default="", max_length=250) via = models.CharField(default="", max_length=250) cap = models.CharField(default="", max_length=250) @@ -28,8 +24,37 @@ class YearSubscription(models.Model): born_date = models.DateField(null=True, default=datetime.fromtimestamp(0)) home_phone = models.CharField(default="", max_length=250) phone = models.CharField(default="", max_length=250) - school = models.CharField(default="", max_length=250) - year = models.IntegerField(default=0) + + +class Document(models.Model): + user = models.ForeignKey(User, default=None, on_delete=models.CASCADE) + group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE) + code = models.IntegerField(default=0) + compilation_date = models.DateTimeField(auto_now_add=True) + status = models.CharField(default="", max_length=50) + document_type = models.ForeignKey( + DocumentType, default=None, on_delete=models.PROTECT) + + personal_data = models.ForeignKey( + PersonalData, default=None, on_delete=models.PROTECT) + + class Meta: + permissions = [ + ("approved", "The user is approved") + ] + + +class KeyVal(models.Model): + container = models.ForeignKey( + Document, db_index=True, on_delete=models.CASCADE) + key = models.CharField(max_length=240, db_index=True) + value = models.CharField(max_length=240, db_index=True) + + +class Keys(models.Model): + container = models.ForeignKey( + DocumentType, db_index=True, on_delete=models.CASCADE) + key = models.CharField(max_length=240, db_index=True) class UserCode(models.Model): diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html new file mode 100644 index 0000000..a52518f --- /dev/null +++ b/client/templates/client/doc_create.html @@ -0,0 +1,42 @@ +{% 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="#!" class="breadcrumb hide-on-med-and-down">Crea 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 'create'%}" method="post" class="col s12"> + {% csrf_token %} + <div class="row"> + <div class="input-field col s12"> + <select name="doctype"> + <option value="" disabled selected>Scegli</option> + {% for doctype in docs%} + <option value="{{doctype.id}}">{{doctype.name}}</option> + {% endfor %} + </select> + <label>Documento</label> + </div> + </div> + <button class="btn waves-effect waves-light" type="submit" name="action">Invia + <i class="material-icons right">send</i> + </button> + </form> + </div> + </div> + </div> +</div> +{% endblock %} + +{% block script %} +$(document).ready(function(){ + $('select').formSelect(); + }); +{% endblock %}
\ No newline at end of file diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 64b4d42..2b19f30 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -7,8 +7,45 @@ {% endblock%} {% block content %} +<div class="tap-target" data-target="add"> + <div class="tap-target-content"> + <h5>Aggiungi un documento</h5> + <p>Usa questo bottone per creare un nuovo documento</p> + </div> +</div> {% if user.is_authenticated %} {% if user.is_staff or perms.client.approved %} + <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 id="add" class="btn-floating btn-large red lightend-1" href="{% url 'create'%}"> + <i class="large material-icons">add</i> + </a> + </div> {% else %} <div class="row"> <div class="col l4 offset-l4 m8 offset-m2 s12"> @@ -34,4 +71,18 @@ </div> </div> {% endif %} +{% endblock %} + +{% block script %} +$(document).ready(function(){ + $('.tap-target').tapTarget(); + {% if empty %} + $('.tap-target').tapTarget('open'); + {% endif %} +}); +$('*').click(function(event) { + if (this === event.target) { + $('.tap-target').tapTarget('close'); + } +}); {% endblock %}
\ No newline at end of file diff --git a/client/urls.py b/client/urls.py index 4e9f08e..b58433e 100644 --- a/client/urls.py +++ b/client/urls.py @@ -4,5 +4,6 @@ from . import views urlpatterns = [ path('', views.index, name='index'), - path('approve', views.approve, name='approve') + path('approve', views.approve, name='approve'), + path('create', views.create, name='create'), ] diff --git a/client/views.py b/client/views.py index 96eb977..78ca7d1 100644 --- a/client/views.py +++ b/client/views.py @@ -1,9 +1,10 @@ from random import randint +from django.contrib.auth.models import Group, Permission, User +from client.models import UserCode, Keys, DocumentType, Document, PersonalData +from django.db.models import Q from django.shortcuts import render -from .models import UserCode - # Create your views here. @@ -19,6 +20,15 @@ def index(request): break userCode = UserCode(user=request.user, code=code) userCode.save() + + documents = Document.objects.filter(user=request.user) + out = [] + for i in documents: + out.append(i) + context = { + "docs": out, + "empty": len(out) == 0, + } return render(request, 'client/index.html', context) @@ -33,3 +43,40 @@ def approve(request): return render(request, 'client/approve.html', context) else: return render(request, 'client/index.html', context) + + +def create(request): + context = {} + if request.user.is_authenticated: + 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} + if request.method == "POST": + usercode = UserCode.objects.filter(user=request.user)[0] + code = 0 + status = 0 + document_type = DocumentType.objects.get( + id=request.POST["doctype"]) + personal_data = PersonalData(parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country, + nationality=usercode.nationality, born_date=usercode.born_date, home_phone=usercode.home_phone, phone=usercode.phone) + personal_data.save() + + while (True): + code = randint(100000, 999999) + if len(Document.objects.filter(code=code)) == 0: + break + + document = Document( + user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data) + document.save() + + return render(request, 'client/doc_create.html', context) + else: + return render(request, 'client/index.html', context) 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) diff --git a/templates/registration/base.html b/templates/registration/base.html index f5a8a80..2e4f5b2 100644 --- a/templates/registration/base.html +++ b/templates/registration/base.html @@ -39,5 +39,9 @@ integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> + <script> + {% block script %} + {% endblock%} + </script> </body> </html>
\ No newline at end of file diff --git a/templates/registration/base_custom.html b/templates/registration/base_custom.html index d38be7a..56b9180 100644 --- a/templates/registration/base_custom.html +++ b/templates/registration/base_custom.html @@ -20,36 +20,8 @@ crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script type="text/javascript"> - var elem = $('.tabs') - var options = { - yearRange:100, - format:'dd.mm.yyyy', - i18n: { - months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ], - monthsShort: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic' ], - weekdays: [ 'domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato' ], - weekdaysShort: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ], - weekdaysAbbrev: [ 'D', 'L', 'M', 'M', 'G', 'V', 'S' ], - today: 'Oggi', - clear: 'Cancella', - close: 'Chiudi', - firstDay: 1, - format: 'dddd d mmmm yyyy', - formatSubmit: 'yyyy/mm/dd', - labelMonthNext: 'Mese successivo', - labelMonthPrev: 'Mese precedente', - labelMonthSelect: 'Seleziona un mese', - labelYearSelect: 'Seleziona un anno' - }} - var instance = M.Tabs.init(elem, options); - document.addEventListener('DOMContentLoaded', function() { - var elems = document.querySelectorAll('.datepicker'); - var instances = M.Datepicker.init(elems, options); - }); - document.addEventListener('DOMContentLoaded', function() { - var elems = document.querySelectorAll('select'); - var instances = M.FormSelect.init(elems, options); - }); + {% block script %} + {% endblock %} </script> </body> </html>
\ No newline at end of file |