# Path: settings.py
# DEBUG = False


from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from django.contrib.comments.signals import comment_was_posted
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from tagging.models import Tag, TaggedItem
from django.template import RequestContext
from snipt.snippet.models import Snippet, Referer
from django.utils.html import escape
from django.utils import simplejson
from tagging.utils import get_tag
from snipt.snippet.utils import *
from django.http import Http404
from settings import DEBUG
from snipt.forms import *
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
      from random import choice
      from django.core.mail import send_mail
    from django.contrib.comments.signals import comment_was_posted
    from django.core.mail import EmailMultiAlternatives
                from snipt.favsnipt.models import FavSnipt
                from operator import attrgetter
                from itertools import chain
            from snipt.favsnipt.models import FavSnipt
            from operator import attrgetter
            from itertools import chain
import md5
    # 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')
            
            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)
            
            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)

# Path: settings.py
# DEBUG = False


# Path: views.py
from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from django.contrib.comments.signals import comment_was_posted
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from tagging.models import Tag, TaggedItem
from django.template import RequestContext
from snipt.snippet.models import Snippet, Referer
from django.utils.html import escape
from django.utils import simplejson
from tagging.utils import get_tag
from snipt.snippet.utils import *
from django.http import Http404
from settings import DEBUG
from snipt.forms import *
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
      from random import choice
      from django.core.mail import send_mail
    from django.contrib.comments.signals import comment_was_posted
    from django.core.mail import EmailMultiAlternatives
                from snipt.favsnipt.models import FavSnipt
                from operator import attrgetter
                from itertools import chain
            from snipt.favsnipt.models import FavSnipt
            from operator import attrgetter
            from itertools import chain
import md5

    # 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')
            
            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)
            
            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: