# Path: cms_content/models.py
# class CMSArticle(models.Model):
#     """Models for CMS's Articles:
# 
#     Article is the third level of cms_content structure. Every article contains
#     the content you write.
#     """
# 
#     PUB_STATUS = (
#         ('pub', _(u'published')),
#         ('hid', _(u'hidden')),
#         ('dra', _(u'draft')),
#         ('del', _(u'deleted')),
#     )
#     
#     title = models.CharField(
#         _(u"Article Title"),
#         max_length=255,
#         blank=False,
#         help_text=_(u"Article's Title"),
#     )
#     slug = models.SlugField(
#         _(u"Slug"),
#         max_length=255,
#         blank=False,
#         unique=True,
#         help_text=_(u"Article's Slug"),
#     )
#     content = models.TextField(
#         _(u"Article Content"),
#         blank=False,
#         help_text=_(u"Article's Content"),
#     )
#     created_by = models.ForeignKey(
#         User,
#         verbose_name=_(u"Author Name"),
#         related_name="cms_article_author",
#         blank=False,
#     )
#     created_date = models.DateTimeField(
#         _(u"Created Date"),
#         auto_now_add=True,
#     )
#     last_modified_by = models.ForeignKey(
#         User,
#         verbose_name=_(u"Last Modified By"),
#         related_name="cms_article_revisor",
#     )
#     last_modified_date = models.DateTimeField(
#         _(u"Last Modified Date"),
#         auto_now=False,
#     )
#     category = models.ForeignKey(
#         CMSCategory,
#         verbose_name=_(u"Category"),
#         related_name="article_of_category",
#         help_text=_(u"Pick a Category as the Article's Parent Level"),
#     )
#     pub_status = models.CharField(
#         _(u"Article Status"),
#         max_length=3,
#         choices=PUB_STATUS,
#         default='pub',
#     )
#     hits = models.IntegerField(
#         _(u"Article His Number"),
#         default=1,
#     )
#     pub_start_date = models.DateTimeField(
#         _(u"Article Publish Start Date"),
#         blank=False,
#         null=False,
#         default=datetime.now,
#     )
#     pub_end_date = models.DateTimeField(
#         _(u"Article Publish End Date"),
#         blank=False,
#         null=False,
#         default=datetime(2030,12,31)
#     )
#     menu = models.OneToOneField(CMSMenuID)
#     tags = TaggableManager()
#     objects = models.Manager()
#     pub_manager = CMSArticlePubManager()
#     
#     class Meta:
#         ordering = ['-created_date']
#         verbose_name = _(u'Article')
#         verbose_name_plural = _(u'Article')
# 
#     def __unicode__(self):
#         return u'%s - %s' % (self.created_by.username, self.title)
# 
#     def get_parent_node(self, nodes):
#         """Get a category node which including queryset's articles
#     
#         Example:
#         parent_node = category_node(article, nodes)
#     
#         """
#         for node in nodes:
#             if node.title == self.category.name:
#                 return node
#         return None
# 
#     @property
#     def previous_article(self):
#         """Return the previous article"""
#         articles = CMSArticle.pub_manager.select_related().filter(created_date__lt=self.created_date)
#         if articles:
#             return articles[0]
#         else:
#             return
#     
#     @property
#     def next_article(self):
#         """Return the next article"""
#         articles = CMSArticle.pub_manager.select_related().filter(created_date__gt=self.created_date)
#         if articles:
#             return articles[0]
#         else:
#             return
#     
#     @property
#     def url(self):
#         return ROOT_URL + 'article/' + "%s/%s/%s/%s/" % (
#             self.created_date.strftime('%Y'),
#             self.created_date.strftime('%m'),
#             self.created_date.strftime('%d'),
#             self.slug,
#             )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms_content_article_detail', None, {
#             "year":  self.created_date.strftime('%Y'),
#             "month": self.created_date.strftime('%m'),
#             "day":   self.created_date.strftime('%d'),
#             "slug":  self.slug,
#             }
#         )


import datetime
from haystack.indexes import *
from haystack import site
from cms_content.models import CMSArticle
# -*- coding: utf-8 -*-




