本文整理汇总了Python中mkt.search.forms.ApiSearchForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ApiSearchForm.is_valid方法的具体用法?Python ApiSearchForm.is_valid怎么用?Python ApiSearchForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.search.forms.ApiSearchForm
的用法示例。
在下文中一共展示了ApiSearchForm.is_valid方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_list
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def get_list(self, request=None, **kwargs):
form = ApiSearchForm(request.GET if request else None)
if not form.is_valid():
raise self.form_errors(form)
# Pluck out status first since it forms part of the base query, but
# only for privileged users.
status = form.cleaned_data['status']
if status != amo.STATUS_PUBLIC and not (
acl.action_allowed(request, 'Apps', 'Review') or
acl.action_allowed(request, 'Admin', '%')):
return http.HttpUnauthorized(
content=json.dumps(
{'reason': 'Unauthorized to filter by status.'}))
# Search specific processing of the results.
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE,
tablet=request.TABLET, status=status)
qs = _filter_search(request, qs, form.cleaned_data, region=region)
paginator = self._meta.paginator_class(request.GET, qs,
resource_uri=self.get_resource_list_uri(),
limit=self._meta.limit)
page = paginator.page()
# Rehydrate the results as per tastypie.
objs = [self.build_bundle(obj=obj, request=request)
for obj in page['objects']]
page['objects'] = [self.full_dehydrate(bundle) for bundle in objs]
# This isn't as quite a full as a full TastyPie meta object,
# but at least it's namespaced that way and ready to expand.
return self.create_response(request, page)
示例2: _filter
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def _filter(self, req, filters, **kwargs):
form = ApiSearchForm(filters)
if form.is_valid():
qs = Webapp.from_search(self.req, **kwargs)
return _filter_search(
self.req, qs, form.cleaned_data)._build_query()
else:
return form.errors.copy()
示例3: get_list
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def get_list(self, request=None, **kwargs):
form = ApiSearchForm(request.GET if request else None)
if not form.is_valid():
raise self.form_errors(form)
# Search specific processing of the results.
qs = _get_query(request, form, form.cleaned_data)
qs = _filter_search(qs, form.cleaned_data)
res = amo.utils.paginate(request, qs)
# Rehydrate the results as per tastypie.
bundles = [self.build_bundle(obj=obj, request=request) for obj in res.object_list]
objs = [self.full_dehydrate(bundle) for bundle in bundles]
# This isn't as quite a full as a full TastyPie meta object,
# but at least it's namespaced that way and ready to expand.
return self.create_response(request, {"objects": objs, "meta": {}})
示例4: get_list
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def get_list(self, request=None, **kwargs):
form = ApiSearchForm(request.GET if request else None)
if not form.is_valid():
raise self.form_errors(form)
# Search specific processing of the results.
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
qs = _get_query(region, gaia=request.GAIA,
mobile=request.MOBILE, tablet=request.TABLET)
qs = _filter_search(qs, form.cleaned_data, region=region)
res = amo.utils.paginate(request, qs)
# Rehydrate the results as per tastypie.
bundles = [self.build_bundle(obj=obj, request=request)
for obj in res.object_list]
objs = [self.full_dehydrate(bundle) for bundle in bundles]
# This isn't as quite a full as a full TastyPie meta object,
# but at least it's namespaced that way and ready to expand.
return self.create_response(request, {'objects': objs, 'meta': {}})
示例5: get_list
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def get_list(self, request=None, **kwargs):
form = ApiSearchForm(request.GET if request else None)
if not form.is_valid():
raise self.form_errors(form)
is_admin = acl.action_allowed(request, "Admin", "%")
is_reviewer = acl.action_allowed(request, "Apps", "Review")
# Pluck out status and addon type first since it forms part of the base
# query, but only for privileged users.
status = form.cleaned_data["status"]
addon_type = form.cleaned_data["type"]
base_filters = {"type": addon_type}
if status and (status == "any" or status != amo.STATUS_PUBLIC):
if is_admin or is_reviewer:
base_filters["status"] = status
else:
return http.HttpUnauthorized(content=json.dumps({"reason": _("Unauthorized to filter by status.")}))
# Search specific processing of the results.
region = getattr(request, "REGION", mkt.regions.WORLDWIDE)
qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters)
qs = _filter_search(request, qs, form.cleaned_data, region=region)
paginator = self._meta.paginator_class(
request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit
)
page = paginator.page()
# Rehydrate the results as per tastypie.
objs = [self.build_bundle(obj=obj, request=request) for obj in page["objects"]]
page["objects"] = [self.full_dehydrate(bundle) for bundle in objs]
# This isn't as quite a full as a full TastyPie meta object,
# but at least it's namespaced that way and ready to expand.
return self.create_response(request, page)
示例6: get_search_data
# 需要导入模块: from mkt.search.forms import ApiSearchForm [as 别名]
# 或者: from mkt.search.forms.ApiSearchForm import is_valid [as 别名]
def get_search_data(self, request):
form = ApiSearchForm(request.GET if request else None)
if not form.is_valid():
raise self.form_errors(form)
return form.cleaned_data