diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-19 15:05:59 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-06-19 15:05:59 +0200 |
commit | 619e0e0f5263875b753334483d9b896194e9a61d (patch) | |
tree | 861b970de54b77ad715aa9d4177eaaad384c198a /client | |
parent | initial commit (diff) | |
download | scout-subs-619e0e0f5263875b753334483d9b896194e9a61d.tar.gz scout-subs-619e0e0f5263875b753334483d9b896194e9a61d.zip |
More data for users
Diffstat (limited to 'client')
-rw-r--r-- | client/migrations/0003_auto_20200619_1044.py | 87 | ||||
-rw-r--r-- | client/migrations/0004_auto_20200619_1045.py | 24 | ||||
-rw-r--r-- | client/migrations/0005_auto_20200619_1047.py | 24 | ||||
-rw-r--r-- | client/migrations/0006_auto_20200619_1049.py | 24 | ||||
-rw-r--r-- | client/models.py | 31 | ||||
-rw-r--r-- | client/templates/client/approve.html | 33 | ||||
-rw-r--r-- | client/templates/client/index.html | 45 | ||||
-rw-r--r-- | client/views.py | 21 |
8 files changed, 248 insertions, 41 deletions
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 %} -<nav> - <div class="nav-wrapper"> - <div class="col s12"> - <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> - <a href="#!" class="breadcrumb">Approva</a> - </div> - </div> -</nav> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a style="margin-left: 10px;" href="{% url 'approve' %}" class="breadcrumb hide-on-med-and-down">Approva</a> {% endblock %} {% block content %} -{{ code }} +{% if okay %} + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <p>Per approvare l'utente invia il seguente codice al capo branca:</p> + <h3 class="center-align">{{code}}<h3> + </div> + </div> + </div> + </div> +{% else %} + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <p>Per approvare l'utente inserire prima i propri dati personali cliccando il proprio nome in alto a destra.</p> + </div> + </div> + </div> + </div> +{% 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%} -<nav> - <div class="nav-wrapper"> - <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> - <ul class="right hide-on-med-and-down"> - <li>{{ user.username}}</li> - <li><a href="{% url 'logout' %}">Logout</a></li> - </ul> - </div> -</nav> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> {% endblock%} {% block content %} {% if user.is_authenticated %} - {% if user.is_staff %} - Ciao {{ user.username }}! - <p><a class="waves-effect waves-light btn" href="{% url 'server' %}">admin</a> - <a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> - {% elif perms.client.approved %} - Ciao {{ user.username }}! - <p><a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> + {% if user.is_staff or perms.client.approved %} {% else %} - Il tuo utente non e` ancora stato approvato. - <p><a class="waves-effect waves-light btn" href="{% url 'approve' %}">approva</a> - <a class="waves-effect waves-light btn" href="{% url 'logout' %}">logout</a></p> + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <p>Il tuo utente non e` ancora stato approvato.</p> + </div> + <div class="card-action"> + <a href="{% url 'approve' %}">Come farsi approvare l'utente</a> + </div> + </div> + </div> + </div> {% endif %} {% else %} - <p>Non hai fatto il login</p> - <p><a class="waves-effect waves-light btn" href="{% url 'login' %}">login</a> - <a class="waves-effect waves-light btn" href="{% url 'signup' %}">registrazione</a></p> + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <p>Se hai gia` un account clicca login in alto a destra. Altrimenti clicca registrazione</p> + </div> + </div> + </div> + </div> {% 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) |