예제 #1
0
파일: group.py 프로젝트: nuannuanwu/weixiao
def update(request, group_id, template_name="oa/class_form.html"):
    """更新班级"""
    ctx = {}
    schools = get_schools(request.user)
    group = get_object_or_404(Group,pk=group_id,school__in=schools)
    if request.method == 'POST':
        form = ClassForm(request.POST, instance=group, user=request.user)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            group = form.save(commit=False)
            group.save()
            class_teacher = request.POST.getlist('class_teacher')
            set_class_teacher(group,class_teacher)
            guide_teacher = request.POST.getlist('guide_teacher')
            set_guide_teacher(group,guide_teacher)
            messages.success(request, u"已成功更新班级: %s " % group.name)
            redirect_url = reverse('oa_class_list') + "?sid=" + str(group.school.id)
            return redirect(redirect_url)

    else:
        school = group.school
        form = ClassForm(instance=group,  user=request.user)
        teachers = school.teacher_set.all()
        class_teachers = teachers
        ctx.update({'teachers':teachers,'class_teachers':class_teachers})
    
    schools = get_schools(request.user)
    schools = [s for s in schools if not s.parent_id==0]
    ctx.update({"form": form, "group": group,"school":school,"schools":schools})
    return render(request, template_name, ctx)
예제 #2
0
파일: group.py 프로젝트: nuannuanwu/weixiao
def create(request,template_name="oa/class_form.html"):
    """创建班级"""
    ctx = {}
    schools = get_schools(request.user)
    schools = [s for s in schools if not s.parent_id==0]
    
    if request.method == 'POST':
        form = ClassForm(request.POST,user=request.user)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            group = form.save(commit=False)
            group.creator = request.user
            group.save()
            ctx.update({"school":group.school})
            if group.id:
                class_teacher = request.POST.getlist('class_teacher')
                set_class_teacher(group,class_teacher)
                guide_teacher = request.POST.getlist('guide_teacher')
                set_guide_teacher(group,guide_teacher)
                messages.success(request, u'已成功创建班级 %s ' % group.name)
                redirect_url = reverse('oa_class_list') + "?sid=" + str(group.school.id)
                return redirect(redirect_url)
    else:
        form = ClassForm(user=request.user)
    ctx.update({'form':form,'schools':schools})
    return render(request, template_name, ctx)