0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

deprecation/1.4: Removed TagSearchable.search

This commit is contained in:
Karl Hobley 2015-12-20 12:56:22 +00:00
parent 84261dec77
commit 6888774280

View File

@ -1,13 +1,9 @@
import warnings
from taggit.models import Tag
from django.contrib.contenttypes.models import ContentType
from django.db.models import Count
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from wagtail.wagtailsearch import index
from wagtail.utils.deprecation import RemovedInWagtail14Warning
class TagSearchable(index.Indexed):
@ -27,35 +23,6 @@ class TagSearchable(index.Indexed):
def get_indexed_objects(cls):
return super(TagSearchable, cls).get_indexed_objects().prefetch_related('tagged_items__tag')
@classmethod
def search(cls, q, results_per_page=None, page=1, prefetch_tags=False, filters={}):
warnings.warn(
"The {class_name}.search() method is deprecated. "
"Please use the {class_name}.objects.search() method instead.".format(class_name=cls.__name__),
RemovedInWagtail14Warning, stacklevel=2)
results = cls.objects.all()
if prefetch_tags:
results = results.prefetch_related('tagged_items__tag')
if filters:
results = results.filter(**filters)
results = results.search(q)
# If results_per_page is set, return a paginator
if results_per_page is not None:
paginator = Paginator(results, results_per_page)
try:
return paginator.page(page)
except PageNotAnInteger:
return paginator.page(1)
except EmptyPage:
return paginator.page(paginator.num_pages)
else:
return results
@classmethod
def popular_tags(cls):
content_type = ContentType.objects.get_for_model(cls)