Exemplo n.º 1
0
def update(request, workgroup_id, template_name="oa/workgroup_form.html"):
    ctx = {}
    school = get_schools(request.user)[0]
    teachers = Teacher.objects.filter(school=school)
    workgroup = get_object_or_404(WorkGroup,pk=workgroup_id)
    ty = workgroup.type
    member_pks = [m.id for m in workgroup.members.all()]
    
    if request.method == 'POST':
        form = WorkGroupForm(request.POST,instance=workgroup)
        if form.is_valid():
            workgroup = form.save(commit=False)
            workgroup.save()
            
            member_pks = request.POST.getlist('to')
            print member_pks,'mmmmmmmmmmmmm'
            members = [t for t in User.objects.filter(pk__in=member_pks)]
            workgroup.members = members
            messages.success(request, u'已成功更新 %s ' % workgroup.name)
            return redirect('oa_workgroup_list')
    else:
        form = WorkGroupForm(instance=workgroup)
        
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'member_pks':member_pks,'workgroup':workgroup,'ty':0,'schools':schools})
    return render(request, template_name, ctx)
Exemplo n.º 2
0
def personal_create(request,template_name="oa/workgroup_form.html"):
    ctx = {}
    school = get_schools(request.user)[0]
    teachers = Teacher.objects.filter(school=school)
    
    if request.method == 'POST':
        form = WorkGroupForm(request.POST)
        if form.is_valid():
            workgroup = form.save(commit=False)
            workgroup.school = school
            workgroup.type = 1
            workgroup.user = request.user
            workgroup.save()
            
            member_pks = request.POST.getlist('to')
            members = [t for t in User.objects.filter(pk__in=member_pks)]
            workgroup.members = members
            messages.success(request, u'已成功创建 %s ' % workgroup.name)
            return redirect('oa_workgroup_personal')
    else:
        form = WorkGroupForm()
    
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'ty':1,'schools':schools})
    return render(request, template_name, ctx)