# Path: blog/models.py
# class Post(models.Model):
#     title = models.CharField(max_length=60)
#     tags = TaggableManager()
#     author = models.ForeignKey(User, null=True)
#     body = models.TextField()
#     created = models.DateTimeField(auto_now_add=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return self.title
#         return unicode(self.created)
# 
# class Comment(models.Model):
#     created = models.DateTimeField(auto_now_add=True)
#     name = models.CharField(max_length=60)
#     email = models.EmailField(max_length=35, null=True)
#     body = models.TextField()
#     post = models.ForeignKey(Post)
# 
#     class meta:
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return unicode("%s: %s" % (self.post, self.body[:60]))
# 
# Path: blog/forms.py
# class CommentsForm(forms.Form):
#     name = forms.CharField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     # A CharField that checks that the value is a valid email address.
#     email = forms.EmailField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     Body = forms.CharField(widget=forms.Textarea(
#         attrs={'cols': 50, 'rows': 5,
#                'class': 'form-control'}))
# 
# class CommentForm(ModelForm):
#     class Meta:
#         model = Comment
#         exclude = ["post"]
# 
# class RegistrationForm(forms.Form):
#     username = forms.RegexField(regex=r'^\w+$', widget=forms.TextInput(attrs=dict(required=True, max_length=30)), label=_("Username"), error_messages={'invalid': _("This value must contain only letters, numbers and underscores.")})
#     email = forms.EmailField(widget=forms.TextInput(attrs=dict(required=True, max_length=30)), label=_("Email address"))
#     password1 = forms.CharField(widget=forms.PasswordInput(attrs=dict(required=True, max_length=30, render_value=False)), label=_("Password"))
#     password2 = forms.CharField(widget=forms.PasswordInput(attrs=dict(required=True, max_length=30, render_value=False)), label=_("Password (again)"))
# 
#     def clean_username(self):
#         try:
#             User.objects.get(username__iexact=self.cleaned_data['username'])
#         except User.DoesNotExist:
#             return self.cleaned_data['username']
#         raise forms.ValidationError(_("The username already exists."))
# 
#     def clean_email(self):
#         try:
#             User.objects.get(email=self.cleaned_data['email'])
#             raise forms.ValidationError("This email already exist")
#         except User.DoesNotExist:
#             return self.cleaned_data['email']
# 
#     def clean(self):
#         if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
#             if self.cleaned_data['password1'] != self.cleaned_data['password2']:
#                 raise forms.ValidationError(_("The two password fields did not match."))
#         return self.cleaned_data
# 
# class LoginForm(forms.Form):
#     email = forms.EmailField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     password = forms.CharField(max_length=32, widget=forms.PasswordInput)
# 
# class FeedbackForm(ModelForm):
#     class Meta:
#         model = Feedback


import time
import re
import warnings
from calendar import month_name
from taggit.models import Tag
from django.conf import settings
from django.http import Http404
from django.core.urlresolvers import reverse
from django.views.generic import TemplateView
from django.contrib.auth.models import User
from django.contrib import messages
from django.contrib.auth import authenticate, login, get_user_model
from django.contrib.auth import logout as auth_logout
from django.core.mail import send_mail, BadHeaderError
from django.views.decorators.csrf import csrf_protect
from django.template import RequestContext
from django.template.loader import Context, get_template
from django.template.response import TemplateResponse
from django.utils.http import urlsafe_base64_decode
from django.utils.translation import ugettext as _
from django.shortcuts import resolve_url
from django.db.models import Q
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
from django.contrib.auth.tokens import default_token_generator
from django.core.paginator import Paginator, \
    InvalidPage, EmptyPage
from django.shortcuts import render, render_to_response, \
    HttpResponseRedirect, HttpResponse, get_object_or_404, redirect
from .models import Post, Comment
from .forms import CommentsForm, CommentForm, RegistrationForm, \
    LoginForm, FeedbackForm

# from django.contrib.auth.decorators import login_required



def home(request):
    return render_to_response("home/base.html",
                              context_instance=RequestContext(request))


def post(request, post_id):
    """Single post with comments and a comment form."""

    try:
        tags = Tag.objects.all()
        post_model = Post.objects.get(pk=post_id)

