Пример #1
0
def class_change(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(reverse_url(request, 'class_list'))
    return render(request, 'form.html', {'form_obj': form_obj, 'title': title})
Пример #2
0
def edit_consult(request, edit_id):
    obj = models.ConsultRecord.objects.filter(pk=edit_id).first()

    form_obj = ConsultForm(instance=obj)

    if request.method == 'POST':
        form_obj = ConsultForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse_url(request, 'consult_list'))

    return render(request, 'edit_consult.html', {'form_obj': form_obj})
Пример #3
0
def add_consult(request):
    obj = models.ConsultRecord(consultant=request.user_obj)

    form_obj = ConsultForm(instance=obj)

    if request.method == 'POST':
        form_obj = ConsultForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse_url(request, 'consult_list'))

    return render(request, 'add_consult.html', {'form_obj': form_obj})
Пример #4
0
def course_record_change(request, class_id=None, record_id=None):
    obj = models.CourseRecord.objects.filter(
        pk=record_id).first() if record_id else models.CourseRecord(
            re_class_id=class_id, teacher=request.user_obj)
    form_obj = CourseRecordForm(instance=obj)
    title = '编辑课程记录' if record_id else '添加课程记录'
    if request.method == 'POST':
        form_obj = CourseRecordForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(
                reverse_url(request, 'course_record_list', class_id))
    return render(request, 'form.html', {'form_obj': form_obj, 'title': title})
Пример #5
0
def enrollment_change(request, customer_id=None, enrollment_id=None):
    obj = models.Enrollment.objects.filter(
        pk=enrollment_id).first() if enrollment_id else models.Enrollment(
            customer_id=customer_id)

    form_obj = EnrollmentForm(instance=obj)
    if request.method == 'POST':
        form_obj = EnrollmentForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()

            return redirect(reverse_url(request, 'enrollment_list'))
    title = '编辑报名记录' if enrollment_id else '新增报名记录'
    return render(request, 'form.html', {'form_obj': form_obj, 'title': title})
Пример #6
0
def add_customer(request):
    # 实例化CustomerForm
    form_obj = CustomerForm()

    if request.method == 'POST':
        # 1. 将前端提交的数据交给CustomerForm对象 并实例化
        form_obj = CustomerForm(request.POST)
        # 2. 对数据进行校验
        if form_obj.is_valid():
            # 2.1 校验成功执行新增
            form_obj.save()
            # 2.2 新增成功跳转到客户展示页面
            return redirect(reverse_url(request, 'customer_list'))

    return render(request, 'consultant/add_customer.html', {'form_obj': form_obj})
Пример #7
0
def edit_customer(request, edit_id):
    obj = models.Customer.objects.filter(pk=edit_id).first()

    form_obj = CustomerForm(instance=obj)

    if request.method == 'POST':
        # 有修改的数据和原始的数据
        form_obj = CustomerForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()

            return redirect(reverse_url(request, 'customer_list'))

    return render(request, 'consultant/edit_customer.html',
                  {'form_obj': form_obj})
Пример #8
0
def add_customer(request):
    # 创建一个没有数据的Form
    form_obj = CustomerForm()

    if request.method == 'POST':
        # 创建一个包含提交数据的Form
        form_obj = CustomerForm(request.POST)
        # 对数据进行校验
        if form_obj.is_valid():
            form_obj.save()  # 新增

            return redirect(reverse_url(request, 'customer_list'))

    return render(request, 'consultant/add_customer.html',
                  {'form_obj': form_obj})
Пример #9
0
def edit_customer(request, edit_id):
    # 1. 从数据库中查询出要修改的客户对象
    obj = models.Customer.objects.filter(pk=edit_id).first()
    # 2. 将客户交给Form对象并实例化(为了在编辑页面展示原始数据)
    form_obj = CustomerForm(instance=obj)

    if request.method == 'POST':
        # 3. 提交修改后数据的和原始的数据
        form_obj = CustomerForm(request.POST, instance=obj)
        # 4. 校验提交的数据
        if form_obj.is_valid():
            # 4.1 校验成功保存
            form_obj.save()
            # 4.2 跳转到客户展示页面
            return redirect(reverse_url(request, 'customer_list'))

    return render(request, 'consultant/edit_customer.html', {'form_obj': form_obj})