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 +++++++++++++++++ 4 files changed, 241 insertions(+), 7 deletions(-) create mode 100644 accounts/templates/accounts/index.html (limited to 'accounts') 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) -- cgit v1.2.1