...
 
Commits (2)
......@@ -7,11 +7,13 @@ from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect
from rules.contrib.views import PermissionRequiredMixin
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from .models import Job, Application, Question, JobMessage
from .forms import JobForm, QuestionFormSet, ApplicationForm, AnswerForm, MessageForm
import logging
logger = logging.getLogger(__name__)
User = get_user_model()
class Index(TemplateView):
......@@ -242,7 +244,7 @@ class MyJobs(LoginRequiredMixin, ListView):
context['my_jobs_page'] = 'active'
return context
@login_required()
def send_message(request):
form = MessageForm(request.POST)
if form.is_valid():
......@@ -252,16 +254,24 @@ def send_message(request):
print("Error")
return redirect('jobs:conversation', pk=request.POST.get('receiver_id'))
@login_required()
def change_status(request):
print(request.POST)
job_id = request.POST.get('job_id')
if job_id is not None:
job = Job.objects.get(id=job_id)
if job.active:
job.active = False
try:
job_obj = Job.objects.get(id=request.POST.get('job_id'))
if job_obj.posted_by == request.user:
if job_obj.active:
job_obj.active = False
else:
job_obj.active = True
job_obj.save()
else:
job.active = True
job.save()
else:
print("Error")
logger.error(
"the user {} tried to toggle the job id {}. But it doesn't belong to him".format(
request.user, request.POST.get('job_id'))
)
except Job.DoesNotExist:
logger.error(
"the user {} tried to toggle the job id {} but it doesn't exist.".format(
request.user, request.POST.get('job_id'))
)
return redirect('jobs:my_jobs')