页面展示
完善个人信息
作用如下:
- 1、是完善之前销售录入有误的信息,例如年龄、身份证、紧急联系电话、转介绍人等,都可以再次纠正;
- 2、查看已报名的课程、价格、班级信息,不能修改。
urls.py
from django.conf.urls import url,include
from crm import views
urlpatterns = [
url(r'^enroll/(\d+)/$', views.student_enroll, name='student_enroll'),
]
forms.py
from django.forms import ModelForm
from crm.models import CustomerInfo
class CustomerInfoForm(ModelForm):
def __new__(cls, *args, **kwargs):
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)
class Meta:
model = CustomerInfo
fields = '__all__'
# 设置不提交字段
exclude = ['consult_content', 'contact_type', 'consultant', 'status', 'source','consult_course']
error_messages = {
'name': {
'required': "名字不能为空",
},
}
views.py
from crm.forms import CustomerInfoForm
from crm.models import StudentEnrollment, CustomerInfo
def student_enroll(request, id):
"""学生完善个人信息"""
# 1、根据取出学生报名对象
student_enroll = StudentEnrollment.objects.filter(id=int(id)).first()
# 2、获得咨询对象以及其他相关信息
customer_obj = student_enroll.customer
price = student_enroll.class_grade.course.price
class_grade = student_enroll.class_grade
course = class_grade.course
if request.method == 'GET':
# 3、实例化form对象
customer_form = CustomerInfoForm(instance=customer_obj)
# 4、获取用户已上传的文件信息
upload_files = []
from django import conf
import os
enrollment_upload_dir = os.path.join(conf.settings.ORM_PATH_DIR,id)
if os.path.isdir(enrollment_upload_dir):
upload_files=os.listdir(enrollment_upload_dir)
pass
elif request.method == 'POST':
# 5、实例化form
customer_form = CustomerInfoForm(instance=customer_obj, data=request.POST)
# 取出错误信息
errors = customer_form.errors
# 自定制errors错误信息
if not request.POST.get('contract_agreed', ''):
errors['contract_agreed'] = '必须勾选阅读'
if not request.POST.get('id_num', ''):
errors['id_num'] = '身份证号码必填'
if not request.POST.get('contact_info', ''):
errors['contact_info'] = '联系电话必填'
if not request.POST.get('emergency_contact', ''):
errors['emergency_contact'] = '紧急联系电话必填'
# 6、验证form表单数据输入是否合乎规则
if customer_form.is_valid():
# 7、排除重复填写此表单
if student_enroll.contract_agreed:
return HttpResponse('您的相关信息已提交至审核')
# 8、修改 合同签订属性和签订时间
student_enroll.contract_agreed = True
import datetime
student_enroll.contract_signed_time = datetime.datetime.now()
print(datetime.datetime.now())
# 9、保存学生报名信息
student_enroll.save()
# 10、保存咨询客户的信息
customer_form.save()
return HttpResponse('待审批....')
return render(request, 'crm/complete_info.html', locals())
前端页面
<form method="post" onsubmit="return before_submit(this)" novalidate>
{% for input_obj in customer_form %}
<div class="form-group">
{# 每行两列,则每列列宽为md-6 #}
<label for="inputEmail3" class="col-sm-2 control-label">{{ input_obj.label }}</label>
<div class="col-sm-4">
{{ input_obj }}<span class="error_tip">{{ input_obj.errors }}</span>
</div>
</div>
{% endfor %}
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">班级</label>
<div class="col-sm-4">
<span class="form-control">{{ class_grade }}</span>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">报名课程</label>
<div class="col-sm-4">
<span class="form-control">{{ course }}</span>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">价格</label>
<div class="col-sm-4">
<span class="form-control">{{ price }}</span>
</div>
</div>
<!-- 合同显示,记得加上pre 标签 -->
<pre style="width:100%;height: 400px">
{{ student_enroll.class_grade.contract_tempalte.content }}
</pre>
<!-- -->
<input type="checkbox" name="contract_agreed" id="agree_contract">
<label for="agree_contract">我已认真阅读以上合同条款,无异议。</label>
<span class="error_tip">{{ errors.contract_agreed }}</span>
<div class="col-md-12">
<input type="submit" class="btn btn-block btn-primary" value="确认" style="margin-top: 20px">
</div>
{% csrf_token %}
</form>
<script>
function before_submit(data) {
{#$('[name=consult_course]').prop('disabled',false);#}
// 若没有上传文件则不提交 并提示
if($('#upload_file_list').children().length==0){
alert('请上传相关证件信息');
return false
}
// 若没有勾选同意合同 则不提交并提示
if(!$('[name=contract_agreed]').prop('checked')){
alert('必须阅读并同意培训协议');
return false
}
}
</script>
关于dropzone插件参考:https://www.cnblogs.com/fqh202/p/9365340.html
原文地址:https://www.cnblogs.com/fqh202/p/9464289.html
时间: 2024-10-09 02:18:49