Ejemplo n.º 1
0
def create(request,template_name="oa/schedule/add_form.html"):
    """添加周课表"""
    user = request.user
    schools = helpers.get_schools(user)
    is_admin = helpers.is_school_admin(request.user)
    if is_admin:
        school_id = schools[0].id
        groups = Group.objects.filter(school_id=school_id).exclude(type=3)
    else:
        group_pks = [g.group_id for g in GroupTeacher.objects.filter(teacher=user.teacher)]
        groups = Group.objects.filter(pk__in=group_pks)
    group_count = groups.count()
    group_id = int(request.GET.get("class_id",-1))
    ctx = {'schools':schools,'groups':groups,'group_count':group_count}

    if request.method == 'POST':
        form = ScheduleForm(request.POST,request.FILES)
        group_id = request.POST.get("group","")
        if form.is_valid():
            schedule = form.save(commit=False)
            schedule.save()
            group = schedule.group
            messages.success(request, u'课表 %s 上传成功' % schedule.name)
            return redirect(request.get_full_path() + '?class_id=' + str(group.id))
    else:
        form = ScheduleForm()
    
    ctx.update({'form':form,"group_id":group_id})
    return render(request, template_name, ctx)
Ejemplo n.º 2
0
def create(request,template_name="schedule/add_form.html"):

    ctx = {}
    group_id = request.GET.get("class_id","")
    if request.method == 'POST':
        form = ScheduleForm(request.POST,request.FILES)
        if form.is_valid():
            schedule = form.save(commit=False)
            schedule.save()
            ctx.update({"group":schedule.group})
            messages.success(request, u'课表 %s 上传成功' % schedule.name)
    else:
        group = get_object_or_404(Group, pk=group_id)
        form = ScheduleForm()
        ctx.update({"group":group})

    ctx.update({'form':form})
    return render(request, template_name, ctx)