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 /accounts | |
parent | initial commit (diff) | |
download | scout-subs-619e0e0f5263875b753334483d9b896194e9a61d.tar.gz scout-subs-619e0e0f5263875b753334483d9b896194e9a61d.zip |
More data for users
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/templates/accounts/index.html | 146 | ||||
-rw-r--r-- | accounts/templates/accounts/signup.html | 23 | ||||
-rw-r--r-- | accounts/urls.py | 1 | ||||
-rw-r--r-- | accounts/views.py | 78 |
4 files changed, 241 insertions, 7 deletions
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%} + <nav class="nav-extended"> + <div class="nav-wrapper red lighten-1"> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="#!" class="breadcrumb hide-on-med-and-down">Account</a> + <ul class="right"> + {% if user.is_staff %} + <li><a href="{% url 'server' %}">Pannello Admin</a></li> + {% endif %} + {% if user.is_authenticated %} + <li><a href="{% url 'personal' %}">{{ user.username }}</a></li> + {% endif %} + {% if user.username != "" %} + <li> + <a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a> + </li> + {% else %} + <li><a href="{% url 'signup' %}">Registrazione</a></li> + <li><a href="{% url 'login' %}">Login</a></li> + {% endif %} + </ul> + </div> + <div class="nav-content red lighten-1"> + <ul class="tabs tabs-transparent"> + <li class="tab"><a class="active" href="#personal">Info Personali</a></li> + <li class="tab"><a href="#medic">Info Mediche</a></li> + </ul> + </div> + </nav> + + <ul class="sidenav" id="mobile-demo"> + {% if user.is_staff %} + <li><a href="{% url 'server' %}">Pannello Admin</a></li> + {% endif %} + {% if user.is_authenticated %} + <li><a href="{% url 'personal' %}">{{ user.username }}</a></li> + {% endif %} + {% if user.username != "" %} + <li> + <a href="{% url 'logout' %}"><i class="material-icons">exit_to_app</i></a> + </li> + {% else %} + <li><a href="{% url 'signup' %}">Registrazione</a></li> + <li><a href="{% url 'login' %}">Login</a></li> + {% endif %} + </ul> +{% endblock%} + +{% block content %} +<div id="personal" class="row"> + <div class="col l8 offset-l2 s12"> + <div class="card-panel"> + <div class="row"> + <form action="{% url 'personal'%}" method="post" id="personal_form" class="col s12"> + {% csrf_token %} + <div class="row"> + <div class="input-field col s4"> + <input name="first_name" value="{{first_name}}" id="first_name" type="text" class="validate"> + <label for="first_name">First Name</label> + </div> + <div class="input-field col s4"> + <input name="last_name" value="{{last_name}}" id="last_name" type="text" class="validate"> + <label for="last_name">Last Name</label> + </div> + <div class="input-field col s4"> + <input name="birth_date" value="{{birth_date}}" id="birth_date" type="text" class="datepicker"> + <label for="birth_date">Data di nascita</label> + </div> + </div> + <div class="row"> + <div class="input-field col s4"> + <select name="branca"> + <option value="" disabled {{branca_default}}>Scegli</option> + <option value="colonia" {{branca_castorini}}>Castorini</option> + <option value="muta" {{branca_lupetti}}>Lupetti</option> + <option value="reparto" {{branca_esploratori}}>Esploratori</option> + <option value="posto" {{branca_pionieri}}>Pionieri</option> + <option value="clan" {{branca_rover}}>Rover</option> + </select> + <label>Branca</label> + </div> + <div class="input-field col s8"> + <input value="{{parent_name}}" name="parent_name" id="parent_name" type="text" class="validate"> + <label for="parent_name">Nome dei genitori</label> + </div> + </div> + <div class="row"> + <div class="input-field col s12"> + <input value="{{via}}" name="via" id="via" type="text" class="validate"> + <label for="via">Via e numero</label> + </div> + </div> + <div class="row"> + <div class="input-field col s4"> + <input value="{{cap}}" name="cap" id="cap" type="text" class="validate"> + <label for="cap">CAP</label> + </div> + <div class="input-field col s4"> + <input value="{{country}}" name="country" id="country" type="text" class="validate"> + <label for="country">Paese</label> + </div> + <div class="input-field col s4"> + <input value="{{nationality}}" name="nationality" id="nationality" type="text" class="validate"> + <label for="nationality">Nazionalita`</label> + </div> + </div> + <div class="row"> + <div class="input-field col s4"> + <input value="{{phone}}" name="phone" id="phone" type="text" class="validate"> + <label for="phone">Cellulare</label> + </div> + <div class="input-field col s4"> + <input value="{{home_phone}}" name="home_phone" id="home_phone" type="text" class="validate"> + <label for="home_phone">Telefono di casa</label> + </div> + <div class="input-field col s4"> + <input value="{{email}}" name="email" id="email" type="text" class="validate"> + <label for="email">Email</label> + </div> + </div> + <div class="row"> + <div class="input-field col s8"> + <input value="{{school}}" name="school" id="school" type="text" class="validate"> + <label for="school">Scuola frequentata</label> + </div> + <div class="input-field col s4"> + <input value="{{year}}" name="year" id="year" type="text" class="validate"> + <label for="year">Classe</label> + </div> + </div> + <div class="fixed-action-btn"> + <a class="btn-floating btn-large red lighten-1" onclick="document.getElementById('personal_form').submit()"> + <i class="large material-icons">save</i> + </a> + </div> + </form> + </div> + </div> + </div> +</div> +<div id="medic" class="col s12">Tabella medica</div> +{% 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 %} - <h2>Iscriviti</h2> - <form method="post"> - {% csrf_token %} - {{ form.as_p }} - <button class="btn waves-effect waves-light" type="submit">Invia</button> - </form> + <div class="row"> + <div class="col l6 offset-l3 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <h2>Iscriviti</h2> + <form method="post"> + {% csrf_token %} + {{ form.as_p }} + <br> + <button class="btn waves-effect waves-light" type="submit">Invia</button> + </form> + </div> + </div> + </div> + </div> {% 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) |