当前位置: 首页>>代码示例>>Python>>正文


Python WRCCUtils.convert_variables_to_list方法代码示例

本文整理汇总了Python中WRCCUtils.convert_variables_to_list方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.convert_variables_to_list方法的具体用法?Python WRCCUtils.convert_variables_to_list怎么用?Python WRCCUtils.convert_variables_to_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WRCCUtils的用法示例。


在下文中一共展示了WRCCUtils.convert_variables_to_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_form

# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import convert_variables_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: variables 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 variables, always needs to be list
        if 'variable' in request.keys() and not 'variables' in request.keys():
            form['variables'] = [form['variable']]
        if 'variables' in request.keys():
            form['variables'] = WRCCUtils.convert_variables_to_list(request['variables'])
    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 variables, always needs to be list
        if 'variable' in request.POST.keys() and not 'variables' in request.POST.keys():
            form['variables'] = [str(request.POST['variable'])]
        if 'variables' in request.POST.keys():
            #form['variables'] = WRCCUtils.convert_variables_to_list(request.POST['variables'])
            els = request.POST.getlist('variables',request.POST.get('variables','').split(','))
            form['variables'] = [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 variables, always needs to be list
        if 'variable' in request.GET.keys() and not 'variables' in request.GET.keys():
            form['variables'] = [str(request.GET['variable'])]
        if 'variables' in request.GET.keys():
            #form['variables'] = WRCCUtils.convert_variables_to_list(request.GET['variables'])
            form['variables'] = request.GET.get('variables','').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 'variables' in form.keys():
        form['variables'] = [str(el) for el in form['variables']]
    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

    #Get element list for vd
    el_list = None
    if 'variable' in form.keys() and not 'variables' in form.keys():
        el_list = [form['variable']]
    if 'variables' in form.keys() and not 'variable' in form.keys():
        if isinstance(form['variables'],basestring):
            el_list = form['variables'].replace(', ',',').split(',')
        else:
            el_list = form['variables']

    #Get valid daterange
    vd = ['9999-99-99', '9999-99-99']
    #Clean Dates and windows
    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']
#.........这里部分代码省略.........
开发者ID:bdaudert,项目名称:my-python-lib,代码行数:103,代码来源:DJANGOUtils.py


注:本文中的WRCCUtils.convert_variables_to_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。