本文整理汇总了Python中WRCCUtils.convert_elements_to_list方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.convert_elements_to_list方法的具体用法?Python WRCCUtils.convert_elements_to_list怎么用?Python WRCCUtils.convert_elements_to_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WRCCUtils
的用法示例。
在下文中一共展示了WRCCUtils.convert_elements_to_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_form
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import convert_elements_to_list [as 别名]
def set_form(request, clean=True):
'''
Coverts request input to usable form input:
Deals with unicode issues
and autofill options for identifiers
NOTE: elements should always be a list (also when clean = False)
If Clean == True,
We also clean up some form fields for submission:
date fields, convert to yyyymmdd
window fields, convert to mmdd
name strings are converted to ids
Combine elemenst weith degree days
'''
try:
req_method = request.method
except:
if isinstance(request,dict):
req_method = 'dict'
else:req_method = None
form= {}
form['req_method'] = req_method
#Convert request object to python dictionary
if req_method == 'dict':
form = copy.deepcopy(request)
#Special case elements, always needs to be list
if 'element' in request.keys() and not 'elements' in request.keys():
form['elements'] = [form['element']]
if 'elements' in request.keys():
form['elements'] = WRCCUtils.convert_elements_to_list(request['elements'])
elif req_method == 'POST':
for key, val in request.POST.items():
form[str(key)]= val
#form = dict((str(x),str(y)) for x,y in request.POST.items())
#Special case elements, always needs to be list
if 'element' in request.POST.keys() and not 'elements' in request.POST.keys():
form['elements'] = [str(request.POST['element'])]
if 'elements' in request.POST.keys():
#form['elements'] = WRCCUtils.convert_elements_to_list(request.POST['elements'])
els = request.POST.getlist('elements',request.POST.get('elements','').split(','))
form['elements'] = [str(el) for el in els]
if 'metadata_keys' in request.POST.keys():
form['metadata_keys'] = request.POST.getlist('metadata_keys',request.POST.get('metadata_keys','').split(','))
elif req_method == 'GET':
#form = dict((str(x),str(y)) for x,y in request.GET.items())
for key, val in request.GET.items():
form[str(key)]= val
#Special case elements, always needs to be list
if 'element' in request.GET.keys() and not 'elements' in request.GET.keys():
form['elements'] = [str(request.GET['element'])]
if 'elements' in request.GET.keys():
#form['elements'] = WRCCUtils.convert_elements_to_list(request.GET['elements'])
form['elements'] = request.GET.get('elements','').split(',')
if 'metadata_keys' in request.GET.keys():
form['metadata_keys'] = request.GET.getlist('metadata_keys',request.GET.get('metadata_keys','').split(','))
else:
form = {}
#set data type for single apps
if 'data_type' not in form.keys():
if 'station_id' in form.keys():
form['data_type'] = 'station'
if 'location' in form.keys():
form['data_type'] = 'grid'
if 'app_name' in form.keys() and form['app_name'] in ['temporal_summary','monthly_spatial_summary']:
form['data_type'] = 'grid'
#Convert unicode to string
if 'elements' in form.keys():
form['elements'] = [str(el) for el in form['elements']]
if 'csrfmiddlewaretoken' in form.keys():
del form['csrfmiddlewaretoken']
if 'formData' in form.keys():
del form['formData']
if 'form_options' in form.keys():
del form['form_options']
if not clean:
return form
#Clean up form for submission
#Clean Dates and windows
vd = None
for key in ['start_date', 'end_date', 'start_year', 'end_year','start_window','end_window']:
if key not in form.keys():
continue
if form[key].lower() == 'por':
if str(key) in ['start_date']:
k=key; idx = 0;sd = 'por'; ed = form['end_date']
if str(key) in ['end_date']:
k=key; idx = 1;ed = 'por'; sd = form['start_date']
if str(key) in ['start_year']:
k='start_date'; idx = 0;sd = 'por'
if form['end_year'].lower() == 'por':ed = 'por'
else:ed = str(int(form['end_year']) -1) + '-12-31'
if str(key) in ['end_year']:
k='end_date'; idx = 1;ed = 'por'
if form['start_year'].lower() == 'por':sd = 'por'
else:sd = form['start_year'] + '-01-01'
if 'element' in form.keys() and not 'elements' in form.keys():
if form['element'] in ['dtr']:
el_list = ['maxt','mint']
if form['element'] in ['pet']:
#.........这里部分代码省略.........