Exemple #1
0
def display_facet(context, filter, facet, type):
    facet = annotate_tags(
        [dict(name=f[0], count=f[1]) for f in facet if f[0] != "0"],
        sort=True,
        small_size=0.7,
        large_size=2.0)

    # If the filter is grouping_pack and there are elements which do not contain the chaarcter "_" means that
    # these sounds do not belong to any pack (as goruping pack values should by "packId_packName" if there is a pack
    # or "soundId" if there is no pack assigned. We did this to be able to filter properly in the facets, as pack names
    # are not unique!. What we do then is filter out the facet elements where, only for the case of grouping_pack,
    # the element name is a single number that does not contain the character "_"

    filtered_facet = []
    for element in facet:
        if filter == "grouping_pack":
            if element['name'].count("_") > 0:
                element['display_name'] = element['name'][
                    element['name'].find("_") +
                    1:]  # We also modify the dispay name to remove the id
                filtered_facet.append(element)
        else:
            element['display_name'] = element['name']
            filtered_facet.append(element)
    context.update({"facet": filtered_facet, "type": type, "filter": filter})
    return context
Exemple #2
0
def display_facet(context, flt, facet, type):
    facet = annotate_tags([dict(name=f[0], count=f[1]) for f in facet if f[0] != "0"],
                          sort=True, small_size=0.7, large_size=2.0)

    # If the filter is grouping_pack and there are elements which do not contain the character "_" means that
    # these sounds do not belong to any pack (as grouping pack values should by "packId_packName" if there is a pack
    # or "soundId" if there is no pack assigned. We did this to be able to filter properly in the facets, as pack names
    # are not unique!. What we do then is filter out the facet elements where, only for the case of grouping_pack,
    # the element name is a single number that does not contain the character "_"

    filter_query = context['filter_query']
    filtered_facet = []
    for element in facet:
        if flt == "grouping_pack":
            if element['name'].count("_") > 0:
                # We also modify the dispay name to remove the id
                element['display_name'] = element['name'][element['name'].find("_")+1:]
                element['params'] = '%s %s:"%s"' % (filter_query, flt, urlquote_plus(element['name']))
                filtered_facet.append(element)
        else:
            element['display_name'] = element['name']
            element['params'] = '%s %s:"%s"' % (filter_query, flt, urlquote_plus(element['name']))
            filtered_facet.append(element)
    context.update({"facet": filtered_facet, "type": type, "filter": flt})
    return context
Exemple #3
0
def display_facet(context, flt, facet, type, title=""):
    facet = annotate_tags(
        [dict(name=f[0], count=f[1]) for f in facet if f[0] != "0"],
        sort=True,
        small_size=0.7,
        large_size=2.0)

    # If the filter is grouping_pack and there are elements which do not contain the character "_" means that
    # these sounds do not belong to any pack (as grouping pack values should by "packId_packName" if there is a pack
    # or "soundId" if there is no pack assigned. We did this to be able to filter properly in the facets, as pack names
    # are not unique!. What we do then is filter out the facet elements where, only for the case of grouping_pack,
    # the element name is a single number that does not contain the character "_"

    filter_query = context['filter_query']
    filtered_facet = []
    for element in facet:
        if flt == "grouping_pack":
            if element['name'].count("_") > 0:
                # We also modify the display name to remove the id
                element['display_name'] = element['name'][element['name'].
                                                          find("_") + 1:]
                element['params'] = u'{0} {1}:"{2}"'.format(
                    filter_query, flt, urlquote_plus(element['name']))
            else:
                # If facet element belongs to "grouping pack" filter but does not have the "_" character in it, it
                # means this corresponds to the "no pack" grouping which we don't want to show as a facet element.
                continue
        else:
            element['display_name'] = element['name']

        element['params'] = u'{0} {1}:"{2}"'.format(
            filter_query, flt, urlquote_plus(element['name']))
        element['id'] = u'{0}--{1}'.format(flt, urlquote_plus(element['name']))
        element['add_filter_url'] = u'.?g={0}&q={1}&f={2}'.format(
            context['grouping'], context['search_query'], element['params'])
        filtered_facet.append(element)

    if using_beastwhoosh(context['request']):
        # In BW ui, we sort the facets of type "cloud" by their frequency of occurrence and apply an opacity filter
        filtered_facet = sorted(filtered_facet,
                                key=lambda x: x['count'],
                                reverse=True)
        max_count = max([element['count'] for element in filtered_facet])
        for element in filtered_facet:
            element['weight'] = (1.0 * element['count']) / max_count

    context.update({
        "facet": filtered_facet,
        "type": type,
        "filter": flt,
        "title": title
    })
    return context
Exemple #4
0
def add_sizes(tags, arguments):
    sort, small_size, large_size = arguments.split(":")
    return annotate_tags(tags,
                         sort.lower() == "true", float(small_size),
                         float(large_size))
Exemple #5
0
def add_sizes(tags, arguments):
    sort, small_size, large_size = arguments.split(":")
    return annotate_tags(tags, sort.lower() == "true", float(small_size), float(large_size))