本文整理匯總了Python中ebpub.db.schemafilters.FilterChain.validate方法的典型用法代碼示例。如果您正苦於以下問題:Python FilterChain.validate方法的具體用法?Python FilterChain.validate怎麽用?Python FilterChain.validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ebpub.db.schemafilters.FilterChain
的用法示例。
在下文中一共展示了FilterChain.validate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: schema_filter
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import validate [as 別名]
def schema_filter(request, slug, args_from_url):
"""
List NewsItems for one schema, filtered by various criteria in the
URL (date, location, or values of SchemaFields).
"""
s = get_object_or_404(get_schema_manager(request), slug=slug, is_special_report=False)
if not s.allow_charting:
return HttpResponsePermanentRedirect(s.url())
context = {
'bodyclass': 'schema-filter',
'bodyid': s.slug,
'schema': s,
}
# Breadcrumbs. We can assign this early because it's a generator,
# so it'll get the full context no matter what.
context['breadcrumbs'] = breadcrumbs.schema_filter(context)
filter_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_filter=True).order_by('display_order'))
textsearch_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_searchable=True).order_by('display_order'))
# Use SortedDict to preserve the display_order.
filter_sf_dict = SortedDict([(sf.name, sf) for sf in filter_sf_list] + [(sf.name, sf) for sf in textsearch_sf_list])
# Determine what filters to apply, based on path and/or query string.
filterchain = FilterChain(request=request, context=context, schema=s)
context['filters'] = filterchain
try:
filterchain.update_from_request(args_from_url, filter_sf_dict)
filters_need_more = filterchain.validate()
except FilterError, e:
if getattr(e, 'url', None) is not None:
return HttpResponseRedirect(e.url)
raise Http404(str(e))
示例2: bigmap_filter
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import validate [as 別名]
def bigmap_filter(request, slug):
s = get_object_or_404(get_schema_manager(request), slug=slug, is_special_report=False)
if not s.allow_charting:
return HttpResponse(status=404)
filter_sf_dict = _get_filter_schemafields(s)
# Determine what filters to apply, based on path and/or query string.
filterchain = FilterChain(request=request, schema=s)
try:
filterchain.update_from_request(filter_sf_dict)
filters_need_more = filterchain.validate()
except:
logger.exception("Unhandled error")
return HttpResponse(status=404)
config = _decode_map_permalink(request, show_default_layers=False, filters=filterchain)
new_url = filterchain.make_url(base_url=reverse("bigmap_filter", args=(slug,)))
if new_url != request.get_full_path():
return HttpResponseRedirect(new_url)
# add in the filter layer
base_url = reverse("ebpub-schema-filter-geojson", args=(slug,))
layer_url = filterchain.make_url(base_url=base_url)
custom_layer = {"url": layer_url, "params": {}, "title": "Custom Filter", "visible": True}
config["layers"].append(custom_layer)
if config["is_widget"]:
return eb_render(request, "richmaps/embed_bigmap.html", {"map_config": simplejson.dumps(config, indent=2)})
else:
return eb_render(request, "richmaps/bigmap.html", {"map_config": simplejson.dumps(config, indent=2)})
示例3: bigmap_filter
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import validate [as 別名]
def bigmap_filter(request, slug, args_from_url):
s = get_object_or_404(get_schema_manager(request), slug=slug, is_special_report=False)
if not s.allow_charting:
return HttpResponse(status=404)
filter_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_filter=True).order_by('display_order'))
textsearch_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_searchable=True).order_by('display_order'))
# Use SortedDict to preserve the display_order.
filter_sf_dict = SortedDict([(sf.name, sf) for sf in filter_sf_list] + [(sf.name, sf) for sf in textsearch_sf_list])
# Determine what filters to apply, based on path and/or query string.
filterchain = FilterChain(request=request, schema=s)
try:
filterchain.update_from_request(args_from_url, filter_sf_dict)
filters_need_more = filterchain.validate()
except:
return HttpResponse(status=404)
config = _decode_map_permalink(request, show_default_layers=False, filters=filterchain)
new_url = filterchain.make_url(base_url=reverse('bigmap_filter', args=(slug,)))
if new_url != request.get_full_path():
return HttpResponseRedirect(new_url)
# add in the filter layer
base_url = reverse('ebpub-schema-filter-geojson', args=(slug,))
layer_url = filterchain.make_url(base_url=base_url)
custom_layer = {
'url': layer_url,
'params': {},
'title': "Custom Filter",
'visible': True
}
config['layers'].append(custom_layer)
if config['is_widget']:
return eb_render(request, 'richmaps/embed_bigmap.html', {
'map_config': simplejson.dumps(config, indent=2)
})
else:
return eb_render(request, 'richmaps/bigmap.html', {
'map_config': simplejson.dumps(config, indent=2)
})
示例4: bigmap_filter
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import validate [as 別名]
def bigmap_filter(request, slug):
"""
Big map with just one Schema (identified by ``slug``) enabled by
default.
"""
s = get_object_or_404(get_schema_manager(request), slug=slug, is_special_report=False)
if not s.allow_charting:
return HttpResponse(status=404)
filter_sf_dict = _get_filter_schemafields(s)
# Determine what filters to apply, based on path and/or query string.
filterchain = FilterChain(request=request, schema=s)
try:
filterchain.update_from_request(filter_sf_dict)
filters_need_more = filterchain.validate()
except:
logger.exception("Unhandled error")
return HttpResponse(status=404)
config = _decode_map_permalink(request, show_default_layers=False, filters=filterchain)
# TODO: This can leave in permalink params eg. 'i', even if there
# is also 'ids', because it doesn't recognize those as being the
# same.
new_url = filterchain.make_url(base_url=reverse('bigmap_filter', args=(slug,)))
if new_url != request.get_full_path():
return HttpResponseRedirect(new_url)
if config['is_widget']:
return eb_render(request, 'richmaps/embed_bigmap.html', {
'map_config': simplejson.dumps(config, indent=2)
})
else:
return eb_render(request, 'richmaps/bigmap.html', {
'map_config': simplejson.dumps(config, indent=2)
})
示例5: schema_filter_geojson
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import validate [as 別名]
def schema_filter_geojson(request, slug, args_from_url):
s = get_object_or_404(get_schema_manager(request), slug=slug, is_special_report=False)
if not s.allow_charting:
return HttpResponse(status=404)
filter_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_filter=True).order_by('display_order'))
textsearch_sf_list = list(SchemaField.objects.filter(schema__id=s.id, is_searchable=True).order_by('display_order'))
# Use SortedDict to preserve the display_order.
filter_sf_dict = SortedDict([(sf.name, sf) for sf in filter_sf_list] + [(sf.name, sf) for sf in textsearch_sf_list])
# Determine what filters to apply, based on path and/or query string.
filterchain = FilterChain(request=request, schema=s)
try:
filterchain.update_from_request(args_from_url, filter_sf_dict)
filters_need_more = filterchain.validate()
except FilterError:
return HttpResponse(status=400)
except BadAddressException:
return HttpResponse(status=400)
except BadDateException:
return HttpResponse(status=400)
if filters_need_more:
return HttpResponse(status=400)
# If there isn't a date filter, add some dates to the queryset,
# but NOT to the filterchain, because need to give the user the
# option of choosing dates.
qs, start_date, end_date = _default_date_filtering(filterchain)
if s.is_event:
qs = qs.order_by('item_date', 'id')
else:
qs = qs.order_by('-item_date', '-id')
page = request.GET.get('page', None)
if page is not None:
try:
page = int(page)
idx_start = (page - 1) * constants.FILTER_PER_PAGE
idx_end = page * constants.FILTER_PER_PAGE
# Get one extra, so we can tell whether there's a next page.
idx_end += 1
except ValueError:
return HttpResponse('Invalid Page', status=400)
else:
idx_start, idx_end = 0, 1000
qs = qs[idx_start:idx_end]
cache_key = 'schema_filter_geojson:' + _make_cache_key_from_queryset(qs)
cache_seconds = 60 * 5
output = cache.get(cache_key, None)
if output is None:
output = api_items_geojson(list(qs))
cache.set(cache_key, output, cache_seconds)
response = HttpResponse(output, mimetype="application/javascript")
patch_response_headers(response, cache_timeout=60 * 5)
return response