# Path: twobuntu/articles/models.py
# class Article(models.Model):
#     """
#     A post written in Markdown by an author.
#     """
# 
#     # Article status constants
#     DRAFT = 0
#     UNAPPROVED = 1
#     PUBLISHED = 2
# 
#     STATUS = (
#         (DRAFT, 'Draft'),
#         (UNAPPROVED, 'Unapproved'),
#         (PUBLISHED, 'Published'),
#     )
# 
#     author = models.ForeignKey(
#         User,
#         help_text="The user writing the article.",
#     )
#     category = models.ForeignKey(
#         Category,
#         help_text="The category of the article.",
#     )
#     title = models.CharField(
#         max_length=200,
#         help_text="The title of the article.",
#     )
#     body = models.TextField(help_text="The body of the article [in Markdown].")
#     image = models.ForeignKey(
#         Image,
#         blank=True,
#         null=True,
#         help_text="An image highlighting the contents of the article.",
#     )
#     status = models.PositiveSmallIntegerField(
#         choices=STATUS,
#         default=DRAFT,
#         help_text="The current status of the article.",
#     )
#     cc_license = models.BooleanField(
#         default=True,
#         help_text="Whether the article is released under the CC-BY-SA 4.0 license or not.",
#     )
#     date = models.DateTimeField()
# 
#     def __str__(self):
#         return '%s%s' % (
#             self.title,
#             ' [%s]' % self.get_status_display() if not self.status == self.PUBLISHED else '',
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         kwargs, slug = {'id': self.id}, slugify(self.title)
#         if slug:
#             kwargs['slug'] = slug
#         return ('articles:view', (), kwargs)
# 
#     def can_edit(self, request):
#         """
#         Determine if the article may be edited by the current user.
#         """
#         # The user must either be staff or have written the article and not published it yet
#         return request.user.is_staff or request.user == self.author and self.status == self.DRAFT
# 
#     def can_view(self, request):
#         """
#         Determine if the article may be viewed by the current user.
#         """
#         # The user must either be staff or have written the article or it must be published
#         return request.user.is_staff or request.user == self.author or self.status == self.PUBLISHED
# 
#     @property
#     def markdown_key(self):
#         """
#         Return the key used for caching markdown.
#         """
#         return 'article-%d-markdown' % self.id
# 
#     def related(self):
#         """
#         Returns a QuerySet of related articles.
#         """
#         return Article.objects.filter(~models.Q(id=self.id), status=self.PUBLISHED, category=self.category)
# 
#     def render(self):
#         """
#         Render the Markdown body.
#         """
#         md = cache.get(self.markdown_key)
#         if not md:
#             md = cmarkdown(self.body)
#             cache.set(self.markdown_key, md)
#         return md
# 
#     @classmethod
#     def apply_filter(cls, request, *args):
#         """
#         Return a QuerySet with the correct filter applied based on the request.
#         """
#         args = list(args)
#         if not request.user.is_staff:
#             args.append(models.Q(author=request.user.id) | models.Q(status=cls.PUBLISHED))
#         return cls.objects.filter(*args)
# 
#     class Meta:
#         ordering = ('status', '-date')
# 
# class ScheduledArticle(models.Model):
#     """
#     An article to be published at a later date.
#     """
# 
#     article = models.OneToOneField(
#         Article,
#         primary_key=True,
#     )
#     date = models.DateTimeField(help_text="Date/time to publish article (YYYY-MM-DD HH:MM:SS).")
# 
#     def __str__(self):
#         return unicode(self.article)


from django import forms
from twobuntu.articles.models import Article, ScheduledArticle



class EditorForm(forms.ModelForm):
    """
    Form for entering or editing articles.
    """

    # The <textarea> needs this set so that the form can validate on the client
    # side without any content (due to ACE editor)
    use_required_attribute = False

    class Meta:
        model = Article
        fields = ('category', 'title', 'body')


class ScheduledArticleForm(forms.ModelForm):
    """
    Form for scheduling articles.
    """

    class Meta:

