11# added changes to update form
This commit is contained in:
parent
f8c4829d55
commit
e2706d640f
@ -7,7 +7,7 @@
|
||||
<div class="row no-gutters slider-text js-fullheight align-items-end justify-content-start" data-scrollax-parent="true">
|
||||
<div class="col-md-8 ftco-animate text-center text-md-left mb-5" data-scrollax=" properties: { translateY: '70%' }">
|
||||
<p class="breadcrumbs" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }"><span class="mr-3"><a href="index.html">Home <i class="ion-ios-arrow-forward"></i></a></span> <span>Login</span></p>
|
||||
<h1 class="mb-3 bread" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }">Login</h1>
|
||||
<h1 class="mb-3 bread" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }">Update Profile</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -51,7 +51,49 @@
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col-md-12">
|
||||
<input type="submit" value="Login" class="btn btn-primary py-2 px-5">
|
||||
<input type="submit" value="Update" class="btn btn-primary py-2 px-5">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_employer %}
|
||||
<form action="#" class="p-5 bg-white" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-dismissible" role="alert">
|
||||
<div id="form_errors">
|
||||
{% for key, value in form.errors.items %}
|
||||
<span class="fieldWrapper">
|
||||
{{ key }}: {{ value }}
|
||||
</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="button" class="close" data-dismiss="alert" aria_hidden="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for field in form.visible_fields|slice:"3" %}
|
||||
<div class="row form-group">
|
||||
<div class="col-md-12 mb-3 mb-md-0">
|
||||
<label class="font-weight-bold" for="fullname">{{ field.label }}</label>
|
||||
<input type="{{ field.field.widget.input_type }}" id="fullname" class="form-control" placeholder="{{ field.label }}" name="{{ field.html_name }}">
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="row form-group">
|
||||
<div class="col-md-12 mb-3 mb-md-0">
|
||||
<label class="font-weight-bold" for="fullname">{{ form.company.label }}</label>
|
||||
<input type="{{ form.company.field.widget.input_type }}" id="fullname" class="form-control" placeholder="{{ form.company.label }}" name="{{ form.company.html_name }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row form-group">
|
||||
<div class="col-md-12">
|
||||
<input type="submit" value="Update" class="btn btn-primary py-2 px-5">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -6,5 +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/<int:pk>/', UserUpdateView.as_view(), name='update'),
|
||||
path('update-profile/<int:pk>/', UserUpdateView.as_view(), name='update_profile'),
|
||||
]
|
||||
|
@ -1,6 +1,10 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import LoginView, LogoutView
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import CreateView, UpdateView
|
||||
|
||||
from users.forms import AccountRegisterForm, UserUpdateForm
|
||||
@ -34,8 +38,22 @@ class UserLogoutView(LogoutView):
|
||||
template_name = 'users/login.html'
|
||||
|
||||
|
||||
@method_decorator(login_required(login_url='/users/login'), name='dispatch')
|
||||
class UserUpdateView(SuccessMessageMixin, UpdateView):
|
||||
model = Profile
|
||||
success_message = "You updated your profile!"
|
||||
template_name = 'users/update.html'
|
||||
form_class = UserUpdateForm
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.user = self.request.user
|
||||
return super(UserUpdateView, self).form_valid(form)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if self.object.user != request.user:
|
||||
return HttpResponseRedirect('/')
|
||||
return super(UserUpdateView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('users: update_profile', kwargs={'pk': self.object.pk})
|
||||
|
Loading…
Reference in New Issue
Block a user