class CMSArticleIndex(SearchIndex):
    text = CharField(document=True)
    author = CharField(model_attr='created_by')
    pub_date = DateTimeField(model_attr='created_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""

# Path: cms_content/models.py
# class CMSArticle(models.Model):
#     """Models for CMS's Articles:
# 
#     Article is the third level of cms_content structure. Every article contains
#     the content you write.
#     """
# 
#     PUB_STATUS = (
#         ('pub', _(u'published')),
#         ('hid', _(u'hidden')),
#         ('dra', _(u'draft')),
#         ('del', _(u'deleted')),
#     )
#     
#     title = models.CharField(
#         _(u"Article Title"),
#         max_length=255,
#         blank=False,
#         help_text=_(u"Article's Title"),
#     )
#     slug = models.SlugField(
#         _(u"Slug"),
#         max_length=255,
#         blank=False,
#         unique=True,
#         help_text=_(u"Article's Slug"),
#     )
#     content = models.TextField(
#         _(u"Article Content"),
#         blank=False,
#         help_text=_(u"Article's Content"),
#     )
#     created_by = models.ForeignKey(
#         User,
#         verbose_name=_(u"Author Name"),
#         related_name="cms_article_author",
#         blank=False,
#     )
#     created_date = models.DateTimeField(
#         _(u"Created Date"),
#         auto_now_add=True,
#     )
#     last_modified_by = models.ForeignKey(
#         User,
#         verbose_name=_(u"Last Modified By"),
#         related_name="cms_article_revisor",
#     )
#     last_modified_date = models.DateTimeField(
#         _(u"Last Modified Date"),
#         auto_now=False,
#     )
#     category = models.ForeignKey(
#         CMSCategory,
#         verbose_name=_(u"Category"),
#         related_name="article_of_category",
#         help_text=_(u"Pick a Category as the Article's Parent Level"),
#     )
#     pub_status = models.CharField(
#         _(u"Article Status"),
#         max_length=3,
#         choices=PUB_STATUS,
#         default='pub',
#     )
#     hits = models.IntegerField(
#         _(u"Article His Number"),
#         default=1,
#     )
#     pub_start_date = models.DateTimeField(
#         _(u"Article Publish Start Date"),
#         blank=False,
#         null=False,
#         default=datetime.now,
#     )
#     pub_end_date = models.DateTimeField(
#         _(u"Article Publish End Date"),
#         blank=False,
#         null=False,
#         default=datetime(2030,12,31)
#     )
#     menu = models.OneToOneField(CMSMenuID)
#     tags = TaggableManager()
#     objects = models.Manager()
#     pub_manager = CMSArticlePubManager()
#     
#     class Meta:
#         ordering = ['-created_date']
#         verbose_name = _(u'Article')
#         verbose_name_plural = _(u'Article')
# 
#     def __unicode__(self):
#         return u'%s - %s' % (self.created_by.username, self.title)
# 
#     def get_parent_node(self, nodes):
#         """Get a category node which including queryset's articles
#     
#         Example:
#         parent_node = category_node(article, nodes)
#     
#         """
#         for node in nodes:
#             if node.title == self.category.name:
#                 return node
#         return None
# 
#     @property
#     def previous_article(self):
#         """Return the previous article"""
#         articles = CMSArticle.pub_manager.select_related().filter(created_date__lt=self.created_date)
#         if articles:
#             return articles[0]
#         else:
#             return
#     
#     @property
#     def next_article(self):
#         """Return the next article"""
#         articles = CMSArticle.pub_manager.select_related().filter(created_date__gt=self.created_date)
#         if articles:
#             return articles[0]
#         else:
#             return
#     
#     @property
#     def url(self):
#         return ROOT_URL + 'article/' + "%s/%s/%s/%s/" % (
#             self.created_date.strftime('%Y'),
#             self.created_date.strftime('%m'),
#             self.created_date.strftime('%d'),
#             self.slug,
#             )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms_content_article_detail', None, {
#             "year":  self.created_date.strftime('%Y'),
#             "month": self.created_date.strftime('%m'),
#             "day":   self.created_date.strftime('%d'),
#             "slug":  self.slug,
#             }
#         )


# Path: cms_content_patch/search_indexes.py
import datetime
from haystack.indexes import *
from haystack import site
from cms_content.models import CMSArticle

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




class CMSArticleIndex(SearchIndex):
    text = CharField(document=True)
    author = CharField(model_attr='created_by')
    pub_date = DateTimeField(model_attr='created_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""

        return CMSArticle.objects.filter(created_date__lte=datetime.datetime.now())