from haystack import indexes
from html2text import html2text

from .models import Etherpad


class EtherpadIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr="title")
    date = indexes.DateField(model_attr="date")
    etherpad = indexes.EdgeNgramField(null=True)

    def get_model(self):
        return Etherpad

    def prepare_etherpad(self, obj):
        return html2text(obj.etherpad_html)
