from fluent_pages.pagetypes.flatpage.models import FlatPage
from fluent_pages.pagetypes.fluentpage.models import FluentPage
from haystack import indexes


class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
    """
    Search index for a fluent page.
    """
    text = indexes.CharField(document=True, use_template=True)
    author = indexes.CharField(model_attr='author')
    publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)

    @staticmethod
    def get_model():
        """
        Get the model for the search index.
        """
        return FluentPage

    def index_queryset(self, using=None):
        """
        Queryset appropriate for this object to allow search for.
        """
        return self.get_model().objects.published()


class FlatPageIndex(FluentPageIndex):
    """
    Search index for a flat page.

    As everything except the model is the same as for a FluentPageIndex
    we shall subclass it and overwrite the one part we need.
    """
    @staticmethod
    def get_model():
        """
        Get the model for the search index.
        """
        return FlatPage

from fluent_pages.pagetypes.flatpage.models import FlatPage
from fluent_pages.pagetypes.fluentpage.models import FluentPage
from haystack import indexes
from django.conf import settings


# Optional search indexes which can be used with the default FluentPage and FlatPage models.
if getattr(settings, 'ICEKIT_USE_SEARCH_INDEXES', True):
    class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
        """
        Search index for a fluent page.
        """
        text = indexes.CharField(document=True, use_template=True)
        author = indexes.CharField(model_attr='author')
        publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)

        @staticmethod
        def get_model():
            """
            Get the model for the search index.
            """
            return FluentPage

        def index_queryset(self, using=None):
            """
            Queryset appropriate for this object to allow search for.
            """
            return self.get_model().objects.published()


    class FlatPageIndex(FluentPageIndex):
        """
        Search index for a flat page.

        As everything except the model is the same as for a FluentPageIndex
        we shall subclass it and overwrite the one part we need.
        """
        @staticmethod
        def get_model():
            """
            Get the model for the search index.
            """
            return FlatPage

Add setting to turn of search indexes.
Add setting to turn of search indexes.

  from fluent_pages.pagetypes.flatpage.models import FlatPage
  from fluent_pages.pagetypes.fluentpage.models import FluentPage
  from haystack import indexes
+ from django.conf import settings
  
  
+ # Optional search indexes which can be used with the default FluentPage and FlatPage models.
+ if getattr(settings, 'ICEKIT_USE_SEARCH_INDEXES', True):
- class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
+     class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
-     """
+         """
-     Search index for a fluent page.
+         Search index for a fluent page.
-     """
+         """
-     text = indexes.CharField(document=True, use_template=True)
+         text = indexes.CharField(document=True, use_template=True)
-     author = indexes.CharField(model_attr='author')
+         author = indexes.CharField(model_attr='author')
-     publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)
+         publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)
  
-     @staticmethod
+         @staticmethod
-     def get_model():
+         def get_model():
-         """
+             """
-         Get the model for the search index.
+             Get the model for the search index.
-         """
+             """
-         return FluentPage
+             return FluentPage
  
-     def index_queryset(self, using=None):
+         def index_queryset(self, using=None):
-         """
+             """
-         Queryset appropriate for this object to allow search for.
+             Queryset appropriate for this object to allow search for.
-         """
+             """
-         return self.get_model().objects.published()
+             return self.get_model().objects.published()
  
  
- class FlatPageIndex(FluentPageIndex):
+     class FlatPageIndex(FluentPageIndex):
-     """
+         """
-     Search index for a flat page.
+         Search index for a flat page.
  
-     As everything except the model is the same as for a FluentPageIndex
+         As everything except the model is the same as for a FluentPageIndex
-     we shall subclass it and overwrite the one part we need.
+         we shall subclass it and overwrite the one part we need.
-     """
-     @staticmethod
-     def get_model():
          """
+         @staticmethod
+         def get_model():
+             """
-         Get the model for the search index.
+             Get the model for the search index.
-         """
+             """
-         return FlatPage
+             return FlatPage
  
Add setting to turn of search indexes.
## Code Before:
from fluent_pages.pagetypes.flatpage.models import FlatPage
from fluent_pages.pagetypes.fluentpage.models import FluentPage
from haystack import indexes


class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
    """
    Search index for a fluent page.
    """
    text = indexes.CharField(document=True, use_template=True)
    author = indexes.CharField(model_attr='author')
    publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)

    @staticmethod
    def get_model():
        """
        Get the model for the search index.
        """
        return FluentPage

    def index_queryset(self, using=None):
        """
        Queryset appropriate for this object to allow search for.
        """
        return self.get_model().objects.published()


class FlatPageIndex(FluentPageIndex):
    """
    Search index for a flat page.

    As everything except the model is the same as for a FluentPageIndex
    we shall subclass it and overwrite the one part we need.
    """
    @staticmethod
    def get_model():
        """
        Get the model for the search index.
        """
        return FlatPage

## Instruction:
Add setting to turn of search indexes.
## Code After:
from fluent_pages.pagetypes.flatpage.models import FlatPage
from fluent_pages.pagetypes.fluentpage.models import FluentPage
from haystack import indexes
from django.conf import settings


# Optional search indexes which can be used with the default FluentPage and FlatPage models.
if getattr(settings, 'ICEKIT_USE_SEARCH_INDEXES', True):
    class FluentPageIndex(indexes.SearchIndex, indexes.Indexable):
        """
        Search index for a fluent page.
        """
        text = indexes.CharField(document=True, use_template=True)
        author = indexes.CharField(model_attr='author')
        publication_date = indexes.DateTimeField(model_attr='publication_date', null=True)

        @staticmethod
        def get_model():
            """
            Get the model for the search index.
            """
            return FluentPage

        def index_queryset(self, using=None):
            """
            Queryset appropriate for this object to allow search for.
            """
            return self.get_model().objects.published()


    class FlatPageIndex(FluentPageIndex):
        """
        Search index for a flat page.

        As everything except the model is the same as for a FluentPageIndex
        we shall subclass it and overwrite the one part we need.
        """
        @staticmethod
        def get_model():
            """
            Get the model for the search index.
            """
            return FlatPage
