Esempio n. 1
0
def class_add_or_edit(request, edit_id=None):
    edit_obj = models.ClassList.objects.filter(id=edit_id).first()
    form_obj = ClassForm(instance=edit_obj)

    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=edit_obj)
        if form_obj.is_valid():
            form_obj.save()

            # 获取要跳转的地址
            next_url = request.GET.get('next')
            if next_url:
                # 跳转到这个地址
                return redirect(next_url)

            return redirect(reverse('class'))

    title = '编辑班级' if edit_id else '添加班级'

    return render(
        request, 'crm/teacher/add_or_edit.html', {
            'form_obj': form_obj,
            'edit_id': edit_id,
            'user': request.user,
            'title': title,
            'next_url': reverse('my_class')
        })
Esempio n. 2
0
def classes(request, edit_id=None):
    obj = models.ClassList.objects.filter(id=edit_id).first()
    form_obj = ClassForm(instance=obj)
    title = '编辑班级' if obj else '新增班级'
    print(request.POST)
    # if request.method == 'POST':
    #     form_obj = ClassForm(request.POST,instance=obj)
    #     if form_obj.is_valid():
    #         form_obj.save()
    #
    #         next = request.GET.get('next')
    #         if next:
    #             return redirect(next)
    #         return redirect(reverse('class_list'))

    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            next = request.GET.get('next')
            if next:
                return redirect(next)
            return redirect(reverse('class_list'))

    return render(request, 'crm/form.html', {
        'title': title,
        'form_obj': form_obj
    })
Esempio n. 3
0
def class_change(request, edit_id=None):
    obj = models.Classlist.objects.filter(pk=edit_id).first()
    form_obj = ClassForm(instance=obj)
    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('class_list'))
    return render(request, 'class_edit.html', {'form_obj': form_obj})
Esempio n. 4
0
def classes(request, edit_id=None):
    obj = models.ClassList.objects.filter(pk=edit_id).first()
    form_obj = ClassForm(instance=obj)
    title = '编辑班级' if edit_id else '新增班级'
    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(rev_url(request, 'class_list'))
    return render(request, 'form.html', {'form_obj': form_obj, 'title': title})
Esempio n. 5
0
def class_list(request, edit_id=None):
    class_obj = ClassList.objects.filter(id=edit_id).first()
    form_obj = ClassForm(instance=class_obj)
    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=class_obj)
        if form_obj.is_valid():
            form_obj.save()
            next_url = request.GET.get('next')
            if next_url:
                return redirect(next_url)
            else:
                return redirect(reverse('crm:class_list'))
    return render(request, 'crm/teacher/class.html', {'form_obj': form_obj})
Esempio n. 6
0
def op_class(request, edit_id=None):
    # 获取信息
    edit_obj = ClassList.objects.filter(pk=edit_id).first()
    form_obj = ClassForm(instance=edit_obj)
    if request.method == 'POST':
        form_obj = ClassForm(request.POST, instance=edit_obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('crm:class_list'))
    return render(request, 'class/op_class.html', {
        'form_obj': form_obj,
        'edit_id': edit_id
    })