From 05b12812786ef4e950ece40a17b198fdfe9bbe6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Epif=C3=A2nio?= Date: Sat, 17 Nov 2018 16:22:24 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Resolve=20#153.=20Possibilita=20edi=C3=A7?= =?UTF-8?q?=C3=B5es=20do=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/brasilio_auth/profile_update_form.html | 10 ++++++++++ brasilio_auth/urls.py | 3 ++- brasilio_auth/views.py | 12 ++++++++++++ core/templates/menu.html | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 brasilio_auth/templates/brasilio_auth/profile_update_form.html diff --git a/brasilio_auth/templates/brasilio_auth/profile_update_form.html b/brasilio_auth/templates/brasilio_auth/profile_update_form.html new file mode 100644 index 00000000..5ececd9c --- /dev/null +++ b/brasilio_auth/templates/brasilio_auth/profile_update_form.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} + +
{% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} diff --git a/brasilio_auth/urls.py b/brasilio_auth/urls.py index 056ac45e..feb7a590 100644 --- a/brasilio_auth/urls.py +++ b/brasilio_auth/urls.py @@ -2,7 +2,7 @@ from django.contrib.auth import views as auth_views from django.urls import path -from brasilio_auth.views import CreateUserView +from brasilio_auth.views import CreateUserView, ProfileUpdate views_config = { @@ -36,4 +36,5 @@ path('troca-senha/atualizada/', views_config['password_reset_complete'], name='password_reset_complete'), path('logout/', views_config['logout'], name='logout'), path('entrar/', CreateUserView.as_view(), name='sign_up'), + path('editar-perfil/', ProfileUpdate.as_view(), name='profile_update_form') ) diff --git a/brasilio_auth/views.py b/brasilio_auth/views.py index 8157d9a2..a41c1cc1 100644 --- a/brasilio_auth/views.py +++ b/brasilio_auth/views.py @@ -2,6 +2,9 @@ from django.contrib.auth import get_user_model, login from django.views.generic.edit import CreateView from django.shortcuts import redirect +from django.views.generic.edit import UpdateView +from django.contrib.auth.models import User +from django.urls import reverse from brasilio_auth.forms import UserCreationForm @@ -24,3 +27,12 @@ def form_valid(self, *args, **kwargs): login(self.request, self.object) url = self.request.POST.get('next', None) or self.success_url return redirect(url) + + +class ProfileUpdate(UpdateView): + model = User + pk_url_kwarg = 'user_id' + fields = ['first_name', 'last_name', 'username'] + template_name = 'brasilio_auth/profile_update_form.html' + def get_success_url(self): + return reverse('brasilio_auth:profile_update_form', args=[self.object.id]) diff --git a/core/templates/menu.html b/core/templates/menu.html index f1c2f9ad..f9a67f86 100644 --- a/core/templates/menu.html +++ b/core/templates/menu.html @@ -1,5 +1,5 @@ {% if request.user.is_authenticated %} -
  • Olá, {{ request.user.username }}
  • +
  • Olá, {{ request.user.username }}
  • Logout
  • {% else %}
  • Cadastre-se
  • From dfc679c5d397bd50c702de8e8277abd17ae2b2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Epif=C3=A2nio?= Date: Sat, 9 Feb 2019 15:39:15 -0300 Subject: [PATCH 2/2] Remove pk na url do profile. Adiciona login_required na url de editar perfil --- brasilio_auth/urls.py | 4 +- brasilio_auth/views.py | 7 +++- core/migrations/0015_auto_20181117_1827.py | 43 ++++++++++++++++++++++ core/templates/menu.html | 2 +- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 core/migrations/0015_auto_20181117_1827.py diff --git a/brasilio_auth/urls.py b/brasilio_auth/urls.py index feb7a590..4702531e 100644 --- a/brasilio_auth/urls.py +++ b/brasilio_auth/urls.py @@ -3,7 +3,7 @@ from django.urls import path from brasilio_auth.views import CreateUserView, ProfileUpdate - +from django.contrib.auth.decorators import login_required views_config = { 'login': auth_views.LoginView.as_view(template_name='brasilio_auth/login.html'), @@ -36,5 +36,5 @@ path('troca-senha/atualizada/', views_config['password_reset_complete'], name='password_reset_complete'), path('logout/', views_config['logout'], name='logout'), path('entrar/', CreateUserView.as_view(), name='sign_up'), - path('editar-perfil/', ProfileUpdate.as_view(), name='profile_update_form') + path('editar-perfil', login_required(ProfileUpdate.as_view()), name='profile_update_form') ) diff --git a/brasilio_auth/views.py b/brasilio_auth/views.py index a41c1cc1..b28d810a 100644 --- a/brasilio_auth/views.py +++ b/brasilio_auth/views.py @@ -31,8 +31,11 @@ def form_valid(self, *args, **kwargs): class ProfileUpdate(UpdateView): model = User - pk_url_kwarg = 'user_id' fields = ['first_name', 'last_name', 'username'] template_name = 'brasilio_auth/profile_update_form.html' + + def get_object(self, queryset=None): + return self.request.user + def get_success_url(self): - return reverse('brasilio_auth:profile_update_form', args=[self.object.id]) + return reverse('brasilio_auth:profile_update_form') diff --git a/core/migrations/0015_auto_20181117_1827.py b/core/migrations/0015_auto_20181117_1827.py new file mode 100644 index 00000000..f4f57b3f --- /dev/null +++ b/core/migrations/0015_auto_20181117_1827.py @@ -0,0 +1,43 @@ +# Generated by Django 2.1.3 on 2018-11-17 18:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0014_auto_20180908_1902'), + ] + + operations = [ + migrations.AlterField( + model_name='field', + name='frontend_filter', + field=models.BooleanField(blank=True, default=False), + ), + migrations.AlterField( + model_name='field', + name='has_choices', + field=models.BooleanField(blank=True, default=False), + ), + migrations.AlterField( + model_name='field', + name='null', + field=models.BooleanField(blank=True, default=True), + ), + migrations.AlterField( + model_name='field', + name='obfuscate', + field=models.BooleanField(blank=True, default=False), + ), + migrations.AlterField( + model_name='field', + name='show', + field=models.BooleanField(blank=True, default=True), + ), + migrations.AlterField( + model_name='field', + name='show_on_frontend', + field=models.BooleanField(blank=True, default=False), + ), + ] diff --git a/core/templates/menu.html b/core/templates/menu.html index f9a67f86..9ab92c69 100644 --- a/core/templates/menu.html +++ b/core/templates/menu.html @@ -1,5 +1,5 @@ {% if request.user.is_authenticated %} -
  • Olá, {{ request.user.username }}
  • +
  • Olá, {{ request.user.username }}
  • Logout
  • {% else %}
  • Cadastre-se