def tag_view(request, tag_slug):
    """
    Renders a tag detail page.

    Allows the user to paginate resultes and sort by preselected options.

    Args:
        request: HttpRequest
        tag_slug: the identifier for the tag

    Returns:
        Rendered response with a tag's resource list

    """
    tag = get_object_or_404(Tag, slug=tag_slug)
    filter_params = {
        'page': 1,
        'order': TagPageForm.CREATED,
    }

    params_form = TagPageForm(data=request.GET)
    if params_form.is_valid():
        filter_params.update(params_form.cleaned_data)

    order_by = filter_params['order']
    if order_by == TagPageForm.RATING:
        data = Resource.resources.approved().with_ratings(tag).order_by(order_by)
    else:
        data = Resource.resources.approved().for_tag(tag).order_by(order_by)

    paginator = Paginator(data, settings.ORB_PAGINATOR_DEFAULT)

    try:
        resources = paginator.page(filter_params['page'])
    except (EmptyPage, InvalidPage):
        resources = paginator.page(paginator.num_pages)

    show_filter_link = tag.category.slug in [slug for name, slug in settings.ADVANCED_SEARCH_CATEGORIES]

    tag_viewed.send(sender=tag, tag=tag, request=request)

    is_geo_tag = tag.category.name == "Geography"

    return render(request, 'orb/tag.html', {
        'tag': tag,
        'page': resources,
        'params_form': params_form,
        'show_filter_link': show_filter_link,
        'is_geo_tag': is_geo_tag,
    })