码迷,mamicode.com
首页 > 其他好文 > 详细

CRM权限管理(4)、报名流程3-销售审核信息

时间:2018-08-12 21:29:24      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:update   mod   label   列表   local   djang   log   val   head   

审核列表

技术分享图片

urls

from django.conf.urls import url,include
from crm import views

urlpatterns = [
    url(r'^audit_list/$', views.audit_list, name='audit_list'), 
]

views.py

from django.shortcuts import render


@login_required
def audit_list(request):
    """待审核学员列表页面"""
    # 1、直接从 StudentEnrollment 筛选出所有同意合同但是没有审核通过的对象
    audit_stu_list = StudentEnrollment.objects.filter(contract_agreed=1,contract_approved=0)
    return render(request,'crm/audit_list.html',locals())

audit_list.html

# 页面1
<table class="table table-bordered">
    <thead>
        <tr>
           <td>学号</td>
           <td >姓名</td>
           <td >班级</td>
        </tr>
    </thead>

    <tbody>
        {% for stu in audit_stu_list %}
        <tr>
            <td><a href="{% url 'audit' stu.id %}">{{ stu.id }}</a></td>
            <td>{{ stu.customer.name }}</td>
            <td>{{ stu.class_grade }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

审核详情页

技术分享图片

urls.py

from django.conf.urls import url,include
from crm import views

urlpatterns = [
   url(r'^audit_list/(\d+)/$', views.audit, name='audit')
]

forms.py

class StudentEnrollForm(ModelForm):
    """信息完善form"""

    class Meta:
        model = StudentEnrollment
        fields = '__all__'
        readonly_fields = ['customer', 'consultant', 'class_grade', 'contract_agreed', 'contract_signed_time']

    def __new__(cls, *args, **kwargs):
        """方法2:在实例化类对象(model_form())的时候给input框增加样式"""
        for field_name, field_obj in cls.base_fields.items():
            field_obj.widget.attrs.update({'class': 'form-control'})

            # 设定只读字段disabled属性
            if field_name in cls.Meta.readonly_fields:
                field_obj.widget.attrs.update({'disabled': True})

        return ModelForm.__new__(cls)

views.py

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from crm.models import StudentEnrollment

@login_required
def audit(request,id):
    """审核学员"""
    student_enroll = StudentEnrollment.objects.filter(id=int(id)).first()
    customer_obj = student_enroll.customer
    from .forms import StudentEnrollForm
    student_enroll_form = StudentEnrollForm(instance=student_enroll)

    if request.method=='POST':
        student_enroll_form = StudentEnrollForm(instance=student_enroll,data=request.POST)
        if student_enroll.contract_approved:
           return HttpResponse('该学员已经通过审核')
        
        if student_enroll_form.data.get('contract_approved',''):
            student_enroll.contract_approved=True
            student_enroll.contract_approved_time=datetime.datetime.now()
            # 修改咨询客户的报名状态
            customer_obj.status=1
            customer_obj.save()
            student_enroll.save()
            return redirect('/crm/audit_list/')

    return render(request,'crm/audit_student_enroll.html',locals())

前端页面

<form method="post">
    {% csrf_token %}
    {% for input_obj in student_enroll_form %}
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">{{ input_obj.label }}</label>
            <div class="col-sm-10">
                {{ input_obj }}
            </div>
        </div>
    {% endfor %}
    <input class="btn btn-success btn-block" type="submit" value="审核通过">
</form>

CRM权限管理(4)、报名流程3-销售审核信息

标签:update   mod   label   列表   local   djang   log   val   head   

原文地址:https://www.cnblogs.com/fqh202/p/9464290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!