def del_group(request): response = {"success": False, "error": ""} try: # 校验参数 group_name = request.POST.get("groupName", None) if group_name is None or str(group_name).strip() == "": response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") # 执行删除操作 group = Group.objects(name=group_name) if len(group) == 0: response["error"] = "未找到该模块!" return HttpResponse(json.dumps(response), mimetype="application/json") else: group.delete() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def check_brach_info(self): # 获取portal所有分支对象 branchs = BranchInfo.objects() svn_utils = SvnUtils() exist = 0 unknown = 0 not_exist = 0 for item in branchs: svn_url = SvnUtils.get_svn_url(item.programName, item.branchTag) flag = None try: flag = svn_utils.svn_url_exists(svn_url) except Exception as e: logger.error(getTraceBack()) logger.error('校验BranchInfo[id=%s][url=%s]异常![%s]' % (str(item.id), svn_url, e.message)) item.is_exist = flag item.save() if flag is True: exist += 1 elif flag is False: not_exist += 1 else: unknown += 1 logger.info('校验BranchInfo对象成功!共计[%s]条!有效路径[%s]条!无效路径[%s]条!未知路径[%s]条!' % (len(branchs), exist, not_exist, unknown))
def compiling_record_del(request): response = {"success": False, "error": ""} try: # 校验参数 id = request.POST.get("id", None) if id is None or str(id).strip() == "": response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") # 执行删除操作 record = CompilingUpdateRecord.objects(pk=id) if len(record) == 0: response["error"] = "未找到该记录!" return HttpResponse(json.dumps(response), mimetype="application/json") record = record[0] record.delete() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def serverMonitor_type_save(request): response = {"success": False, "error": ""} if request.method == "POST": try: monitor_setting = json.loads(request.POST.get('json')) setting_id = monitor_setting["setting_id"] setting_name = monitor_setting["setting_name"] setting_detail = monitor_setting["setting_detail"] name_type = monitor_setting["name_type"] if setting_name is None or setting_name == "" or setting_detail is None or setting_detail == "": response["success"] = False response["error"] = "执行失败,必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") if name_type == "add": setting = ServerMonitorLogType() setting.log_type = setting_name setting.detail = setting_detail setting.create_user = User.objects.get(pk=request.user.id) setting.create_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") setting.save() elif name_type == "edit": setting = ServerMonitorLogType.objects.get(pk=setting_id) setting.log_type = setting_name setting.detail = setting_detail setting.create_user = User.objects.get(pk=request.user.id) setting.create_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") setting.save() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "[%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def sync_svn_info(self): svn_dict = {} # 获取portal所有分支对象 branchs = BranchInfo.objects(programName__in=[TT_SERVICE, QUOTER, XT_TRADE_CLIENT, TT_MANAGEMENT_PORTAL, DEAMON, UPDATER]) client = pysvn.Client() revision_start = pysvn.Revision(pysvn.opt_revision_kind.head) revision_end = pysvn.Revision(pysvn.opt_revision_kind.number, 0) limit = 1 for item in branchs: svn_url = SvnUtils.get_svn_url(item.programName, item.branchTag) try: # get last svn log data = client.log(svn_url, revision_start=revision_start, revision_end=revision_end, limit=limit)[0].data svn_revision = data['revision'].number svn_author = data['author'] svn_message = data.get('message', '') svn_commit_time = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(data['date'])) svn_dict[svn_url] = [str(svn_revision), '%s %s %s -> %s' % (svn_revision, svn_commit_time, svn_author, svn_message)] except Exception as e: logger.error(getTraceBack()) logger.error('同步SVN信息[url:%s]异常![%s]' % (svn_url, e.message)) global _svn_dict _svn_dict = svn_dict logger.info('同步SVN信息成功!共计[%s]条!' % len(_svn_dict))
def gdbm_view(request): if request.method == "GET": search_key = request.GET.get('search_key', None) host = request.GET.get('host', None) port = request.GET.get('port', None) strDb = 'XtTradeData' param_key = {'strDb': strDb} param_value = {} if host and port: r = RPCClient(host=host, port=int(port)) keys = r.request('getAllKeys', param_key).values()[0] results = [] for item in keys: if re.search(search_key, item): param_value = {'strDb': strDb, 'strKey': item} ret = r.request('readData', param_value).values()[0] results.append([item, json.dumps(ret)]) return render_to_response("demo/gdbm_view.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def delete_package(request): """ 删除版本 :param request: :return: """ response = {"success": False, "error": ""} try: package_id = request.POST.get('id', None) if package_id is None: response['error'] = "版本ID为空!" return HttpResponse(json.dumps(response), mimetype="application/json") package = Package.objects(pk=package_id) if len(package) == 0: response['error'] = "未获取到版本对象[id=%s]" % package_id return HttpResponse(json.dumps(response), mimetype="application/json") package = package[0] package.delete() response['success'] = True response['error'] = '删除成功!' return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response['error'] = "程序异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def redis_view(request): if request.method == "GET": search_key = request.GET.get('search_key', None) host = request.GET.get('host', None) port = request.GET.get('port', None) if search_key: r = redis.StrictRedis(host=host, port=int(port), db=0) keys = r.keys(search_key) results = [] for item in keys: results.append([ item, json.dumps(BSON(zlib.decompress(r.get(item))).decode()) ]) return render_to_response("demo/redis_view.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def key_del(request): if request.method == "POST": response = {"success": False, "error": ""} try: id = request.POST.get('id', None) if not id: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype='application/json') submit = KeySubmit.objects(pk=id).first() if not submit: response['error'] = '未找到对象!' return HttpResponse(json.dumps(response), mimetype='application/json') submit.delete() response['success'] = True response['error'] = '执行成功!' return HttpResponse(json.dumps(response), mimetype='application/json') except Exception as e: response['error'] = '程序异常![%s]' % e.message logger.error(response['error'] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype='application/json') else: response = {"success": False, "error": "请使用http-post方法请求!"} return HttpResponse(json.dumps(response), mimetype="application/json")
def videoPost(request): """ 提交视频信息 :param request: :return: """ if request.method == "GET": return render_to_response("demo/videoUpload.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": True, "error": "上传成功!"} try: # 获取参数 tittle = request.POST.get("tittle", None) description = request.POST.get("description", None) url = request.POST.get("url", None) create_time = datetime.datetime.now() create_user = User.objects.get(pk=request.user.id) # 保存视频信息 logInfo = VideoInfo() logInfo.tittle = tittle logInfo.description = description logInfo.create_time = create_time logInfo.create_user = create_user logInfo.attachment_url = url logInfo.save() return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response["success"] = False response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def get_branch_from_url(svn_url): """ 根据SVN链接获取BranchInfo对象 :param svn_url: :return: """ try: arr = None if svn_url.find('/server5/') > 0: arr = svn_url.split(SVN_ROOT + 'server5/')[1].split('/', 1) else: arr = svn_url.split(SVN_ROOT)[1].split('/', 1) program_name = arr[0] branch_tag = arr[1] branch_info = BranchInfo.objects(programName=program_name, branchTag=branch_tag) if len(branch_info) == 0: logger.error( '根据SVN:[url=%s][program_name=%s][branch_tag=%s]获取BranchInfo对象为空!' % (svn_url, program_name, branch_tag)) return None return branch_info[0] except Exception as e: logger.error('根据SVN:[url=%s]获取BranchInfo对象异常![%s]' % (svn_url, getTraceBack())) return None
def gdbm_view(request): if request.method == "GET": search_key = request.GET.get("search_key", None) host = request.GET.get("host", None) port = request.GET.get("port", None) strDb = "XtTradeData" param_key = {"strDb": strDb} param_value = {} if host and port: r = RPCClient(host=host, port=int(port)) keys = r.request("getAllKeys", param_key).values()[0] results = [] for item in keys: if re.search(search_key, item): param_value = {"strDb": strDb, "strKey": item} ret = r.request("readData", param_value).values()[0] results.append([item, json.dumps(ret)]) return render_to_response("demo/gdbm_view.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def redis_view(request): if request.method == "GET": search_key = request.GET.get("search_key", None) host = request.GET.get("host", None) port = request.GET.get("port", None) if search_key: r = redis.StrictRedis(host=host, port=int(port), db=0) keys = r.keys(search_key) results = [] for item in keys: results.append([item, json.dumps(BSON(zlib.decompress(r.get(item))).decode())]) return render_to_response("demo/redis_view.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def getStockAndTrade(request): try: saveToFile() command = "cd %s; tar -zcf datas.tar.gz datas" % (StockAndTradePATH) os.system(command) except Exception as e: error = "下载文件异常![getStockAndTrade][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
def create(request): """ 创建用户 :param request: :return: """ if request.method == "GET": groups = UserGroup.objects.all() return render_to_response("user/user_create.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: # 获取参数 json_str = request.POST.get('json', None) if not json_str: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") json_obj = json.loads(json_str) username = json_obj.get('username', None) password = json_obj.get('password', None) group_str = json_obj.get('group', None) telphone = json_obj.get('telphone', None) email = json_obj.get('email', None) is_staff = json_obj.get('is_staff', None) is_active = json_obj.get('is_active', None) if not username or not password: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") # UserGroup group = UserGroup.objects(key=group_str) if not group: response['error'] = '非法用户组!' return HttpResponse(json.dumps(response), mimetype="application/json") group = group[0] # User if User.objects(username=username): response['error'] = '用户名已存在!' return HttpResponse(json.dumps(response), mimetype="application/json") user_obj = User.create_user(username, password, group.key, telphone=telphone, is_staff=is_staff, is_active=is_active, is_superuser=True if group.key == USER_GROUP_ADMIN else False, email=email if email else None) response["id"] = str(user_obj.id) response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def StockAndTrade(request): try: file0 = StockAndTradeDIR dirs = os.listdir(file0) if request.method == "GET": return render_to_response("demo/downStockAndTrade.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = "下载文件异常![StockAndTrade][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
def getStockAndTrade(request): try: saveToFile() command = "cd %s; tar -zcf datas.tar.gz datas" % (StockAndTradePATH) os.system(command) except Exception as e: error = "下载文件异常![getStockAndTrade][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def run(self): while True: try: self.lock.acquire() self.check_brach_info() self.lock.release() except Exception as e: logger.error(e.message) logger.error(getTraceBack()) finally: time.sleep(self.sleep_time)
def run(self): while True: try: self.lock.acquire() self.sync_svn_info() self.lock.release() except Exception as e: logger.error(e.message) logger.error(getTraceBack()) finally: time.sleep(self.sleep_time)
def del_module(request): response = {"success": False, "error": ""} try: # 校验参数 module_id = request.POST.get("moduleId", None) if module_id is None or str(module_id).strip() == "": response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") path = request.path is_sys = None if path == '/customer/system/list/': is_sys = True elif path == '/customer/list/': is_sys = False else: is_sys = False customers = Customer.objects(is_sys=is_sys).order_by('+tag') error = request.GET.get("error", None) # 执行删除操作 module = Module.objects(pk=module_id) if len(module) == 0: response["error"] = "未找到该模块!" return HttpResponse(json.dumps(response), mimetype="application/json") module = module[0] for item in module.files: if not isinstance(item, DBRef): item.delete() for item in module.runInfos: if not isinstance(item, DBRef): item.delete() for customer in customers: cus_modules = customer.modules for cus_module in cus_modules: if module.name == cus_module.name: response["error"] = "此模块被客户[%s]使用,不能删除!" % str( customer.name) return HttpResponse(json.dumps(response), mimetype="application/json") module.delete() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def showBaseSoft(request): try: DIR = "/home/ftpuser/linux_soft/" file0 = DIR + "soft" file1 = DIR + "soft.tar.gz" dirs = os.listdir(file0) return render_to_response("demo/soft_view.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = "下载文件异常![show_base_soft][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
def logPost(request): """ 提交日志信息 :param request: :return: """ if request.method == "GET": customer = Customer.objects() serverMonitorLogType = ServerMonitorLogType.objects() serverMonitorModule = ServerMonitorModule.objects() return render_to_response("serverMonitor/logPost.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": True, "error": "上传成功!"} try: #获取参数 cus_name = request.POST.get('cus_name', None) customer = Customer.objects.get(pk=cus_name) log_type = request.POST.get('log_type', None) log_type = ServerMonitorLogType.objects.get(pk=log_type) monitor_type = request.POST.get('monitor_type', None) module_type = request.POST.get('module_type', None) module = ServerMonitorModule.objects.get(module=module_type) detail = request.POST.get('detail', None) url = request.POST.get('url', None) create_time = datetime.datetime.now() create_user = User.objects.get(pk=request.user.id) # 保存监控日志信息 logInfo = ServerMonitorLog() logInfo.cus = customer logInfo.log_type = log_type logInfo.monitor_type = int(monitor_type) logInfo.module_type = module logInfo.detail = detail logInfo.create_time = create_time logInfo.cus_uuid = customer.machines[0].code logInfo.create_user = create_user logInfo.attachment_url = url logInfo.save() return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response["success"] = False response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def StockAndTrade(request): try: file0 = StockAndTradeDIR dirs = os.listdir(file0) if request.method == 'GET': return render_to_response("demo/downStockAndTrade.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = "下载文件异常![StockAndTrade][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def get_branch_info(self): try: program_name, branch_tag = self._get_program_name_and_branch_tag() branch_info = BranchInfo.objects(programName=program_name, branchTag=branch_tag) if len(branch_info) == 0: logger.error( '根据SVN:[url=%s][program_name=%s][branch_tag=%s]获取BranchInfo对象为空!' % (self.svn_url, program_name, branch_tag)) return None return branch_info[0] except Exception as e: logger.error('根据SVN:[url=%s]获取BranchInfo对象异常![%s][%s]' % (self.svn_url, e.message, getTraceBack())) return None
def showBaseSoft(request): try: DIR = "/home/ftpuser/linux_soft/" file0 = DIR + "soft" file1 = DIR + "soft.tar.gz" dirs = os.listdir(file0) return render_to_response("demo/soft_view.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = "下载文件异常![show_base_soft][%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def downloadZip(request): try: DIR = "/home/ftpuser/linux_soft/" file1 = DIR + "soft.tar.gz" fp0 = open(file1, "r") content = fp0.read() size = len(content) response = HttpResponse(content) response["Content-Length"] = size response["Content-Disposition"] = "attachment; filename=%s" % "soft.tar.gz" return response except Exception as e: error = "下载文件异常![%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
def monitorModule_del(request): response = {"success": False, "error": ""} if request.method == "POST": try: setting_id = request.POST.get("settingId", None) setting = ServerMonitorModule.objects(pk=setting_id) setting = setting[0] setting.delete() response["success"] = True response["error"] = "删除成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "[%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def create(request): """ 创建版本 :param request: :return: """ if request.method == "GET": return render_to_response("package/package_create.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": ""} try: file_obj = request.FILES.get('uploadFile', None) file_name = file_obj.name file_size = file_obj.size #json_info = request.POST.get('json') remark = request.GET.get('remark') package_version = request.GET.get('package_version') package = Package() package.version = package_version #package.json_info = json.dumps(json.loads(json_info), ensure_ascii=False).encode(ENCODE) package.is_enabled = True package_suffix = file_name[file_name.rindex('.') + 1:] #写入流文件 package.package.put(file_obj, content_type=CONTENT_TYPE[package_suffix]) #文件名 package.package_full_name = file_name package.package_name = file_name[0:file_name.rindex('.')] package.package_suffix = package_suffix package.package_size = file_size package.remark = remark package.upload_user = User.objects(pk=request.user.id)[0] package.create_time = datetime.datetime.now() package.source = SOURCE_UPLOAD package.save() response["success"] = True response["id"] = str(package.id) response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def downStockAndTrade(request): try: file1 = StockAndTradePATH + "datas.tar.gz" fp0 = open(file1, "r") content = fp0.read() size = len(content) response = HttpResponse(content) response["Content-Length"] = size response["Content-Disposition"] = "attachment; filename=%s" % "datas.tar.gz" return response except Exception as e: error = "下载文件异常![%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
def list(request): """ 版本列表 :param request: :return: """ try: packages = Package.objects().order_by('-create_time') return render_to_response("package/package_list.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = "程序异常![%s]" % (str(e)) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def login_on_server(request, user): try: if user is None: user = request.user if SESSION_KEY in request.session: if request.session[SESSION_KEY] != user.id: request.session.flush() else: request.session.cycle_key() request.session[SESSION_KEY] = user.id request.session[BACKEND_SESSION_KEY] = user.backend if hasattr(request, 'user'): request.user = user user.last_login = datetime.datetime.now() user.save() except Exception, e: logger.error(str(e) + getTraceBack()) raise e
def view(request): if request.method == "GET": try: cus_id = request.GET.get("cus_id", None) if cus_id is None: error = '查看用户时ID为空!' logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) return render_to_response("customer/customer_create.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = '查看用户异常![%s]' % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) elif request.method == 'POST': error = "非法请求方式!" logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def downloadZip(request): try: DIR = "/home/ftpuser/linux_soft/" file1 = DIR + "soft.tar.gz" fp0 = open(file1, "r") content = fp0.read() size = len(content) response = HttpResponse(content) response['Content-Length'] = size response[ 'Content-Disposition'] = 'attachment; filename=%s' % 'soft.tar.gz' return response except Exception as e: error = "下载文件异常![%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def downStockAndTrade(request): try: file1 = StockAndTradePATH + "datas.tar.gz" fp0 = open(file1, "r") content = fp0.read() size = len(content) response = HttpResponse(content) response['Content-Length'] = size response[ 'Content-Disposition'] = 'attachment; filename=%s' % 'datas.tar.gz' return response except Exception as e: error = "下载文件异常![%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def delete(request): response = {"success": False, "error": ""} try: # 校验参数 id = request.POST.get('id', None) if not id: response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") user = User.objects.get(pk=id) user.delete() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def sync_svn_info(self): svn_dict = {} # 获取portal所有分支对象 branchs = BranchInfo.objects(programName__in=[ TT_SERVICE, QUOTER, XT_TRADE_CLIENT, TT_MANAGEMENT_PORTAL, DEAMON, UPDATER ]) client = pysvn.Client() revision_start = pysvn.Revision(pysvn.opt_revision_kind.head) revision_end = pysvn.Revision(pysvn.opt_revision_kind.number, 0) limit = 1 for item in branchs: svn_url = SvnUtils.get_svn_url(item.programName, item.branchTag) try: # get last svn log data = client.log(svn_url, revision_start=revision_start, revision_end=revision_end, limit=limit)[0].data svn_revision = data['revision'].number svn_author = data['author'] svn_message = data.get('message', '') svn_commit_time = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(data['date'])) svn_dict[svn_url] = [ str(svn_revision), '%s %s %s -> %s' % (svn_revision, svn_commit_time, svn_author, svn_message) ] except Exception as e: logger.error(getTraceBack()) logger.error('同步SVN信息[url:%s]异常![%s]' % (svn_url, e.message)) global _svn_dict _svn_dict = svn_dict logger.info('同步SVN信息成功!共计[%s]条!' % len(_svn_dict))
def view(request): if request.method == 'GET': try: is_view = True module_id = request.GET.get("module_id", None) if module_id is None or module_id == '': error = "模块ID为空!" logger.error(error) return render_to_response( "item/temp.html", locals(), context_instance=RequestContext(request)) module = Module.objects(pk=module_id) if len(module) == 0: error = "模块[ID=%s]并不存在!" % module_id logger.error(error) return render_to_response( "item/temp.html", locals(), context_instance=RequestContext(request)) groups = Group.objects() module = module[0] return render_to_response("module/module_create.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = '查看模块信息异常[%s]' % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) elif request.method == 'POST': error = "非法请求方式!" logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def createGroup(request): if request.method == "GET": return render_to_response("module/group_create.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: # 获取参数 request_json = json.loads(request.POST.get("json")) now = datetime.datetime.now() # 校验参数 group_name = request_json["groupName"] group = None if group_name is not None: group = Group.objects(name=group_name) if len(group) == 0: group = Group() group.name = group_name group.createTime = now group.save() else: response["error"] = "组名称重复!" logger.error(response["error"]) return HttpResponse(json.dumps(response), mimetype="application/json") response["success"] = True response["id"] = str(group.id) response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def download_package(request): """ 下载版本 :param request: :return: """ try: package_id = request.GET.get('id', None) if package_id is None: error = "版本ID为空!" logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) package = Package.objects(pk=package_id) if len(package) == 0: error = "未获取到版本对象[id=%s]" % package_id logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) package = package[0] content = package.package.read() size = len(content) response = HttpResponse(content) response['Content-Length'] = size response[ 'Content-Disposition'] = 'attachment; filename=%s' % package.package_full_name.encode( 'utf-8') return response except Exception as e: error = "下载文件异常![%s]" % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request))
def change_status(request): """ 改变状态 :param request: :return: """ response = {"success": False, "error": ""} try: path = request.path is_enabled = None if path == '/package/enable/': is_enabled = True elif path == '/package/disable/': is_enabled = False package_id = request.POST.get('id', None) if package_id is None: response['error'] = "版本ID为空!" return HttpResponse(json.dumps(response), mimetype="application/json") package = Package.objects(pk=package_id) if len(package) == 0: response['error'] = "未获取到版本对象[id=%s]" % package_id return HttpResponse(json.dumps(response), mimetype="application/json") package = package[0] package.is_enabled = is_enabled package.save() response['success'] = True response['error'] = '启用成功!' if is_enabled else '禁用成功!' return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response['error'] = "程序异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def get_branch_from_url(svn_url): """ 根据SVN链接获取BranchInfo对象 :param svn_url: :return: """ try: arr = None if svn_url.find('/server5/') > 0: arr = svn_url.split(SVN_ROOT + 'server5/')[1].split('/', 1) else: arr = svn_url.split(SVN_ROOT)[1].split('/', 1) program_name = arr[0] branch_tag = arr[1] branch_info = BranchInfo.objects(programName=program_name, branchTag=branch_tag) if len(branch_info) == 0: logger.error('根据SVN:[url=%s][program_name=%s][branch_tag=%s]获取BranchInfo对象为空!' % (svn_url, program_name, branch_tag)) return None return branch_info[0] except Exception as e: logger.error('根据SVN:[url=%s]获取BranchInfo对象异常![%s]' % (svn_url, getTraceBack())) return None
def serverMonitor_type_save(request): response = {"success": False, "error": ""} if request.method == "POST": try: monitor_setting = json.loads(request.POST.get('json')) setting_id = monitor_setting["setting_id"] setting_name = monitor_setting["setting_name"] setting_detail = monitor_setting["setting_detail"] name_type = monitor_setting["name_type"] if setting_name is None or setting_name == "" or setting_detail is None or setting_detail == "": response["success"] = False response["error"] = "执行失败,必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") if name_type == "add": setting = ServerMonitorLogType() setting.log_type = setting_name setting.detail = setting_detail setting.create_user = User.objects.get(pk=request.user.id) setting.create_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") setting.save() elif name_type == "edit": setting = ServerMonitorLogType.objects.get(pk=setting_id) setting.log_type = setting_name setting.detail = setting_detail setting.create_user = User.objects.get(pk=request.user.id) setting.create_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") setting.save() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "[%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def login(request): if request.method == "GET": logger.info('跳转到登陆界面') if request.user.id is None: return render_to_response("login.html", locals(), context_instance=RequestContext(request)) return render_page(request, "index.html", locals()) else: logger.info('点击登陆') response = {"success": False, "error": ""} try: username = request.POST.get("username") password = request.POST.get("password") user = authenticate(username=username, password=password) if user: # 判断是否允许登陆 is_staff = user.is_staff is_active = user.is_active is_superuser = user.is_superuser if not is_staff: response["error"] = "禁止登陆!" return HttpResponse(json.dumps(response), mimetype="application/json") if not is_active: response["error"] = "用户未启用!" return HttpResponse(json.dumps(response), mimetype="application/json") login_on_server(request, user) response["success"] = True response["error"] = "执行成功!" else: response["error"] = "登陆失败!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response["error"] = str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def edit(request): """ 编辑用户 :param request: :return: """ if request.method == "GET": try: # 标记编辑 is_edit = True id = request.GET.get("id", None) if id is None: error = '必要参数为空!' logger.error(error) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) user_obj = User.objects.get(pk=id) groups = UserGroup.objects.all() return render_to_response("user/user_create.html", locals(), context_instance=RequestContext(request)) except Exception as e: error = '编辑用户异常![%s]' % str(e) logger.error(error + getTraceBack()) return render_to_response('item/temp.html', locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: # 获取参数 json_str = request.POST.get('json', None) if not json_str: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") json_obj = json.loads(json_str) user_id = json_obj.get('user_id', None) password = json_obj.get('password', None) group_str = json_obj.get('group', None) email = json_obj.get('email', None) is_staff = json_obj.get('is_staff', None) is_active = json_obj.get('is_active', None) if not user_id or not password: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") # UserGroup group = UserGroup.objects(key=group_str) if not group: response['error'] = '非法用户组!' return HttpResponse(json.dumps(response), mimetype="application/json") group = group[0] # User user = User.objects(pk=user_id) if not user: response['error'] = '用户未找到!' return HttpResponse(json.dumps(response), mimetype="application/json") user = user[0] user.password = make_password(password) user.group = group.key user.email = email if email else None user.is_staff = is_staff user.is_active = is_active user.is_superuser = True if group.key == USER_GROUP_ADMIN else False user.save() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def get_branch_info(self): try: program_name, branch_tag = self._get_program_name_and_branch_tag() branch_info = BranchInfo.objects(programName=program_name, branchTag=branch_tag) if len(branch_info) == 0: logger.error('根据SVN:[url=%s][program_name=%s][branch_tag=%s]获取BranchInfo对象为空!' % (self.svn_url, program_name, branch_tag)) return None return branch_info[0] except Exception as e: logger.error('根据SVN:[url=%s]获取BranchInfo对象异常![%s][%s]' % (self.svn_url, e.message, getTraceBack())) return None
def operate(request): """ SVN相关操作 :param request: :return: """ response = {"success": False, "error": ""} if request.method == "POST": try: # 获取参数 cmd = request.POST.get('cmd', None) id = request.POST.get('id', None) if not cmd or not id: response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") branch = BranchInfo.objects(pk=id) if len(branch) == 0: response["error"] = "未找到对象!" return HttpResponse(json.dumps(response), mimetype="application/json") branch = branch[0] path = getLocalDir(branch.programName) + "/" + branch.branchTag # 直接删除URL,无须变更操作目录 if cmd != 'delete': os.chdir(path) if cmd == 'update': p = Popen(["svn", "up"], stdin=PIPE, stdout=PIPE, stderr=PIPE) outStr, errorStr = p.communicate() if len(errorStr) > 0: response["error"] = '更新失败![%s]' % errorStr return HttpResponse(json.dumps(response), mimetype="application/json") elif cmd == 'clean': p = Popen(["make", "clean"], stdin=PIPE, stdout=PIPE, stderr=PIPE) p.wait() elif cmd == 'compile': p = Popen(["make", "-j8", "all"], stdin=PIPE, stdout=PIPE, stderr=PIPE) outStr, errorStr = p.communicate() if len(errorStr) > 0: response["error"] = '编译失败![%s]' % errorStr return HttpResponse(json.dumps(response), mimetype="application/json") elif cmd == 'delete': svn_url = SvnUtils.get_svn_url(branch.programName, branch.branchTag) logger.info('删除目录 : [%s]!' % svn_url) if SvnUtils().svn_url_exists(svn_url): p = Popen(["svn", "delete", "-m", "%s delete %s" % (User.objects.get(pk=request.user.id).username, svn_url), svn_url], stdin=PIPE, stdout=PIPE, stderr=PIPE) outStr, errorStr = p.communicate() if len(errorStr.strip()) > 0 and not str(errorStr).startswith('svn: E160013:'): response["error"] = '删除失败![%s]' % errorStr return HttpResponse(json.dumps(response, ensure_ascii=False), mimetype="application/json") branch.delete() response["id"] = id else: response["error"] = "限制操作!" return HttpResponse(json.dumps(response), mimetype="application/json") response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def key_create(request): if request.method == "GET": branchs = BranchInfo.objects().order_by('-programName', 'branchTag') program_list = [] tag_dict = {} for branch in branchs: program_name = branch.programName if program_name in tag_dict: tag_dict[program_name].append({ 'id': str(branch.id), 'tag': branch.branchTag }) else: program_list.append(program_name) tag_dict[program_name] = [{'id': str(branch.id), 'tag': branch.branchTag}] program_list_json = json.dumps(program_list) tag_dict_json = json.dumps(tag_dict) return render_to_response("programBranch/key_submit_create.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": ""} try: # 获取参数 json_str = request.POST.get('json', None) if not json_str: response['error'] = '必要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") json_obj = json.loads(json_str) remark = json_obj['remark'] id = json_obj['id'] revision_1 = int(json_obj['revision_1']) revision_2 = json_obj['revision_2'] revision_2 = revision_1 if revision_2 is None else int(revision_2) branch = BranchInfo.objects(pk=id) if not branch: response['error'] = '未找到分支对象!' return HttpResponse(json.dumps(response), mimetype="application/json") branch = branch[0] # 验证是否重叠 exists = KeySubmit.objects(branch=branch, revision_start__lte=revision_1, revision_end__gte=revision_2) if exists: response['error'] = '关键提交重叠!' return HttpResponse(json.dumps(response), mimetype="application/json") key_submit = KeySubmit() key_submit.branch = branch key_submit.revision_start = revision_1 key_submit.revision_end = revision_2 key_submit.remark = remark key_submit.create_time = datetime.datetime.now() key_submit.create_user = User.objects.get(pk=request.user.id) key_submit.save() response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def svn_list_read(request): response = {"success": False, "error": ""} if request.method == "GET": try: id = request.GET.get('id', None) revision_start_number = request.GET.get('revision_start', None) revision_end_number = request.GET.get('revision_end', None) limit = int(request.GET.get('limit', 30)) if not id: response['error'] = '你要参数为空!' return HttpResponse(json.dumps(response), mimetype="application/json") branch = BranchInfo.objects(pk=id) if not branch: response['error'] = '未找到分支对象!' return HttpResponse(json.dumps(response), mimetype="application/json") branch = branch[0] # 读取最近50条更新 svn_url = SvnUtils.get_svn_url(branch.programName, branch.branchTag) client = pysvn.Client() revision_start = pysvn.Revision(pysvn.opt_revision_kind.head) if revision_start_number: revision_start = pysvn.Revision(pysvn.opt_revision_kind.number, int(revision_start_number)) limit += 1 revision_end = pysvn.Revision(pysvn.opt_revision_kind.number, 0 if not revision_end_number else revision_end_number) svn_logs = client.log(svn_url, revision_start=revision_start, revision_end=revision_end, limit=limit) if revision_start_number: # 过滤掉页面已有数据 svn_logs = svn_logs[1:] svn_log_json = convert_svn_log_json(svn_logs) key_submit_dict = {} if svn_logs: svn_revision_start = svn_logs[0].data['revision'].number svn_revision_end = svn_logs[len(svn_logs) - 1].data['revision'].number # 查询已有关键提交,标记之 key_submits = KeySubmit.objects(Q(branch=branch) & (Q(revision_end__lte=svn_revision_start) & Q(revision_end__gte=svn_revision_end)) | (Q(revision_start__lte=svn_revision_start) & Q(revision_start__gte=svn_revision_end))).order_by('-revision_start') for item in key_submits: revision_start_item = item.revision_start revision_end_item = item.revision_end # 版本号开始在区间内 if svn_revision_start >= revision_start_item >= svn_revision_end: result = {'type': ['start'], 'remark': item.remark, 'create_user': item.create_user.username, 'id': str(item.id), 'time': item.create_time.strftime('%Y-%m-%d %H:%M:%S')} key_submit_dict[revision_start_item] = result # 版本号结束在区间内 if svn_revision_start >= revision_end_item >= svn_revision_end: result = {'type': ['end'], 'remark': item.remark, 'create_user': item.create_user.username, 'id': str(item.id), 'time': item.create_time.strftime('%Y-%m-%d %H:%M:%S')} if revision_end_item in key_submit_dict: key_submit_dict[revision_end_item]['type'].append('end') else: key_submit_dict[revision_end_item] = result response['data'] = svn_log_json response['key_submit'] = key_submit_dict response['success'] = True return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response["error"] = "程序异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json") else: response['error'] = '请使用Http-GET方式请求!' return HttpResponse(json.dumps(response), mimetype="application/json")
def platform_operate(request): """ 平台保存,删除,更新 :param request: :return: """ if request.method == "GET": error = "非法请求方式!" logger.error(error) return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": # cmd in [update, save, delete] # cmd in [更新, 保存, 删除] response = {"success": False, "error": ""} try: # 获取参数 cmd = request.POST.get("cmd", None) id = request.POST.get("id", None) m_nId = request.POST.get("m_nId", None) m_nId = int(m_nId) if m_nId else None m_nType = request.POST.get("m_nType", None) m_nType = int(m_nType) if m_nType else None m_strName = request.POST.get("m_strName", None) m_strAbbrName = request.POST.get("m_strAbbrName", None) m_strSoName = request.POST.get("m_strSoName", None) m_strConfig = request.POST.get("m_strConfig", None) m_strLogo = request.POST.get("m_strLogo", None) m_strQuoterTag = request.POST.get("m_strQuoterTag", None) m_strBrokerTag = request.POST.get("m_strBrokerTag", None) m_strfastTag = request.POST.get("m_strfastTag", None) if cmd is None: response["error"] = "CMD参数不能为空!" return HttpResponse(json.dumps(response), mimetype="application/json") param_is_none = False if not m_nId or not m_nType: param_is_none = True if ( (cmd == "delete" and id is None) or (cmd == "save" and param_is_none) or (cmd == "update" and (param_is_none or id is None)) ): response["error"] = "必要参数为空!" return HttpResponse(json.dumps(response), mimetype="application/json") # 创建 if cmd == "save": # 判断是否已有 param_exist = Platform.objects(m_strName=m_strName, m_nType=m_nType) if len(param_exist) > 0: response["error"] = "已存在相同平台!请在原基础修改!" return HttpResponse(json.dumps(response), mimetype="application/json") platform = Platform() platform.m_nId = m_nId platform.m_nType = m_nType platform.m_strName = m_strName platform.m_strAbbrName = m_strAbbrName platform.m_strSoName = m_strSoName platform.m_strConfig = m_strConfig platform.m_strLogo = m_strLogo platform.m_strQuoterTag = m_strQuoterTag platform.m_strBrokerTag = m_strBrokerTag platform.m_strfastTag = m_strfastTag platform.save() response["id"] = str(platform.id) # 更新 elif cmd == "update": # 查找对象 platform = Platform.objects(pk=id) if len(platform) == 0: response["error"] = "未找到可更新对象!" return HttpResponse(json.dumps(response), mimetype="application/json") platform = platform[0] platform.m_nId = m_nId platform.m_nType = m_nType platform.m_strName = m_strName platform.m_strAbbrName = m_strAbbrName platform.m_strSoName = m_strSoName platform.m_strConfig = m_strConfig platform.m_strLogo = m_strLogo platform.m_strQuoterTag = m_strQuoterTag platform.m_strBrokerTag = m_strBrokerTag platform.m_strfastTag = m_strfastTag platform.save() # 删除 elif cmd == "delete": # 查找对象 platform = Platform.objects(pk=id) if len(platform) == 0: response["error"] = "未找到可删除对象!" return HttpResponse(json.dumps(response), mimetype="application/json") platform = platform[0] path = request.path is_sys = None if path == "/customer/system/list/": is_sys = True elif path == "/customer/list/": is_sys = False else: is_sys = False customers = Customer.objects(is_sys=is_sys).order_by("+tag") for customer in customers: cus_modules = customer.modules for module in cus_modules: if module.group == "Broker实盘" or module.group == "Broker模拟": name_list = module.name.split("_") if len(name_list) >= 3: if str(platform.m_nId) == name_list[2]: response["error"] = "该平台被客户[%s]使用,不能删除!" % str(customer.name) return HttpResponse(json.dumps(response), mimetype="application/json") platform.delete() else: response["error"] = "CMD指令异常!" return HttpResponse(json.dumps(response), mimetype="application/json") response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception as e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def quickSearch(request): if request.method == "GET": search_customer = request.GET.get("customer", None) search_manager = request.GET.get("manager", None) search_status = request.GET.get("status", None) search_module = request.GET.get("module", None) search_permission = request.GET.get("permission", None) search_perm_num = request.GET.get("num", None) search_perm_bool = request.GET.get("bool", None) search_config = request.GET.get("config", None) is_actual = request.GET.get("isActual", None) search_position = request.GET.get("position", None) if search_customer: if is_actual == "是": customers = Customer.objects(is_sys=False).order_by("+tag") elif is_actual == "否": customers = Customer.objects(is_sys=True).order_by("+tag") elif is_actual == "任意": customers = Customer.objects().order_by("+tag") cus_states = CustomerDeployStatus.objects() error = request.GET.get("error", None) cus_aftersales = [] for customer in customers: if customer.aftersale in cus_aftersales: continue cus_aftersales.append(customer.aftersale) results = [] if search_customer: for customer in customers: if search_customer == customer.name: results.append(customer) if search_manager and search_manager != "任意": for customer in customers: if search_manager == customer.aftersale: if is_actual == "是": if "实盘" in customer.name: results.append(customer) else: results.append(customer) if search_status and search_status != "任意": for customer in customers: if search_status == customer.customerstatus: if is_actual == "是": if "实盘" in customer.name: results.append(customer) else: results.append(customer) if search_module and search_module != "任意": for customer in customers: cus_modules = customer.modules for module in cus_modules: if search_module == module.name: if is_actual == "是": if "实盘" in customer.name: results.append(customer) else: results.append(customer) if search_permission and search_permission != "任意": for customer in customers: cus_permission = customer.permissions perm_settings = CustomerPermissionSettings.objects() for perm_setting in perm_settings: if perm_setting.name == search_permission[1:]: perm_id = str(perm_setting.id) if str(search_perm_num) == str(cus_permission[perm_id]) or str(search_perm_bool) == str( cus_permission[perm_id] ): if is_actual == "是": if "实盘" in customer.name: results.append(customer) else: results.append(customer) if search_config: for customer in customers: setting = customer.settings pattern = re.compile(search_config, re.X) match = pattern.search(setting) if match is not None: if is_actual == "是": if "实盘" in customer.name: results.append(customer) else: results.append(customer) if is_actual == "是": for customer in customers: if "实盘" in customer.name: results.append(customer) elif is_actual == "否": for customer in customers: results.append(customer) if search_position and search_position != "任意": for customer in customers: if customer.position == search_position: results.append(customer) else: customers = Customer.objects().order_by("+tag") cus_states = CustomerDeployStatus.objects() error = request.GET.get("error", None) cus_aftersales = [] results = [] for customer in customers: if customer.aftersale in cus_aftersales: continue cus_aftersales.append(customer.aftersale) results.append(customer) return render_to_response("demo/search_view.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")