CRM客户关系管理系统(十二) 十二章、学员报名流程开发 2

十二章、学员报名流程开发 2

 12.1.学员报名合同和证件信息上传

功能:

  • 必须勾选报名合同协议
  • 必须上传个人证件信息
  • 最多只能上传三个文件
  • 文件大小2M以内
  • 列出已上传文件

(1)crm/urls.py

urlpatterns = [
        #上传个人证件信息
    url(r'^enrollment/(\d+)/fileupload/$', views.enrollment_fileupload,name='enrollment_fileupload'),
]

(2)crm./views.py

建一个上传文件的文件夹

import os,json

from django.views.decorators.csrf import csrf_exempt
from django import conf

@csrf_exempt
def enrollment_fileupload(request,enrollment_id):
    '''学员报名文件上传'''
    enrollment_upload_dir = os.path.join(conf.settings.CRM_FILE_UOLOAD_DIR,enrollment_id)
    #第一次上传图片就创建目录,学员上传第二章图片的时候,会判断目录是否已经存在
    #因为如果目录存在还mkdir就会报错,所以这里要做判断
    if not os.path.isdir(enrollment_upload_dir):
        os.mkdir(enrollment_upload_dir)
    #获取上传文件的对象
    file_obj = request.FILES.get('file')
    #最多只允许上传3个文件
    if len(os.listdir(enrollment_upload_dir)) <= 3:
        #把图片名字拼接起来(file.name:上传的文件名字)
        with open(os.path.join(enrollment_upload_dir,file_obj.name),'wb') as f:
            for chunks in file_obj.chunks():
                f.write(chunks)
    else:
        return HttpResponse(json.dumps({'status':False,'err_msg':'最多只能上传三个文件'}))

    return HttpResponse(json.dumps({'status':True,}),)


def enrollment(request,enrollment_id):
    '''学员在线报名表地址'''

    enrollment_obj = models.StudentEnrollment.objects.get(id=enrollment_id)

    if request.method == 'POST':
        customer_form = form.CustomerForm(instance=enrollment_obj.customer,data=request.POST)
        if customer_form.is_valid():
            customer_form.save()
            return HttpResponse("你已成功提交报名信息,请等待审核,欢迎加入仙剑奇侠传")
    else:
        customer_form = form.CustomerForm(instance=enrollment_obj.customer)

    # 列出学员已上传的文件
    upload_files = []
    enrollment_upload_dir = os.path.join(conf.settings.CRM_FILE_UOLOAD_DIR, enrollment_id)
    if os.path.isdir(enrollment_upload_dir):
        upload_files = os.listdir(enrollment_upload_dir)

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

 (3)settings.py

#学员个人信息图片上传路径
CRM_FILE_UOLOAD_DIR = os.path.join(BASE_DIR,'crm/upload_files/enrollment_data',)

(4)crm/enrollment.html

dropzone下载和使用

 css和js放到statics下面

