Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. import os
  2. from datetime import datetime
  3.  
  4. from django.conf import settings
  5. from django.contrib.auth.decorators import login_required
  6. from django.shortcuts import redirect
  7. from django.shortcuts import render
  8.  
  9.  
  10. @login_required
  11. def manual_add_candidate(request):
  12.     candidate = None
  13.     form_add_candidate = None
  14.     if request.method == 'POST':
  15.         form_add_candidate = AddCandidateForm(request.POST, request.FILES, instance=candidate)
  16.         if form_add_candidate.is_valid():
  17.             if len(form_add_candidate.cleaned_data['fio']) > 1:
  18.                 temp_candidate = form_add_candidate.save()
  19.                 temp_candidate.source = 'MANUAL'
  20.                 temp_candidate.save()
  21.  
  22.                 alert = {'type': 'success',
  23.                          'lead': 'Кандидат добавлен!',
  24.                          'description': f'Кандидат "{temp_candidate.fio}" добавлен в актуальные резюме'
  25.                          }
  26.                 request.session['alert'] = alert
  27.  
  28.                 response = redirect(f'/candidate/{temp_candidate.id}')
  29.                 return response
  30.             else:
  31.                 alert = {'type': 'danger',
  32.                          'lead': 'Что-то пошло не так!',
  33.                          'description': f'Резюме не удалось добавить. Попробуйте еще раз'
  34.                          }
  35.                 request.session['alert'] = alert
  36.  
  37.                 response = redirect(f'/candidate')
  38.                 return response
  39.     elif request.method == 'GET':
  40.         form_add_candidate = AddCandidateForm(instance=candidate)
  41.     data = {'form_add_candidate': form_add_candidate,
  42.             'is_manual': True}
  43.     return render(request, 'candidate/manual_add_candidate.html', data)
  44.  
  45.  
  46. @login_required
  47. def delete_candidate(request, candidate_id):
  48.     try:
  49.         candidate = Candidate.objects.get(id=candidate_id)
  50.     except Exception as e:
  51.         print(e)
  52.     candidate.type = 'DELETED'
  53.     candidate.deleted = datetime.now()
  54.     candidate.save()
  55.  
  56.     alert = {'type': 'danger',
  57.              'lead': 'Удалено!',
  58.              'description': f'Кандидат "{candidate.fio}" перемещен в архив'
  59.              }
  60.     request.session['alert'] = alert
  61.  
  62.     response = redirect(f'/candidate')
  63.     return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement