From 80653d69a0dd7bb6a089b6fda05fbe98ff7ac9fb Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Fri, 30 Oct 2020 20:47:10 +0100 Subject: renaming, max partecipant number, only "capi" docs --- client/migrations/0005_documenttype_staff_only.py | 18 +++ .../migrations/0006_documenttype_max_instances.py | 18 +++ client/models.py | 2 + client/templates/client/doc_create.html | 123 +++++++++++++-------- client/templates/client/doc_edit.html | 6 +- client/templates/client/index.html | 28 ++--- client/views.py | 31 +++++- 7 files changed, 157 insertions(+), 69 deletions(-) create mode 100644 client/migrations/0005_documenttype_staff_only.py create mode 100644 client/migrations/0006_documenttype_max_instances.py (limited to 'client') diff --git a/client/migrations/0005_documenttype_staff_only.py b/client/migrations/0005_documenttype_staff_only.py new file mode 100644 index 0000000..3211c26 --- /dev/null +++ b/client/migrations/0005_documenttype_staff_only.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2020-10-30 16:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0004_auto_20200903_1828'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='staff_only', + field=models.BooleanField(default=False), + ), + ] diff --git a/client/migrations/0006_documenttype_max_instances.py b/client/migrations/0006_documenttype_max_instances.py new file mode 100644 index 0000000..750ff0e --- /dev/null +++ b/client/migrations/0006_documenttype_max_instances.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2020-10-30 17:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0005_documenttype_staff_only'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='max_instances', + field=models.IntegerField(default=0), + ), + ] diff --git a/client/models.py b/client/models.py index c85ca14..d14a267 100644 --- a/client/models.py +++ b/client/models.py @@ -16,6 +16,8 @@ class DocumentType(models.Model): 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) diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html index 18940d8..04f08e6 100644 --- a/client/templates/client/doc_create.html +++ b/client/templates/client/doc_create.html @@ -1,9 +1,9 @@ {% extends 'registration/base_client.html' %} -{% block title %}Crea Documento{% endblock %} +{% block title %}Crea iscrizione{% endblock %} {% block breadcrumb %} - Crea Documento + Crea Iscrizione {% endblock %} {% block content %} @@ -23,7 +23,7 @@ {% endfor %} - + @@ -33,75 +33,100 @@ navigate_next {% else %} - -
-
- - + +
+
+ + +
-
- {% if personal_data %} + {% if no_free_places%}

- Il documento conterrà le informazioni personali, prego verificare che siano corrette e aggiornate + Siamo spiacenti abbiamo esaurito i posti disponibili per questa iscrizione.

- {% endif %} - {% if medical_data %}
-
-
-

- Il documento conterrà le informazioni mediche, prego verificare che siano corrette e aggiornate -

+
+ + navigate_beforeIndietro + + Annulla + cancel + +
+
+ {% else %} + {% if personal_data %} +
+
+
+
+

+ Il documento conterrà le informazioni personali, prego verificare che siano corrette e aggiornate +

+
-
- {% endif %} - {% if custom_message %} -
-
-
-
-

- {{custom_message_text}} -

+ {% endif %} + {% if medical_data %} +
+
+
+
+

+ Il documento conterrà le informazioni mediche, prego verificare che siano corrette e aggiornate +

+
-
- {% endif %} - {% if custom_data %} - {% for key in keys %} + {% endif %} + {% if custom_message %}
-
- - +
+
+
+

+ {{custom_message_text}} +

+
+
- {% endfor %} - {% endif %} -
-
-
- - navigate_beforeIndietro - - Crea - create - + {% endif %} + {% if custom_data %} + {% for key in keys %} +
+
+ + +
+
+ {% endfor %} + {% endif %} + -
+ {% endif %} {% endif %}
diff --git a/client/templates/client/doc_edit.html b/client/templates/client/doc_edit.html index 278f34c..f7e8f72 100644 --- a/client/templates/client/doc_edit.html +++ b/client/templates/client/doc_edit.html @@ -1,9 +1,9 @@ {% extends 'registration/base_client.html' %} -{% block title %}Modifica documento{% endblock %} +{% block title %}Modifica iscrizione{% endblock %} {% block breadcrumb %} - Modifica Documento + Modifica iscrizione {% endblock %} {% block content %} @@ -19,7 +19,7 @@ - +
{% if personal_data %} diff --git a/client/templates/client/index.html b/client/templates/client/index.html index b63fa49..b5d1135 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -5,8 +5,8 @@ {% block content %}
-
Aggiungi un documento
-

Usa questo bottone per creare un nuovo documento

+
Aggiungi un'iscrizione
+

Usa questo bottone per creare una nuova iscrizione

@@ -36,17 +36,17 @@ {% if doc.0.status == "wait" %}

@@ -54,8 +54,8 @@

diff --git a/client/views.py b/client/views.py index 8b0ac7b..821bc9b 100644 --- a/client/views.py +++ b/client/views.py @@ -15,7 +15,6 @@ from subprocess import check_output from datetime import datetime import pytz - def index(request): context = {} # check if user is logged @@ -138,8 +137,11 @@ def create(request): group = Group.objects.get(name=parent_group) # get available types for user - doctypes = DocumentType.objects.filter( - (Q(group_private=False) | Q(group=group)) & Q(enabled=True)) + filter = (Q(group_private=False) | Q(group=group)) & Q(enabled=True) + if not request.user.is_staff and "capi" not in request.user.groups.values_list('name',flat = True): + filter = filter & Q(staff_only=False) + + doctypes = DocumentType.objects.filter(filter) out = [] for doc in doctypes: # check if user has already that document type @@ -159,7 +161,15 @@ def create(request): context['next'] = True document_type = DocumentType.objects.get( id=request.POST["doctype"]) + context['doctype'] = document_type + + # check if there are still free spaces + context['no_free_places'] = False + if document_type.max_instances != 0: + if len(Document.objects.filter(document_type=document_type)) - len(Document.objects.filter(document_type=document_type, status="archive")) >= document_type.max_instances: + context['no_free_places'] = True + context['personal_data'] = document_type.personal_data context['medical_data'] = document_type.medical_data context['custom_data'] = document_type.custom_data @@ -177,6 +187,21 @@ def create(request): document_type = DocumentType.objects.get( id=request.POST["doctype"]) + # check if there are free spaces + if document_type.max_instances != 0: + if len(Document.objects.filter(document_type=document_type)) - len(Document.objects.filter(document_type=document_type, status="archive")) >= document_type.max_instances: + # there aren't user is cheating + return + + # check if user has permission to use that type + if document_type.staff_only and not request.user.is_staff and "capi" not in request.user.groups.values_list('name', flat = True): + # user is cheating abort + return + + if not document_type.custom_group and document_type.group.name not in request.user.groups.values_list('name', flat=True): + # user is cheating abort + return + # get list of docs with that type current_docs = Document.objects.filter(user=request.user).filter(document_type=document_type) if len(current_docs) > 0: -- cgit v1.2.1