# Path: apps/wklej/models.py
# class Wklejka(models.Model):
#     """
#     This model represents a single paste, both for anonymous and authenticated
#     pasters.
#     """
# 
#     nickname = models.CharField(max_length=30, null=True)
#     user = models.ForeignKey(User, blank=True, null=True)
#     body = models.TextField()
#     pub_date = models.DateTimeField(auto_now_add=True)
#     mod_date = models.DateTimeField(auto_now=True)
#     hash = models.CharField(max_length=45, blank=True)
# 
#     # syntax
#     syntax = models.CharField(max_length=30, choices=LEXERS,
#                               blank=True, null=True)
#     guessed_syntax = models.CharField(max_length=30, blank=True, null=True)
# 
#     # inheritance:
#     parent = models.ForeignKey('self', blank=True, null=True)
# 
#     # flags:
#     is_private = models.BooleanField(default=False)
#     is_deleted = models.BooleanField(default=False)
#     is_spam = models.BooleanField(default=False)
# 
#     # new:
#     comment = models.TextField(blank=True, null=True)
#     wherefrom = models.CharField(max_length=100, blank=True, null=True)
#     ip = models.CharField(max_length=20, blank=True, null=True)
# 
#     class Meta:
#         verbose_name = "Wklejka"
#         verbose_name_plural = "Wklejki"
#         ordering = ['-pub_date']
#         db_table = 'wklej_wklejka'
# 
#     def __unicode__(self):
#         return "%s at %s" % (self.author, str(self.pub_date))
# 
#     @property
#     def author(self):
#         return self.user if self.user else self.nickname
# 
#     @property
#     def is_public(self):
#         return not self.is_private
# 
#     @property
#     def hl(self):
#         return self.syntax or self.guessed_syntax
# 
#     def get_absolute_url(self):
#         if self.is_private:
#             return self.get_hash_url()
#         return self.get_id_url()
# 
#     def get_id_url(self):
#         return reverse('single', kwargs={'id': self.id})
# 
#     def get_hash_url(self):
#         return reverse('single', kwargs={"hash": self.hash})
# 
#     def get_del_url(self):
#         if self.is_private:
#             return reverse('delete', kwargs={"hash": self.hash})
#         return reverse('delete', kwargs={"id": self.id})
# 
#     def get_txt_url(self):
#         if self.is_private:
#             return reverse('txt', kwargs={"hash": self.hash})
#         return reverse('txt', kwargs={"id": self.id})
# 
#     def get_download_url(self):
#         if self.is_private:
#             return reverse('download', kwargs={"hash": self.hash})
#         return reverse('download', kwargs={"id": self.id})
# 
#     def is_parent(self):
#         if self.wklejka_set.all():
#             return True
#         return False
# 
#     def children(self):
#         return self.wklejka_set.all()
# 
#     def children_count(self):
#         return self.children().count()
# 
#     def is_child(self):
#         if self.parent:
#             return True
#         return False
# 
#     def get_10_lines(self):
#         return "\n".join(self.body.splitlines()[:10])
# 
# BANNED_LEXERS = [
#     'antlr-objc',
#     'raw',
#     'c-objdump',
#     'opa',
# ]


from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from wklej.forms import RotateSyntaxForm
from wklej.forms import WklejkaForm
from apps.wklej.models import Wklejka, BANNED_LEXERS
def txt(request, id=0, hash=0):
    """
    This one tooks care of txt view for single paste.
    It display it's content without syntax highlighting, with mimetype
    text/plain which (by most browsers) should be taken care of
    as a plaintext document. It does both private (using hash) and public
    (using id) pastes.
    """

    if id:
        w = get_object_or_404(Wklejka, pk=id, is_private=False)
    elif hash:
        w = get_object_or_404(Wklejka, hash=hash, is_private=True)

    return HttpResponse(w.body, mimetype='text/plain; charset=utf-8')


def download(request, id=0, hash=0):
    """
    This view is responsible for downloading a single paste.
    It literally force (due to mime app/x-force-download) browser to download
    a specially prepared request.

    # New in wklej .v04: its adding proper extension based on hilighting
    (either chosen or guessed by pygments), insted of older .wklej extension
    """

    if id:
        w = get_object_or_404(Wklejka, pk=id, is_private=False)
    elif hash:

