def post_job(request): if request.method == 'POST': print(1) application = JobApplication() id = create_job_id(4) application.id = id application.org = request.user.profile_org application.title = request.POST.get('title') application.type = request.POST.get('type') application.category = request.POST.get('category') application.salary = request.POST.get('salary') application.location = request.POST.get('location') application.descr = request.POST.get('about') req_skills = request.POST.get('req_skills') req_skills = req_skills.split(',') for skill in req_skills: application.req_skills.add(skill) msg = ["Job Added, Job Id is:" + str(id)] application.save() create_action(request.user, "posted a new job", 'new_job', application) return render(request, 'post_job.html', context={'messages': msg}) else: print(0) return render(request, 'post_job.html')
def user_follow(request): user_id = request.POST.get('id') action = request.POST.get('action') if user_id and action: try: user = Client.objects.get(id=user_id) if action == 'follow': Contact.objects.get_or_create(user_from=request.user, user_to=user) create_action(request.user, "started following", 'follow', user) else: Contact.objects.filter(user_from=request.user, user_to=user).delete() return JsonResponse({'status': 'ok'}) except Client.DoesNotExist: return JsonResponse({'status': 'ko'}) return JsonResponse({'status': 'ko'})
def see_add_response(request, app_id): application = AppliedJobs.objects.filter(id=app_id) application = application[0] if request.method == 'POST' and request.user.is_organisation(): application.status = True application.response = request.POST.get('text') application.save() create_action(request.user, "responded to your job application", 'job_response', application) message = ["Response Sent!"] return render(request, 'response.html', context={ 'messages': message, 'application': application }) else: return render(request, 'response.html', context={'application': application})
def view_job(request, id): user = request.user job = JobApplication.objects.get(id=id) job_tags_ids = job.req_skills.values_list('id', flat=True) print(job_tags_ids) similar_jobs = JobApplication.objects.filter( req_skills__in=job_tags_ids).exclude(id=id) similar_jobs = similar_jobs.annotate( same_req_skills=Count('req_skills')).order_by('-same_req_skills')[:4] if request.method == 'POST': new_app = AppliedJobs() new_app.id = create_job_id(5) new_app.job = job new_app.user = user.profile new_app.date_responded = now() new_app.save() create_action(request.user, 'applied to a job', 'applied_to_job', new_app) return render(request, 'view_single_job.html', context={ 'job': job, 'user': user, 'application': new_app, 'similar_jobs': similar_jobs }) else: try: application = AppliedJobs.objects.filter(job=job).filter( user=user.profile) except: application = None if application: application = application[0] if request.user.is_authenticated: if user.is_organisation(): print(1) return render(request, 'view_single_job.html', context={ 'job': job, 'user': user, 'similar_jobs': similar_jobs }) else: print(9) return render(request, 'view_single_job.html', context={ 'job': job, 'user': user, 'application': application, 'similar_jobs': similar_jobs }) else: error = ["You must login first!"] return render(request, 'login.html', context={'errors': error})