Exemple #1
0
def submit_time(request):
    """
        后端应在此处提交本次问卷填写结果
        然后返回是否成功
    """
    if 'volunteer_id' not in request.session.keys():
        return redirect('/login/')
    vol_id = str(request.session.get('volunteer_id'))
    print "vol id" + vol_id
    print request.POST
    ac_id = request.POST.get('activity_id')  # 活动问卷的id
    time_list = request.POST.get('time').split(',')  # 列表,存储全部可选的时间
    checked_list = request.POST.get('checked').split(
        ',')  # 列表,和上一个列表对应,1表示选中,0表示未选中
    # print ac_id
    # print time_list
    # print checked_list

    timer = back.getTimerbyDict({Timer.ID: int(ac_id)})[0]
    info_dic = back.getTimerAllDictByObject(timer)
    vol_dic = info_dic[Timer.VOLUNTEER_DIC]
    vol_dic[vol_id] = checked_list

    if back.setTimer(timer, Timer.VOLUNTEER_DIC, vol_dic):
        return JsonResponse({'success': 'true'})  # 成功返回true否则false
    else:
        return JsonResponse({'success': 'false'})  # 成功返回true否则false
def generateTimerXLS(timer_id, teacher_id, filename):
    timer = back.getTimerbyDict({Timer.ID: int(timer_id)})[0]
    info_dic = back.getTimerAllDictByObject(timer)
    (day_list, nouse) = back.date_start_to_end(info_dic[Timer.START_TIME],
                                               info_dic[Timer.END_TIME])
    vol_id_list = info_dic[Timer.VOLUNTEER_DIC].keys()
    vol_name_list = []
    for vol_id in vol_id_list:
        account = vol.idToAccountVolunteer(str(vol_id))
        vol_name_list.append(vol.getVolunteer(account, Volunteer.REAL_NAME))

    info = [vol_name_list]
    for day in day_list:
        tmp_list = day.split('/')
        day = datetime.date(int(tmp_list[0]), int(tmp_list[1]),
                            int(tmp_list[2]))
        this_day_list = []
        for vol_id in vol_id_list:
            if back.check_volunteerID_date(timer_id, vol_id, day):
                this_day_list.append(u'有空')
            else:
                this_day_list.append(' ')

        info.append(this_day_list)
    outputXLS('', filename, 'sheet1', info, ['name'] + day_list)
def get_all_activity(request):
    '''
        后端在此处返回老师可见的活动列表,放在dic字典的'acticity'键对应的值里返回给前端
    '''
    id = request.session.get('teacher_id', -1)
    if id == -1:
        return HttpResponse('Access denied')
    dict = {
        'activity': [{
            'name': '第一次组会',
            'proposer': '李三胖',
            'start_time': '2016/10/1',
            'end_time': '2016/10/10',
            'number': '12',
            'activity_id': '12'
        }, {
            'name': '一对一解答',
            'proposer': '屁孩',
            'start_time': '2016/10/10',
            'end_time': '2016/10/11',
            'number': '99',
            'activity_id': '32'
        }, {
            'name': '庆功会',
            'proposer': '王大神',
            'start_time': '2016/10/10',
            'end_time': '2016/10/19',
            'number': '3',
            'activity_id': '9'
        }]
    }

    activity_list = []
    timer_list = back.getTimerbyDict({})
    for timer in timer_list:
        info_dic = back.getTimerAllDictByObject(timer)
        dic = {}
        dic['name'] = info_dic[Timer.NAME]
        teacher_account = tch.idToAccountTeacher(
            int(info_dic[Timer.TEACHER_ID]))
        dic['proposer'] = tch.getTeacher(teacher_account, Teacher.REAL_NAME)
        dic['start_time'] = info_dic[Timer.START_TIME].strftime("%Y/%m/%d")
        dic['end_time'] = info_dic[Timer.END_TIME].strftime("%Y/%m/%d")
        try:
            dic['number'] = len(info_dic[Timer.VOLUNTEER_DIC].keys())
        except:
            dic['number'] = 0
        dic['activity_id'] = info_dic[Timer.ID]
        activity_list.append(dic)
    dict['activity'] = activity_list
    return JsonResponse(dict)
Exemple #4
0
def get_all_activity(request):
    """
        后端应在此处返回该志愿者可以提交的时间问卷列表,包括填过未填过的
        然后放到下面样例写好的dic的'activity'键对应的列表值中,列表里有若干字典
    """
    print "activity "
    dic = {
        'activity': [{
            'name': '第一次组会',
            'proposer': '李三胖',
            'state': '未填写',
            'activity_id': '12'
        }, {
            'name': '一对一解答',
            'proposer': '屁孩',
            'state': '已填写',
            'activity_id': '32'
        }, {
            'name': '庆功会',
            'proposer': '王大神',
            'state': '未填写',
            'activity_id': '9'
        }]
    }

    if 'volunteer_id' not in request.session.keys():
        return redirect('/login/')
    id = request.session.get('volunteer_id', -1)
    print 'vol id', id
    ret_list = []
    timer_list = back.getTimerbyDict({})
    for item in timer_list:
        tmp_dic = {}
        info_dic = back.getTimerAllDictByObject(item)
        tmp_dic['name'] = info_dic[Timer.NAME]
        teacher_account = tch.idToAccountTeacher(info_dic[Timer.TEACHER_ID])
        tmp_dic['proposer'] = tch.getTeacher(teacher_account,
                                             Teacher.REAL_NAME)
        ret_list.append(tmp_dic)

        vol_dic = info_dic[Timer.VOLUNTEER_DIC]
        if str(id) in vol_dic.keys():
            tmp_dic['state'] = u'已填写'
        else:
            tmp_dic['state'] = u'未填写'
        tmp_dic['activity_id'] = info_dic[Timer.ID]
    dic['activity'] = ret_list
    return JsonResponse(dic)
Exemple #5
0
def get_activity_time(request):
    """
        后端应在此处根据活动的id返回该活动可选择的时间段
        然后放到下面样例写好的dic的'time'键对应的列表值中
        'checked'键表示上次选择的结果
    """
    if 'volunteer_id' not in request.session.keys():
        return redirect('/login/')
    vol_id = str(request.session.get('volunteer_id', -1))
    print 'ac_id=:', request.POST.get('activity_id')
    timer = back.getTimerbyDict(
        {Timer.ID: int(request.POST.get('activity_id'))})[0]
    info_dic = back.getTimerAllDictByObject(timer)
    (time_list,
     checked_list) = back.date_start_to_end(info_dic[Timer.START_TIME],
                                            info_dic[Timer.END_TIME])
    checked_list = []
    for item in time_list:
        checked_list.append('0')
    if vol_id in info_dic[Timer.VOLUNTEER_DIC].keys():
        checked_list = info_dic[Timer.VOLUNTEER_DIC][vol_id]
    dic = {'time': time_list, 'checked': checked_list}
    return JsonResponse(dic)