# 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 not user and not slug and not snipt_id:
        return home_page(request)
    elif user and snipt_id:
        if snipt_id == 'feed':
            return user_page(request, user, slug, True)
        else:
            return snipt_page(request, user, snipt_id)
    else:
        return user_page(request, user, slug)

def search(request):
    query_string = ''
    found_snipts = None
    if ('q' in request.GET) and request.GET['q'].strip():
        query_string = request.GET['q']
        entry_query = get_query(query_string, ['code', 'description', 'tags',])
        snipts = Snippet.objects.filter(entry_query).filter(Q(public=1) | Q(user=request.user.id)).order_by('-created')
        disable_wrap = request.session.get('disable_wrap')
        disable_message = request.session.get('disable_message')
        snipts_count = snipts.count()
    search = True
    return render_to_response('search.html', locals(), context_instance=RequestContext(request))

def feed(request, user, slug):
    return render_to_response('feed.html', locals(), context_instance=RequestContext(request))

def embed(request, snipt):
    try:
        snipt = Snippet.objects.get(key=snipt)
        snipt.code_stylized = highlight(snipt.code.replace("\\\"","\\\\\""), get_lexer_by_name(snipt.lexer, encoding='UTF-8'), HtmlFormatter(style="native", noclasses=True, prestyles="-moz-border-radius: 5px; border-radius: 5px; -webkit-border-radius: 5px; margin: 0; display: block; font: 11px Monaco, monospace !important; padding: 15px; background-color: #1C1C1C; overflow: auto; color: #D0D0D0;"))

# 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 not user and not slug and not snipt_id:
        return home_page(request)
    elif user and snipt_id:
        if snipt_id == 'feed':
            return user_page(request, user, slug, True)
        else:
            return snipt_page(request, user, snipt_id)
    else:
        return user_page(request, user, slug)

def search(request):
    query_string = ''
    found_snipts = None
    if ('q' in request.GET) and request.GET['q'].strip():
        query_string = request.GET['q']
        entry_query = get_query(query_string, ['code', 'description', 'tags',])
        snipts = Snippet.objects.filter(entry_query).filter(Q(public=1) | Q(user=request.user.id)).order_by('-created')
        disable_wrap = request.session.get('disable_wrap')
        disable_message = request.session.get('disable_message')
        snipts_count = snipts.count()
    search = True
    return render_to_response('search.html', locals(), context_instance=RequestContext(request))

def feed(request, user, slug):
    return render_to_response('feed.html', locals(), context_instance=RequestContext(request))

def embed(request, snipt):
    try:
        snipt = Snippet.objects.get(key=snipt)
        snipt.code_stylized = highlight(snipt.code.replace("\\\"","\\\\\""), get_lexer_by_name(snipt.lexer, encoding='UTF-8'), HtmlFormatter(style="native", noclasses=True, prestyles="-moz-border-radius: 5px; border-radius: 5px; -webkit-border-radius: 5px; margin: 0; display: block; font: 11px Monaco, monospace !important; padding: 15px; background-color: #1C1C1C; overflow: auto; color: #D0D0D0;"))

        snipt.code_stylized = snipt.code_stylized.split('\n')