本文整理汇总了Python中beeswax.forms.QueryForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python QueryForm.is_valid方法的具体用法?Python QueryForm.is_valid怎么用?Python QueryForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beeswax.forms.QueryForm
的用法示例。
在下文中一共展示了QueryForm.is_valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_query
# 需要导入模块: from beeswax.forms import QueryForm [as 别名]
# 或者: from beeswax.forms.QueryForm import is_valid [as 别名]
def execute_query(request, design_id=None):
"""
View function for executing an arbitrary query.
It understands the optional GET/POST params:
on_success_url
If given, it will be displayed when the query is successfully finished.
Otherwise, it will display the view query results page by default.
"""
authorized_get_design(request, design_id)
error_message = None
form = QueryForm()
action = request.path
log = None
design = safe_get_design(request, models.SavedQuery.HQL, design_id)
on_success_url = request.REQUEST.get('on_success_url')
if request.method == 'POST':
form.bind(request.POST)
to_explain = request.POST.has_key('button-explain')
to_submit = request.POST.has_key('button-submit')
# Always validate the saveform, which will tell us whether it needs explicit saving
if form.is_valid():
to_save = form.saveform.cleaned_data['save']
to_saveas = form.saveform.cleaned_data['saveas']
if to_saveas and not design.is_auto:
# Save As only affects a previously saved query
design = design.clone()
if to_submit or to_save or to_saveas or to_explain:
explicit_save = to_save or to_saveas
design = save_design(request, form, models.SavedQuery.HQL, design, explicit_save)
action = urlresolvers.reverse(execute_query, kwargs=dict(design_id=design.id))
if to_explain or to_submit:
query_str = form.query.cleaned_data["query"]
query_server = get_query_server(form.query_servers.cleaned_data["server"])
# (Optional) Parameterization.
parameterization = get_parameterization(request, query_str, form, design, to_explain)
if parameterization:
return parameterization
try:
query = HQLdesign(form)
if to_explain:
return explain_directly(request, query, design, query_server)
else:
notify = form.query.cleaned_data.get('email_notify', False)
return execute_directly(request, query, query_server, design, on_success_url=on_success_url, notify=notify)
except BeeswaxException, ex:
print ex.errorCode
print ex.SQLState
db = dbms.get(request.user, query_server)
error_message, log = expand_exception(ex, db)
示例2: _run_parameterized_query
# 需要导入模块: from beeswax.forms import QueryForm [as 别名]
# 或者: from beeswax.forms.QueryForm import is_valid [as 别名]
def _run_parameterized_query(request, design_id, explain):
"""
Given a design and arguments to parameterize that design, runs the query.
- explain is a boolean to determine whether to run as an explain or as an
execute.
This is an extra "step" in the flow from execute_query.
"""
design = authorized_get_design(request, design_id, must_exist=True)
# Reconstitute the form
design_obj = beeswax.design.HQLdesign.loads(design.data)
query_form = QueryForm()
params = design_obj.get_query_dict()
params.update(request.POST)
databases = _get_db_choices(request)
query_form.bind(params)
query_form.query.fields["database"].choices = databases # Could not do it in the form
if not query_form.is_valid():
raise PopupException(_("Query form is invalid: %s") % query_form.errors)
query_str = query_form.query.cleaned_data["query"]
app_name = get_app_name(request)
query_server = get_query_server_config(app_name)
query_type = SavedQuery.TYPES_MAPPING[app_name]
parameterization_form_cls = make_parameterization_form(query_str)
if not parameterization_form_cls:
raise PopupException(_("Query is not parameterizable."))
parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")
if parameterization_form.is_valid():
real_query = substitute_variables(query_str, parameterization_form.cleaned_data)
query = HQLdesign(query_form, query_type=query_type)
query._data_dict["query"]["query"] = real_query
try:
if explain:
return explain_directly(request, query, design, query_server)
else:
return execute_directly(request, query, query_server, design)
except Exception, ex:
db = dbms.get(request.user, query_server)
error_message, log = expand_exception(ex, db)
return render(
"execute.mako",
request,
{
"action": reverse(get_app_name(request) + ":execute_query"),
"design": design,
"error_message": error_message,
"form": query_form,
"log": log,
"autocomplete_base_url": reverse(get_app_name(request) + ":autocomplete", kwargs={}),
},
)
示例3: _run_parameterized_query
# 需要导入模块: from beeswax.forms import QueryForm [as 别名]
# 或者: from beeswax.forms.QueryForm import is_valid [as 别名]
def _run_parameterized_query(request, design_id, explain):
"""
Given a design and arguments to parameterize that design, runs the query.
- explain is a boolean to determine whether to run as an explain or as an
execute.
This is an extra "step" in the flow from execute_query.
"""
design = authorized_get_design(request, design_id, must_exist=True)
# Reconstitute the form
design_obj = beeswax.design.HQLdesign.loads(design.data)
query_form = QueryForm()
params = design_obj.get_query_dict()
params.update(request.POST)
query_form.bind(params)
assert query_form.is_valid()
query_str = query_form.query.cleaned_data["query"]
query_server = get_query_server_config(get_app_name(request))
parameterization_form_cls = make_parameterization_form(query_str)
if not parameterization_form_cls:
raise PopupException(_("Query is not parameterizable."))
parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")
if parameterization_form.is_valid():
real_query = substitute_variables(query_str, parameterization_form.cleaned_data)
query = HQLdesign(query_form)
query._data_dict['query']['query'] = real_query
try:
if explain:
return explain_directly(request, query, design, query_server)
else:
return execute_directly(request, query, query_server, design)
except Exception, ex:
db = dbms.get(request.user, query_server)
error_message, log = expand_exception(ex, db)
return render('execute.mako', request, {
'action': reverse(get_app_name(request) + ':execute_query'),
'design': design,
'error_message': error_message,
'form': query_form,
'log': log,
'autocomplete': json.dumps({}),
})
示例4: execute_query
# 需要导入模块: from beeswax.forms import QueryForm [as 别名]
# 或者: from beeswax.forms.QueryForm import is_valid [as 别名]
def execute_query(request, design_id=None):
"""
View function for executing an arbitrary query.
It understands the optional GET/POST params:
on_success_url
If given, it will be displayed when the query is successfully finished.
Otherwise, it will display the view query results page by default.
"""
authorized_get_design(request, design_id)
error_message = None
form = QueryForm()
action = request.path
log = None
app_name = get_app_name(request)
query_type = SavedQuery.TYPES_MAPPING[app_name]
design = safe_get_design(request, query_type, design_id)
on_success_url = request.REQUEST.get('on_success_url')
query_server = get_query_server_config(app_name)
db = dbms.get(request.user, query_server)
databases = _get_db_choices(request)
if request.method == 'POST':
form.bind(request.POST)
form.query.fields['database'].choices = databases # Could not do it in the form
to_explain = request.POST.has_key('button-explain')
to_submit = request.POST.has_key('button-submit')
# Always validate the saveform, which will tell us whether it needs explicit saving
if form.is_valid():
to_save = form.saveform.cleaned_data['save']
to_saveas = form.saveform.cleaned_data['saveas']
if to_saveas and not design.is_auto:
# Save As only affects a previously saved query
design = design.clone()
if to_submit or to_save or to_saveas or to_explain:
explicit_save = to_save or to_saveas
design = save_design(request, form, query_type, design, explicit_save)
action = reverse(app_name + ':execute_query', kwargs=dict(design_id=design.id))
if to_explain or to_submit:
query_str = form.query.cleaned_data["query"]
# (Optional) Parameterization.
parameterization = get_parameterization(request, query_str, form, design, to_explain)
if parameterization:
return parameterization
try:
query = HQLdesign(form, query_type=query_type)
if to_explain:
return explain_directly(request, query, design, query_server)
else:
download = request.POST.has_key('download')
return execute_directly(request, query, query_server, design, on_success_url=on_success_url, download=download)
except Exception, ex:
error_message, log = expand_exception(ex, db)
示例5: execute_query
# 需要导入模块: from beeswax.forms import QueryForm [as 别名]
# 或者: from beeswax.forms.QueryForm import is_valid [as 别名]
def execute_query(request, design_id=None):
"""
View function for executing an arbitrary query.
It understands the optional GET/POST params:
on_success_url
If given, it will be displayed when the query is successfully finished.
Otherwise, it will display the view query results page by default.
"""
authorized_get_design(request, design_id)
request.session['start_time'] = time.time() # FIXME: add job id to not intersect simultaneous jobs
error_message = None
form = QueryForm()
action = request.path
log = None
app_name = get_app_name(request)
query_type = SavedQuery.TYPES_MAPPING['beeswax']
design = safe_get_design(request, query_type, design_id)
on_success_url = request.REQUEST.get('on_success_url')
query_server = get_query_server_config(app_name)
db = dbms.get(request.user, query_server)
databases = _get_db_choices(request)
if request.method == 'POST':
form.bind(request.POST)
form.query.fields['database'].choices = databases # Could not do it in the form
to_explain = request.POST.has_key('button-explain')
to_submit = request.POST.has_key('button-submit')
# Always validate the saveform, which will tell us whether it needs explicit saving
if form.is_valid():
to_save = form.saveform.cleaned_data['save']
to_saveas = form.saveform.cleaned_data['saveas']
if to_save or to_saveas:
if 'beeswax-autosave' in request.session:
del request.session['beeswax-autosave']
if to_saveas and not design.is_auto:
# Save As only affects a previously saved query
design = design.clone()
if to_submit or to_save or to_saveas or to_explain:
explicit_save = to_save or to_saveas
design = save_design(request, form, query_type, design, explicit_save)
action = urlresolvers.reverse(app_name + ':execute_query', kwargs=dict(design_id=design.id))
if to_explain or to_submit:
query_str = form.query.cleaned_data["query"]
if conf.CHECK_PARTITION_CLAUSE_IN_QUERY.get():
query_str = _strip_trailing_semicolon(query_str)
# check query. if a select query on partitioned table without partition keys,
# intercept it and raise a PopupException.
_check_partition_clause_in_query(form.query.cleaned_data.get('database', None), query_str, db)
# (Optional) Parameterization.
parameterization = get_parameterization(request, query_str, form, design, to_explain)
if parameterization:
return parameterization
try:
query = HQLdesign(form, query_type=query_type)
if to_explain:
return explain_directly(request, query, design, query_server)
else:
download = request.POST.has_key('download')
download_format = form.query.cleaned_data.get('download_format', None)
if not download_format: download_format = None
if download_format in common.DL_FORMATS:
request.session['dl_status'] = True
return execute_directly(request, query, query_server, design, on_success_url=on_success_url, download_format=download_format, download=download)
except QueryServerException, ex:
error_message, log = expand_exception(ex, db)