예제 #1
0
def ad_apply(request, job_id, ad_url):
    ad = get_object_or_404(Job, pk=job_id, ad_url=ad_url)
    if request.method == 'POST' and ad.apply_online and listings_settings.LISTINGS_APPLICATION_NOTIFICATIONS:
        ip = getIP(request)
        mb = minutes_between()

        form = ApplicationForm(request.POST,
                               request.FILES,
                               applicant_data={'ip': ip, 'mb': mb})

        if form.is_valid():
            application_mail = MailApplyOnline(ad, request)
            application_mail.start()

            #Save JobStat application
            ja = JobStat(job=ad, ip=ip, stat_type='A')
            ja.save()
            messages.add_message(request, messages.INFO, _('Your application was sent successfully.'))
        else:
            request.session['application_form'] = form

        return HttpResponseRedirect(reverse('listings_ad_detail', kwargs={'pk': ad.id, 'ad_url': ad.ad_url}))
    raise Http404
예제 #2
0
def job_detail(request, job_id, ad_url):
    ''' Displays an active job and its application form depending if
        the job has online applications or not. Handles the job applications
        and sends notifications emails.
    '''
    try:
        job = Job.active.get(pk=job_id, ad_url=ad_url)
        extra_context = {'page_type': 'detail', 'cv_extensions': listings_settings.LISTINGS_CV_EXTENSIONS}

        # Increment views
        job.increment_view_count(request)

        # Gets poster ip
        ip = getIP(request)

        # Only if the job has online applications ON and application
        # notifications are activated can the user apply online
        mb = minutes_between()
        if job.apply_online and listings_settings.LISTINGS_APPLICATION_NOTIFICATIONS:

            # Add CSRF protection
            extra_context.update(csrf(request))

            # If it's a job application
            if request.method == 'POST':

                # Gets the application
                form = ApplicationForm(request.POST,
                                       request.FILES,
                                       applicant_data={'ip': ip, 'mb': mb})

                # If the form is OK then send it to the job poster
                if form.is_valid():
                    application_mail = MailApplyOnline(job, request)
                    application_mail.start()

                    #Save JobStat application
                    ja = JobStat(job=job, ip=ip, stat_type='A')
                    ja.save()
                    messages.add_message(request, messages.INFO, _('Your application was sent successfully.'))
                    extra_context['page_type'] = 'application'
                    queryset = Job.active.filter(ad_url=ad_url)
                    return object_detail(request, queryset=queryset, object_id=job_id, extra_context=extra_context)
                else:
                    extra_context['form_error'] = True

            # Else create an empty application form
            else:
                form = ApplicationForm(applicant_data={'ip': ip, 'mb': mb})
            extra_context['apform'] = form
            extra_context['ad'] = job
            return render_to_response('listings/job_detail.html', extra_context, context_instance=RequestContext(request))

        # Only display the job, without an application form
        else:
            queryset = Job.active.filter(ad_url=ad_url)
            return object_detail(request, queryset=queryset, object_id=job_id, extra_context=extra_context, template_object_name='ad')

    # Instead of throwing a 404 error redirect to job unavailable page
    except Job.DoesNotExist:
        return redirect('listings_job_unavailable', permanent=True)