Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from datetime import datetime
- from django.conf import settings
- from django.contrib.auth.decorators import login_required
- from django.shortcuts import redirect
- from django.shortcuts import render
- @login_required
- def manual_add_candidate(request):
- candidate = None
- form_add_candidate = None
- if request.method == 'POST':
- form_add_candidate = AddCandidateForm(request.POST, request.FILES, instance=candidate)
- if form_add_candidate.is_valid():
- if len(form_add_candidate.cleaned_data['fio']) > 1:
- temp_candidate = form_add_candidate.save()
- temp_candidate.source = 'MANUAL'
- temp_candidate.save()
- alert = {'type': 'success',
- 'lead': 'Кандидат добавлен!',
- 'description': f'Кандидат "{temp_candidate.fio}" добавлен в актуальные резюме'
- }
- request.session['alert'] = alert
- response = redirect(f'/candidate/{temp_candidate.id}')
- return response
- else:
- alert = {'type': 'danger',
- 'lead': 'Что-то пошло не так!',
- 'description': f'Резюме не удалось добавить. Попробуйте еще раз'
- }
- request.session['alert'] = alert
- response = redirect(f'/candidate')
- return response
- elif request.method == 'GET':
- form_add_candidate = AddCandidateForm(instance=candidate)
- data = {'form_add_candidate': form_add_candidate,
- 'is_manual': True}
- return render(request, 'candidate/manual_add_candidate.html', data)
- @login_required
- def delete_candidate(request, candidate_id):
- try:
- candidate = Candidate.objects.get(id=candidate_id)
- except Exception as e:
- print(e)
- candidate.type = 'DELETED'
- candidate.deleted = datetime.now()
- candidate.save()
- alert = {'type': 'danger',
- 'lead': 'Удалено!',
- 'description': f'Кандидат "{candidate.fio}" перемещен в архив'
- }
- request.session['alert'] = alert
- response = redirect(f'/candidate')
- return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement