def post(self, request):
        user = request.user
        if user.is_anonymous:
            return redirect(reverse('login'))

        company = Company.objects.filter(owner=user).first()
        if company is None:
            company = Company()
        form = CompanyForm(request.POST)
        context = {'form': form, 'company': company}
        if form.is_valid():
            data = form.cleaned_data
            company.name = data['name']
            company.location = data['location']
            # Не знаю, как надо загружать logo
            # в request.POST данные есть, а в cleaned_data - нет
            # company.logo = data['logo']
            #
            # file_name = request.POST.get('logo')
            # company.logo.storage.save(file_name)
            company.description = data['description']
            company.employee_count = data['employee_count']
            company.owner = user
            company.save()
            context['info_updated'] = True
        return render(self.request, 'vacancies/company-edit.html', context)
    def post(self, request):
        form = CompanyForm(request.POST, request.FILES)
        if not form.is_valid():
            return render(request, 'vacancies/user/company_edit.html', {'form': form})

        company = self.get_company(request)

        if company:
            company.title = form.cleaned_data['title']
            company.location = form.cleaned_data['location']
            if form.cleaned_data['logo']:
                company.logo = form.cleaned_data['logo']
            company.description = form.cleaned_data['description']
            company.employee_count = form.cleaned_data['employee_count']
            company.owner = get_user(request)
        else:
            company = Company(
                title=form.cleaned_data['title'],
                location=form.cleaned_data['location'],
                logo=form.cleaned_data['logo'],
                description=form.cleaned_data['description'],
                employee_count=form.cleaned_data['employee_count'],
                owner=get_user(request),
            )
        company.save()
        return redirect(reverse('my_company_form') + '?submitted=True')
 def post(self, request, *args, **kwargs):
     form = CompanyForm(request.POST)
     if form.is_valid():
         company = form.save(commit=False)
         company.owner = request.user
         company.save()
         return redirect('my_company_and_my_vacancies')
Exemple #4
0
 def post(self, request):
     instance = Company.objects.get(owner_id=request.user.id)
     form = CompanyForm(request.POST, request.FILES, instance=instance)
     if form.is_valid():
         form.save()
         messages.add_message(request, messages.INFO, 'Информация о компании обновлена')
         return redirect('mycompany')
     return render(request, 'company/company-edit.html', {'form': form})
Exemple #5
0
 def post(self, request):
     form = CompanyForm(request.POST, request.FILES)
     if form.is_valid():
         company = form.save(commit=False)
         company.owner = User.objects.get(id=request.user.id)
         company.save()
         messages.add_message(request, messages.INFO, 'Компания успешно создана')
         return redirect('mycompany')
     return render(request, 'company/company-edit.html', {'form': form})
Exemple #6
0
 def post(self, request):
     form = CompanyForm(request.POST)
     if form.is_valid():
         company = form.save(commit=False)
         company.owner = request.user
         company.save()
         messages.success(request, 'Кампания успешно создана!')
         return redirect('edit_company')
     messages.error(request, 'Вы ввели неверные данные!')
     return render(request, 'vacancies/vacancy.html', {'form': form})
Exemple #7
0
    def post(self, request):

        if not request.user.is_authenticated:
            return redirect('/login')

        company_form = CompanyForm(request.POST, request.FILES)
        print(company_form['location'])
        if company_form.is_valid():
            data_for_save = company_form.cleaned_data
            if data_for_save['logo'] is None:
                data_for_save['logo'] = Companies.objects.get(
                    id=data_for_save['id']).logo
            print(data_for_save['logo'])
            data_for_save['owner'] = User.objects.get(id=request.user.id)
            Companies(**data_for_save).save()

        return redirect('my_company')
Exemple #8
0
 def post(self, request):
     if request.user.is_authenticated:
         form = CompanyForm(request.POST)
         if form.is_valid():
             data = form.cleaned_data
             # Если у пользователя уже есть компания, обновляем данные о ней
             if hasattr(request.user, 'company'):
                 company = request.user.company
                 company.name = data["name"]
                 company.employee_count = data["employee_count"]
                 company.location = data["location"]
                 company.description = data["description"]
                 company.save()
             # Если у пользователя еще нет компании, создаем ее
             else:
                 data.update({"user": request.user})
                 Company.objects.create(**data)
             return render(request, 'mycompany/company-edit.html',
                           {'form': form})
     else:
         return HttpResponseRedirect('/')