From f8c4829d5529fbcd9f3b5c84f4f7909c8fc905e7 Mon Sep 17 00:00:00 2001 From: Eligiusz Kurzawa Date: Mon, 11 Jan 2021 20:40:44 +0100 Subject: [PATCH] 10# created user profile update form --- templates/users/update.html | 86 +++++++++++++++++++++++++++++++++++++ users/forms.py | 12 +++++- users/urls.py | 1 + users/views.py | 12 +++++- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 templates/users/update.html diff --git a/templates/users/update.html b/templates/users/update.html new file mode 100644 index 0000000..7df66ad --- /dev/null +++ b/templates/users/update.html @@ -0,0 +1,86 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} + +
+
+
+
+ +

Login

+
+
+
+
+ +
+
+
+ +
+ {% if user.is_employee %} +
+ {% csrf_token %} + {% if form.errors %} + + {% endif %} + {% for field in form.visible_fields|slice:"3" %} +
+
+ + +
+
+ {% endfor %} +
+
Resume
+ {{ form.media }} + {{ form.resume }} +
+
+
+
+ +
+
+ +
+ {% endif %} +
+ +
+
+

Contact Info

+

Address

+

203 Fake St. Mountain View, San Francisco, California, USA

+ +

Phone

+

+1 232 3235 324

+ +

Email Address

+

[email protected]

+ +
+ +
+

More Info

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa ad iure porro mollitia architecto hic consequuntur. Distinctio nisi perferendis dolore, ipsa consectetur

+

Learn More

+
+
+
+
+
+ + {% endblock %} \ No newline at end of file diff --git a/users/forms.py b/users/forms.py index 65625a7..e44dd5f 100644 --- a/users/forms.py +++ b/users/forms.py @@ -1,6 +1,6 @@ from django import forms from django.contrib.auth.forms import UserCreationForm -from users.models import Account +from users.models import Account, Profile class AccountRegisterForm(UserCreationForm): @@ -10,3 +10,13 @@ class AccountRegisterForm(UserCreationForm): class Meta: model = Account fields = ['email', 'first_name', 'last_name'] + + +class UserUpdateForm(forms.ModelForm): + class Meta: + model = Profile + exclude = ('user',) + + widgets = { + 'birthday': forms.DateInput(attrs={'type': 'date'}) + } diff --git a/users/urls.py b/users/urls.py index 7670fd8..df5f78a 100644 --- a/users/urls.py +++ b/users/urls.py @@ -6,4 +6,5 @@ urlpatterns = [ path('register/', UserRegisterView.as_view(), name='register'), path('login/', UserLoginView.as_view(), name='login'), path('logout/', UserLogoutView.as_view(), name='logout'), + path('update//', UserUpdateView.as_view(), name='update'), ] diff --git a/users/views.py b/users/views.py index a1788dd..3071f1c 100644 --- a/users/views.py +++ b/users/views.py @@ -1,9 +1,10 @@ from django.contrib.auth.views import LoginView, LogoutView from django.contrib.messages.views import SuccessMessageMixin from django.shortcuts import redirect -from django.views.generic import CreateView +from django.views.generic import CreateView, UpdateView -from users.forms import AccountRegisterForm +from users.forms import AccountRegisterForm, UserUpdateForm +from users.models import Profile class UserRegisterView(SuccessMessageMixin, CreateView): @@ -31,3 +32,10 @@ class UserLoginView(LoginView): class UserLogoutView(LogoutView): template_name = 'users/login.html' + + +class UserUpdateView(SuccessMessageMixin, UpdateView): + model = Profile + success_message = "You updated your profile!" + template_name = 'users/update.html' + form_class = UserUpdateForm