Esempio n. 1
0
def get_jobs_and_counts(request):
    # Text uses html_description instead of just description.
    fl = list(helpers.search_fields)
    fl.append('html_description')

    filters = get_filters(request)
    site_config = get_site_config(request)
    num_jobs = int(site_config.num_job_items_to_show) * 2
    percent_featured = site_config.percent_featured

    args = (request, filters, num_jobs)
    kwargs = {'fl': fl}
    default_jobs, featured_jobs, facet_counts = helpers.jobs_and_counts(*args, **kwargs)

    total_default_jobs = default_jobs.count()
    total_featured_jobs = featured_jobs.count()

    args = (featured_jobs.count(), default_jobs.count(), num_jobs,
            percent_featured)
    featured_needed, default_needed, _, _ = helpers.featured_default_jobs(*args)

    default_jobs = default_jobs[:default_needed]
    featured_jobs = featured_jobs[:featured_needed]

    jobs = list(chain(featured_jobs, default_jobs))
    for job in jobs:
        helpers.add_text_to_job(job)

    return (default_jobs, total_default_jobs, featured_jobs,
            total_featured_jobs, facet_counts)
Esempio n. 2
0
    def test_featured_default_jobs(self):
        """
        Requests the number and offsets for featured and default jobs
        based on possible queryset job counts, offsets, and number of
        items requested.

        """
        p = Decimal(0.5)
        input_outputs = [
            #Getting jobs from sets of 25 featured andj
            #55 default, 50% split, in slices of 20 and 10
            ((25, 55, 20, p, 0), (10, 10, 0, 0)),
            ((25, 55, 20, p, 20), (10, 10, 10, 10)),
            ((25, 55, 20, p, 40), (5, 15, 20, 20)),
            ((25, 55, 10, p, 60), (0, 10, 30, 35)),
            ((25, 55, 20, p, 70), (0, 10, 35, 45)),
            #Offset higher than available jobs
            ((0, 50, 20, p, 50), (0, 0, 25, 50))
        ]
        io2 = []
        for i, o in input_outputs:
            #Reverse counts for featured and default jobs
            io2.append(((i[1], i[0], i[2], i[3], i[4]),
                        (o[1], o[0], o[3], o[2])))
            #No Featured Facet jobs
            io2.append(((0, 90, i[2], i[3], i[4]),
                        (0, i[2], int(i[4]*i[3]), i[4])))
        input_outputs.extend(io2)
        #Rounding should favor featured jobs. Here the first element to be
        #returned is a featured job, and the second is a default job
        input_outputs.append(((1, 1, 1, p, 0), (1, 0, 0, 0)))
        input_outputs.append(((1, 1, 1, p, 1), (0, 1, 1, 0)))

        for i, o in input_outputs:
            self.assertEqual(helpers.featured_default_jobs(*i), o)
Esempio n. 3
0
def get_jobs_and_counts(request):
    # Text uses html_description instead of just description.
    fl = list(helpers.search_fields)
    fl.append('html_description')

    filters = get_filters(request)
    site_config = get_site_config(request)
    num_jobs = int(site_config.num_job_items_to_show) * 2
    percent_featured = site_config.percent_featured

    args = (request, filters, num_jobs)
    kwargs = {'fl': fl}
    default_jobs, featured_jobs, facet_counts = helpers.jobs_and_counts(
        *args, **kwargs)

    total_default_jobs = default_jobs.count()
    total_featured_jobs = featured_jobs.count()

    args = (featured_jobs.count(), default_jobs.count(), num_jobs,
            percent_featured)
    featured_needed, default_needed, _, _ = helpers.featured_default_jobs(
        *args)

    default_jobs = default_jobs[:default_needed]
    featured_jobs = featured_jobs[:featured_needed]

    jobs = list(chain(featured_jobs, default_jobs))
    for job in jobs:
        helpers.add_text_to_job(job)

    return (default_jobs, total_default_jobs, featured_jobs,
            total_featured_jobs, facet_counts)
