From 619e0e0f5263875b753334483d9b896194e9a61d Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Fri, 19 Jun 2020 15:05:59 +0200 Subject: More data for users --- client/migrations/0003_auto_20200619_1044.py | 87 ++++++++++++++++++++++++++++ client/migrations/0004_auto_20200619_1045.py | 24 ++++++++ client/migrations/0005_auto_20200619_1047.py | 24 ++++++++ client/migrations/0006_auto_20200619_1049.py | 24 ++++++++ client/models.py | 31 +++++++++- client/templates/client/approve.html | 33 ++++++++--- client/templates/client/index.html | 45 +++++++------- client/views.py | 21 ++++--- 8 files changed, 248 insertions(+), 41 deletions(-) create mode 100644 client/migrations/0003_auto_20200619_1044.py create mode 100644 client/migrations/0004_auto_20200619_1045.py create mode 100644 client/migrations/0005_auto_20200619_1047.py create mode 100644 client/migrations/0006_auto_20200619_1049.py (limited to 'client') diff --git a/client/migrations/0003_auto_20200619_1044.py b/client/migrations/0003_auto_20200619_1044.py new file mode 100644 index 0000000..29503c0 --- /dev/null +++ b/client/migrations/0003_auto_20200619_1044.py @@ -0,0 +1,87 @@ +# Generated by Django 3.0.7 on 2020-06-19 08:44 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('client', '0002_usercode_user'), + ] + + operations = [ + migrations.AddField( + model_name='usercode', + name='born_date', + field=models.DateField(default=None), + ), + migrations.AddField( + model_name='usercode', + name='cap', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='country', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='home_phone', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='nationality', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='parent_name', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='phone', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='school', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='via', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='usercode', + name='year', + field=models.IntegerField(default=0), + ), + migrations.CreateModel( + name='YearSubscription', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('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)), + ('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=None)), + ('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)), + ('user', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/client/migrations/0004_auto_20200619_1045.py b/client/migrations/0004_auto_20200619_1045.py new file mode 100644 index 0000000..d7ca433 --- /dev/null +++ b/client/migrations/0004_auto_20200619_1045.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-19 08:45 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0003_auto_20200619_1044'), + ] + + operations = [ + migrations.AlterField( + model_name='usercode', + name='born_date', + field=models.DateField(default=datetime.datetime(2020, 6, 19, 10, 45, 47, 43395)), + ), + migrations.AlterField( + model_name='yearsubscription', + name='born_date', + field=models.DateField(default=datetime.datetime(2020, 6, 19, 10, 45, 47, 42414)), + ), + ] diff --git a/client/migrations/0005_auto_20200619_1047.py b/client/migrations/0005_auto_20200619_1047.py new file mode 100644 index 0000000..64d88bb --- /dev/null +++ b/client/migrations/0005_auto_20200619_1047.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-19 08:47 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0004_auto_20200619_1045'), + ] + + operations = [ + migrations.AlterField( + model_name='usercode', + name='born_date', + field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0)), + ), + migrations.AlterField( + model_name='yearsubscription', + name='born_date', + field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0)), + ), + ] diff --git a/client/migrations/0006_auto_20200619_1049.py b/client/migrations/0006_auto_20200619_1049.py new file mode 100644 index 0000000..833317f --- /dev/null +++ b/client/migrations/0006_auto_20200619_1049.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-19 08:49 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0005_auto_20200619_1047'), + ] + + operations = [ + migrations.AlterField( + model_name='usercode', + name='born_date', + field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0), null=True), + ), + migrations.AlterField( + model_name='yearsubscription', + name='born_date', + field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0), null=True), + ), + ] diff --git a/client/models.py b/client/models.py index 970c489..d6e8578 100644 --- a/client/models.py +++ b/client/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth.models import User +from datetime import datetime # Create your models here. @@ -13,6 +14,34 @@ class Document(models.Model): ] -class UserCode(models.Model): +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) + 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) + + +class UserCode(models.Model): user = models.ForeignKey(User, default=None, on_delete=models.CASCADE) + 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) diff --git a/client/templates/client/approve.html b/client/templates/client/approve.html index 026a66d..e00aedc 100644 --- a/client/templates/client/approve.html +++ b/client/templates/client/approve.html @@ -3,16 +3,31 @@ {% block title %}Approva{% endblock %} {% block nav %} - + Home + Approva {% endblock %} {% block content %} -{{ code }} +{% if okay %} +
+
+
+
+

Per approvare l'utente invia il seguente codice al capo branca:

+

{{code}}

+

+
+
+
+{% else %} +
+
+
+
+

Per approvare l'utente inserire prima i propri dati personali cliccando il proprio nome in alto a destra.

+
+
+
+
+{% endif %} {% endblock %} \ No newline at end of file diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 2c55dbc..64b4d42 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -3,34 +3,35 @@ {% block title %}Home{% endblock %} {%block nav%} - + Home {% endblock%} {% block content %} {% if user.is_authenticated %} - {% if user.is_staff %} - Ciao {{ user.username }}! -

admin - logout

- {% elif perms.client.approved %} - Ciao {{ user.username }}! -

logout

+ {% if user.is_staff or perms.client.approved %} {% else %} - Il tuo utente non e` ancora stato approvato. -

approva - logout

+
+
+
+
+

Il tuo utente non e` ancora stato approvato.

+
+ +
+
+
{% endif %} {% else %} -

Non hai fatto il login

-

login - registrazione

+
+
+
+
+

Se hai gia` un account clicca login in alto a destra. Altrimenti clicca registrazione

+
+
+
+
{% endif %} {% endblock %} \ No newline at end of file diff --git a/client/views.py b/client/views.py index 5a8f808..96eb977 100644 --- a/client/views.py +++ b/client/views.py @@ -9,12 +9,7 @@ from .models import UserCode def index(request): context = {} - return render(request, 'client/index.html', context) - - -def approve(request): - context = {} - if not (request.user.is_staff or request.user.has_perm('approved')): + if (request.user.is_authenticated): users = UserCode.objects.filter(user=request.user) code = None if (len(users) == 0): @@ -24,9 +19,17 @@ def approve(request): break userCode = UserCode(user=request.user, code=code) userCode.save() - else: - code = UserCode.objects.filter(user=request.user)[0].code - context = {'code': 'U' + str(code), } + return render(request, 'client/index.html', context) + + +def approve(request): + context = {} + if not (request.user.is_staff or request.user.has_perm('approved')): + usercode = UserCode.objects.filter(user=request.user)[0] + okay = False + if request.user.first_name != "" and request.user.last_name != "" and request.user.email != "" and len(request.user.groups.values_list('name', flat=True)) != 0: + okay = True + context = {'code': 'U' + str(usercode.code), 'okay': okay} return render(request, 'client/approve.html', context) else: return render(request, 'client/index.html', context) -- cgit v1.2.1