implementation for searching something in 'News' and 'Intern'
This commit is contained in:
@@ -9,7 +9,8 @@ from django.utils import timezone
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from documents import create_pad
|
||||
from documents import create_pad, get_pad_html
|
||||
from documents.api import get_pad_link
|
||||
from tasks.models import TaskList
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -139,6 +140,12 @@ class Etherpad(models.Model):
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return get_pad_link(self.__get_pad_name())
|
||||
|
||||
def __get_pad_name(self):
|
||||
return (
|
||||
slugify(self.date)
|
||||
@@ -170,8 +177,12 @@ class Etherpad(models.Model):
|
||||
_(f"Etherpad '{pad_name}' konnte nicht erstellt werden."),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@property
|
||||
def etherpad_html(self):
|
||||
if not self.__get_pad_name():
|
||||
return None
|
||||
|
||||
return get_pad_html(self.__get_pad_name())
|
||||
|
||||
|
||||
class FileUpload(models.Model):
|
||||
|
||||
17
fet2020/intern/search_indexes.py
Normal file
17
fet2020/intern/search_indexes.py
Normal file
@@ -0,0 +1,17 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user