aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2021-07-23 18:07:47 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2021-07-23 18:07:59 +0200
commitc5789583a04c435acb460bae050f9387e67527cb (patch)
treeeaa73777353a9669be5c57269cee67e1e35bdf07 /client
parentexport csv of users or document types (diff)
parentadd notification if user of group capi views document (diff)
downloadscout-subs-0.3.tar.gz
scout-subs-0.3.zip
Merge branch 'dev'0.3
Diffstat (limited to '')
-rw-r--r--client/migrations/0007_groupsettings.py23
-rw-r--r--client/migrations/0009_merge_20210723_1805.py14
-rw-r--r--client/models.py234
-rw-r--r--client/templates/client/index.html12
-rw-r--r--client/views.py17
5 files changed, 184 insertions, 116 deletions
diff --git a/client/migrations/0007_groupsettings.py b/client/migrations/0007_groupsettings.py
new file mode 100644
index 0000000..b5a23fa
--- /dev/null
+++ b/client/migrations/0007_groupsettings.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.1.2 on 2021-03-17 20:06
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('auth', '0012_alter_user_first_name_max_length'),
+ ('client', '0006_documenttype_max_instances'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='GroupSettings',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('view_documents', models.BooleanField(default=False)),
+ ('group', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auth.group')),
+ ],
+ ),
+ ]
diff --git a/client/migrations/0009_merge_20210723_1805.py b/client/migrations/0009_merge_20210723_1805.py
new file mode 100644
index 0000000..014ac28
--- /dev/null
+++ b/client/migrations/0009_merge_20210723_1805.py
@@ -0,0 +1,14 @@
+# Generated by Django 3.1.4 on 2021-07-23 16:05
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0007_groupsettings'),
+ ('client', '0008_usercode_avs_number'),
+ ]
+
+ operations = [
+ ]
diff --git a/client/models.py b/client/models.py
index 3d4e63d..db31194 100644
--- a/client/models.py
+++ b/client/models.py
@@ -1,115 +1,119 @@
-from django.db import models
-from django.contrib.auth.models import User, Group
-from datetime import datetime
-
-# Create your models here.
-
-
-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)
- custom_group = models.BooleanField(default=False)
- personal_data = models.BooleanField(default=False)
- medical_data = models.BooleanField(default=False)
- custom_data = models.BooleanField(default=False)
- custom_message = models.BooleanField(default=False)
- custom_message_text = models.CharField(default="", max_length=250)
- staff_only = models.BooleanField(default=False)
- max_instances = models.IntegerField(default=0)
- name = models.CharField(default="", max_length=250)
-
-
-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)
- country = models.CharField(default="", max_length=250)
- nationality = models.CharField(default="", max_length=250)
- 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)
- school = models.CharField(default="", max_length=250)
- year = models.IntegerField(default=0)
- avs_number = 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)
- vac_certificate = models.FileField(upload_to='documents/', null=True)
- health_care_certificate = models.FileField(default=None, upload_to='documents/', null=True)
-
-
-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, null=True)
-
- medical_data = models.ForeignKey(
- MedicalData, default=None, on_delete=models.SET_NULL, null=True)
-
- signed_doc = models.FileField(default=None, upload_to='documents/', null=True)
-
- class Meta:
- permissions = [
- ("approved", "The user is approved"),
- ("staff", "The user is staff of the non primary group")
- ]
-
-
-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):
- 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)
- 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(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)
- avs_number = models.CharField(default="", max_length=250) \ No newline at end of file
+from django.db import models
+from django.contrib.auth.models import User, Group
+from datetime import datetime
+
+# Create your models here.
+
+
+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)
+ custom_group = models.BooleanField(default=False)
+ personal_data = models.BooleanField(default=False)
+ medical_data = models.BooleanField(default=False)
+ custom_data = models.BooleanField(default=False)
+ custom_message = models.BooleanField(default=False)
+ custom_message_text = models.CharField(default="", max_length=250)
+ staff_only = models.BooleanField(default=False)
+ max_instances = models.IntegerField(default=0)
+ name = models.CharField(default="", max_length=250)
+
+
+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)
+ country = models.CharField(default="", max_length=250)
+ nationality = models.CharField(default="", max_length=250)
+ 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)
+ school = models.CharField(default="", max_length=250)
+ year = models.IntegerField(default=0)
+ avs_number = 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)
+ vac_certificate = models.FileField(upload_to='documents/', null=True)
+ health_care_certificate = models.FileField(default=None, upload_to='documents/', null=True)
+
+
+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, null=True)
+
+ medical_data = models.ForeignKey(
+ MedicalData, default=None, on_delete=models.SET_NULL, null=True)
+
+ signed_doc = models.FileField(default=None, upload_to='documents/', null=True)
+
+ class Meta:
+ permissions = [
+ ("approved", "The user is approved"),
+ ("staff", "The user is staff of the non primary group")
+ ]
+
+
+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):
+ 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)
+ 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(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)
+ avs_number = models.CharField(default="", max_length=250)
+
+class GroupSettings(models.Model):
+ group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE)
+ view_documents = models.BooleanField(default=False)
diff --git a/client/templates/client/index.html b/client/templates/client/index.html
index 7f0edec..1fc6c73 100644
--- a/client/templates/client/index.html
+++ b/client/templates/client/index.html
@@ -17,6 +17,18 @@
{% if user.is_authenticated %}
{% if user.is_staff or perms.client.approved %}
+ <div id="modal_capi" class="modal">
+ <div class="modal-content">
+ <h4>Attenzione</h4>
+ <p>Il tuo capo branca verrĂ  notificato dell'accesso alla pagina dei documenti.<br>
+ Sei sicuro di voler continuare?
+ </p>
+ </div>
+ <div class="modal-footer">
+ <a style="color:red" href="#!" class="modal-close waves-effect waves-green btn-flat">Annulla</a>
+ <a href="{% url 'doclistro' %}" class="modal-close waves-effect waves-green btn-flat">Continua</a>
+ </div>
+ </div>
{% if not empty %}
<ul class="collapsible">
{% for doc in docs %}
diff --git a/client/views.py b/client/views.py
index 6f8efb3..73a252a 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, MedicalData
+from client.models import GroupSettings, UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData
from django.db.models import Q
from django.http import HttpResponseRedirect, FileResponse, HttpResponse
from django.contrib.auth.decorators import login_required
@@ -17,6 +17,7 @@ import pytz
def index(request):
context = {}
+ group_view = False
# check if user is logged
if (request.user.is_authenticated):
if not (request.user.is_staff or request.user.has_perm("client.approved")):
@@ -39,6 +40,19 @@ def index(request):
user_code = "U" + str(usercode.code)
context = {"user_code": user_code}
else:
+ # get user group
+ group = request.user.groups.values_list('name', flat=True)[0]
+
+ # get group settings
+ settings = GroupSettings.objects.filter(group__name=group)
+
+ # check if settings exists
+ if len(settings) == 0:
+ group_view = False
+ else:
+ # set settings value
+ group_view = settings[0].view_documents
+
# user action
if request.method == "POST":
# get document id
@@ -123,6 +137,7 @@ def index(request):
context = {
"docs": out,
"empty": len(out) == 0,
+ "group_view": group_view,
}
return render(request, 'client/index.html', context)