def setVolunteerGroupbyList(volunteer, id_list):
    try:
        vol_id = str(getattr(volunteer, Volunteer.ID))
    except:
        vol_id = str(1)

    group_all_list = back.getGroupbyDict({})
    for group in group_all_list:
        vol_list = back.getGroupAllDictByObject(group)[Group.VOL_LIST].split(
            '_')
        if vol_id in vol_list:
            vol_list.remove(vol_id)
        if '' in vol_list:
            vol_list.remove('')
        vol_string = '_'.join(vol_list)
        back.setGroup(group, Group.VOL_LIST, vol_string)

    for new_id in id_list:
        new_id = str(new_id)
        if len(back.getGroupbyDict({Group.ID: new_id})) <= 0:
            continue
        group = back.getGroupbyDict({Group.ID: new_id})[0]
        vol_list = back.getGroupAllDictByObject(group)[Group.VOL_LIST].split(
            '_')
        if '' in vol_list:
            vol_list.remove('')
        if vol_id in vol_list:
            print 'Big bug!'
        else:
            vol_list.append(vol_id)
        back.setGroup(group, Group.VOL_LIST, '_'.join(vol_list))
    return True
def setStudentGroupbyList(student, id_list):
    try:
        stu_id = str(getattr(student, Student.ID))
    except:
        stu_id = str(1)

    group_all_list = back.getGroupbyDict({})
    for group in group_all_list:
        stu_list = back.getGroupAllDictByObject(group)[Group.STU_LIST].split(
            '_')
        if stu_id in stu_list:
            stu_list.remove(stu_id)
        if '' in stu_list:
            stu_list.remove('')
        stu_string = '_'.join(stu_list)
        back.setGroup(group, Group.STU_LIST, stu_string)

    for new_id in id_list:
        new_id = str(new_id)
        if len(back.getGroupbyDict({Group.ID: new_id})) <= 0:
            continue
        group = back.getGroupbyDict({Group.ID: new_id})[0]
        stu_list = back.getGroupAllDictByObject(group)[Group.STU_LIST].split(
            '_')
        if '' in stu_list:
            stu_list.remove('')
        if stu_id in stu_list:
            print 'Big bug!'
        else:
            stu_list.append(stu_id)
        back.setGroup(group, Group.STU_LIST, '_'.join(stu_list))
    return True
示例#3
0
def new_message_to_group(request):
    # by dqn14 Nov 7, 2016
    # use this if-else to block violent access
    if request.is_ajax() and request.method == 'POST':
        try:
            title = request.POST.get('title')
            target_group = request.POST.get('group_val')
            text = request.POST.get('maintext')
            teacher_id = request.session.get('teacher_id', -1)
            print title, target_group, text, teacher_id

            group = back.getGroupbyDict({Group.ID: int(target_group)})[0]
            stu_id_list_str = getattr(group, Group.STU_LIST).split('_')
            if '' in stu_id_list_str:
                stu_id_list_str.remove('')
            stu_id_list = []
            for item in stu_id_list_str:
                stu_id_list.append(int(item))

            back.createNoticebyDict({Notice.TITLE: title,
                                     Notice.TEXT: text,
                                     Notice.TEACHER_ID: int(teacher_id),
                                     Notice.RECEIVE_STU: stu_id_list})
            t = {}
            t['success']='Y'
            t['message']=u'发布成功'
            return JsonResponse(t)

        except:
            t = {}
            t['success']='N'
            t['message']=u'发布失败'
            return JsonResponse(t)
    else:
        return HttpResponse('Access denied.')
示例#4
0
def batch_add_to_group(request):
    # by dqn14 Nov 7, 2016
    # use this if-else to block violent access
    if request.is_ajax() and request.method == 'POST':
        stu_num = int(request.POST.get('student_num'))
        group_id = int(request.POST.get('group'))    # This is a string

        key_list = []
        for i in range(0, stu_num):
            key_list.append('student_id_%s'%(str(i)))
        id_list = []
        for item in key_list:
            id_list.append(int(request.POST.get(item)))

        group = back.getGroupbyDict({Group.ID: group_id})[0]
        stu_list = getattr(group, Group.STU_LIST).split('_')
        if '' in stu_list:
            stu_list.remove('')
        for item in id_list:
            item = str(item)
            if item not in stu_list:
                stu_list.append(item)

        back.setGroup(group, Group.STU_LIST, '_'.join(stu_list))


        t = {}
        if stu_num > 0:
            t['success'] = 'Y'
        else:
            t['success']='N'
            t['message']='该组已满'
        return JsonResponse(t)
    else:
        return HttpResponse('Access denied.')
