コード例 #1
0
ファイル: views.py プロジェクト: TSS2/a
def statistics_form_2():
    filter_pass = request.args.get('filter_pass', 0, type=int)
    list = [u'球',u'国家',u'省',u'市',u'校']
    from datetime import date
    year_now = date.today().year
    year_select = [str(year) for year in range(year_now-4,year_now+1)]
    cur_year = request.args.get('year', year_now, type=int) #获取连接里面的参数的值。year的值
    awards_level = Awards.get_level_by_level()

    # 得到国家级省级...
    if awards_level:
        level_list = []
        number = []
        for l in list:
            for a in awards_level:
                if l in a and not l in level_list:
                    level_list.append(l)

        if filter_pass != -1:
            level_selected = level_list[filter_pass]
        else:
            level_selected = u'所有'
            for l in level_list:
                n = 0
                for a in awards_level:
                    if l in a:
                        n = n + 1
                number.append(n)
        awards_num = Awards.get_awards_num2(cur_year,level_selected)
        department = []
        ad = Awards.get_all()
        for d in ad:
            if not d.department in department:
                department.append(d.department)
        list_len = len(awards_num) / len(department)

        dicts = {}
        level_sum = {}
        y = 0
        if filter_pass != -1:
            for a in awards_level:
                if level_selected in a:
                    dicts.setdefault(a)
                    level_sum.setdefault(a)
                    dicts_list = []
                    x = y
                    while x < len(awards_num):
                        dicts_list.append(awards_num[x])
                        x = x + list_len
                    dicts[a] = dicts_list
                    level_sum[a] = sum(dicts_list)
                    y = y + 1
        else:
            for a in awards_level:
                dicts.setdefault(a)
                level_sum.setdefault(a)
                dicts_list = []
                x = y
                while x < len(awards_num):
                    dicts_list.append(awards_num[x])
                    x = x + list_len
                dicts[a] = dicts_list
                level_sum[a] = sum(dicts_list)
                y = y + 1
        d = Awards.get_student_num(cur_year,level_selected)
        print d
    else:
        awards_num = 0
        level_list = []
        list_len = 0
        department = []
        number = []
        dicts = {}
        level_sum = 0

    return render_template('admin/statisticsform2.html',
                           title = u'统计',
                           filter_pass = filter_pass,
                           list = list,
                           year_select = year_select,
                           awards_level = awards_level,
                           awards_num = awards_num,
                           level_list = level_list,
                           list_len = list_len,
                           cur_year = cur_year,
                           department = department,
                           number = number,
                           dicts = dicts,
                           level_sum = level_sum
                           )