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


Python WRCCUtils.convert_db_dates方法代码示例

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


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

示例1: sub_tables

# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import convert_db_dates [as 别名]
def sub_tables(request):
    tbl_name = request.GET.get('tbl_name', None)
    ucan_id = request.GET.get('ucan_id', None)
    network_station_ids_list = request.GET.getlist('network_station_id', [])
    network_station_ids_list = [str(n_id) for n_id in network_station_ids_list]
    context = {
        'title': 'Table ADD Tool',
        'tbl_name': tbl_name,
        'network_station_ids_list':network_station_ids_list,
        'ucan_id': ucan_id
    }
    obj = secondary_tables[tbl_name]
    table_dicts = {}
    max_instances = 0
    for idx, network_station_id in enumerate(network_station_ids_list):
        table_dicts[network_station_id] = []
        instances = obj.objects.filter(network_station_id=network_station_id)
        if len(instances) > max_instances:max_instances = len(instances)
        for inst_idx, inst in enumerate(instances):
            inst_list = convert_query_set(inst,'python_list')
            table_dicts[network_station_id].append(inst_list)
    #Format for html loop
    station = convert_query_set(models.Station.objects.filter(ucan_station_id=ucan_id), 'python_dict')
    init = {
        'ucan_station_id':ucan_id,
        'begin_date':WRCCUtils.convert_db_dates(station['begin_date']),
        'end_date':WRCCUtils.convert_db_dates(station['end_date']),
    }
    form_class = getattr(mforms, tbl_name)
    form = form_class()
    if max_instances == 0:
        results = [[[] for idx in range(len(network_station_ids_list)+1)] for inst in range(1)]
        for idx, network_station_id in enumerate(network_station_ids_list):
            init['network_station_id'] = network_station_id
            for key, val in form.__dict__.iteritems():
                if key[0]!= '_':
                    if key in init.keys():
                        results[0][idx].append([key, init[key]])
                    else:
                        results[0][idx].append([key, val])
        #results[0][-1] = results[0][-2]
        for idx in range(len(results[0]) - 1):
            results[0][idx] = []
    else:
        results = [[[] for idx in range(len(network_station_ids_list)+1)] for inst in range(max_instances)]
        for inst in range(max_instances):
            for idx, network_station_id in enumerate(network_station_ids_list):
                if len(table_dicts[network_station_id]) > inst:
                    results[inst][idx]=table_dicts[network_station_id][inst]
                else:
                    continue
        #add forms at end of each row
        for idx, network_station_id in enumerate(network_station_ids_list):
            if not table_dicts[network_station_id]:
                init['network_station_id'] = network_station_id
                for key, val in form.__dict__.iteritems():
                    if key[0]!= '_':
                        if key in init.keys():
                            results[idx][-1].append([key, init[key]])
                        else:
                            results[idx][-1].append([key, val])
            else:
                results[idx][-1]=results[idx][idx]

    #Write to metadata load file
    if 'form_add' in request.POST or 'form_edit' in request.POST:
        form_idx = int(request.POST['form_id']) - 1
        for key in request.POST:
            for idx,key_val in enumerate(results[form_idx][-1]):
                if str(key) == key_val[0]:
                    results[form_idx][-1][idx][1] = str(request.POST[key])
        meta_str = ''
        with open(load_tables_dir + load_tables[tbl_name],'a+') as f:
            for idx,key in enumerate(key_list[tbl_name]):
                if idx != len(key_list[tbl_name]) - 1:
                    end_char = '|'
                else:
                    end_char = '\n'
                try:
                    meta_str+=str(request.POST[key]) + end_char
                except:
                    #WTF?? Some db Variable tables have 'network' key but some have 'network_id' key
                    #instead
                    if key == 'network':
                        meta_str+=str(request.POST['network_id']) + end_char

            if 'form_edit' in request.POST:
                pass
            else:
                f.write(meta_str)
        #Double check
        #os.chmod(load_tables_dir + load_tables[tbl_name], 0777)
        with open(load_tables_dir + load_tables[tbl_name], 'r') as f:
            if f.readlines()[-1] == meta_str:
                context['merge_successful'] = True
                context['form_id'] = int(request.POST['form_id'])
    context['results'] = results
    return render_to_response('wrcc_meta/sub_tables.html', context, context_instance=RequestContext(request))
开发者ID:bdaudert,项目名称:dj-projects,代码行数:100,代码来源:views.py

示例2: station_tables_merge

# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import convert_db_dates [as 别名]
def station_tables_merge(request):
    tbl_name = request.GET.get('tbl_name', None)
    ucan_id_list = request.GET.getlist('ucan_id', [])
    ucan_id_list = [str(uid) for uid in ucan_id_list]
    tbl_done_list = request.GET.getlist('tbl_done', [])
    context = {
        'title': tbl_name + ' Table Merge Tool',
        'tbl_done_list':tbl_done_list
    }
    tbl_done = False
    if tbl_name in tbl_done_list:tbl_done=True;context['tbl_done']=True
    if not tbl_name or not ucan_id_list:
        return render_to_response('wrcc_meta/station_tables_merge.html', context, context_instance=RequestContext(request))
    context['ucan_id_list'] = ucan_id_list
    context['tbl_name'] = tbl_name
    table_dicts = {}
    #Find table instances for each ucan id
    ucan_station_id_acis = None
    ucan_station_id_form = None
    wrcc_id = None
    network_station_ids_dict = {}
    for idx, ucan_id in enumerate(ucan_id_list):
        if int(ucan_id) < 1000000:
            ucan_station_acis = ucan_id
        else:
            wrcc_id = ucan_id
        table_dicts[ucan_id] = []
        obj = primary_tables[tbl_name]
        if tbl_name == 'StationNetwork':
            network_station_ids_dict[ucan_id] = []
        instances = obj.objects.filter(ucan_station_id=ucan_id)
        for i, instance in enumerate(instances):
            inst_list = convert_query_set(instance,'python_list')
            table_dicts[ucan_id].append(inst_list)
            #Get network_station_id for Variable, StationDigital tables
            #if we are looking at the StationNetwork table
            if tbl_name == 'StationNetwork':
                inst_dict = convert_query_set(instance,'python_dict')
                network_station_ids_dict[ucan_id].append(str(inst_dict['network_station_id']))
    context['network_station_ids_dict'] = network_station_ids_dict

    #query station_table entries in db for wrcc id entry
    if wrcc_id:
        station = convert_query_set(models.Station.objects.filter(ucan_station_id=wrcc_id), 'python_dict')
        if ucan_station_id_acis:
            ucan_station_id_form = ucan_station_id_acis
        else:
            ucan_station_id_form = ucan_id_list[0]
    else:
        if ucan_station_id_acis:
            station = convert_query_set(models.Station.objects.filter(ucan_station_id=ucan_station_id_form), 'python_dict')
            ucan_station_id_form = ucan_station_id_acis
        else:
            station = convert_query_set(models.Station.objects.filter(ucan_station_id=ucan_id_list[0]), 'python_dict')
            ucan_station_id_form = ucan_id_list[0]

    #Reorder results for easy html formatting
    max_instances = max([len(table_dicts[uid]) for uid in ucan_id_list])
    if  max_instances == 0:
        #set up blank form for table
        #get station table for start, end dates and data flags
        init = {
            'ucan_station_id':ucan_station_id_form,
            'begin_date':WRCCUtils.convert_db_dates(station['begin_date']),
            'end_date':WRCCUtils.convert_db_dates(station['end_date']),
            'begin_date_flag':station['begin_date_flag'],
            'end_date_flag':station['end_date_flag'],
            'history_flag':station['history_flag'],
            'src_quality_code':station['src_quality_code'],
            'updated_by': 'WRCCsync',
            'last_updated':today_yr + '-' + today_month + '-' + today_day
            }
        form_class = getattr(mforms, tbl_name + 'Form')
        form = form_class(initial=init)
        for field in form.fields:
            if form[field].value():
                table_dicts[ucan_station_id_form].append([str(field), str(form[field].value())])
            else:
                table_dicts[ucan_station_id_form].append([str(field),''])
        results=[[table_dicts[ucan_station_id_form]]]
    else:
        #Format for html display
        results = [[[] for idx in range(len(ucan_id_list)+1)] for inst in range(max_instances)]
        for inst in range(max_instances):
            for idx, ucan_id in enumerate(ucan_id_list):
                if len(table_dicts[ucan_id]) > inst:
                    results[inst][idx]=table_dicts[ucan_id][inst]
                    if ucan_id >1000000:
                        results[inst][-1] = []
                        for idx, key_val in enumerate(table_dicts[ucan_id][inst]):
                            results[inst][-1].append([key_val[0], key_val[1]])
            if not results[inst][-1]:
                for idx, key_val in enumerate(table_dicts[ucan_id_list[-1]][inst]):
                    results[inst][-1].append([key_val[0], key_val[1]])
            #Overwrite editable form with wrcc values if they exist
            #and replace updated_by, last _updated and ucan_id
            context['x'] =  WRCCUtils.convert_db_dates(station['begin_date'])
            if tbl_done:
                for idx, key_val in enumerate(results[inst][-1]):
                    results[inst][-1][idx][1] = ''
#.........这里部分代码省略.........
开发者ID:bdaudert,项目名称:dj-projects,代码行数:103,代码来源:views.py


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