Esempio n. 4
0
    def test_featured_default_jobs(self):
        """
        Requests the number and offsets for featured and default jobs
        based on possible queryset job counts, offsets, and number of
        items requested.

        """
        p = Decimal(0.5)
        input_outputs = [
            # Getting jobs from sets of 25 featured andj
            # 55 default, 50% split, in slices of 20 and 10
            ((25, 55, 20, p, 0), (10, 10, 0, 0)),
            ((25, 55, 20, p, 20), (10, 10, 10, 10)),
            ((25, 55, 20, p, 40), (5, 15, 20, 20)),
            ((25, 55, 10, p, 60), (0, 10, 30, 35)),
            ((25, 55, 20, p, 70), (0, 10, 35, 45)),
            # Offset higher than available jobs
            ((0, 50, 20, p, 50), (0, 0, 25, 50))
        ]
        io2 = []
        for i, o in input_outputs:
            # Reverse counts for featured and default jobs
            io2.append(
                ((i[1], i[0], i[2], i[3], i[4]), (o[1], o[0], o[3], o[2])))
            # No Featured Facet jobs
            io2.append(
                ((0, 90, i[2], i[3], i[4]), (0, i[2], int(i[4] * i[3]), i[4])))
        input_outputs.extend(io2)
        # Rounding should favor featured jobs. Here the first element to be
        # returned is a featured job, and the second is a default job
        input_outputs.append(((1, 1, 1, p, 0), (1, 0, 0, 0)))
        input_outputs.append(((1, 1, 1, p, 1), (0, 1, 1, 0)))

        for i, o in input_outputs:
            self.assertEqual(helpers.featured_default_jobs(*i), o)
Esempio n. 5
0
def get_jobs_and_counts(request):
    filters = get_filters(request)
    site_config = get_site_config(request)
    num_jobs = int(site_config.num_job_items_to_show) * 2
    percent_featured = site_config.percent_featured

    args = (request, filters, num_jobs)
    default_jobs, featured_jobs, facet_counts = helpers.jobs_and_counts(*args)

    total_default_jobs = default_jobs.count()
    total_featured_jobs = featured_jobs.count()

    args = (featured_jobs.count(), default_jobs.count(), num_jobs,
            percent_featured)
    featured_needed, default_needed, _, _ = helpers.featured_default_jobs(*args)

    default_jobs = default_jobs[:default_needed]
    featured_jobs = featured_jobs[:featured_needed]

    jobs = list(chain(featured_jobs, default_jobs))
    for job in jobs:
        helpers.add_text_to_job(job)

    return (default_jobs, total_default_jobs, featured_jobs,
            total_featured_jobs, facet_counts)
Esempio n. 6
0
def create_arranged_jobs(request, featured_jobs, default_jobs, site_config):
    percent_featured = site_config.percent_featured
    jobs_shown = (int(request.GET.get('num_items',
                                      site_config.num_job_items_to_show))
                  if request.is_ajax() else site_config.num_job_items_to_show)

    (f_shown, d_shown, _, _) = featured_default_jobs(len(featured_jobs),
                                                     len(default_jobs),
                                                     jobs_shown,
                                                     percent_featured)
    jobs = []
    if not request.is_ajax():
        # Shown jobs
        jobs.append({
            'jobs': featured_jobs[:f_shown],
            'class': 'featured_jobListing'
        })
        jobs.append({
            'jobs': default_jobs[:d_shown],
            'class': 'default_jobListing'
        })

        # Hidden jobs
        jobs.append({
            'jobs': featured_jobs[f_shown:],
            'class': 'featured_jobListing direct_hiddenOption'
        })
        jobs.append({
            'jobs': default_jobs[d_shown:],
            'class': 'default_jobListing direct_hiddenOption'
        })
    else:
        jobs.append({
            'jobs': featured_jobs,
            'class': 'featured_jobListing direct_hiddenOption'
        })
        jobs.append({
            'jobs': default_jobs,
            'class': 'default_jobListing direct_hiddenOption'
        })

    # There are no jobs at all, or there are no default jobs and no
    # featured jobs. This allows us to easily know whether or not there
    # are any jobs inside the templates.
    if not jobs or (not jobs[0]['jobs'] and not jobs[1]['jobs']):
        jobs = []

    return jobs