def user_page(request, user, slug, feed=False):
    
    # Set disable message to false.
    # request.session['disable_message'] = False
    
    # If the user has requested a tag listing page, handle accordingly, otherwise serve latest snipts.
    if request.user.username != user:
        mine = False
        try:
            context_user = User.objects.get(username=user)
            if context_user.username == 'public':
                public = True
            else:
                public = False
        except:
            raise Http404()
    else:
        mine = True
        context_user = request.user
    if slug is not None:
        slug = slug.replace('tag/','')

        """
        Attempt to retrieve the tag for this particular slug.  In the event that there is no tag
        associated with this slug, set tag to 'None'.
        """
        try:
            tag = Tag.objects.get(name = slug)
        except:
            tag = None

        # If the tag exists, retrieve the snipts that this user has tagged with this particular tag.
        if tag is not None:
            if mine:
                snipts = TaggedItem.objects.get_by_model(Snippet.objects.filter(user=context_user.id).order_by('-created'), tag)
                
                from snipt.favsnipt.models import FavSnipt
                favsnipts = FavSnipt.objects.filter(user=context_user.id)
                favrd = []
                for fs in favsnipts:
                    fs.snipt.favrd = True
                    fs.snipt.created = fs.created
                    if str(tag) in fs.snipt.tags:
                        favrd.append(fs.snipt)

                from operator import attrgetter
                from itertools import chain
                snipts = sorted(
                    chain(snipts, favrd),
                    key=attrgetter('created'), reverse=True)
                
            elif not public:
                snipts = TaggedItem.objects.get_by_model(Snippet.objects.filter(user=context_user.id, public='1').order_by('-created'), tag)
            else:
                snipts = TaggedItem.objects.get_by_model(Snippet.objects.filter(public='1').order_by('-created'), tag)

        # If the tag does not exist, raise 404.
        else:
            raise Http404()

        # If the tag exists, but the user has no snipts for this particular tag, raise 404.
        if len(snipts) == 0:
            raise Http404()

    # If the user is at the homepage (no tag specified).
    else:

        # Retrieve latest 20 snipts for user.
        if mine:
            snipts = Snippet.objects.filter(user=context_user.id).order_by('-created')
            
            from snipt.favsnipt.models import FavSnipt
            favsnipts = FavSnipt.objects.filter(user=context_user.id)
            favrd = []
            for fs in favsnipts:
                fs.snipt.favrd = True
                fs.snipt.created = fs.created
                favrd.append(fs.snipt)
            
            from operator import attrgetter
            from itertools import chain
            snipts = sorted(
                chain(snipts, favrd),
                key=attrgetter('created'), reverse=True)
            
        elif not public:
            snipts = Snippet.objects.filter(user=context_user.id, public='1').order_by('-created')
        else:
            snipts = Snippet.objects.filter(public='1').order_by('-created')[:100]

    # Compile the list of tags that this user has used.
    if mine:
        user_tags_list = Tag.objects.usage_for_queryset(Snippet.objects.filter(user=context_user.id).order_by('-created'), counts=True)
    elif not public:
        user_tags_list = Tag.objects.usage_for_queryset(Snippet.objects.filter(user=context_user.id, public='1').order_by('-created'), counts=True)
    else:
        user_tags_list = Tag.objects.usage_for_queryset(Snippet.objects.filter(public='1'), counts=True)
        if not DEBUG:
            user_tags_list.sort(key=lambda x: x.count, reverse=True)
        user_tags_list = user_tags_list[:40]
    
    for usertag in user_tags_list:
        usertag.slug = str(usertag)

    disable_wrap = request.session.get('disable_wrap')
    disable_message = request.session.get('disable_message')

    if mine:
        total_count = Snippet.objects.filter(user=context_user.id).count()
    elif not public:
        total_count = Snippet.objects.filter(user=context_user.id, public='1').count()
    else:
        total_count = Snippet.objects.filter(public='1').count()

    if 0 > total_count:
        # Get the last lexer used so we can auto-select that one.
        if mine:
            last_lexer = Snippet.objects.filter(user=context_user.id).order_by('-created')[0].lexer
            
    snipts_count = len(snipts)
    
    # Send a modified version of the request path so we may compare it to the list of tag slugs (to identify current page).
    if mine:
        request_tag = request.path.replace('/' + request.user.username + '/tag/','')
    else:
        request_tag = request.path.replace('/' + context_user.username + '/tag/','')

    if feed:
        try:
            snipts = TaggedItem.objects.get_by_model(Snippet.objects.filter(user=context_user.id, public='1').order_by('-created'), tag)
        except:
            snipts = Snippet.objects.filter(user=context_user.id, public='1').order_by('-created')
        real_path = request.path.replace('/feed', '')
        if '/all' not in request.path:
            snipts = snipts.filter()[:20]
        return render_to_response('feed.xml', locals(), context_instance=RequestContext(request), mimetype="application/rss+xml")
    else:
        return render_to_response('home_user.html', locals(), context_instance=RequestContext(request))
dataset/ETHPy150Open nicksergeant/snipt-old/views.py/user_page/swapped operands of `>`