def removeStudentAccount(_account):
    stu_id = str(accountToIDStudent(_account))
    group_list = back.getGroupbyDict({})
    for group in group_list:
        stu_list = getattr(group, Group.STU_LIST).split('_')
        if stu_id in stu_list:
            stu_list.remove(stu_id)
        if '' in stu_list:
            stu_list.remove('')
        back.setGroup(group, Group.STU_LIST, '_'.join(stu_list))
    getAllInStudent().filter(account=_account).delete()
def getVolunteerGroupIDListString(volunteer):
    try:
        vol_id = getattr(volunteer, Volunteer.ID)
    except:
        vol_id = 1

    group_all_list = back.getGroupbyDict({})
    id_list = []
    for group in group_all_list:
        vol_list = back.getGroupAllDictByObject(group)[Group.VOL_LIST].split(
            '_')
        if str(vol_id) in vol_list:
            id_list.append(str(getattr(group, Group.ID)))
    return ' '.join(id_list)
def getStudentGroupIDListString(student):
    stu_id = 0
    try:
        stu_id = getattr(student, Student.ID)
    except:
        stu_id = 1

    group_all_list = back.getGroupbyDict({})
    id_list = []
    for group in group_all_list:
        stu_list = back.getGroupAllDictByObject(group)[Group.STU_LIST].split(
            '_')
        if str(stu_id) in stu_list:
            id_list.append(str(getattr(group, Group.ID)))
    return ' '.join(id_list)
示例#8
0
def get_grouplist(request):
    # by dqn14 Nov 7, 2016
    # use this if-else to block violent access
    if request.is_ajax() and request.method == 'POST':
        group_list = back.getGroupbyDict({})
        ret_list = []
        t = [{'value':'', 'string':''}]
        for group in group_list:
            group_info = back.getGroupAllDictByObject(group)
            group_id = group_info[Group.ID]
            group_name = group_info[Group.NAME]
            t.append({'value': str(group_id), 'string': '%s:%s'%(str(group_id), str(group_name))})
        return JsonResponse(t, safe=False)
    else:
        return HttpResponse('Access denied.')
def get_can_see_students(vol_id):
    all_group = back.getGroupbyDict({})
    stu_id_list = []
    for group in all_group:
        vol_list = getattr(group, Group.VOL_LIST).split('_')
        if '' in vol_list:
            vol_list.remove('')
        if str(vol_id) in vol_list:
            tmp_list = getattr(group, Group.STU_LIST).split('_')
            stu_id_list = stu_id_list + tmp_list

    ret = []
    for _id in stu_id_list:
        if _id != '':
            try:
                ret.append(int(_id))
            except:
                pass
    return ret
def removeVolunteerAccount(_account):

    vol_id = str(accountToIDVolunteer(_account))
    group_list = back.getGroupbyDict({})
    for group in group_list:
        vol_list = getattr(group, Group.VOL_LIST).split('_')
        if vol_id in vol_list:
            vol_list.remove(vol_id)
        if '' in vol_list:
            vol_list.remove('')
        back.setGroup(group, Group.VOL_LIST, '_'.join(vol_list))

    timer_list = back.getTimerbyDict({})
    for timer in timer_list:
        timer_dic = eval(getattr(timer, Timer.VOLUNTEER_DIC, '{}'))
        if vol_id in timer_dic.keys():
            timer_dic.pop(vol_id)
        back.setTimer(timer, Timer.VOLUNTEER_DIC, timer_dic)
    getAllInVolunteer().filter(account=_account).delete()
示例#11
0
def set_volunteer(request):
    # by dqn14 Nov 2, 2016
    # use this if-else to block violent access
    if request.is_ajax() and request.method == 'POST':
        group_id = int(request.POST.get('group_id'))
        student_id_num = request.POST.get('student_num')

        vol_list = vol.getVolunteerbyField(Volunteer.STUDENT_ID, student_id_num)
        if len(vol_list) == 0:
            t = {}
            t['success'] = 'N'
            t['message'] = u'不存在这个志愿者,请重新输入学号,亲'
            return JsonResponse(t)

        volunteer = vol_list[0]
        vol_id = getattr(volunteer, Volunteer.ID)
        try:
            group = back.getGroupbyDict({Group.ID: group_id})[0]
        except:
            t = {}
            t['success'] = 'N'
            t['message'] = u'真的有这个组吗,老师?'
            return JsonResponse(t)

        vol_list = back.getGroupAllDictByObject(group)[Group.VOL_LIST].split('_')
        if '' in vol_list:
            vol_list.remove('')

        if str(vol_id) not in vol_list:
            vol_list.append(str(vol_id))

        back.setGroup(group, Group.VOL_LIST, '_'.join(vol_list))


        t = {}
        t['success']='Y'
        t['message']=u'设置成功'
        return JsonResponse(t)
    else:
        return HttpResponse('Access denied.')