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')
    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)
Exemple #4
0
    def get(self, request, *args, **kwargs):
        try:
            form = CompanyForm(instance=self.get_object())
            return render(request, 'vacancies/company-edit.html',
                          {'form': form})

        except Company.DoesNotExist:
            return redirect('create_company_lets_start')
Exemple #5
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 #6
0
 def get(self, request):
     if not Company.objects.filter(owner_id=request.user.id).exists():
         return render(request, 'company/company-create.html')
     company = Company.objects.get(owner_id=request.user.id)
     context = {
         'form': CompanyForm(instance=company),
     }
     return render(request, 'company/company-edit.html', context)
 def get(self, request, *args, **kwargs):
     template_name = 'vacancies/my_company_and_my_vacancies/my_company_create-edit.html'
     user = request.user
     try:
         company = user.company
     except Company.DoesNotExist:
         return redirect('my_company_lets_start')
     company_form = CompanyForm(instance=company)
     return render(request, template_name, {'form': company_form})
    def get(self, request):
        user = request.user
        if user.is_anonymous:
            return redirect(reverse('login'))

        company = Company.objects.filter(owner=user).first()
        template_name = 'vacancies/company-create.html' if company is None else 'vacancies/company-edit.html'
        return render(self.request, template_name,
                      {'form': CompanyForm(), 'company': company, 'title_left': 'Моя компания'})
Exemple #9
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 #10
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})
def create_user_company(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(owner=user, name='')
    return render(request, 'vacancies/company-edit.html',
                  {'form': CompanyForm(), 'company': company, 'title_left': 'Моя компания'})
Exemple #12
0
    def get(self, request):
        if not request.user.is_authenticated:
            return redirect('/login')

        my_company_exist = False

        data_about_company = {
            'name': '0',
            'location': '',
            'logo': 'no-image.png',
            'description': '',
            'employee_count': 0
        }

        list_of_company = Companies.objects.filter(owner_id=request.user.id)
        if list_of_company.count() > 0:
            data_about_company = list_of_company.first()
            my_company_exist = True
        elif "createNewCompany" in request.GET.keys():
            Companies.objects.create(
                name='',
                location=' ',
                logo='no-image.png',
                description='',
                employee_count=1,
                owner=User.objects.get(id=request.user.id),
            )
            data_about_company = Companies.objects.filter(
                owner_id=request.user.id).first()
            my_company_exist = True

        context = {
            'base_site_config': get_config_dict(),
            'data_about_company': data_about_company,
            'myCompanyExist': my_company_exist,
        }

        if my_company_exist:
            context['form'] = CompanyForm({
                'id':
                data_about_company.id,
                'name':
                data_about_company.name,
                'location':
                data_about_company.location,
                'logo':
                data_about_company.logo,
                'description':
                data_about_company.description,
                'employee_count':
                data_about_company.employee_count
            })

        return render(request, 'vacancies/mycompany.html', context=context)
Exemple #13
0
 def get(self, request):
     if request.user.is_authenticated:
         # Если у пользователя есть компания, подтягиваем данные о ней
         if hasattr(request.user, 'company'):
             company = request.user.company
             initial_data = {
                 "name": company.name,
                 "employee_count": company.employee_count,
                 "location": company.location,
                 "description": company.description
             }
             form = CompanyForm(initial=initial_data)
             return render(request, 'mycompany/company-edit.html',
                           {'form': form})
         # Если у пользователя нет компании, выводим пустую форму
         else:
             form = CompanyForm()
             return render(request, 'mycompany/company-edit.html',
                           {'form': form})
     else:
         return HttpResponseRedirect('/')
 def get(self, request):
     form = CompanyForm()
     company = self.get_company(request)
     if company:
         form.initial = {
             'title': company.title,
             'location': company.location,
             'description': company.description,
             'employee_count': company.employee_count,
         }
         return render(request, 'vacancies/user/company_edit.html', {'form': form, 'logo': company.logo})
     return render(request, 'vacancies/user/company_edit.html', {'form': form})
 def get(self, request, *args, **kwargs):
     template_name = 'vacancies/my_company_and_my_vacancies/my_company_create-edit.html'
     user = request.user
     if not user.is_authenticated:
         return redirect('login')
     try:
         request.user.company
         return redirect('my_company_and_my_vacancies')
     except Company.DoesNotExist:
         company_form = CompanyForm()
         context = {}
         context['form'] = company_form
         return render(request, template_name, context=context)
Exemple #16
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 #17
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('/')