當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。