# Path: app_author/models.py
# class Profile(models.Model):
#     """
#     Author Model
#     """
#     user = models.OneToOneField(
#         User,
#         on_delete=models.CASCADE
#     )
# 
#     profile_picture = models.ImageField(
#         upload_to='images/%Y/%m/%d',
#         validators=[validate_image],
#         blank=True,
#         null=True
#     )
# 
#     profile_name = models.CharField(
#         verbose_name='Name',
#         null=True,
#         blank=True,
#         max_length=50
#     )
# 
#     profile_email = models.EmailField(
#         verbose_name='Email Address',
#         null=True,
#         blank=True
#     )
# 
#     profile_location = models.CharField(
#         verbose_name='Origin/City',
#         null=True,
#         blank=True,
#         max_length=50
#     )
# 
#     profile_github = models.URLField(
#         verbose_name='Github URL',
#         null=True,
#         blank=True
#     )
# 
#     slug = models.SlugField()
# 
#     is_created = models.DateTimeField(
#         null=True,
#         blank=True
#     )
# 
#     is_moderator = models.BooleanField(
#         default=False,
#     )
# 
#     def __str__(self):
#         return str(self.user)
# 
#     def save(self, **kwargs):
#         if not self.slug:
#             from djangoid.utils import get_unique_slug
#             self.slug = get_unique_slug(instance=self, field='profile_name')
#         super(Profile, self).save(**kwargs)
# 
# Path: app_forum/forms.py
# class ThreadForm(forms.ModelForm):
#     """
#     Comment Form
#     """
#     class Meta:
#         model = Forum
#         fields = (
#             'forum_title',
#             'forum_category',
#             'forum_content',
#         )
#         comment_content = MarkdownxFormField()
#         exclude = ['forum_author', 'is_hot']
#         widgets = {'forum_author': forms.HiddenInput()}
# 
# class CommentForm(forms.ModelForm):
#     """
#     Comment Form
#     """
#     class Meta:
#         model = Comment
#         fields = (
#             'comment_content',
#         )
#         comment_content = MarkdownxFormField()
#         exclude = ['comment_author']
#         widgets = {'comment_author': forms.HiddenInput()}
# 
# Path: app_forum/models.py
# class Forum(models.Model):
#     """
#     Thread Model
#     """
# 
#     class Meta:
#         verbose_name_plural = "Title"
# 
#     forum_author = models.ForeignKey(
#         Profile,
#         related_name='user_forums',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
# 
#     forum_title = models.CharField(
#         max_length=225,
#         verbose_name=u'Title',
#         blank=False,
#         null=False
#     )
# 
#     forum_category = models.ForeignKey(
#         'Category',
#         on_delete=models.CASCADE,
#         verbose_name=u'Category',
#     )
# 
#     forum_content = MarkdownxField(
#         verbose_name=u'Content (Use Markdown)',
#     )
# 
#     is_created = models.DateTimeField(
#         auto_now_add=True,
#         null=True,
#         blank=True
#     )
# 
#     is_modified = models.DateTimeField(
#         auto_now=True,
#         null=True,
#         blank=True
#     )
# 
#     is_hot = models.BooleanField(
#         default=False
#     )
# 
#     is_closed = models.BooleanField(
#         default=False
#     )
# 
#     def __str__(self):
#         return str(self.forum_title)
# 
#     def latest_comment_author(self):
#         return self.forum_comments.latest('is_created').comment_author
# 
#     def latest_comment_date(self):
#         return self.forum_comments.latest('is_created').is_created
# 
#     def get_absolute_url(self):
#         """
#         Call Forum ID
#         """
#         return 'app_forum:forum'
# 
# class Comment(models.Model):
#     """
#     Comment Model
#     """
# 
#     class Meta:
#         verbose_name_plural = "Comment"
#         
#     forum = models.ForeignKey(
#         'Forum',
#         on_delete=models.CASCADE,
#         related_name='forum_comments'
#     )
# 
#     comment_author = models.ForeignKey(
#         Profile,
#         related_name='user_comments',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
# 
#     comment_content = MarkdownxField(
#         verbose_name=u'Markdown',
#     )
# 
#     is_created = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     is_modified = models.DateTimeField(
#         auto_now=True,
#     )
# 
#     def __str__(self):
#         return self.comment_content


from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from app_author.models import Profile
from .forms import ThreadForm, CommentForm
from .models import Forum, Comment




def forum_list_view(request):
    """
    Render All Threads List
    :param request:
    :return:
    """

