aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/migrations/0007_auto_20200619_1508.py26
-rw-r--r--client/migrations/0008_auto_20200619_1538.py74
-rw-r--r--client/migrations/0009_auto_20200619_1546.py32
-rw-r--r--client/migrations/0010_documenttype_enabled.py18
-rw-r--r--client/migrations/0011_keys.py22
-rw-r--r--client/migrations/0012_document_group.py20
-rw-r--r--client/models.py57
-rw-r--r--client/templates/client/doc_create.html42
-rw-r--r--client/templates/client/index.html51
-rw-r--r--client/urls.py3
-rw-r--r--client/views.py51
11 files changed, 377 insertions, 19 deletions
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)