Esempio n. 1
0
def get_urls(facet_tups, param, request):
    """
    Creates urls for facets of search with facet applied as a filter..

    """
    url = request.build_absolute_uri()
    date_start = request.REQUEST.get('date_start', None)
    date_end = request.REQUEST.get('date_end', None)
    if date_start:
        url = update_url_param(url, 'date_start',
                               request.REQUEST.get('date_start'))
    if date_end:
        url = update_url_param(url, 'date_end',
                               request.REQUEST.get('date_end'))

    facets = []

    if param in ['Country', 'Region', 'City']:
        param = 'location'

    for tup in facet_tups:
        url_parts = list(urlparse(url))
        query = dict(parse_qsl(url_parts[4]))
        term = urllib.quote(tup[0].encode('utf8'))
        if param == 'location' and 'location' in query:

            query['location'] = "%s-%s" % (query['location'],
                                           tup[0].split("##")[-1])
        else:
            params = {param.lower(): term}
            query.update(params)
        url_parts[4] = urllib.urlencode(query)
        facets.append(tup + (urlunparse(url_parts), ))

    return facets
Esempio n. 2
0
def get_all_jobs_link(saved_search):
    """
    Determines whether saved_search.feed or saved_search.url should be used
    as the view all jobs link.
    """
    url = saved_search.url

    if url.startswith('http://my.jobs') or url.startswith('https://my.jobs'):
        feed = saved_search.feed
        if feed:
            url = feed.replace('/feed/rss', '')

    url = update_url_param(url, 'sort', 'date')

    return url
Esempio n. 3
0
def get_all_jobs_link(saved_search):
    """
    Determines whether saved_search.feed or saved_search.url should be used
    as the view all jobs link.
    """
    url = saved_search.url

    if url.startswith('http://my.jobs'):
        feed = saved_search.feed
        if feed:
            url = feed.replace('/feed/rss', '')

    url = update_url_param(url, 'sort', 'date')

    return url
Esempio n. 4
0
def url_for_sort_field(context, field):
    current_url = context['request'].build_absolute_uri()
    new_url = update_url_param(current_url, 'sort', field)
    return mark_safe('<a href=%s rel="nofollow">Sort by %s</a>' %
                     (new_url, field.title()))
Esempio n. 5
0
def url_for_sort_field(context, field):
    current_url = context['request'].build_absolute_uri()
    new_url = update_url_param(current_url, 'sort', field)
    return mark_safe('<a href=%s rel="nofollow">Sort by %s</a>' %
                     (new_url, field.title()))
Esempio n. 6
0
def apply_facets_and_filters(request, user_solr=None, facet_solr=None):
    """
    Applies facets to solr based on filters currently applied and creates
    a dictionary of removable terms and the resulting url with the term removed.

    inputs:
    :user_solr: A Solr instance used for retrieving SavedSearch documents
        from solr.
    :facet_solr: A Solr instance used for retrieving facets based on
        ProfileUnits data.
    :loc_solr: A solr instance used for retrieving facets based on
        location slabs.

    outputs:
    user_solr, facet_solr, and loc_solr appropriately filtered as well as a
    dictionary of
    {'the applied filter': 'resulting url if the filter were removed'}
    """
    url = request.build_absolute_uri()
    date_start = request.REQUEST.get('date_start', None)
    date_end = request.REQUEST.get('date_end', None)
    if date_start:
        url = update_url_param(url, 'date_start',
                               request.REQUEST.get('date_start'))
    if date_end:
        url = update_url_param(url, 'date_end',
                               request.REQUEST.get('date_end'))

    filters = {}
    user_solr = Solr() if not user_solr else user_solr
    facet_solr = Solr() if not facet_solr else facet_solr

    # The location parameter should be "Country-Region-City". Faceting
    # is determined on what is already in the location parameter.
    # No location facets on country, country parameter facets on state, and
    # country-state facets on city.
    if not 'location' in request.GET:
        facet_solr = facet_solr.add_facet_field('Address_country_code')
        facet_solr = facet_solr.add_facet_field('Address_region')
    else:
        fieldname = 'Address_full_location'

        term = urllib.unquote(request.GET.get('location'))
        search_term = term.replace("-", "##").replace(" ", "\ ")
        if len(term.split("-")) == 3:
            q = '%s:%s' % (fieldname, search_term)
        else:
            q = '%s:%s##*' % (fieldname, search_term)
        user_solr = user_solr.add_query(q)
        facet_solr = facet_solr.add_filter_query(q)

        term_list = term.split("-")
        term_len = len(term_list)

        prefix = '%s##' % term.replace('-', '##')
        if term_len == 3:
            # Country, Region, City included. No reason to facet on location.
            city = term_list[2] if term_list[2] else 'None'
            region = term_list[1] if term_list[1] else 'None'
            country = term_list[0]
            remove_term = "%s, %s, %s" % (city, region, country)
            new_val = "%s-%s" % (term_list[0], term_list[1])
            filters[remove_term] = update_url_param(url, 'location', new_val)
        elif term_len == 2:
            # Country, Region included.
            region = term_list[1] if term_list[1] else 'None'
            country = term_list[0]
            remove_term = "%s, %s" % (region, country)
            filters[remove_term] = update_url_param(url, 'location', term_list[0])
            facet_solr = facet_solr.add_facet_field(fieldname)
            facet_solr = facet_solr.add_facet_prefix(prefix, fieldname=fieldname)
        elif term_len == 1:
            # Country included.
            country = country_codes.get(term_list[0], term_list[0])
            filters[country] = remove_param_from_url(url, 'location')
            facet_solr = facet_solr.add_facet_field('Address_region')
            facet_solr = facet_solr.add_facet_prefix(prefix, fieldname=fieldname)

    if not 'education' in request.GET:
        facet_solr = facet_solr.add_facet_field('Education_education_level_code')
    else:
        term = urllib.unquote(request.GET.get('education'))
        term_name = edu_codes.get(int(term))
        filters[term_name] = remove_param_from_url(url, 'education')

        q = 'Education_education_level_code:%s' % term
        user_solr = user_solr.add_query(q)
        facet_solr = facet_solr.add_filter_query(q)

    if not 'license' in request.GET:
        facet_solr = facet_solr.add_facet_field('License_license_name')
    else:
        term = urllib.unquote(request.GET.get('license'))
        filters[term] = remove_param_from_url(url, 'license')

        q = 'License_license_name:"%s"' % term
        user_solr = user_solr.add_query(q)
        facet_solr = facet_solr.add_filter_query(q)

    return user_solr, facet_solr, filters