# Path: twobuntu/articles/models.py
# class Article(models.Model):
#     """
#     A post written in Markdown by an author.
#     """
# 
#     # Article status constants
#     DRAFT = 0
#     UNAPPROVED = 1
#     PUBLISHED = 2
# 
#     STATUS = (
#         (DRAFT, 'Draft'),
#         (UNAPPROVED, 'Unapproved'),
#         (PUBLISHED, 'Published'),
#     )
# 
#     author = models.ForeignKey(
#         User,
#         help_text="The user writing the article.",
#     )
#     category = models.ForeignKey(
#         Category,
#         help_text="The category of the article.",
#     )
#     title = models.CharField(
#         max_length=200,
#         help_text="The title of the article.",
#     )
#     body = models.TextField(help_text="The body of the article [in Markdown].")
#     image = models.ForeignKey(
#         Image,
#         blank=True,
#         null=True,
#         help_text="An image highlighting the contents of the article.",
#     )
#     status = models.PositiveSmallIntegerField(
#         choices=STATUS,
#         default=DRAFT,
#         help_text="The current status of the article.",
#     )
#     cc_license = models.BooleanField(
#         default=True,
#         help_text="Whether the article is released under the CC-BY-SA 4.0 license or not.",
#     )
#     date = models.DateTimeField()
# 
#     def __str__(self):
#         return '%s%s' % (
#             self.title,
#             ' [%s]' % self.get_status_display() if not self.status == self.PUBLISHED else '',
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         kwargs, slug = {'id': self.id}, slugify(self.title)
#         if slug:
#             kwargs['slug'] = slug
#         return ('articles:view', (), kwargs)
# 
#     def can_edit(self, request):
#         """
#         Determine if the article may be edited by the current user.
#         """
#         # The user must either be staff or have written the article and not published it yet
#         return request.user.is_staff or request.user == self.author and self.status == self.DRAFT
# 
#     def can_view(self, request):
#         """
#         Determine if the article may be viewed by the current user.
#         """
#         # The user must either be staff or have written the article or it must be published
#         return request.user.is_staff or request.user == self.author or self.status == self.PUBLISHED
# 
#     @property
#     def markdown_key(self):
#         """
#         Return the key used for caching markdown.
#         """
#         return 'article-%d-markdown' % self.id
# 
#     def related(self):
#         """
#         Returns a QuerySet of related articles.
#         """
#         return Article.objects.filter(~models.Q(id=self.id), status=self.PUBLISHED, category=self.category)
# 
#     def render(self):
#         """
#         Render the Markdown body.
#         """
#         md = cache.get(self.markdown_key)
#         if not md:
#             md = cmarkdown(self.body)
#             cache.set(self.markdown_key, md)
#         return md
# 
#     @classmethod
#     def apply_filter(cls, request, *args):
#         """
#         Return a QuerySet with the correct filter applied based on the request.
#         """
#         args = list(args)
#         if not request.user.is_staff:
#             args.append(models.Q(author=request.user.id) | models.Q(status=cls.PUBLISHED))
#         return cls.objects.filter(*args)
# 
#     class Meta:
#         ordering = ('status', '-date')
# 
# class ScheduledArticle(models.Model):
#     """
#     An article to be published at a later date.
#     """
# 
#     article = models.OneToOneField(
#         Article,
#         primary_key=True,
#     )
#     date = models.DateTimeField(help_text="Date/time to publish article (YYYY-MM-DD HH:MM:SS).")
# 
#     def __str__(self):
#         return unicode(self.article)


# Path: twobuntu/articles/forms.py
from django import forms
from twobuntu.articles.models import Article, ScheduledArticle




class EditorForm(forms.ModelForm):
    """
    Form for entering or editing articles.
    """

    # The <textarea> needs this set so that the form can validate on the client
    # side without any content (due to ACE editor)
    use_required_attribute = False

    class Meta:
        model = Article
        fields = ('category', 'title', 'body')


class ScheduledArticleForm(forms.ModelForm):
    """
    Form for scheduling articles.
    """

    class Meta:

        model = ScheduledArticle