# Path: apps/wklej/models.py
# class Wklejka(models.Model):
#     """
#     This model represents a single paste, both for anonymous and authenticated
#     pasters.
#     """
# 
#     nickname = models.CharField(max_length=30, null=True)
#     user = models.ForeignKey(User, blank=True, null=True)
#     body = models.TextField()
#     pub_date = models.DateTimeField(auto_now_add=True)
#     mod_date = models.DateTimeField(auto_now=True)
#     hash = models.CharField(max_length=45, blank=True)
# 
#     # syntax
#     syntax = models.CharField(max_length=30, choices=LEXERS,
#                               blank=True, null=True)
#     guessed_syntax = models.CharField(max_length=30, blank=True, null=True)
# 
#     # inheritance:
#     parent = models.ForeignKey('self', blank=True, null=True)
# 
#     # flags:
#     is_private = models.BooleanField(default=False)
#     is_deleted = models.BooleanField(default=False)
#     is_spam = models.BooleanField(default=False)
# 
#     # new:
#     comment = models.TextField(blank=True, null=True)
#     wherefrom = models.CharField(max_length=100, blank=True, null=True)
#     ip = models.CharField(max_length=20, blank=True, null=True)
# 
#     class Meta:
#         verbose_name = "Wklejka"
#         verbose_name_plural = "Wklejki"
#         ordering = ['-pub_date']
#         db_table = 'wklej_wklejka'
# 
#     def __unicode__(self):
#         return "%s at %s" % (self.author, str(self.pub_date))
# 
#     @property
#     def author(self):
#         return self.user if self.user else self.nickname
# 
#     @property
#     def is_public(self):
#         return not self.is_private
# 
#     @property
#     def hl(self):
#         return self.syntax or self.guessed_syntax
# 
#     def get_absolute_url(self):
#         if self.is_private:
#             return self.get_hash_url()
#         return self.get_id_url()
# 
#     def get_id_url(self):
#         return reverse('single', kwargs={'id': self.id})
# 
#     def get_hash_url(self):
#         return reverse('single', kwargs={"hash": self.hash})
# 
#     def get_del_url(self):
#         if self.is_private:
#             return reverse('delete', kwargs={"hash": self.hash})
#         return reverse('delete', kwargs={"id": self.id})
# 
#     def get_txt_url(self):
#         if self.is_private:
#             return reverse('txt', kwargs={"hash": self.hash})
#         return reverse('txt', kwargs={"id": self.id})
# 
#     def get_download_url(self):
#         if self.is_private:
#             return reverse('download', kwargs={"hash": self.hash})
#         return reverse('download', kwargs={"id": self.id})
# 
#     def is_parent(self):
#         if self.wklejka_set.all():
#             return True
#         return False
# 
#     def children(self):
#         return self.wklejka_set.all()
# 
#     def children_count(self):
#         return self.children().count()
# 
#     def is_child(self):
#         if self.parent:
#             return True
#         return False
# 
#     def get_10_lines(self):
#         return "\n".join(self.body.splitlines()[:10])
# 
# BANNED_LEXERS = [
#     'antlr-objc',
#     'raw',
#     'c-objdump',
#     'opa',
# ]


# Path: apps/wklej/views.py
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from wklej.forms import RotateSyntaxForm
from wklej.forms import WklejkaForm
from apps.wklej.models import Wklejka, BANNED_LEXERS

def txt(request, id=0, hash=0):
    """
    This one tooks care of txt view for single paste.
    It display it's content without syntax highlighting, with mimetype
    text/plain which (by most browsers) should be taken care of
    as a plaintext document. It does both private (using hash) and public
    (using id) pastes.
    """

    if id:
        w = get_object_or_404(Wklejka, pk=id, is_private=False)
    elif hash:
        w = get_object_or_404(Wklejka, hash=hash, is_private=True)

    return HttpResponse(w.body, mimetype='text/plain; charset=utf-8')


def download(request, id=0, hash=0):
    """
    This view is responsible for downloading a single paste.
    It literally force (due to mime app/x-force-download) browser to download
    a specially prepared request.

    # New in wklej .v04: its adding proper extension based on hilighting
    (either chosen or guessed by pygments), insted of older .wklej extension
    """

    if id:
        w = get_object_or_404(Wklejka, pk=id, is_private=False)
    elif hash:

        w = get_object_or_404(Wklejka, hash=hash, is_private=True)