# Path: blog/models.py
# class Post(models.Model):
#     title = models.CharField(max_length=60)
#     tags = TaggableManager()
#     author = models.ForeignKey(User, null=True)
#     body = models.TextField()
#     created = models.DateTimeField(auto_now_add=True)
# 
#     class Meta:
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return self.title
#         return unicode(self.created)
# 
# class Comment(models.Model):
#     created = models.DateTimeField(auto_now_add=True)
#     name = models.CharField(max_length=60)
#     email = models.EmailField(max_length=35, null=True)
#     body = models.TextField()
#     post = models.ForeignKey(Post)
# 
#     class meta:
#         ordering = ['-created']
# 
#     def __unicode__(self):
#         return unicode("%s: %s" % (self.post, self.body[:60]))
# 
# Path: blog/forms.py
# class CommentsForm(forms.Form):
#     name = forms.CharField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     # A CharField that checks that the value is a valid email address.
#     email = forms.EmailField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     Body = forms.CharField(widget=forms.Textarea(
#         attrs={'cols': 50, 'rows': 5,
#                'class': 'form-control'}))
# 
# class CommentForm(ModelForm):
#     class Meta:
#         model = Comment
#         exclude = ["post"]
# 
# class RegistrationForm(forms.Form):
#     username = forms.RegexField(regex=r'^\w+$', widget=forms.TextInput(attrs=dict(required=True, max_length=30)), label=_("Username"), error_messages={'invalid': _("This value must contain only letters, numbers and underscores.")})
#     email = forms.EmailField(widget=forms.TextInput(attrs=dict(required=True, max_length=30)), label=_("Email address"))
#     password1 = forms.CharField(widget=forms.PasswordInput(attrs=dict(required=True, max_length=30, render_value=False)), label=_("Password"))
#     password2 = forms.CharField(widget=forms.PasswordInput(attrs=dict(required=True, max_length=30, render_value=False)), label=_("Password (again)"))
# 
#     def clean_username(self):
#         try:
#             User.objects.get(username__iexact=self.cleaned_data['username'])
#         except User.DoesNotExist:
#             return self.cleaned_data['username']
#         raise forms.ValidationError(_("The username already exists."))
# 
#     def clean_email(self):
#         try:
#             User.objects.get(email=self.cleaned_data['email'])
#             raise forms.ValidationError("This email already exist")
#         except User.DoesNotExist:
#             return self.cleaned_data['email']
# 
#     def clean(self):
#         if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
#             if self.cleaned_data['password1'] != self.cleaned_data['password2']:
#                 raise forms.ValidationError(_("The two password fields did not match."))
#         return self.cleaned_data
# 
# class LoginForm(forms.Form):
#     email = forms.EmailField(widget=forms.TextInput(
#         attrs={'size': '48',
#                'class': 'form-control'}))
#     password = forms.CharField(max_length=32, widget=forms.PasswordInput)
# 
# class FeedbackForm(ModelForm):
#     class Meta:
#         model = Feedback


# Path: blog/views.py
import time
import re
import warnings
from calendar import month_name
from taggit.models import Tag
from django.conf import settings
from django.http import Http404
from django.core.urlresolvers import reverse
from django.views.generic import TemplateView
from django.contrib.auth.models import User
from django.contrib import messages
from django.contrib.auth import authenticate, login, get_user_model
from django.contrib.auth import logout as auth_logout
from django.core.mail import send_mail, BadHeaderError
from django.views.decorators.csrf import csrf_protect
from django.template import RequestContext
from django.template.loader import Context, get_template
from django.template.response import TemplateResponse
from django.utils.http import urlsafe_base64_decode
from django.utils.translation import ugettext as _
from django.shortcuts import resolve_url
from django.db.models import Q
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
from django.contrib.auth.tokens import default_token_generator
from django.core.paginator import Paginator, \
    InvalidPage, EmptyPage
from django.shortcuts import render, render_to_response, \
    HttpResponseRedirect, HttpResponse, get_object_or_404, redirect
from .models import Post, Comment
from .forms import CommentsForm, CommentForm, RegistrationForm, \
    LoginForm, FeedbackForm


# from django.contrib.auth.decorators import login_required



def home(request):
    return render_to_response("home/base.html",
                              context_instance=RequestContext(request))


def post(request, post_id):
    """Single post with comments and a comment form."""

    try:
        tags = Tag.objects.all()
        post_model = Post.objects.get(pk=post_id)

        comment_model = Comment.objects.filter(post=post_model)