27# added update, delete job

This commit is contained in:
Eligiusz Kurzawa 2021-01-16 08:52:53 +01:00
parent 4dfae071fb
commit 52d74c36be
2 changed files with 84 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView, ListView, CreateView, DetailView, UpdateView, DeleteView
from jobs.forms import CreateJobForm, ApplyJobForm, UpdateJobForm
@ -114,6 +115,35 @@ class UpdateJobView(SuccessMessageMixin ,UpdateView):
form_class = UpdateJobForm
success_message = "You updated your job!"
def form_valid(self, form):
form.instance.employer = self.request.user
return super(UpdateJobView, self).form_valid(form)
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.employer != request.user:
return HttpResponseRedirect('/')
return super(UpdateJobView, self).get(request, *args, **kwargs)
def get_success_url(self):
return reverse('jobs:single_job', kwargs={"pk":self.object.pk, "slug":self.object.slug})
class DeleteJobView(SuccessMessageMixin, DeleteView):
pass
model = Job
success_url = '/'
template_name = 'jobs/delete.html'
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.employer == request.user:
self.object.delete()
return HttpResponseRedirect(self.success_url)
else:
return HttpResponseRedirect(self.success_url)
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.employer != request.user:
return HttpResponseRedirect('/')
return super(DeleteJobView, self).get(request, *args, **kwargs)

View File

@ -0,0 +1,53 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<div class="hero-wrap js-fullheight" style="background-image: url('{% static 'images/bg_2.jpg' %}');" data-stellar-background-ratio="0.5"> <div class="overlay"></div>
<div class="container">
<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>Delete a job</span></p>
<h1 class="mb-3 bread" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }">Delete a job</h1>
</div>
</div>
</div>
</div>
<div class="ftco-section bg-light">
<div class="container">
<div class="row">
<div class="col-md-12 col-lg-8 mb-5">
<h2 class="mb-4">Are you sure to delete?</h2>
<form method="post">
{% csrf_token %}
<a href="{% url 'jobs:single_job' slug=job.slug pk=job.pk %}" class="btn btn-primary py-2 mr-1">No</a>
<button type="submit" class="btn btn-danger py-2 mr-1">Yes</button>
</form>
</div>
<div class="col-lg-4">
<div class="p-4 mb-3 bg-white">
<h3 class="h5 text-black mb-3">Contact Info</h3>
<p class="mb-0 font-weight-bold">Address</p>
<p class="mb-4">203 Fake St. Mountain View, San Francisco, California, USA</p>
<p class="mb-0 font-weight-bold">Phone</p>
<p class="mb-4"><a href="#">+1 232 3235 324</a></p>
<p class="mb-0 font-weight-bold">Email Address</p>
<p class="mb-0"><a href="#"><span class="__cf_email__" data-cfemail="671e081215020a060e0b2703080a060e094904080a">[email&#160;protected]</span></a></p>
</div>
<div class="p-4 mb-3 bg-white">
<h3 class="h5 text-black mb-3">More Info</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa ad iure porro mollitia architecto hic consequuntur. Distinctio nisi perferendis dolore, ipsa consectetur</p>
<p><a href="#" class="btn btn-primary py-2 px-4">Learn More</a></p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}