Exemplo n.º 1
0
def post(request):
    job_posted = False
    company = request.user.companies.first()
    if request.method == 'POST':
        company_form = CompanyForm(request.POST, instance=company)
        job_form = JobForm(request.POST)
        if company_form.is_valid() and job_form.is_valid():
            company = company_form.save(commit=False)
            company.user = request.user
            company.save()
            job = job_form.save(commit=False)
            job.user = request.user
            job.company = company
            job.save()
            job_posted = True
    else:
        company_form = CompanyForm(instance=company)
        job_form = JobForm()

    if job_posted:
        notify_slack("New job posting: {}".format(job.title),
                     settings.SLACK_BOARD_CHANNEL)

    context = dict(job_posted=job_posted,
                   company_form=company_form,
                   job_form=job_form)
    return render(request, 'jobs/post.html', context)
Exemplo n.º 2
0
 def post(self, request):
     if request.method == "POST":
         form = CompanyForm(request.POST)
         print(form.is_valid(), form.errors)
         if form.is_valid():
             form = form.save(commit=False)
             form.owner = request.user
             form.logo = 'https://place-hold.it/130x80'
             form.save()
             return redirect('/mycompany/', pk=form.pk)
     else:
         form = CompanyForm()
     return render(request, 'company_create.html', {'form': form})
Exemplo n.º 3
0
 def get(self, request):
     if Company.objects.filter(owner=request.user):
         return redirect('company')
     else:
         company_form = CompanyForm()
         context = {'company_form': company_form}
         return render(request, 'jobs/employer/company-edit.html', context)
Exemplo n.º 4
0
    def post(self, request):
        current_user = request.user
        company = Company.objects.get(owner=current_user)

        form = CompanyForm(request.POST, instance=company)

        if form.is_valid():
            form = form.save(commit=False)
            form.owner = current_user
            form.save()
            return redirect('/mycompany/')
        else:
            form = CompanyForm(instance=company)

        return render(request,
                      'company_edit.html',
                      context={
                          'form': form,
                          'company': company
                      })
Exemplo n.º 5
0
 def get(self, request):
     try:
         company = Company.objects.get(owner=request.user)
         form = CompanyForm(instance=company)
         return render(request,
                       'company_edit.html',
                       context={
                           'company': company,
                           'form': form
                       })
     except Company.DoesNotExist:
         return render(request, 'company_not_found.html', context={})
Exemplo n.º 6
0
 def get(self, request):
     try:
         company = Company.objects.get(owner=request.user)
     except Company.DoesNotExist:
         return render(request, 'jobs/employer/company-create.html')
     else:
         company_form = CompanyForm()
         company_form['name'].initial = company.name
         company_form['location'].initial = company.location
         company_form['logo'].initial = company.logo
         company_form['description'].initial = company.description
         company_form['employee_count'].initial = company.employee_count
         context = {'company': company, 'company_form': company_form}
         return render(request, 'jobs/employer/company-edit.html', context)
Exemplo n.º 7
0
    def post(self, request):
        form = CompanyForm(request.POST)
        company = request.user.mycompany.first()
        if form.is_valid():
            data = form.cleaned_data
            company.name = data['name']
            company.location = data['location']
            company.logo = data['logo']
            company.description = data['description']
            company.employee_count = data['employee_count']
            company.save()

            return redirect('/mycompany/')
        return render(request, 'company_new_create.html', {'form': form})
Exemplo n.º 8
0
 def post(self, request):
     company_form = CompanyForm(request.POST, request.FILES)
     if company_form.is_valid():
         Company.objects.create(
             name=company_form.cleaned_data['name'],
             location=company_form.cleaned_data['location'],
             logo=company_form.cleaned_data['logo'],
             description=company_form.cleaned_data['description'],
             employee_count=company_form.cleaned_data['employee_count'],
             owner=request.user,
         )
         messages.success(request, 'success')
         return redirect('company')
     else:
         raise Http404
Exemplo n.º 9
0
 def post(self, request):
     company = Company.objects.get(owner=request.user)
     company_form = CompanyForm(request.POST, request.FILES)
     if company_form.is_valid():
         changed_data = company_form.cleaned_data
         company.name = changed_data['name']
         company.location = changed_data['location']
         company.logo = changed_data['logo'] if changed_data['logo'] is not None else company.logo
         company.description = changed_data['description']
         company.employee_count = changed_data['employee_count']
         company.save()
         messages.success(request, 'success')
         return HttpResponseRedirect(request.path_info)
     else:
         raise Http404
Exemplo n.º 10
0
 def post(self, request):
     form = CompanyForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         user = request.user
         company = Company.objects.create(
             name=data['name'],
             location=data['location'],
             logo=data['logo'],
             description=data['description'],
             employee_count=data['employee_count'],
             owner=user,
         )
         return redirect('/mycompany/')
     return render(request, 'company_new_create.html', {'form': form})
Exemplo n.º 11
0
 def get(self, request):
     company = request.user.mycompany.all()
     no_company = 0
     user = request.user
     if len(company) == no_company:
         return redirect(reverse('letsstart'))
     else:
         form = CompanyForm(
             initial={
                 'name': request.user.mycompany.first().name,
                 'location': request.user.mycompany.first().location,
                 'logo': request.user.mycompany.first().logo,
                 'description': request.user.mycompany.first().description,
                 'employee_count':
                 request.user.mycompany.first().employee_count,
                 'owner': user,
             })
         context = {
             'form': form,
         }
     return render(request, 'company-edit.html', context=context)
Exemplo n.º 12
0
    def get(self, request):

        form = CompanyForm()

        return render(request, 'company_create.html', context={'form': form})