# Path: apps/wklej/forms.py
# class WklejkaForm(forms.ModelForm):
#     nickname = forms.CharField(required=False)
# 
#     class Meta:
#         model = Wklejka
#         fields = '__all__'
# 
#     def clean_nickname(self):
#         if len(self.cleaned_data['nickname']) == 0:
#             self.cleaned_data['nickname'] = 'Anonim'
#         elif len(self.cleaned_data['nickname']) > 30:
#             self.cleaned_data['nickname'] = self.cleaned_data['nickname'][:29]
# 
#         return self.cleaned_data['nickname']
# 
#     def clean_body(self):
#         if settings.USE_CAPTCHA and check_for_link_spam(self.cleaned_data['body']):
#             raise forms.ValidationError("This paste looks like spam.")
#         return self.cleaned_data['body']
# 
# class WklejkaCaptchaForm(forms.ModelForm):
#     recaptcha = ReCaptchaField()
#     has_captcha = forms.CharField(widget=forms.HiddenInput, required=False)
#     nickname = forms.CharField(required=False)
# 
#     class Meta:
#         model = Wklejka
#         fields = '__all__'
# 
#     def clean_nickname(self):
#         if len(self.cleaned_data['nickname']) == 0:
#             self.cleaned_data['nickname'] = 'Anonim'
#         elif len(self.cleaned_data['nickname']) > 30:
#             self.cleaned_data['nickname'] = self.cleaned_data['autor'][:29]
# 
#         return self.cleaned_data['nickname']


from django.http import HttpResponseRedirect
from django.conf import settings
from django.template.response import TemplateResponse
from pygments.lexers import guess_lexer
from apps.wklej.forms import WklejkaForm, WklejkaCaptchaForm
import hashlib
import random
#-*- coding: utf-8 -*-



def homepage(request):
    """
    This view is responsible for displaying form on the homepage.
    This is actualy all what it's doing. it displays, validate, and submits
    new paste into database.
    """

    if not request.method == 'POST':
        # if it's not a POST request, i just display pure homepage.html
        # with empty form. When user has cookie with previously used highlight
        # he recieves form with initial syntax

        if 'highlight' in request.COOKIES:
            syntax = request.COOKIES['highlight']
            form = WklejkaForm(initial={'syntax': syntax})
        else:

# Path: apps/wklej/forms.py
# class WklejkaForm(forms.ModelForm):
#     nickname = forms.CharField(required=False)
# 
#     class Meta:
#         model = Wklejka
#         fields = '__all__'
# 
#     def clean_nickname(self):
#         if len(self.cleaned_data['nickname']) == 0:
#             self.cleaned_data['nickname'] = 'Anonim'
#         elif len(self.cleaned_data['nickname']) > 30:
#             self.cleaned_data['nickname'] = self.cleaned_data['nickname'][:29]
# 
#         return self.cleaned_data['nickname']
# 
#     def clean_body(self):
#         if settings.USE_CAPTCHA and check_for_link_spam(self.cleaned_data['body']):
#             raise forms.ValidationError("This paste looks like spam.")
#         return self.cleaned_data['body']
# 
# class WklejkaCaptchaForm(forms.ModelForm):
#     recaptcha = ReCaptchaField()
#     has_captcha = forms.CharField(widget=forms.HiddenInput, required=False)
#     nickname = forms.CharField(required=False)
# 
#     class Meta:
#         model = Wklejka
#         fields = '__all__'
# 
#     def clean_nickname(self):
#         if len(self.cleaned_data['nickname']) == 0:
#             self.cleaned_data['nickname'] = 'Anonim'
#         elif len(self.cleaned_data['nickname']) > 30:
#             self.cleaned_data['nickname'] = self.cleaned_data['autor'][:29]
# 
#         return self.cleaned_data['nickname']


# Path: homepage.py
from django.http import HttpResponseRedirect
from django.conf import settings
from django.template.response import TemplateResponse
from pygments.lexers import guess_lexer
from apps.wklej.forms import WklejkaForm, WklejkaCaptchaForm
import hashlib
import random

#-*- coding: utf-8 -*-



def homepage(request):
    """
    This view is responsible for displaying form on the homepage.
    This is actualy all what it's doing. it displays, validate, and submits
    new paste into database.
    """

    if not request.method == 'POST':
        # if it's not a POST request, i just display pure homepage.html
        # with empty form. When user has cookie with previously used highlight
        # he recieves form with initial syntax

        if 'highlight' in request.COOKIES:
            syntax = request.COOKIES['highlight']
            form = WklejkaForm(initial={'syntax': syntax})
        else:

            form = WklejkaForm()