# Path: app_author/models.py
# class Profile(models.Model):
#     """
#     Author Model
#     """
#     user = models.OneToOneField(
#         User,
#         on_delete=models.CASCADE
#     )
# 
#     profile_picture = models.ImageField(
#         upload_to='images/%Y/%m/%d',
#         validators=[validate_image],
#         blank=True,
#         null=True
#     )
# 
#     profile_name = models.CharField(
#         verbose_name='Name',
#         null=True,
#         blank=True,
#         max_length=50
#     )
# 
#     profile_email = models.EmailField(
#         verbose_name='Email Address',
#         null=True,
#         blank=True
#     )
# 
#     profile_location = models.CharField(
#         verbose_name='Origin/City',
#         null=True,
#         blank=True,
#         max_length=50
#     )
# 
#     profile_github = models.URLField(
#         verbose_name='Github URL',
#         null=True,
#         blank=True
#     )
# 
#     slug = models.SlugField()
# 
#     is_created = models.DateTimeField(
#         null=True,
#         blank=True
#     )
# 
#     is_moderator = models.BooleanField(
#         default=False,
#     )
# 
#     def __str__(self):
#         return str(self.user)
# 
#     def save(self, **kwargs):
#         if not self.slug:
#             from djangoid.utils import get_unique_slug
#             self.slug = get_unique_slug(instance=self, field='profile_name')
#         super(Profile, self).save(**kwargs)
# 
# Path: app_forum/forms.py
# class ThreadForm(forms.ModelForm):
#     """
#     Comment Form
#     """
#     class Meta:
#         model = Forum
#         fields = (
#             'forum_title',
#             'forum_category',
#             'forum_content',
#         )
#         comment_content = MarkdownxFormField()
#         exclude = ['forum_author', 'is_hot']
#         widgets = {'forum_author': forms.HiddenInput()}
# 
# class CommentForm(forms.ModelForm):
#     """
#     Comment Form
#     """
#     class Meta:
#         model = Comment
#         fields = (
#             'comment_content',
#         )
#         comment_content = MarkdownxFormField()
#         exclude = ['comment_author']
#         widgets = {'comment_author': forms.HiddenInput()}
# 
# Path: app_forum/models.py
# class Forum(models.Model):
#     """
#     Thread Model
#     """
# 
#     class Meta:
#         verbose_name_plural = "Title"
# 
#     forum_author = models.ForeignKey(
#         Profile,
#         related_name='user_forums',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
# 
#     forum_title = models.CharField(
#         max_length=225,
#         verbose_name=u'Title',
#         blank=False,
#         null=False
#     )
# 
#     forum_category = models.ForeignKey(
#         'Category',
#         on_delete=models.CASCADE,
#         verbose_name=u'Category',
#     )
# 
#     forum_content = MarkdownxField(
#         verbose_name=u'Content (Use Markdown)',
#     )
# 
#     is_created = models.DateTimeField(
#         auto_now_add=True,
#         null=True,
#         blank=True
#     )
# 
#     is_modified = models.DateTimeField(
#         auto_now=True,
#         null=True,
#         blank=True
#     )
# 
#     is_hot = models.BooleanField(
#         default=False
#     )
# 
#     is_closed = models.BooleanField(
#         default=False
#     )
# 
#     def __str__(self):
#         return str(self.forum_title)
# 
#     def latest_comment_author(self):
#         return self.forum_comments.latest('is_created').comment_author
# 
#     def latest_comment_date(self):
#         return self.forum_comments.latest('is_created').is_created
# 
#     def get_absolute_url(self):
#         """
#         Call Forum ID
#         """
#         return 'app_forum:forum'
# 
# class Comment(models.Model):
#     """
#     Comment Model
#     """
# 
#     class Meta:
#         verbose_name_plural = "Comment"
#         
#     forum = models.ForeignKey(
#         'Forum',
#         on_delete=models.CASCADE,
#         related_name='forum_comments'
#     )
# 
#     comment_author = models.ForeignKey(
#         Profile,
#         related_name='user_comments',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
# 
#     comment_content = MarkdownxField(
#         verbose_name=u'Markdown',
#     )
# 
#     is_created = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     is_modified = models.DateTimeField(
#         auto_now=True,
#     )
# 
#     def __str__(self):
#         return self.comment_content


# Path: app_forum/views.py
from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from app_author.models import Profile
from .forms import ThreadForm, CommentForm
from .models import Forum, Comment





def forum_list_view(request):
    """
    Render All Threads List
    :param request:
    :return:
    """

    forum_list = Forum.objects.filter(is_hot=False).order_by("-is_modified")