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 --- accounts/templates/accounts/index.html | 146 +++++++++++++++++++++++++++ accounts/templates/accounts/signup.html | 23 +++-- accounts/urls.py | 1 + accounts/views.py | 78 ++++++++++++++ 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 ++-- server/templates/server/approve_user.html | 14 +-- server/templates/server/index.html | 14 +-- server/templates/server/user_list.html | 14 +-- server/views.py | 50 +++++++-- templates/registration/base.html | 30 +++++- templates/registration/base_custom.html | 55 ++++++++++ templates/registration/base_simple.html | 17 ++++ templates/registration/login.html | 22 ++-- 20 files changed, 656 insertions(+), 97 deletions(-) create mode 100644 accounts/templates/accounts/index.html 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 create mode 100644 templates/registration/base_custom.html create mode 100644 templates/registration/base_simple.html diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html new file mode 100644 index 0000000..c01878c --- /dev/null +++ b/accounts/templates/accounts/index.html @@ -0,0 +1,146 @@ +{% extends 'registration/base_custom.html' %} + +{% block title %}Home{% endblock %} + +{%block nav%} + + + +{% endblock%} + +{% block content %} +
+
+
+
+
+ {% csrf_token %} +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
Tabella medica
+{% endblock %} \ No newline at end of file diff --git a/accounts/templates/accounts/signup.html b/accounts/templates/accounts/signup.html index e1591aa..a8a517c 100644 --- a/accounts/templates/accounts/signup.html +++ b/accounts/templates/accounts/signup.html @@ -1,12 +1,21 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_simple.html' %} {% block title %}Iscriviti{% endblock %} {% block content %} -

Iscriviti

-
- {% csrf_token %} - {{ form.as_p }} - -
+
+
+
+
+

Iscriviti

+
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+
+
+
+
{% endblock %} \ No newline at end of file diff --git a/accounts/urls.py b/accounts/urls.py index d89128b..332a16b 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('signup/', views.SignUp.as_view(), name='signup'), + path('personal/', views.personal, name='personal'), ] diff --git a/accounts/views.py b/accounts/views.py index 0483fad..0723482 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -2,9 +2,87 @@ from django.shortcuts import render from django.contrib.auth.forms import UserCreationForm from django.urls import reverse_lazy from django.views import generic +from django.contrib.auth.models import Group + +from client.models import UserCode + +import dateparser class SignUp(generic.CreateView): form_class = UserCreationForm success_url = reverse_lazy('login') template_name = 'accounts/signup.html' + + +def personal(request): + context = {} + if request.user.is_authenticated: + usercode = UserCode.objects.filter(user=request.user)[0] + debug = "" + branca_default = "" + branca_castorini = "" + branca_lupetti = "" + branca_esploratori = "" + branca_pionieri = "" + branca_rover = "" + + if request.method == "POST": + request.user.first_name = request.POST["first_name"] + request.user.last_name = request.POST["last_name"] + request.user.email = request.POST["email"] + request.user.save() + usercode.parent_name = request.POST["parent_name"] + usercode.via = request.POST["via"] + usercode.cap = request.POST["cap"] + usercode.country = request.POST["country"] + usercode.nationality = request.POST["nationality"] + usercode.born_date = dateparser.parse(request.POST["birth_date"]) + usercode.home_phone = request.POST["home_phone"] + usercode.phone = request.POST["phone"] + usercode.school = request.POST["school"] + usercode.year = request.POST["year"] + usercode.save() + + if request.POST["branca"] != "": + request.user.groups.clear() + request.user.groups.add( + Group.objects.get(name=request.POST["branca"])) + + if len(request.user.groups.values_list('name', flat=True)) == 0: + branca_default = "selected" + else: + parent_group = request.user.groups.values_list('name', flat=True)[ + 0] + if parent_group == "muta": + branca_lupetti = "selected" + elif parent_group == "reparto": + branca_esploratori = "selected" + else: + branca_default = "selected" + + context = { + 'first_name': request.user.first_name, + 'last_name': request.user.last_name, + 'email': request.user.email, + 'parent_name': usercode.parent_name, + 'via': usercode.via, + 'cap': usercode.cap, + 'country': usercode.country, + 'nationality': usercode.nationality, + 'birth_date': usercode.born_date, + 'home_phone': usercode.home_phone, + 'phone': usercode.phone, + 'school': usercode.school, + 'year': usercode.year, + 'branca_default': branca_default, + 'branca_castorini': branca_castorini, + 'branca_lupetti': branca_lupetti, + 'branca_esploratori': branca_esploratori, + 'branca_pionieri': branca_pionieri, + 'branca_rover': branca_rover, + } + + return render(request, 'accounts/index.html', context) + else: + return render(request, 'client/index.html', context) 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) diff --git a/server/templates/server/approve_user.html b/server/templates/server/approve_user.html index ae9dc8b..126c0b9 100644 --- a/server/templates/server/approve_user.html +++ b/server/templates/server/approve_user.html @@ -3,17 +3,9 @@ {% block title %}Admin - Approva Utente{% endblock %} {% block nav %} - + Home + Admin + Approva Utente {% endblock %} {% block content %} diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 4790a1d..37a553b 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -3,21 +3,13 @@ {% block title %}Admin{% endblock %} {% block nav %} - + Admin {% endblock %} {% block content %}
-
+

@@ -45,7 +37,7 @@

-
+

I am a very simple card. I am good at containing small bits of information. diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html index daf7303..3837619 100644 --- a/server/templates/server/user_list.html +++ b/server/templates/server/user_list.html @@ -3,17 +3,9 @@ {% block title %}Admin - Lista Utenti{% endblock %} {% block nav %} -

+ Home + Admin + Lista Utenti {% endblock %} {% block content %} diff --git a/server/views.py b/server/views.py index ab94fd6..aa2dc3a 100644 --- a/server/views.py +++ b/server/views.py @@ -18,7 +18,7 @@ def index(request): code = 'U' + str(UserCode.objects.filter(user=user)[0].code) status = "" if user.is_staff: - status = "Capo" + status = "Staff" elif user.has_perm("client.approved"): status = "Attivo" else: @@ -83,17 +83,55 @@ def ulist(request): out = [] for user in users: code = "" - if len(UserCode.objects.filter(user=user)) > 0: - code = 'U' + str(UserCode.objects.filter(user=user)[0].code) + parent_name = "" + via = "" + cap = "" + country = "" + nationality = "" + born_date = "" + home_phone = "" + phone = "" + school = "" + year = "" status = "" if user.is_staff: - status = "Capo" + status = "Staff" elif user.has_perm("approved"): status = "Attivo" else: status = "In attesa" - out.append([user.username, user.first_name, - user.last_name, code, status]) + if len(UserCode.objects.filter(user=user)) > 0: + usercode = UserCode.objects.filter(user=user)[0] + code = 'U' + str(usercode.code) + 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 + school = usercode.school + year = usercode.year + else: + status = "Non registrato" + out.append([ + status, + user.username, + user.first_name, + user.last_name, + born_date, + parent_name, + user.email, + phone, + home_phone, + via, + cap, + country, + nationality, + school, + year, + code]) context = {'users': out} return render(request, 'server/user_list.html', context) else: diff --git a/templates/registration/base.html b/templates/registration/base.html index 51dad17..f5a8a80 100644 --- a/templates/registration/base.html +++ b/templates/registration/base.html @@ -8,12 +8,36 @@ {% block title %}Scout Brega{% endblock %} - {% block nav %} - {% endblock %} +
{% block content %} {% endblock %}
- + + \ No newline at end of file diff --git a/templates/registration/base_custom.html b/templates/registration/base_custom.html new file mode 100644 index 0000000..d38be7a --- /dev/null +++ b/templates/registration/base_custom.html @@ -0,0 +1,55 @@ + + + + + + + + {% block title %}Scout Brega{% endblock %} + + + {% block nav %} + {% endblock %} +
+ {% block content %} + {% endblock %} +
+ + + + + \ No newline at end of file diff --git a/templates/registration/base_simple.html b/templates/registration/base_simple.html new file mode 100644 index 0000000..82087bc --- /dev/null +++ b/templates/registration/base_simple.html @@ -0,0 +1,17 @@ + + + + + + + + {% block title %}Scout Brega{% endblock %} + + +
+ {% block content %} + {% endblock %} +
+ + + \ No newline at end of file diff --git a/templates/registration/login.html b/templates/registration/login.html index 71880b3..9459f93 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -1,12 +1,20 @@ -{% extends 'registration/base.html' %} +{% extends 'registration/base_simple.html' %} {% block title %}Login{% endblock %} {% block content %} -

Login

-
- {% csrf_token %} - {{ form.as_p }} - -
+
+
+
+
+
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+
+
+
+
{% endblock %} \ No newline at end of file -- cgit v1.2.1