def appstore(request, template='appstore/appstore_base.html'):
    page_length = 10
    include_unapproved = (True if (request.GET.get('is_approved', '') == 'false') else False)
    if (include_unapproved and (not request.user.is_superuser)):
        raise Http404()
    (params, _) = parse_args_for_es(request)
    page = params.pop('page', 1)
    page = int((page[0] if isinstance(page, list) else page))
    results = es_snapshot_query(params, SNAPSHOT_FACETS)
    hits = results.get('hits', {}).get('hits', [])
    hits = deduplicate(hits)
    d_results = [Domain.wrap(res['_source']) for res in hits]
    starter_apps = request.GET.get('is_starter_app', None)
    sort_by = request.GET.get('sort_by', None)
    if (sort_by == 'newest'):
        pass
    else:
        d_results = Domain.hit_sort(d_results)
    persistent_params = {}
    if sort_by:
        persistent_params['sort_by'] = sort_by
    if include_unapproved:
        persistent_params['is_approved'] = 'false'
    persistent_params = urlencode(persistent_params)
    more_pages = (False if (len(d_results) <= (page * page_length)) else True)
    facet_map = fill_mapping_with_facets(SNAPSHOT_MAPPING, results, params)
    vals = dict(apps=d_results[((page - 1) * page_length):(page * page_length)], page=page, prev_page=(page - 1), next_page=(page + 1), more_pages=more_pages, sort_by=sort_by, show_starter_apps=starter_apps, include_unapproved=include_unapproved, facet_map=facet_map, facets=results.get('facets', []), query_str=request.META['QUERY_STRING'], search_query=params.get('search', [''])[0], persistent_params=persistent_params)
    return render(request, template, vals)
def appstore(request, template='appstore/appstore_base.html'):
    page_length = 10
    include_unapproved = (True if (request.GET.get('is_approved', ) == 'false') else False)
    if (include_unapproved and (not request.user.is_superuser)):
        raise Http404()
    (params, _) = parse_args_for_es(request)
    page = params.pop('page', 1)
    page = int((page[0] if isinstance(page, list) else page))
    results = es_snapshot_query(params, SNAPSHOT_FACETS)
    hits = results.get('hits', {}).get('hits', [])
    hits = deduplicate(hits)
    d_results = [Domain.wrap(res['_source']) for res in hits]
    starter_apps = request.GET.get('is_starter_app', None)
    sort_by = request.GET.get('sort_by', None)
    if (sort_by == 'newest'):
        pass
    else:
        d_results = Domain.hit_sort(d_results)
    persistent_params = {}
    if sort_by:
        persistent_params['sort_by'] = sort_by
    if include_unapproved:
        persistent_params['is_approved'] = 'false'
    persistent_params = urlencode(persistent_params)
    more_pages = (False if (len(d_results) <= (page * page_length)) else True)
    facet_map = fill_mapping_with_facets(SNAPSHOT_MAPPING, results, params)
    vals = dict(apps=d_results[((page - 1) * page_length):(page * page_length)], page=page, prev_page=(page - 1), next_page=(page + 1), more_pages=more_pages, sort_by=sort_by, show_starter_apps=starter_apps, include_unapproved=include_unapproved, facet_map=facet_map, facets=results.get('facets', []), query_str=request.META['QUERY_STRING'], search_query=params.get('search', [])[0], persistent_params=persistent_params)
    return render(request, template, vals)