{#templates/crm/enrollment.html#}

{% extends 'index.html' %}
{% load staticfiles %}

{% block extra-css %}
    <link rel="stylesheet" href="{% static 'plugins/dropzone/dropzone.css' %}">

{% endblock %}

{% block body %}

    <div class="container">
        <h3>仙剑奇侠传|学员报名</h3>

        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">学员在线报名</h3>
            </div>

            <div class="panel-body">

                <form class="form" method="post" onsubmit="return BeforeFormSubmit(this)">
                    {% csrf_token %}
                    {% for field in customer_form %}
                        <div class="form-group col-lg-6">
                            <label class="col-sm-2 control-label">{{ field.label }}</label>
                            <div class="col-sm-10">
                                {{ field }}
                                <span style="color: red;">{{ field.errors.0 }}</span>
                            </div>
                        </div>
                    {% endfor %}

                    <div class="form-group col-lg-6">
                        <label class="col-sm-2 control-label">报名班级</label>
                        <div class="col-sm-10">
                            {{ enrollment_obj.class_grade }}
                        </div>
                    </div>

                    <div class="form-group col-lg-6">
                        <label class="col-sm-2 control-label">学费</label>
                        <div class="col-sm-10">
                            {{ enrollment_obj.class_grade.course.price }}
                        </div>
                    </div>
                    <hr>
                    <pre style="height: 400px;">{{ enrollment_obj.class_grade.contract_template.content }}</pre>
                    <input type="checkbox" name="contract_agreed">我已认真阅读,无条件同意。

{#                    <div class="col-sm-offset-11 col-sm-2">#}
                        <input style="padding: 10px;" type="submit" class="btn btn-success col-sm-offset-11" value="提交">
{#                    </div>#}
                </form>
                <br>
                    <p style="color: blueviolet;">已上传文件列表</p>
                    <ul id="uploaded_files">
                        {% for file in upload_files %}
                            <li>{{ file }}</li>
                        {% endfor %}
                    </ul>


                 <form id="myAwesomeDropzone" action="{% url 'enrollment_fileupload' enrollment_obj.id %}" class="dropzone">
                  <div class="fallback">
                    <input name="file" type="file" multiple />
                  </div>
                </form>

            </div>

            <div class="panel-footer"><a href="http://www.cnblogs.com/derek1184405959/">zhang_derek</a></div>
        </div>


    </div>

<script>

    function BeforeFormSubmit(ele) {
        $(":disabled").removeAttr("disabled");

        if ($("#uploaded_files").children().length ==0){
            alert("请上传个人证件信息!")
            return false
        }

        if (!$("input[name='contract_agreed']").prop("checked")){
            alert("必须勾选仙剑奇侠传合同协议")
            return false
        }
        //return false;
    }

</script>

{% endblock %}

{% block extra-js %}
    <script src="{% static 'plugins/dropzone/dropzone.js' %}"></script>

 <script>

        // "myAwesomeDropzone" is the camelized version of the HTML element's ID
        Dropzone.options.myAwesomeDropzone = {
          paramName: "file", // The name that will be used to transfer the file
          maxFilesize: 2, // MB
          maxFiles:2,
          parallelUploads:1,
          accept: function(file, done) {
            if (file.name == "justinbieber.jpg") {
              done("Naha, you don't.");
            }
            else { done(); }
          }
        };

        $(function() {
          // Now that the DOM is fully loaded, create the dropzone, and setup the
          // event listeners
          // Prevent Dropzone from auto discovering this element:
          Dropzone.options.myAwesomeDropzone = false;
          var myDropzone = new Dropzone("#myAwesomeDropzone");
          myDropzone.on("success", function(file,response) {
            /* Maybe display some more file information on your page */
             console.log("completet", file, response);
             var response = JSON.parse(response);
             if (!response.status){
                 alert(response.err_msg);
             }else {
                 $("#uploaded_files").append("<li>"+ file.name +"</li>");

             }

          });
        })

    </script>

{% endblock %}

效果:

合同

 上传证件信息(直接把文件拖进去就可以了)

12.2.合同审核

 (1)学员提交报名信息后,把contract_agreed改为True,并保存提交的时间

(2)提交报名信息后,就应该是等待审核状态

(3)已经生产报名链接的,点“下一步”,跳转“合同审核”页面

  • 没有生产报名链接的点“下一步”,生产报名连接
  • 已经生成过的,点“下一步”,会报错,因为赢生成过了链接
  • 所以在这里要抓住这个异常,生成过的点“下一步”,应该是跳到“合同审核”页面

抓住异常

@login_required
def stu_enrollment(request):
    '''学员报名'''
    customers = models.CustomerInfo.objects.all()
    class_lists = models.ClassList.objects.all()

    if request.method == 'POST':
        #获取提交的客户id和班级id,然后生成报名链接
        customer_id = request.POST.get('customer_id')
        class_grade_id = request.POST.get('class_grade_id')
        try:
            enrollment_obj = models.StudentEnrollment.objects.create(
                customer_id = customer_id,
                class_grade_id = class_grade_id,
                consultant_id = request.user.userprofile.id
            )
        #已经生成过报名链接,就进入审核页面
        except IntegrityError as e:
            enrollment_obj = models.StudentEnrollment.objects.get(customer_id = customer_id,class_grade_id = class_grade_id)
            if enrollment_obj.contract_agreed:
                return redirect("/crm/stu_enrollment/%s/contract_audit/"% enrollment_obj.id)

        #生成链接返回到前端
        enrollment_link = "http://localhost:8000/crm/enrollment/%s"% enrollment_obj.id

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

 合同审核

(4)crm/urls.py

#合同审核
    url(r'^stu_enrollment/(\d+)/contract_audit/$', views.contract_audit,name='contract_audit'),

(5)crm/views.py

  • 获取到学员信息表单
  • 勾选审核后,提交
  • 后台:把学生加到对应班级里面
  • 把学生的状态改成报名
@login_required
def contract_audit(request,enrollment_id):
    '''合同审核'''

    enrollment_obj = models.StudentEnrollment.objects.get(id=enrollment_id)
    if request.method == 'POST':
        enrollment_form = form.EnrollmentForm(instance=enrollment_obj,data=request.POST)
        if enrollment_form.is_valid():
            enrollment_form.save()
            stu_obj = models.Student.objects.get_or_create(customer=enrollment_obj.customer)[0]
            #m2m, 添加班级
            stu_obj.class_grades.add(enrollment_obj.class_grade_id)
            stu_obj.save()
            #改变报名
            enrollment_obj.customer.status = 1
            enrollment_obj.save()
            return redirect("/kingadmin/crm/customerinfo/%s/change"%enrollment_obj.customer.id)
    else:
        #拿到客户信息的表单
        customer_form = form.CustomerForm(instance=enrollment_obj.customer)
        enrollment_form = form.EnrollmentForm(instance=enrollment_obj)
    return render(request,'crm/contract_audit.html',locals())

(6)crm/contract_audit.html

{#crm/contract_audit.html#}

{% extends 'index.html' %}

{% block right-content-container %}
<h3>学员报名|合同审核</h3>

<form class="form-horizontal" method="post" onsubmit="BeforeFormSubmit(this)">{% csrf_token %}

    {{ customer_form }}
    {{ enrollment_form }}

  <input type="submit" class="btn btn-success pull-right"  value="审核通过" >

</form>

<script>
    function BeforeFormSubmit(ele) {
        $(":disabled").removeAttr("disabled");
    }

</script>
{% endblock %}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏玄魂工作室

Hacker基础之Linux篇:一、系统简介

前言: 因为大佬玄魂最近比较忙,所以从今天开始我就在这个平台发布一些关于Hacker的基础知识,一开始准备了两个模块,一个是Linux基础,一...

43311
来自专栏FreeBuf

DeathStar:一键自动化域渗透工具

Empire和BloodHound这两个Github项目极大程度地简化了针对活动目录(AD)的渗透测试过程,至少在我当前所遇到的95%的环境中是这样的。随着年月...

2947
来自专栏腾讯技术工程官方号的专栏

支撑起腾讯公司计费业务的TDSQL(附PPT)

作者介绍:bluesea,腾讯金融云专家工程师,从事分布式数据库TDSQL研发工作。出版著作:《数据库查询优化器的艺术 原理解析与SQL性能优化》、《数据库事...

5618
来自专栏北京马哥教育

想要自己搭建NAS服务器?看这篇文章,小白也能学会!(二)

? 本文为《想要自己搭建NAS服务器?看这篇文章,小白也能学会!》的第二篇,本片主讲内容为NAS服务器...

3.1K6
来自专栏BestSDK

Oculus 发布1.5.0版 SDK,新增 Touch 功能

1.5.0 版本 SDK 的发布主要是引入了新的 Touch 的功能,以及为静态层添加了压缩格式的支持。 新特性 · SDK现在可以检测到用户的拇指是否接触到T...

2408
来自专栏SAP最佳业务实践

SAP最佳业务实践:SD–退货和投诉(111)-1业务概览

用途 该业务情景描述销售订单的退货处理 优点 系统集成处理客户的退货和投诉 处理流程中涉及的公司角色: 销售助理 仓库文员 应收会计 销售开票员 包含的关...

3765
来自专栏逸鹏说道

03.SQLServer性能优化之---存储优化系列

汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 概 述:http://www.cnblogs....

3025
来自专栏沃趣科技

容器化RDS|计算存储分离架构下的 IO 优化

在基于 Kubernetes 和 Docker 构建的私有 RDS 中,普遍采用了计算存储分离架构。该架构优势明显, 但对于数据库类 Latency Sensi...

3314
来自专栏北京马哥教育

想要自己搭建NAS服务器?看这篇文章,小白也能学会!(一)

? NAS即网络附加存储(Network Attached Storage),通过网络提供数据访问服务。 本人不推荐自攒NAS,稳定性差,迷你主板和家用机电源...

1.8K6
来自专栏IT大咖说

容器化RDS|计算存储分离架构下的 IO 优化

摘要 在基于 Kubernetes 和 Docker 构建的私有 RDS 中,普遍采用了计算存储分离架构。该架构优势明显, 但对于数据库类 Latency Se...

3618

扫码关注云+社区

领取腾讯云代金券