def Post_Job(request): if request.user.get_profile().type() != "C": return redirect ("/") company = request.user.get_profile().company job_form = JobForm() if request.method == "POST": job_form = JobForm(data=request.POST) if job_form.is_valid(): job_vacancy = job_form.save(commit = False) job_vacancy.company = company job_vacancy.save() return HttpResponseRedirect(reverse('company.views.Company_Job')) return render(request, 'job_new.html', {'job_form':job_form,'company':company})
def job_detail(request, pk): data = {} job = get_object_or_404(Job, pk=pk) form = JobForm(instance=job, company=job.company) context = {'form': form, 'company': job.company} data['disable_all'] = True data['html_form'] = render_to_string('company/job/job_detail.html', context, request=request) return JsonResponse(data)
def create_job(request,company_pk=None): """ Creates a job listing. """ form = JobForm() if company_pk: company = get_object_or_404(Company,pk=company_pk) form.initial['company'] = company if request.method == "POST": form = JobForm(request.POST) if form.is_valid(): #check that this person is a founder of the company if request.user not in form.instance.company.founders.all(): messages.error(request,"Cannot create job listings for a company that you are not part of.") return render_to_response("company/job_form.html",{"form":form},context_instance=RequestContext(request)) job = form.save() return HttpResponseRedirect(reverse("job_listing",args=(job.pk,))) return render_to_response("company/job_form.html",{"form":form},context_instance=RequestContext(request))
def Edit_Job(request,job_id): if request.user.get_profile().type() != "C": return redirect ("/") company = request.user.get_profile().company job = Job_Vacancy.objects.get(pk = job_id) if company != job.company: raise Http404 job_form = JobForm(instance = job) if request.method == "POST": job_form = JobForm(data=request.POST,instance = job) if job_form.is_valid(): job_vacancy = job_form.save(commit = False) job_vacancy.save() return HttpResponseRedirect(reverse('company.views.Edit_Job',args=(job.id,) )) return render(request, 'edit_job.html', {'job_form':job_form,'job':job})
def Post_Job(request): if request.user.get_profile().type() != "C": return redirect("/") company = request.user.get_profile().company job_form = JobForm() if request.method == "POST": job_form = JobForm(data=request.POST) if job_form.is_valid(): job_vacancy = job_form.save(commit=False) job_vacancy.company = company job_vacancy.save() return HttpResponseRedirect(reverse('company.views.Company_Job')) return render(request, 'job_new.html', { 'job_form': job_form, 'company': company })
def Edit_Job(request, job_id): if request.user.get_profile().type() != "C": return redirect("/") company = request.user.get_profile().company job = Job_Vacancy.objects.get(pk=job_id) if company != job.company: raise Http404 job_form = JobForm(instance=job) if request.method == "POST": job_form = JobForm(data=request.POST, instance=job) if job_form.is_valid(): job_vacancy = job_form.save(commit=False) job_vacancy.save() return HttpResponseRedirect( reverse('company.views.Edit_Job', args=(job.id, ))) return render(request, 'edit_job.html', {'job_form': job_form, 'job': job})
def add(request): if (request.method == 'POST'): company_form = CompanyForm(prefix="company_form", data=request.POST) job_form = JobForm(prefix="job_form", data=request.POST) attachment_form = AttachmentForm(prefix='attachment_form', files=request.FILES) consent_deadline_form = ConsentDeadlineForm( prefix='consent_deadline_form', data=request.POST) print(company_form.errors.as_data()) print(job_form.errors.as_data()) print(attachment_form.errors.as_data()) print(consent_deadline_form.errors.as_data()) if company_form.is_valid() and job_form.is_valid( ) and attachment_form.is_valid() and consent_deadline_form.is_valid(): #print ('valid') company = company_form.save() #company = Company.objects.latest('id') job = job_form.save(commit=False) job.company = company job.save() job_form.save_m2m() locations = request.POST.getlist('location') for loc in locations: print(loc) if (len(loc) > 0): JobLocation.objects.create(job=job, location=loc) files = request.FILES.getlist('attachment_form-file') for f in files: instance = Attachment(file=f) instance.job = job instance.save() deadline_date = consent_deadline_form.cleaned_data['deadline_date'] deadline_time = consent_deadline_form.cleaned_data['deadline_time'] slack_time = consent_deadline_form.cleaned_data['slack_time'] deadline = datetime.combine(deadline_date, deadline_time) ConsentDeadline.objects.create(job=job, deadline=deadline, slack_time=slack_time) consent_format = request.POST.getlist('A') cgpa_type = 'cgpa_upto_semester' position = 1 for slug in consent_format: print(slug) if (slug in ['cgpa_of_semester', 'cgpa_upto_semester']): cgpa_type = slug else: if (len(slug) <= 2): field = UserDataFields.objects.get(slug=cgpa_type) FieldOrder.objects.create(job=job, field=field, optional=int(slug), position=position) else: field = UserDataFields.objects.get(slug=slug) FieldOrder.objects.create(job=job, field=field, position=position) position += 1 return HttpResponseRedirect('/consent/home') else: if request.user.groups.filter(name='Coordinator').exists(): company_form = CompanyForm(prefix='company_form', label_suffix='') job_form = JobForm(prefix='job_form', label_suffix='') attachment_form = AttachmentForm(prefix='attachment_form', label_suffix='') consent_deadline_form = ConsentDeadlineForm( prefix='consent_deadline_form', label_suffix='') default_fields = UserDataFields.objects.filter( default_position__gte=1).order_by( 'default_position').values_list('slug', 'name') optional_fields = UserDataFields.objects.filter( default_position=0).values_list('slug', 'name') half = int(len(optional_fields) / 2) optional_fields_1 = optional_fields[:half] optional_fields_2 = optional_fields[half:] return render( request, 'company/add.html', { 'company_form': company_form, 'job_form': job_form, 'attachment_form': attachment_form, 'consent_deadline_form': consent_deadline_form, 'default_fields': default_fields, 'optional_fields_1': optional_fields_1, 'optional_fields_2': optional_fields_2, }) else: return HttpResponseRedirect('/consent/home')
def add(request): if (request.method == 'POST'): company_form = CompanyForm(prefix="company_form", data=request.POST) job_form = JobForm(prefix="job_form", data=request.POST) attachment_form = AttachmentForm(prefix='attachment_form', files=request.FILES) consent_deadline_form = ConsentDeadlineForm(prefix='consent_deadline_form', data=request.POST) print (company_form.errors.as_data()) print (job_form.errors.as_data()) print (attachment_form.errors.as_data()) print (consent_deadline_form.errors.as_data()) company = None company_name = company_form['name'].value().strip() # print (company_name) if Company.objects.filter(name=company_name).count() == 1: company = Company.objects.get(name=company_name) if company is not None or (company is None and company_form.is_valid()): if job_form.is_valid() and attachment_form.is_valid() and consent_deadline_form.is_valid(): if company is None: company = company_form.save() job = job_form.save(commit=False) job.company = company job.added_by = request.user job.is_active = True job.save() job_form.save_m2m() eb = job.eligible_branches.filter(name='ALL') for all_type_branch in eb: all_branches = Branch.objects.filter(degree=all_type_branch.degree).exclude(name='ALL') for branch in all_branches: job.eligible_branches.add(branch) job.eligible_branches.remove(all_type_branch) locations = request.POST.getlist('location'); for loc in locations: if(len(loc)>0): JobLocation.objects.create(job=job, location=loc) files = request.FILES.getlist('attachment_form-file') for f in files: instance = Attachment(file=f) instance.job = job instance.save() deadline_date = consent_deadline_form.cleaned_data['deadline_date'] deadline_time = consent_deadline_form.cleaned_data['deadline_time'] slack_time = consent_deadline_form.cleaned_data['slack_time'] deadline = datetime.combine(deadline_date, deadline_time) ConsentDeadline.objects.create(job=job, deadline=deadline, slack_time=slack_time) consent_format = request.POST.getlist('A'); cgpa_type = 'cgpa_upto_semester' position = 1 for slug in consent_format: if (slug in ['cgpa_of_semester', 'cgpa_upto_semester']): cgpa_type = slug else: if (len(slug)<=2): field = UserDataFields.objects.get(slug=cgpa_type) FieldOrder.objects.create(job=job, field=field, optional=int(slug), position=position) else: field = UserDataFields.objects.get(slug=slug) FieldOrder.objects.create(job=job, field=field, position=position) position += 1 messages.success(request, 'The company was successfully added!') return HttpResponseRedirect('/consent/home') else: print ('Invalid state reached!!!') else: if request.user.groups.filter(name='Coordinator').exists(): company_form = CompanyForm(prefix='company_form', label_suffix='') job_form = JobForm(prefix='job_form', label_suffix='') attachment_form = AttachmentForm(prefix='attachment_form', label_suffix='') consent_deadline_form = ConsentDeadlineForm(prefix='consent_deadline_form', label_suffix='') default_fields = UserDataFields.objects.filter(default_position__gte=1).order_by( 'default_position').values_list('slug', 'name') optional_fields = UserDataFields.objects.filter(default_position=0).values_list('slug', 'name') half = int(len(optional_fields)/2) optional_fields_1 = optional_fields[:half] optional_fields_2 = optional_fields[half:] return render(request, 'company/add.html', { 'company_form': company_form, 'job_form': job_form, 'attachment_form': attachment_form, 'consent_deadline_form': consent_deadline_form, 'default_fields': default_fields, 'optional_fields_1': optional_fields_1, 'optional_fields_2': optional_fields_2, }) else: return HttpResponseRedirect('/consent/home')