|
@@ -257,7 +257,8 @@ def add_class(request):
|
|
|
uid = request.user.id
|
|
|
qdata = request.json
|
|
|
#need_params = ["name","subject_id","subject_item","signup_limit","remark"]
|
|
|
- need_params = ["name","subject_item","signup_limit","remark"]
|
|
|
+ #need_params = ["name","subject_id","subject_item","signup_limit","remark"]
|
|
|
+ need_params = ["name","subject_id","signup_limit","remark"]
|
|
|
mse = ccf.check_params(*need_params,**qdata)
|
|
|
if mse:
|
|
|
raise ce.TipException(mse)
|
|
@@ -265,7 +266,8 @@ def add_class(request):
|
|
|
need_params.append("remind")
|
|
|
vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
vals["cid"] = uid
|
|
|
- vals["subject_name"] = vals["subject_item"].split("|")[0]
|
|
|
+ vals["subject_id"] = json.dumps(vals["subject_id"])
|
|
|
+ #vals["subject_name"] = vals["subject_item"].split("|")[0]
|
|
|
obj = cm.Class.objects.create(**vals)
|
|
|
return obj.id
|
|
|
|
|
@@ -750,6 +752,15 @@ def update_signup(request):
|
|
|
else:
|
|
|
send_training_notice(phone,subject_item,begin_time,end_time)
|
|
|
cn.send_training_notice(user_id,subject_item,begin_time,end_time)
|
|
|
+ #更新用户信息
|
|
|
+ uid = cm.SignupOrders.objects.filter(id=_id).first().user_id
|
|
|
+ userinfo = cm.UserInfo.objects.filter(id=uid).first().userinfo
|
|
|
+ userinfo = json.loads(userinfo) if userinfo else {}
|
|
|
+ #if userinfo:
|
|
|
+ # vals.update(userinfo)
|
|
|
+ userinfo.update(vals)
|
|
|
+ cm.UserInfo.objects.filter(id=uid).update(userinfo=json.dumps(userinfo))
|
|
|
+
|
|
|
vals["cid"] = uid
|
|
|
vals["update_time"] = datetime.datetime.now()
|
|
|
obj = cm.SignupOrders.objects.filter(id__in=ids).update(**vals)
|
|
@@ -847,13 +858,19 @@ def get_subject_tree(sub=None,data=None):
|
|
|
for citem in roots:
|
|
|
citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
for rn in roots:
|
|
|
+ rn["label"] = rn["name"]
|
|
|
+ rn["value"] = rn["id"]
|
|
|
children = list(cm.Subject.objects.filter(pid=rn["id"]).values())
|
|
|
for citem in children:
|
|
|
+ citem["label"] = citem["name"]
|
|
|
+ citem["value"] = citem["id"]
|
|
|
citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
rn["children"] = children
|
|
|
for rnn in rn["children"]:
|
|
|
children = list(cm.Subject.objects.filter(pid=rnn["id"]).values())
|
|
|
for citem in children:
|
|
|
+ citem["label"] = citem["name"]
|
|
|
+ citem["value"] = citem["id"]
|
|
|
citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
rnn["children"] = children
|
|
|
return roots
|
|
@@ -959,6 +976,18 @@ def get_subject_info(request):
|
|
|
rst = cm.Subject.objects.filter(id=id).values().first()
|
|
|
return rst
|
|
|
|
|
|
+
|
|
|
+def get_subject_ids(subject_id,data=None):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ data = data if data else []
|
|
|
+ data.append(int(subject_id))
|
|
|
+ #subobj = cm.Subject.objects.filter(pid=subject_id).first()
|
|
|
+ subobjs = cm.Subject.objects.filter(pid=subject_id)
|
|
|
+ for subobj in subobjs:
|
|
|
+ get_subject_ids(subobj.id,data)
|
|
|
+ return data
|
|
|
+
|
|
|
def get_signup_list(request):
|
|
|
"""
|
|
|
"""
|
|
@@ -968,7 +997,11 @@ def get_signup_list(request):
|
|
|
if qdata.get("train_type"):
|
|
|
qset = qset.filter(train_type=qdata.get("train_type"))
|
|
|
if qdata.get("subject_item"):
|
|
|
- qset = qset.filter(subject_item__icontains=qdata.get("subject_item"))
|
|
|
+ subject_item = qdata.get("subject_item").split("|")[-1]
|
|
|
+ subject_id = cm.Subject.objects.filter(name=subject_item).first().id
|
|
|
+ subject_ids = get_subject_ids(subject_id)
|
|
|
+ #qset = qset.filter(subject_item__icontains=qdata.get("subject_item"))
|
|
|
+ qset = qset.filter(subject_id__in=subject_ids)
|
|
|
if qdata.get("name"):
|
|
|
qset = qset.filter(name__icontains=qdata.get("name"))
|
|
|
if qdata.get("idno"):
|
|
@@ -1005,13 +1038,21 @@ def get_signup_list(request):
|
|
|
qset = qset.filter(order_status=qdata.get("order_status"))
|
|
|
if qdata.get("class_id"):
|
|
|
qset = qset.filter(class_id=qdata.get("class_id"))
|
|
|
- page = qdata.get("page",1)
|
|
|
- page_size = qdata.get("page_size",20)
|
|
|
|
|
|
- total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+ qset1 = qset.filter(status=1).exclude(order_status=7).order_by("-update_time")
|
|
|
+
|
|
|
+ qset2 = qset.filter(status=1,order_status=7).order_by("-update_time")
|
|
|
+
|
|
|
+ data = list(qset1.values())+list(qset2.values())
|
|
|
+
|
|
|
+ page = int(qdata.get("page",1))
|
|
|
+ page_size = int(qdata.get("page_size",20))
|
|
|
+
|
|
|
+ #total,qset = ccc.get_page_qset(qset,page,page_size)
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
|
|
|
#data = list(qset.values("name","phone","order_status","remark","subject_item","train_type","ctime","id"))
|
|
|
- data = list(qset.values())
|
|
|
+ #data = list(qset.values())
|
|
|
for d in data:
|
|
|
if d["train_time_start"] and d["train_time_end"]:
|
|
|
d["train_time"] = ccf.datetime_to_str(d["train_time_start"])+","+ccf.datetime_to_str(d["train_time_end"])
|
|
@@ -1024,15 +1065,15 @@ def get_signup_list(request):
|
|
|
d["signup_time"] = d["pay_time"]
|
|
|
return total,data
|
|
|
|
|
|
-def get_subject_ids(subject_id,data=None):
|
|
|
- """
|
|
|
- """
|
|
|
- data = data if data else []
|
|
|
- data.append(int(subject_id))
|
|
|
- subobj = cm.Subject.objects.filter(id=subject_id).first()
|
|
|
- if subobj and int(subobj.pid):
|
|
|
- get_subject_ids(subobj.pid,data)
|
|
|
- return data
|
|
|
+#def get_subject_ids(subject_id,data=None):
|
|
|
+# """
|
|
|
+# """
|
|
|
+# data = data if data else []
|
|
|
+# data.append(int(subject_id))
|
|
|
+# subobj = cm.Subject.objects.filter(id=subject_id).first()
|
|
|
+# if subobj and int(subobj.pid):
|
|
|
+# get_subject_ids(subobj.pid,data)
|
|
|
+# return data
|
|
|
|
|
|
|
|
|
#def get_signup_info(request):
|
|
@@ -1404,50 +1445,56 @@ def download_zip(request):
|
|
|
tpl_4 = os.path.join(root,"apply_template_tzsb.docx")
|
|
|
files = []
|
|
|
for o in qset:
|
|
|
- subject_item = o.subject_item
|
|
|
- if u"特种作业" in subject_item:
|
|
|
- doc = DocxTemplate(tpl_1)
|
|
|
- elif u"负责人" in subject_item:
|
|
|
- doc = DocxTemplate(tpl_2)
|
|
|
- elif u"特种设备" in subject_item:
|
|
|
- doc = DocxTemplate(tpl_4)
|
|
|
- else:
|
|
|
- doc = DocxTemplate(tpl_3)
|
|
|
- subject_item0 = o.subject_item.split("|")[0]
|
|
|
- subject_item1 = o.subject_item.split("|")[1]
|
|
|
- subject_item2 = o.subject_item.split("|")[2]
|
|
|
- subject_item_code = re.search(r"\w+",subject_item2).group()
|
|
|
- fname = u"{}_{}.docx".format(o.name,subject_item2)
|
|
|
- #fname = u"{}.docx".format(o.name)
|
|
|
- #fname = unicode(fname,"utf-8")
|
|
|
- fname = os.path.join(root,fname)
|
|
|
- birthday = "{}-{}-{}".format(o.idno[6:10],o.idno[10:12],o.idno[12:14])
|
|
|
- idnoimg_face = o.idnoimg_face.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
- idnoimg_back = o.idnoimg_back.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
- education_img = o.education_img.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
- oldcard_img = o.oldcard_img.replace(settings.HOST,settings.STATIC_ROOT) if o.oldcard_img else None
|
|
|
- classhour_cert_url = o.classhour_cert_url.replace(settings.HOST,settings.STATIC_ROOT) if o.classhour_cert_url else None
|
|
|
- halfbody_img = o.halfbody_img.replace(settings.HOST,settings.STATIC_ROOT) if o.halfbody_img else None
|
|
|
- context = {"name":o.name,"sex":o.sex,"education":o.education,"idno":o.idno,"class_id":o.class_id,
|
|
|
- "company":o.company,"phone":o.phone,"train_type":o.train_type,"subject_item1":subject_item1,
|
|
|
- "subject_item2":subject_item2,"train_time_start":o.train_time_start,"subject_item_code":subject_item_code,
|
|
|
- "train_time_end":o.train_time_end,"birthday":birthday,
|
|
|
- "idnoimg_face":InlineImage(doc,idnoimg_face,height=Mm(82.5),width=Mm(140.66)),
|
|
|
- "idnoimg_back":InlineImage(doc,idnoimg_back,height=Mm(82.5),width=Mm(140.66)),
|
|
|
- "halfbody_img":InlineImage(doc,halfbody_img,height=Mm(40.97),width=Mm(28.91)),
|
|
|
- "education_img":InlineImage(doc,education_img,height=Mm(82.5),width=Mm(140.66))
|
|
|
- }
|
|
|
- if oldcard_img and o.train_type in [u"复审",u"换证"]:
|
|
|
- context.update({
|
|
|
- "oldcard_img":InlineImage(doc,oldcard_img,height=Mm(82.5),width=Mm(140.66))
|
|
|
- })
|
|
|
- if classhour_cert_url:
|
|
|
- context.update({
|
|
|
- "classhour_cert_url":InlineImage(doc,classhour_cert_url,height=Mm(82.5),width=Mm(140.66))
|
|
|
- })
|
|
|
- doc.render(context)
|
|
|
- doc.save(fname)
|
|
|
- files.append(fname)
|
|
|
+ try:
|
|
|
+ subject_item = o.subject_item
|
|
|
+ if u"特种作业" in subject_item:
|
|
|
+ doc = DocxTemplate(tpl_1)
|
|
|
+ elif u"负责人" in subject_item:
|
|
|
+ doc = DocxTemplate(tpl_2)
|
|
|
+ elif u"特种设备" in subject_item:
|
|
|
+ doc = DocxTemplate(tpl_4)
|
|
|
+ else:
|
|
|
+ doc = DocxTemplate(tpl_3)
|
|
|
+ subject_item0 = o.subject_item.split("|")[0]
|
|
|
+ subject_item1 = o.subject_item.split("|")[1]
|
|
|
+ subject_item2 = o.subject_item.split("|")[2]
|
|
|
+ try:
|
|
|
+ subject_item_code = re.search(r"\w+",subject_item2).group()
|
|
|
+ except:
|
|
|
+ subject_item_code = ""
|
|
|
+ fname = u"{}_{}.docx".format(o.name,subject_item2)
|
|
|
+ #fname = u"{}.docx".format(o.name)
|
|
|
+ #fname = unicode(fname,"utf-8")
|
|
|
+ fname = os.path.join(root,fname)
|
|
|
+ birthday = "{}-{}-{}".format(o.idno[6:10],o.idno[10:12],o.idno[12:14])
|
|
|
+ idnoimg_face = o.idnoimg_face.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
+ idnoimg_back = o.idnoimg_back.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
+ education_img = o.education_img.replace(settings.HOST,settings.STATIC_ROOT)
|
|
|
+ oldcard_img = o.oldcard_img.replace(settings.HOST,settings.STATIC_ROOT) if o.oldcard_img else None
|
|
|
+ classhour_cert_url = o.classhour_cert_url.replace(settings.HOST,settings.STATIC_ROOT) if o.classhour_cert_url else None
|
|
|
+ halfbody_img = o.halfbody_img.replace(settings.HOST,settings.STATIC_ROOT) if o.halfbody_img else None
|
|
|
+ context = {"name":o.name,"sex":o.sex,"education":o.education,"idno":o.idno,"class_id":o.class_id,
|
|
|
+ "company":o.company,"phone":o.phone,"train_type":o.train_type,"subject_item1":subject_item1,
|
|
|
+ "subject_item2":subject_item2,"train_time_start":o.train_time_start,"subject_item_code":subject_item_code,
|
|
|
+ "train_time_end":o.train_time_end,"birthday":birthday,
|
|
|
+ "idnoimg_face":InlineImage(doc,idnoimg_face,height=Mm(82.5),width=Mm(140.66)),
|
|
|
+ "idnoimg_back":InlineImage(doc,idnoimg_back,height=Mm(82.5),width=Mm(140.66)),
|
|
|
+ "halfbody_img":InlineImage(doc,halfbody_img,height=Mm(40.97),width=Mm(28.91)),
|
|
|
+ "education_img":InlineImage(doc,education_img,height=Mm(82.5),width=Mm(140.66))
|
|
|
+ }
|
|
|
+ if oldcard_img and o.train_type in [u"复审",u"换证"]:
|
|
|
+ context.update({
|
|
|
+ "oldcard_img":InlineImage(doc,oldcard_img,height=Mm(82.5),width=Mm(140.66))
|
|
|
+ })
|
|
|
+ if classhour_cert_url:
|
|
|
+ context.update({
|
|
|
+ "classhour_cert_url":InlineImage(doc,classhour_cert_url,height=Mm(82.5),width=Mm(140.66))
|
|
|
+ })
|
|
|
+ doc.render(context)
|
|
|
+ doc.save(fname)
|
|
|
+ files.append(fname)
|
|
|
+ except Exception as e:
|
|
|
+ continue
|
|
|
else:
|
|
|
files = []
|
|
|
data = {}
|