aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <aleporia@gmail.com>2023-07-24 13:41:51 +0200
committerAndrea Lepori <aleporia@gmail.com>2023-07-24 13:41:52 +0200
commitb8513cbb8059400b825fd74c9bfff3142201d3c4 (patch)
treec0632648ea27ebab5de038163a2b25f8e131c269
parentbetter usercode debug formatting (diff)
downloadscout-subs-b8513cbb8059400b825fd74c9bfff3142201d3c4.tar.gz
scout-subs-b8513cbb8059400b825fd74c9bfff3142201d3c4.zip
show all docs for all owned ucs
Diffstat (limited to '')
-rw-r--r--client/migrations/0017_document_usercode.py19
-rw-r--r--client/models.py60
-rw-r--r--client/templates/client/index.html19
-rw-r--r--client/views.py43
-rw-r--r--version.txt2
5 files changed, 81 insertions, 62 deletions
diff --git a/client/migrations/0017_document_usercode.py b/client/migrations/0017_document_usercode.py
new file mode 100644
index 0000000..df16615
--- /dev/null
+++ b/client/migrations/0017_document_usercode.py
@@ -0,0 +1,19 @@
+# Generated by Django 4.1.5 on 2023-07-24 11:33
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0016_usercode_branca_usercode_email_usercode_first_name_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='document',
+ name='usercode',
+ field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='client.usercode'),
+ ),
+ ]
diff --git a/client/models.py b/client/models.py
index c9fe42f..1548893 100644
--- a/client/models.py
+++ b/client/models.py
@@ -66,7 +66,38 @@ class MedicalData(models.Model):
health_care_certificate = models.FileField(default=None, upload_to='documents/', null=True)
+class Keys(models.Model):
+ container = models.ForeignKey(
+ DocumentType, db_index=True, on_delete=models.CASCADE)
+ key = models.CharField(max_length=2048, db_index=True)
+ key_extra = models.CharField(max_length=2048, default="")
+
+
+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)
+ branca = models.ForeignKey(Group, default=1, on_delete=models.PROTECT)
+ first_name = models.CharField(default="", max_length=250)
+ last_name = models.CharField(default="", max_length=250)
+ email = models.CharField(default="", max_length=250)
+ 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)
+ midata_id = models.IntegerField(default=0)
+ midata_token = models.CharField(default="", max_length=1024)
+
+
class Document(models.Model):
+ usercode = models.ForeignKey(UserCode, default=1, on_delete=models.CASCADE)
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)
@@ -97,35 +128,6 @@ class KeyVal(models.Model):
value = models.CharField(max_length=2048, db_index=True)
-class Keys(models.Model):
- container = models.ForeignKey(
- DocumentType, db_index=True, on_delete=models.CASCADE)
- key = models.CharField(max_length=2048, db_index=True)
- key_extra = models.CharField(max_length=2048, default="")
-
-
-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)
- branca = models.ForeignKey(Group, default=0, on_delete=models.PROTECT)
- first_name = models.CharField(default="", max_length=250)
- last_name = models.CharField(default="", max_length=250)
- email = models.CharField(default="", max_length=250)
- 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)
- midata_id = models.IntegerField(default=0)
- midata_token = models.CharField(default="", max_length=1024)
-
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 ce71127..443308a 100644
--- a/client/templates/client/index.html
+++ b/client/templates/client/index.html
@@ -30,8 +30,11 @@
</div>
</div>
{% if not empty %}
+ {% for data in docs %}
+ {% if data.1|length > 0 %}
+ <h6>{{data.0.first_name}} {{data.0.last_name}} ({{data.0.born_date}})</h6>
<ul class="collapsible">
- {% for doc in docs %}
+ {% for doc in data.1 %}
{% if doc.status == "autosign" %}
<div id="modal{{doc.id}}" class="modal">
<div class="modal-content">
@@ -411,6 +414,8 @@
{% endfor %}
</ul>
{% endif %}
+ {% endfor %}
+ {% endif %}
<div class="fixed-action-btn">
<a id="add" class="btn-floating btn-large {{color}}" href="{% url 'create'%}">
<i class="large material-icons">add</i>
@@ -421,14 +426,10 @@
<div class="col l4 offset-l4 m8 offset-m2 s12">
<div class="card">
<div class="card-content">
- <p>Il tuo utente non &egrave; ancora stato approvato.</p>
- <br>
- {% if user_code %}
- <p>Per approvare l'utente invia il seguente codice al capo branca:</p>
- <h3 class="center-align">{{user_code}}<h3>
- {% else %}
- <p>Per approvare l'utente inserire prima i propri dati personali e medici selezionando il proprio nome in alto a destra e in seguito "Gestione account". Torna in seguito su questa pagina per i prossimi passaggi.</p>
- {% endif %}
+ <p>Il tuo utente non contiene nessuna persona fisica. Per creare una nuova persona aggiungerla
+ dal profilo utente. Seleziona il proprio nome in alto a destra e in seguito "Gestione account".
+ Torna in seguito su questa pagina per creare una nuova iscrizione.
+ </p>
</div>
</div>
</div>
diff --git a/client/views.py b/client/views.py
index 79783f1..4404cb5 100644
--- a/client/views.py
+++ b/client/views.py
@@ -25,29 +25,20 @@ def migration_usercode(void):
uc.branca = user.groups.all()[0]
uc.save()
+ # also iterate all docs and set usercode
+ for d in Document.objects.all():
+ uc = UserCode.objects.filter(user=d.user)[0]
+ d.usercode = uc
+ d.save()
+
@login_required()
def index(request):
context = {}
- if not (request.user.is_staff or request.user.has_perm("client.approved")):
- # generate code if user has no code
- users = UserCode.objects.filter(user=request.user)
- code = None
- if (len(users) == 0):
- while (True):
- code = randint(100000, 999999)
- if len(UserCode.objects.filter(code=code)) == 0:
- break
- medic = MedicalData()
- medic.save()
- userCode = UserCode(user=request.user, code=code, medic=medic)
- userCode.save()
+ ucs = UserCode.objects.filter(user=request.user)
- user_code = None
- usercode = UserCode.objects.filter(user=request.user)[0]
- if request.user.first_name != "" and request.user.last_name != "" and request.user.email != "" and usercode.phone != "":
- user_code = "U" + str(usercode.code)
- context = {"user_code": user_code}
- return render(request, 'client/index.html', context)
+ if (len(ucs) == 0):
+ # the user has no person
+ return render(request, 'client/index.html', {})
groups = request.user.groups.all()
@@ -101,18 +92,24 @@ def index(request):
context['custom_message_text'] = document_type.custom_message_text
return edit_wrapper(request, context)
+ # divide the docs for each uc
+ docs = []
+ for uc in ucs:
+ documents = Document.objects.filter(
+ Q(usercode=uc) & ~Q(status='archive')).select_related("personal_data", "medical_data", "document_type", "user")
+ docs.append([uc, documents])
# show only docs of the user and non archived
- documents = Document.objects.filter(
- Q(user=request.user) & ~Q(status='archive')).select_related("personal_data", "medical_data", "document_type", "user")
vac_file = ["/server/media/", "/vac_certificate/doc"]
health_file = ["/server/media/", "/health_care_certificate/doc"]
sign_doc_file = ["/server/media/", "/signed_doc/doc"]
+ print(docs)
+
context = {
- "docs": documents,
+ "docs": docs,
"base_group": groups[0].name,
- "empty": len(documents) == 0,
+ "empty": len(docs) == 0,
"vac_file": vac_file,
"health_file": health_file,
"sign_doc_file": sign_doc_file
diff --git a/version.txt b/version.txt
index cba5c39..c46dc81 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
version=0.6
-rev=25
+rev=26