def initialize(args, request, is_pass=False): error_msg = '' project_id = utils.get_id(args) page = utils.get_page(args) # 获取当前页面 if is_pass: _projects_dict = utils.get_pass_projects() else: _projects_dict = utils.get_all_projects() page_list = utils.get_pages(page, _projects_dict) projects_dict, page, project_id = utils.adjust_info(_projects_dict, page, project_id) return error_msg, page, page_list, projects_dict, project_id
def capitalpool(request, *args, **kwargs): if not request.session.get( 'is_login', False) or request.session['user_type'] != 'admin': return redirect("/index") _projects_dict = utils.get_pass_projects() projects_dict = {} years_info = {} for key, item in _projects_dict: if item.get('start', None) and item['start'][:4].isdigit: year = int(item['start'][:4]) if year not in projects_dict: projects_dict[year] = [] projects_dict[year].append((key, item)) if year not in years_info: years_info[year] = { "total": 0, "use": 0, } years_info[year]['total'] += item['budget'] years_info[year]['use'] += item['real'] + item['maintain'] years_info[year][ 'left'] = years_info[year]['total'] - years_info[year]['use'] year = None for item in args: if item is not None and "year=" in item and len(item) > 6: year = int(item[6:]) break if not year or year not in years_info.keys(): year = max(years_info.keys()) years_info = years_info.items() years_info.sort(reverse=True) if request.method == "GET": return render( request, 'admin_capitalpool.html', { "projects_dict": projects_dict[year], "years_info": years_info, "year": year, })
def capitalpool(request, *args, **kwargs): if not request.session.get( 'is_login', False) or request.session['user_type'] != 'information': return redirect("/index") _projects_dict = utils.get_pass_projects() projects_dict = {} years_info = {} current_year = int(time.strftime('%Y', time.localtime(time.time()))) current_date = int(time.strftime('%m%d', time.localtime(time.time()))) for key, item in _projects_dict: item['year'] = 0 if item.get('start', None) and item['start'][:4].isdigit: year = int(item['start'][:4]) if year not in projects_dict: projects_dict[year] = [] projects_dict[year].append((key, item)) if year not in years_info: years_info[year] = { "total": 0, "use": 0, } years_info[year]['total'] += item['budget'] years_info[year]['use'] += item['real'] years_info[year][ 'left'] = years_info[year]['total'] - years_info[year]['use'] if item.get('end', None) and item['end'][:4].isdigit and item.get( "status", None) == "使用中": end_year = int(item['end'][:4]) end_date = int(item['end'][5:7] + item['end'][8:]) for year in range(end_year + 1, current_year + 1): if year not in projects_dict: projects_dict[year] = [] projects_dict[year].append((key, item)) if year not in years_info: years_info[year] = { "total": 0, "use": 0, } item['year'] = current_year - end_year years_info[year]['total'] += item['maintain'] if year < current_year or end_date < current_date: years_info[year]['use'] += item['maintain'] else: item['year'] -= 1 years_info[year]['left'] = years_info[year][ 'total'] - years_info[year]['use'] year = None for item in args: if item is not None and "year=" in item and len(item) > 6: year = int(item[6:]) break if not year or year not in years_info.keys(): year = max(years_info.keys()) years_info = years_info.items() years_info.sort(reverse=True) if request.method == "GET": return render( request, 'Administrators_capitalpool.html', { "projects_dict": projects_dict[year], "years_info": years_info, "year": year, "stryear": str(year) })