本文整理汇总了Python中wagtail.wagtailsearch.index.class_is_indexed函数的典型用法代码示例。如果您正苦于以下问题:Python class_is_indexed函数的具体用法?Python class_is_indexed怎么用?Python class_is_indexed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了class_is_indexed函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: search
def search(self, query_string, model_or_queryset, fields=None, filters=None, prefetch_related=None, operator=None):
# Find model/queryset
if isinstance(model_or_queryset, QuerySet):
model = model_or_queryset.model
queryset = model_or_queryset
else:
model = model_or_queryset
queryset = model_or_queryset.objects.all()
# Model must be a class that is in the index
if not class_is_indexed(model):
return []
# Check that theres still a query string after the clean up
if query_string == "":
return []
# Apply filters to queryset
if filters:
queryset = queryset.filter(**filters)
# Prefetch related
if prefetch_related:
for prefetch in prefetch_related:
queryset = queryset.prefetch_related(prefetch)
# Check operator
if operator is not None:
operator = operator.lower()
if operator not in ['or', 'and']:
raise ValueError("operator must be either 'or' or 'and'")
# Search
search_query = self.search_query_class(queryset, query_string, fields=fields, operator=operator)
return self.search_results_class(self, search_query)
开发者ID:webbyfox,项目名称:wagtail,代码行数:35,代码来源:base.py
示例2: search
def search(self, query_string, model_or_queryset, fields=None, filters=None, prefetch_related=None):
# Find model/queryset
if isinstance(model_or_queryset, QuerySet):
model = model_or_queryset.model
queryset = model_or_queryset
else:
model = model_or_queryset
queryset = model_or_queryset.objects.all()
# Model must be a class that is in the index
if not class_is_indexed(model):
return []
# Check that theres still a query string after the clean up
if query_string == "":
return []
# Apply filters to queryset
if filters:
queryset = queryset.filter(**filters)
# Prefetch related
if prefetch_related:
for prefetch in prefetch_related:
queryset = queryset.prefetch_related(prefetch)
# Search
return self._search(queryset, query_string, fields=fields)
开发者ID:AustinBurns,项目名称:wagtail,代码行数:28,代码来源:base.py
示例3: add
def add(self, obj):
# Make sure the object can be indexed
if not class_is_indexed(obj.__class__):
return
# Get mapping
mapping = ElasticSearchMapping(obj.__class__)
# Add document to index
self.es.index(self.es_index, mapping.get_document_type(), mapping.get_document(obj), id=mapping.get_document_id(obj))
开发者ID:gilsondev,项目名称:wagtail,代码行数:10,代码来源:elasticsearch.py
示例4: choose
def choose(request, app_label, model_name):
model = get_snippet_model_from_url_params(app_label, model_name)
items = model.objects.all()
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and "q" in request.GET:
search_form = SearchForm(
request.GET, placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name}
)
if search_form.is_valid():
search_query = search_form.cleaned_data["q"]
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(
placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name}
)
# Pagination
paginator, paginated_items = paginate(request, items, per_page=25)
# If paginating or searching, render "results.html"
if request.GET.get("results", None) == "true":
return render(
request,
"wagtailsnippets/chooser/results.html",
{
"model_opts": model._meta,
"items": paginated_items,
"query_string": search_query,
"is_searching": is_searching,
},
)
return render_modal_workflow(
request,
"wagtailsnippets/chooser/choose.html",
"wagtailsnippets/chooser/choose.js",
{
"model_opts": model._meta,
"items": paginated_items,
"is_searchable": is_searchable,
"search_form": search_form,
"query_string": search_query,
"is_searching": is_searching,
},
)
开发者ID:XLeonardo,项目名称:wagtail,代码行数:55,代码来源:chooser.py
示例5: list
def list(request, app_label, model_name):
model = get_snippet_model_from_url_params(app_label, model_name)
permissions = [
get_permission_name(action, model)
for action in ['add', 'change', 'delete']
]
if not any([request.user.has_perm(perm) for perm in permissions]):
return permission_denied(request)
items = model.objects.all()
# Preserve the snippet's model-level ordering if specified, but fall back on PK if not
# (to ensure pagination is consistent)
if not items.ordered:
items = items.order_by('pk')
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and 'q' in request.GET:
search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': model._meta.verbose_name_plural
})
if search_form.is_valid():
search_query = search_form.cleaned_data['q']
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': model._meta.verbose_name_plural
})
paginator, paginated_items = paginate(request, items)
# Template
if request.is_ajax():
template = 'wagtailsnippets/snippets/results.html'
else:
template = 'wagtailsnippets/snippets/type_index.html'
return render(request, template, {
'model_opts': model._meta,
'items': paginated_items,
'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
'is_searchable': is_searchable,
'search_form': search_form,
'is_searching': is_searching,
'query_string': search_query,
})
开发者ID:kapito,项目名称:wagtail,代码行数:55,代码来源:snippets.py
示例6: list
def list(request, content_type_app_name, content_type_model_name):
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
model = content_type.model_class()
permissions = [
get_permission_name(action, model)
for action in ['add', 'change', 'delete']
]
if not any([request.user.has_perm(perm) for perm in permissions]):
return permission_denied(request)
snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)
items = model.objects.all()
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and 'q' in request.GET:
search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': snippet_type_name_plural
})
if search_form.is_valid():
search_query = search_form.cleaned_data['q']
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': snippet_type_name_plural
})
paginator, paginated_items = paginate(request, items)
# Template
if request.is_ajax():
template = 'wagtailsnippets/snippets/results.html'
else:
template = 'wagtailsnippets/snippets/type_index.html'
return render(request, template, {
'content_type': content_type,
'snippet_type_name': snippet_type_name,
'snippet_type_name_plural': snippet_type_name_plural,
'items': paginated_items,
'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
'is_searchable': is_searchable,
'search_form': search_form,
'is_searching': is_searching,
'query_string': search_query,
})
开发者ID:Tivix,项目名称:wagtail,代码行数:55,代码来源:snippets.py
示例7: choose
def choose(request, content_type_app_name, content_type_model_name):
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
model = content_type.model_class()
snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)
items = model.objects.all()
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and 'q' in request.GET:
search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': snippet_type_name_plural
})
if search_form.is_valid():
search_query = search_form.cleaned_data['q']
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
'snippet_type_name': snippet_type_name_plural
})
# Pagination
paginator, paginated_items = paginate(request, items, per_page=25)
# If paginating or searching, render "results.html"
if request.GET.get('results', None) == 'true':
return render(request, "wagtailsnippets/chooser/results.html", {
'content_type': content_type,
'snippet_type_name': snippet_type_name,
'items': paginated_items,
'query_string': search_query,
'is_searching': is_searching,
})
return render_modal_workflow(
request,
'wagtailsnippets/chooser/choose.html', 'wagtailsnippets/chooser/choose.js',
{
'content_type': content_type,
'snippet_type_name': snippet_type_name,
'items': paginated_items,
'is_searchable': is_searchable,
'search_form': search_form,
'query_string': search_query,
'is_searching': is_searching,
}
)
开发者ID:Tivix,项目名称:wagtail,代码行数:54,代码来源:chooser.py
示例8: list
def list(request, app_label, model_name):
model = get_snippet_model_from_url_params(app_label, model_name)
permissions = [get_permission_name(action, model) for action in ["add", "change", "delete"]]
if not any([request.user.has_perm(perm) for perm in permissions]):
return permission_denied(request)
items = model.objects.all()
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and "q" in request.GET:
search_form = SearchForm(
request.GET,
placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural},
)
if search_form.is_valid():
search_query = search_form.cleaned_data["q"]
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(
placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural}
)
paginator, paginated_items = paginate(request, items)
# Template
if request.is_ajax():
template = "wagtailsnippets/snippets/results.html"
else:
template = "wagtailsnippets/snippets/type_index.html"
return render(
request,
template,
{
"model_opts": model._meta,
"items": paginated_items,
"can_add_snippet": request.user.has_perm(get_permission_name("add", model)),
"is_searchable": is_searchable,
"search_form": search_form,
"is_searching": is_searching,
"query_string": search_query,
},
)
开发者ID:qjardon,项目名称:wagtail,代码行数:52,代码来源:snippets.py
示例9: delete
def delete(self, obj):
# Make sure the object can be indexed
if not class_is_indexed(obj.__class__):
return
# Get mapping
mapping = ElasticSearchMapping(obj.__class__)
# Delete document
try:
self.es.delete(self.es_index, mapping.get_document_type(), mapping.get_document_id(obj))
except NotFoundError:
pass # Document doesn't exist, ignore this exception
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:13,代码来源:elasticsearch.py
示例10: search
def search(self, query_string, model_or_queryset, fields=None, filters=None,
prefetch_related=None, operator=None, order_by_relevance=True):
# Find model/queryset
if isinstance(model_or_queryset, QuerySet):
model = model_or_queryset.model
queryset = model_or_queryset
else:
model = model_or_queryset
queryset = model_or_queryset.objects.all()
# Model must be a class that is in the index
if not class_is_indexed(model):
return []
# Check that theres still a query string after the clean up
if query_string == "":
return []
# Only fields that are indexed as a SearchField can be passed in fields
if fields:
allowed_fields = {field.field_name for field in model.get_searchable_search_fields()}
for field_name in fields:
if field_name not in allowed_fields:
raise FieldError(
'Cannot search with field "' + field_name + '". Please add index.SearchField(\'' +
field_name + '\') to ' + model.__name__ + '.search_fields.'
)
# Apply filters to queryset
if filters:
queryset = queryset.filter(**filters)
# Prefetch related
if prefetch_related:
for prefetch in prefetch_related:
queryset = queryset.prefetch_related(prefetch)
# Check operator
if operator is not None:
operator = operator.lower()
if operator not in ['or', 'and']:
raise ValueError("operator must be either 'or' or 'and'")
# Search
search_query = self.query_class(
queryset, query_string, fields=fields, operator=operator, order_by_relevance=order_by_relevance
)
return self.results_class(self, search_query)
开发者ID:InnovaCo,项目名称:wagtail,代码行数:49,代码来源:base.py
示例11: add_bulk
def add_bulk(self, model, obj_list):
if not class_is_indexed(model):
return
# Get mapping
mapping = ElasticSearchMapping(model)
doc_type = mapping.get_document_type()
# Create list of actions
actions = []
for obj in obj_list:
# Create the action
action = {"_index": self.es_index, "_type": doc_type, "_id": mapping.get_document_id(obj)}
action.update(mapping.get_document(obj))
actions.append(action)
# Run the actions
bulk(self.es, actions)
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:18,代码来源:elasticsearch.py
示例12: add_items
def add_items(self, model, obj_list):
if not class_is_indexed(model):
return
# Get mapping
mapping = ElasticSearchMapping(model)
doc_type = mapping.get_document_type()
# Create list of actions
actions = []
for obj in obj_list:
# Create the action
action = {
'_index': self.index_name,
'_type': doc_type,
'_id': mapping.get_document_id(obj),
}
action.update(mapping.get_document(obj))
actions.append(action)
# Run the actions
bulk(self.es, actions)
开发者ID:julzhk,项目名称:wagtail,代码行数:22,代码来源:elasticsearch.py
示例13: list
def list(request, content_type_app_name, content_type_model_name):
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
model = content_type.model_class()
permissions = [get_permission_name(action, model) for action in ["add", "change", "delete"]]
if not any([request.user.has_perm(perm) for perm in permissions]):
return permission_denied(request)
snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)
items = model.objects.all()
# Search
is_searchable = class_is_indexed(model)
is_searching = False
search_query = None
if is_searchable and "q" in request.GET:
search_form = SearchForm(
request.GET, placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": snippet_type_name_plural}
)
if search_form.is_valid():
search_query = search_form.cleaned_data["q"]
search_backend = get_search_backend()
items = search_backend.search(search_query, items)
is_searching = True
else:
search_form = SearchForm(
placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": snippet_type_name_plural}
)
# Pagination
p = request.GET.get("p", 1)
paginator = Paginator(items, 20)
try:
paginated_items = paginator.page(p)
except PageNotAnInteger:
paginated_items = paginator.page(1)
except EmptyPage:
paginated_items = paginator.page(paginator.num_pages)
# Template
if request.is_ajax():
template = "wagtailsnippets/snippets/results.html"
else:
template = "wagtailsnippets/snippets/type_index.html"
return render(
request,
template,
{
"content_type": content_type,
"snippet_type_name": snippet_type_name,
"snippet_type_name_plural": snippet_type_name_plural,
"items": paginated_items,
"can_add_snippet": request.user.has_perm(get_permission_name("add", model)),
"is_searchable": is_searchable,
"search_form": search_form,
"is_searching": is_searching,
"query_string": search_query,
},
)
开发者ID:niceguydave,项目名称:wagtail,代码行数:65,代码来源:snippets.py
注:本文中的wagtail.wagtailsearch.index.class_is_indexed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论