def post(self, request, vacancy_id): vacancy = get_object_or_404(Vacancy, id=vacancy_id) form = ApplicationForm(request.POST) if form.is_valid(): data = form.cleaned_data Application.objects.create(written_username=data['written_username'], written_phone=data['written_phone'], written_cover_letter=data['written_cover_letter'], vacancy=vacancy, user=request.user) return redirect(reverse('vacancy_sent', kwargs={'vacancy_id': vacancy_id})) return render(request, self.template_name, {'form': form, 'vacancy_id': vacancy_id, 'vacancy': vacancy})
def post(self, request, vacancy): this_vacancy = get_object_or_404(Vacancy, id=vacancy) form = ApplicationForm(request.POST) if form.is_valid(): application = form.save(commit=False) application.user = request.user application.vacancy = get_object_or_404(Vacancy, id=vacancy) application.save() return redirect('send_request_vacancy', vacancy) return render(request, 'vacancies/vacancy.html', { 'form': form, 'this_vacancy': this_vacancy })
def post(self, request, vacancy_id): form = ApplicationForm(request.POST) user = get_current_user(request) if user is None: return redirect('login') vacancy = Vacancy.objects.filter( pk=vacancy_id).select_related('specialty') if form.is_valid(): application = form.save(commit=False) application.user = user application.vacancy = vacancy application.save() return redirect('send', vacancy_id) return render(request, 'vacancies/vacancy.html', {'form': form})
def post(self, request, vacancy_id): if not request.user.is_authenticated: return redirect('/login') application_form = ApplicationForm(request.POST) if application_form.is_valid(): data_for_save = application_form.cleaned_data data_for_save['vacancy'] = Vacancies.objects.get(id=vacancy_id) data_for_save['user'] = User.objects.get(id=request.user.id) Application(**data_for_save).save() return redirect('/success') else: application_form.add_error('written_username', 'Use YYYY/MM/DD format')
def get(self, request, vacancy_id): vacancy = get_object_or_404(Vacancy, id=vacancy_id) form = ApplicationForm() return render(request, 'vacancies/vacancy.html', { 'vacancy': vacancy, 'form': form })
def post(self, request, *args, **kwargs): self.object = self.get_object() # noqa form = ApplicationForm(request.POST or None) if form.is_valid(): application = form.save(commit=False) application.vacancy = self.object if request.user.is_authenticated: application.user = self.request.user application.save() return self.form_valid(form) return self.form_invalid(form)
def post(self, request, pk): application_form = ApplicationForm(request.POST) if application_form.is_valid(): user = request.user.id written_username = application_form.cleaned_data.get( 'written_username') written_phone = application_form.cleaned_data.get('written_phone') written_cover_letter = application_form.cleaned_data.get( 'written_cover_letter') Application.objects.create( written_username=written_username, written_phone=written_phone, written_cover_letter=written_cover_letter, user_id=user, vacancy=Vacancy.objects.get(id=pk)) return redirect('SendView', pk) return render(request, "vacancies/vacancy.html", {"form": ApplicationForm})
def get_context_data(self, **kwargs): context = super(VacancyView, self).get_context_data(**kwargs) vacancy_id = self.kwargs['vacancy_id'] vacancy = get_object_or_404(Vacancy, id=vacancy_id) context['vacancy'] = vacancy application_form = ApplicationForm() application_form.helper.form_action = reverse_lazy( 'vacancy', kwargs={'vacancy_id': vacancy_id}) context['form'] = application_form return context
def post(self, request, vacancy_id): user = request.user if not user.is_authenticated: return HttpResponseRedirect(reverse('login')) vacancy = self.get_vacancy(vacancy_id) application_form = ApplicationForm(request.POST) if application_form.is_valid(): application = application_form.save(commit=False) application.user = user application.vacancy = vacancy application.save() return HttpResponseRedirect(redirect_to='send') return render(request, 'vacancies/vacancy.html', context={ 'vacancy': vacancy, 'form': application_form })
def get(self, request, vacancy_id, *args, **kwargs): form = ApplicationForm() user = self.get_current_user(request) vacancy = self.get_vacancy(vacancy_id) return render(request, self.template_name, context={ 'form': form, 'vacancy': vacancy, 'user': user })
def get_context_data(self, vacancy_id, **kwargs): context = super(VacancyView, self).get_context_data(**kwargs) if vacancy_id is None: raise Http404 vacancy = Vacancy.objects.get(id=vacancy_id) context['form'] = ApplicationForm() context['vacancy'] = vacancy context['title_left'] = 'Вакансия' return context
def get(self, request, vacancy_id): data_of_vacancy = self.get_vacancy_data(vacancy_id) application_form = ApplicationForm() if data_of_vacancy is None: raise Http404 return render(request, 'vacancies/vacancy.html', context={ 'base_site_config': get_config_dict(), 'data_of_vacancy': data_of_vacancy, 'form': application_form })
def vacancy_view(request, job_id): vacancy = get_object_or_404(Vacancy, id=job_id) user = get_user(request) if request.method == 'GET': form = ApplicationForm() if not user.is_anonymous: written_username = f'{user.first_name} {user.last_name}' form.initial = { 'written_username': written_username, } return render(request, 'vacancies/main/vacancy.html', { 'vacancy': vacancy, 'form': form }) form = ApplicationForm(request.POST) if not form.is_valid(): return render(request, 'vacancies/main/vacancy.html', { 'vacancy': vacancy, 'form': form }) if user.is_anonymous: user = None Application.objects.create( written_username=form.cleaned_data['written_username'], written_phone=form.cleaned_data['written_phone'], written_cover_letter=form.cleaned_data['written_cover_letter'], vacancy=vacancy, user=user, ) return render(request, 'vacancies/main/sent.html', {'job_id': job_id})
def get(self, request, vacancy_id): form = ApplicationForm() try: vacancy = Company.objects.get(id=vacancy_id) except KeyError: raise Http404 return render( request, 'pages/vacancy.html', context={ 'vacancy': Vacancy.objects.get(id=vacancy.id), 'form': form, }, )
def post(self, request, vacancy_id): if not request.user.is_authenticated: return redirect('login') form = ApplicationForm(request.POST) user = self.get_current_user(request) vacancy = self.get_vacancy(vacancy_id) if form.is_valid() and user is not None: form = form.save(commit=False) form.vacancy = vacancy form.user = user form.save() return redirect(f'/vacancies/{vacancy_id}/send/') return render(request, self.template_name, context={ 'form': form, 'vacancy': vacancy, 'user': user })
def get_context_data(self, vacancy_id, **kwargs): context = super().get_context_data() vacancy = get_object_or_404(Vacancy, pk=vacancy_id) context['vacancy'] = vacancy context['application_form'] = ApplicationForm() return context
def post(self, request, vacancy_id): form = ApplicationForm(request.POST) if form.is_valid(): return HttpResponseRedirect( reverse('application_send', kwargs={'vacancy_id': vacancy_id}))