1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| def ci_test(request): try: if request.POST.has_key("send"): xml_string="" final_xml = "" file_obj = request.FILES.get('file', None) for keys in request.POST: if request.POST[keys]: print keys,request.POST[keys] xml_string = "<%s>%s</%s>n%s" % (keys,request.POST[keys],keys,xml_string) final_xml = "<root>n%s</root>" % xml_string dirname = os.path.dirname(os.path.abspath(__file__)) parent = os.path.split(dirname)[0] if request.POST["source"] == "text" and file_obj: if file_obj.name.endswith(".txt"): filepath = "%s/core/emaillist.txt" % parent open(filepath,'w').write(file_obj.read()) else: raise forms.ValidationError("上传文件类型错误!") path = "%s/core/config/%s.xml" % (parent,request.POST['txtDate']) open(path,'w').write(final_xml.encode('utf-8')) else: smtp = request.POST['smtp'] username = request.POST['username'] passwd = request.POST['passwd'] title = request.POST['title'] content = request.POST['content'] attach = request.POST['useattach'] ctype = request.POST['c_type'] testsend = request.POST['testsend'] subtem = u"%s: %s" % (u"测试",title) conn = creat_conn(smtp, username, passwd) tem = testsend.split(';') if ctype.upper() == "HTML": final_body = creat_htmlbody(content) final_testmail(subtem,final_body,username,tem,conn,attach) print "test send to %s sucess!" % tem else: final_testmail(subtem,content,username,tem,conn,"test") print "test send to %s sucess!" % tem return render(request,'test.html',{"msg":"请求已经提交,关闭本页面即可"}) except forms.ValidationError: print "in my error" return render(request,'test.html',{{"msg":"文件类型错误,请重新操作!"}}) except Exception: return render(request,'test.html',{{"msg":"发生错误,请重新操作!"}})
|