aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-06-20 23:32:55 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-06-20 23:32:55 +0200
commit26fb6c43a27c014383127d0e4b3fb29f8b923690 (patch)
tree05fd542c342cf12cac72b49e5b4b44db7411d91a /client
parentDocument custom field (diff)
downloadscout-subs-26fb6c43a27c014383127d0e4b3fb29f8b923690.tar.gz
scout-subs-26fb6c43a27c014383127d0e4b3fb29f8b923690.zip
Doc, doctypes, users all done
Diffstat (limited to 'client')
-rw-r--r--client/migrations/0015_personaldata_email.py18
-rw-r--r--client/migrations/0016_auto_20200620_1733.py26
-rw-r--r--client/migrations/0017_usercode_medic.py19
-rw-r--r--client/migrations/0018_auto_20200620_2007.py18
-rw-r--r--client/migrations/0019_auto_20200620_2008.py18
-rw-r--r--client/migrations/0020_auto_20200620_2200.py109
-rw-r--r--client/migrations/0021_documenttype_sign_req.py18
-rw-r--r--client/migrations/0022_auto_20200620_2316.py18
-rw-r--r--client/models.py29
-rw-r--r--client/templates/client/doc_create.html8
-rw-r--r--client/templates/client/doc_edit.html86
-rw-r--r--client/templates/client/index.html99
-rw-r--r--client/urls.py1
-rw-r--r--client/views.py113
14 files changed, 542 insertions, 38 deletions
diff --git a/client/migrations/0015_personaldata_email.py b/client/migrations/0015_personaldata_email.py
new file mode 100644
index 0000000..86f7213
--- /dev/null
+++ b/client/migrations/0015_personaldata_email.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-06-20 15:29
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0014_auto_20200620_1506'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='personaldata',
+ name='email',
+ field=models.CharField(default='', max_length=250),
+ ),
+ ]
diff --git a/client/migrations/0016_auto_20200620_1733.py b/client/migrations/0016_auto_20200620_1733.py
new file mode 100644
index 0000000..11fb49f
--- /dev/null
+++ b/client/migrations/0016_auto_20200620_1733.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.0.7 on 2020-06-20 15:33
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0015_personaldata_email'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='MedicalData',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('medic_name', models.CharField(default='', max_length=250)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='document',
+ name='medical_data',
+ field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='client.MedicalData'),
+ ),
+ ]
diff --git a/client/migrations/0017_usercode_medic.py b/client/migrations/0017_usercode_medic.py
new file mode 100644
index 0000000..1c4071a
--- /dev/null
+++ b/client/migrations/0017_usercode_medic.py
@@ -0,0 +1,19 @@
+# Generated by Django 3.0.7 on 2020-06-20 18:04
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0016_auto_20200620_1733'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='usercode',
+ name='medic',
+ field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, to='client.MedicalData'),
+ ),
+ ]
diff --git a/client/migrations/0018_auto_20200620_2007.py b/client/migrations/0018_auto_20200620_2007.py
new file mode 100644
index 0000000..17f40b3
--- /dev/null
+++ b/client/migrations/0018_auto_20200620_2007.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-06-20 18:07
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0017_usercode_medic'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='medicaldata',
+ name='medic_name',
+ field=models.CharField(default='', max_length=250, null=True),
+ ),
+ ]
diff --git a/client/migrations/0019_auto_20200620_2008.py b/client/migrations/0019_auto_20200620_2008.py
new file mode 100644
index 0000000..15dff2f
--- /dev/null
+++ b/client/migrations/0019_auto_20200620_2008.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-06-20 18:08
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0018_auto_20200620_2007'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='medicaldata',
+ name='medic_name',
+ field=models.CharField(default='', max_length=250),
+ ),
+ ]
diff --git a/client/migrations/0020_auto_20200620_2200.py b/client/migrations/0020_auto_20200620_2200.py
new file mode 100644
index 0000000..cdf9cc9
--- /dev/null
+++ b/client/migrations/0020_auto_20200620_2200.py
@@ -0,0 +1,109 @@
+# Generated by Django 3.0.7 on 2020-06-20 20:00
+
+import datetime
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0019_auto_20200620_2008'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='medicaldata',
+ name='address',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='allergy',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='cell_phone',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='drugs',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='drugs_bool',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='emer_name',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='emer_phone',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='emer_relative',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='health_care',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='injuries',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='medic_address',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='medic_phone',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='misc',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='misc_bool',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='rc',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='rega',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='sickness',
+ field=models.CharField(default='', max_length=250),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='tetanus_date',
+ field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0), null=True),
+ ),
+ migrations.AddField(
+ model_name='medicaldata',
+ name='vaccine',
+ field=models.CharField(default='', max_length=250),
+ ),
+ ]
diff --git a/client/migrations/0021_documenttype_sign_req.py b/client/migrations/0021_documenttype_sign_req.py
new file mode 100644
index 0000000..5538a2f
--- /dev/null
+++ b/client/migrations/0021_documenttype_sign_req.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-06-20 21:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0020_auto_20200620_2200'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='documenttype',
+ name='sign_req',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/client/migrations/0022_auto_20200620_2316.py b/client/migrations/0022_auto_20200620_2316.py
new file mode 100644
index 0000000..37a602b
--- /dev/null
+++ b/client/migrations/0022_auto_20200620_2316.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-06-20 21:16
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0021_documenttype_sign_req'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='documenttype',
+ old_name='sign_req',
+ new_name='auto_sign',
+ ),
+ ]
diff --git a/client/models.py b/client/models.py
index e7142ac..78b8df4 100644
--- a/client/models.py
+++ b/client/models.py
@@ -7,6 +7,7 @@ from datetime import datetime
class DocumentType(models.Model):
enabled = models.BooleanField(default=False)
+ auto_sign = 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)
@@ -26,6 +27,30 @@ class PersonalData(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)
+ email = models.CharField(default="", max_length=250)
+
+
+class MedicalData(models.Model):
+ emer_name = models.CharField(default="", max_length=250)
+ emer_relative = models.CharField(default="", max_length=250)
+ cell_phone = models.CharField(default="", max_length=250)
+ address = models.CharField(default="", max_length=250)
+ emer_phone = models.CharField(default="", max_length=250)
+ health_care = models.CharField(default="", max_length=250)
+ injuries = models.CharField(default="", max_length=250)
+ rc = models.CharField(default="", max_length=250)
+ rega = models.BooleanField(default=False)
+ medic_name = models.CharField(default="", max_length=250)
+ medic_phone = models.CharField(default="", max_length=250)
+ medic_address = models.CharField(default="", max_length=250)
+ sickness = models.CharField(default="", max_length=250)
+ vaccine = models.CharField(default="", max_length=250)
+ tetanus_date = models.DateField(null=True, default=datetime.fromtimestamp(0))
+ allergy = models.CharField(default="", max_length=250)
+ drugs_bool = models.BooleanField(default=False)
+ drugs = models.CharField(default="", max_length=250)
+ misc_bool = models.BooleanField(default=False)
+ misc = models.CharField(default="", max_length=250)
class Document(models.Model):
@@ -40,6 +65,9 @@ class Document(models.Model):
personal_data = models.ForeignKey(
PersonalData, default=None, on_delete=models.PROTECT, null=True)
+ medical_data = models.ForeignKey(
+ MedicalData, default=None, on_delete=models.PROTECT, null=True)
+
class Meta:
permissions = [
("approved", "The user is approved")
@@ -61,6 +89,7 @@ class Keys(models.Model):
class UserCode(models.Model):
user = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
+ medic = models.ForeignKey(MedicalData, default=None, on_delete=models.PROTECT)
code = models.IntegerField(default=0)
parent_name = models.CharField(default="", max_length=250)
via = models.CharField(default="", max_length=250)
diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html
index 550eb54..39deb2d 100644
--- a/client/templates/client/doc_create.html
+++ b/client/templates/client/doc_create.html
@@ -1,6 +1,6 @@
{% extends 'registration/base.html' %}
-{% block title %}Admin - Modifica Tipo{% endblock %}
+{% block title %}Crea Documento{% endblock %}
{% block nav %}
<a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a>
@@ -46,14 +46,14 @@
{% if personal_data %}
<div class="row">
<div class="col s12">
- <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&aacute le informazioni personali, prego verificare che siano corrette e aggiornate</a>
+ <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&agrave; le informazioni personali, prego verificare che siano corrette e aggiornate</a>
</div>
</div>
{% endif %}
{% if medical_data %}
<div class="row">
<div class="col s12">
- <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&aacute le informazioni mediche, prego verificare che siano corrette e aggiornate</a>
+ <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&agrave; le informazioni mediche, prego verificare che siano corrette e aggiornate</a>
</div>
</div>
{% endif %}
@@ -68,7 +68,7 @@
{% for key in keys %}
<div class="row">
<div class="input-field col s12">
- <input value="{{key.1}}" name="{{key.0.id}}" id="{{key.0.id}}" type="text" class="validate">
+ <input value="{{key.1}}" name="{{key.0.id}}" id="{{key.0.id}}" type="text">
<label for="{{key.0.id}}">{{key.0.key}}</label>
</div>
</div>
diff --git a/client/templates/client/doc_edit.html b/client/templates/client/doc_edit.html
new file mode 100644
index 0000000..8cd5a98
--- /dev/null
+++ b/client/templates/client/doc_edit.html
@@ -0,0 +1,86 @@
+{% extends 'registration/base.html' %}
+
+{% block title %}Modifica documento{% endblock %}
+
+{% block nav %}
+ <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a>
+ <a href="#!" class="breadcrumb hide-on-med-and-down">Modifica Documento</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 'edit'%}" method="post" class="col s12">
+ {% csrf_token %}
+ <input type="hidden" name="doc" value="{{doc.id}}">
+ <div class="row">
+ <div class="input-field col s12">
+ <select>
+ <option disabled selected>{{doc.document_type.name}}</option>
+ </select>
+ <label>Documento</label>
+ </div>
+ </div>
+ {% if personal_data %}
+ <div class="row">
+ <div class="col s12">
+ <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&agrave; le informazioni personali, prego verificare che siano corrette e aggiornate</a>
+ </div>
+ </div>
+ {% endif %}
+ {% if medical_data %}
+ <div class="row">
+ <div class="col s12">
+ <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterr&agrave; le informazioni mediche, prego verificare che siano corrette e aggiornate</a>
+ </div>
+ </div>
+ {% endif %}
+ {% if custom_message %}
+ <div class="row">
+ <div class="col s12">
+ <a style="pointer-events: none; cursor: default;" class="btn red lighten-1">{{custom_message_text}}</a>
+ </div>
+ </div>
+ {% endif %}
+ {% if custom_data %}
+ {% for key in keys %}
+ <div class="row">
+ <div class="input-field col s12">
+ <input value="{{key.1}}" name="{{key.0.id}}" id="{{key.0.id}}" type="text">
+ <label for="{{key.0.id}}">{{key.0.key}}</label>
+ </div>
+ </div>
+ {% endfor %}
+ {% endif %}
+ <div class="row">
+ <div class="col s12">
+ <br>
+ <a class="btn waves-effect waves-light" onclick="window.history.back();" >
+ <i class="material-icons left">navigate_before</i>Indietro
+ </a>
+ <a class="btn waves-effect waves-light" onclick="send('save')" >Salva
+ <i class="material-icons right">save</i>
+ </a>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+</div>
+{% endblock %}
+
+{% block script %}
+$(document).ready(function(){
+ $('select').formSelect();
+ {% if error %}
+ M.toast({html: '{{ error_text}}', classes: 'orange'})
+ {% endif %}
+ });
+function send(id) {
+ var form = document.getElementById('form')
+ form.submit()
+}
+{% endblock %} \ No newline at end of file
diff --git a/client/templates/client/index.html b/client/templates/client/index.html
index 96179b2..733f62f 100644
--- a/client/templates/client/index.html
+++ b/client/templates/client/index.html
@@ -13,6 +13,12 @@
<p>Usa questo bottone per creare un nuovo documento</p>
</div>
</div>
+
+<form id="form" method="post" action="{% url 'index'%}">
+ {% csrf_token %}
+ <input type="hidden" name="action" id="action">
+</form>
+
{% if user.is_authenticated %}
{% if user.is_staff or perms.client.approved %}
{% if not empty %}
@@ -24,40 +30,83 @@
<i class="material-icons">timelapse</i>
{% elif doc.0.status == "ok" %}
<i class="material-icons">check</i>
+ {% elif doc.0.status == "autosign" %}
+ <i class="material-icons">assignment_turned_in</i>
{% endif %}
{{doc.0.document_type.name}}
- <span class="badge" data-badge-caption="">{{doc.0.compilation_date}}</span></div>
+ <span class="badge" data-badge-caption="">{{doc.0.compilation_date}}</span>
</div>
<div class="collapsible-body"><span>
{% if doc.0.status == "wait" %}
- <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a>
- <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">delete</i> Elimina documento</a>
- <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">edit</i> Modifica documento</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('f{{doc.0.id}}')"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a>
+ <br>
+ <br>
+ {% elif doc.0.status == "autosign" %}
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('a{{doc.0.id}}')"><i class="material-icons left">check</i>Approva documento</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a>
<br>
<br>
{% endif %}
+ <ul class="collapsible">
{% if doc.0.document_type.personal_data %}
- <i class="material-icons">person</i>
+ <li>
+ <div class="collapsible-header">
+ <i class="material-icons">person</i>Dati personali
+ </div>
+ <div class="collapsible-body"><span>
+ <table class="striped">
+ <tbody>
+ {% for field in doc.2 %}
+ <tr>
+ <td>{{field}}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </span></div>
+ </li>
{% endif %}
{% if doc.0.document_type.medical_data %}
- <i class="material-icons">healing</i>
+ <li>
+ <div class="collapsible-header">
+ <i class="material-icons">healing</i>Dati medici
+ </div>
+ <div class="collapsible-body"><span>
+ <table class="striped">
+ <tbody>
+ {% for field in doc.3 %}
+ <tr>
+ <td>{{field}}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </span></div>
+ </li>
{% endif %}
{% if doc.0.document_type.custom_data %}
- <i class="material-icons">add_circle_outline</i>
- {% endif %}
- {% if doc.0.document_type.custom_data %}
- <br>
- <table class="striped">
- <tbody>
- {% for key in doc.1 %}
- <tr>
- <td>{{key.key}}</td>
- <td>{{key.value}}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ <li>
+ <div class="collapsible-header">
+ <i class="material-icons">add_circle_outline</i>Dati aggiuntivi
+ </div>
+ <div class="collapsible-body"><span>
+ <table class="striped">
+ <tbody>
+ {% for key in doc.1 %}
+ <tr>
+ <td>{{key.key}}</td>
+ <td>{{key.value}}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </span></div>
+ </li>
{% endif %}
+ </ul>
</span></div>
</li>
{% endfor %}
@@ -73,7 +122,7 @@
<div class="col l4 offset-l4 m8 offset-m2 s12">
<div class="card">
<div class="card-content">
- <p>Il tuo utente non e` ancora stato approvato.</p>
+ <p>Il tuo utente non &egrave; ancora stato approvato.</p>
</div>
<div class="card-action">
<a href="{% url 'approve' %}">Come farsi approvare l'utente</a>
@@ -87,7 +136,7 @@
<div class="col l4 offset-l4 m8 offset-m2 s12">
<div class="card">
<div class="card-content">
- <p>Se hai gia` un account clicca login in alto a destra. Altrimenti clicca registrazione</p>
+ <p>Se hai gi&agrave; un account clicca login in alto a destra. Altrimenti clicca registrazione</p>
</div>
</div>
</div>
@@ -108,4 +157,10 @@ $('*').click(function(event) {
$('.tap-target').tapTarget('close');
}
});
+function send(id) {
+ var form = document.getElementById('form')
+ var action = document.getElementById('action')
+ action.setAttribute('value', id);
+ form.submit()
+}
{% endblock %} \ No newline at end of file
diff --git a/client/urls.py b/client/urls.py
index b58433e..164eefc 100644
--- a/client/urls.py
+++ b/client/urls.py
@@ -6,4 +6,5 @@ urlpatterns = [
path('', views.index, name='index'),
path('approve', views.approve, name='approve'),
path('create', views.create, name='create'),
+ path('edit', views.edit, name='edit'),
]
diff --git a/client/views.py b/client/views.py
index f70d930..b610962 100644
--- a/client/views.py
+++ b/client/views.py
@@ -1,6 +1,6 @@
from random import randint
from django.contrib.auth.models import Group, Permission, User
-from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal
+from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData
from django.db.models import Q
from django.http import HttpResponseRedirect
@@ -19,17 +19,54 @@ def index(request):
code = randint(100000, 999999)
if len(UserCode.objects.filter(code=code)) == 0:
break
- userCode = UserCode(user=request.user, code=code)
+ medic = MedicalData()
+ medic.save()
+ userCode = UserCode(user=request.user, code=code, medic=medic)
userCode.save()
+ if request.method == "POST":
+ document = Document.objects.get(id=request.POST["action"][1:])
+ if request.POST["action"][0] == 'f':
+ pass
+ elif request.POST["action"][0] == 'a':
+ document.status = "ok"
+ document.save()
+ elif request.POST["action"][0] == 'd':
+ document.delete()
+ elif request.POST["action"][0] == 'e':
+ document_type = document.document_type
+ context = {
+ 'doctype': document_type,
+ }
+ context['doc'] = document
+ context['personal_data'] = document_type.personal_data
+ context['medical_data'] = document_type.medical_data
+ context['custom_data'] = document_type.custom_data
+ keys = Keys.objects.filter(container=document_type)
+ out_keys = []
+ for i in keys:
+ out_keys.append([i, KeyVal.objects.filter(Q(container=document) & Q(key=i.key))[0].value])
+ context['keys'] = out_keys
+ context['custom_message'] = document_type.custom_message
+ context['custom_message_text'] = document_type.custom_message_text
+ return edit_wrapper(request, context)
+
documents = Document.objects.filter(Q(user=request.user) & ~Q(status='archive'))
out = []
for i in documents:
- out.append([i, KeyVal.objects.filter(container=i)])
+ personal = None
+ medical = None
+ if i.document_type.personal_data:
+ personal = i.personal_data.__dict__.values()
+ if i.document_type.medical_data:
+ medical = i.medical_data.__dict__.values()
+
+ out.append([i, KeyVal.objects.filter(container=i), personal, medical])
context = {
"docs": out,
"empty": len(out) == 0,
}
+
return render(request, 'client/index.html', context)
@@ -45,7 +82,6 @@ def approve(request):
else:
return render(request, 'client/index.html', context)
-
def create(request):
context = {}
if request.user.is_authenticated:
@@ -59,7 +95,7 @@ def create(request):
if len(Document.objects.filter(Q(user=request.user) & Q(document_type=doc))) == 0:
out.append(doc)
- context = {'docs': out}
+ context['docs'] = out
if request.method == "POST":
if request.POST["action"] == "details":
if "doctype" not in request.POST.keys():
@@ -85,31 +121,84 @@ def create(request):
code = 0
status = "wait"
personal_data = None
+ medical_data = None
document_type = DocumentType.objects.get(
id=request.POST["doctype"])
+
+ if document_type.auto_sign:
+ status = "autosign"
+
keys = []
if document_type.personal_data:
- personal_data = PersonalData(parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country,
+ personal_data = PersonalData(email=request.user.email, 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()
+ if document_type.medical_data:
+ medic = usercode.medic
+ medical_data = MedicalData(emer_name=medic.emer_name, emer_relative=medic.emer_relative, cell_phone=medic.cell_phone, address=medic.address, emer_phone=medic.emer_phone, health_care=medic.health_care, injuries=medic.injuries, rc=medic.rc, rega=medic.rega, medic_name=medic.medic_name, medic_phone=medic.medic_phone, medic_address=medic.medic_address, sickness=medic.sickness, vaccine=medic.vaccine, tetanus_date=medic.tetanus_date, allergy=medic.allergy, drugs_bool=medic.drugs_bool, drugs=medic.drugs, misc_bool=medic.misc_bool, misc=medic.misc)
+ medical_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)
+ user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data, medical_data=medical_data)
document.save()
- for i in request.POST.keys():
- if i == "doctype" or i=="csrfmiddlewaretoken" or i=="action":
- continue
- key = KeyVal(container=document, key=Keys.objects.get(id=i).key, value=request.POST[i])
- key.save()
+ if document_type.custom_data:
+ for i in request.POST.keys():
+ if i == "doctype" or i=="csrfmiddlewaretoken" or i=="action":
+ continue
+ key = KeyVal(container=document, key=Keys.objects.get(id=i).key, value=request.POST[i])
+ key.save()
return HttpResponseRedirect('/')
return render(request, 'client/doc_create.html', context)
else:
return render(request, 'client/index.html', context)
+
+def edit(request):
+ return edit_wrapper(request, {})
+
+def edit_wrapper(request, context):
+ if request.user.is_authenticated:
+ if request.method == "POST":
+ if "action" not in request.POST.keys():
+ document = Document.objects.get(id=request.POST["doc"])
+ usercode = UserCode.objects.filter(user=document.user)[0]
+
+ if document.document_type.personal_data:
+ personal_data = PersonalData(email=request.user.email, 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()
+ old_data = document.personal_data
+ document.personal_data = personal_data
+ document.save()
+ old_data.delete()
+
+ if document.document_type.medical_data:
+ medic = usercode.medic
+ medical_data = MedicalData(emer_name=medic.emer_name, emer_relative=medic.emer_relative, cell_phone=medic.cell_phone, address=medic.address, emer_phone=medic.emer_phone, health_care=medic.health_care, injuries=medic.injuries, rc=medic.rc, rega=medic.rega, medic_name=medic.medic_name, medic_phone=medic.medic_phone, medic_address=medic.medic_address, sickness=medic.sickness, vaccine=medic.vaccine, tetanus_date=medic.tetanus_date, allergy=medic.allergy, drugs_bool=medic.drugs_bool, drugs=medic.drugs, misc_bool=medic.misc_bool, misc=medic.misc)
+ medical_data.save()
+ old_data = document.medical_data
+ document.medical_data = medical_data
+ document.save()
+ old_data.delete()
+
+ if document.document_type.custom_data:
+ for i in request.POST.keys():
+ if i == "doc" or i=="csrfmiddlewaretoken":
+ continue
+ key = KeyVal.objects.filter(Q(container=document) & Q(key=Keys.objects.get(id=i).key))[0]
+ key.value = request.POST[i]
+ key.save()
+
+ return HttpResponseRedirect('/')
+
+ return render(request, 'client/doc_edit.html', context)
+ else:
+ return render(request, 'client/index.html', context)