def init_dict(self): method = 'Map.get_map' content = {} result = lib_post(method, content) MyDialog.my_dict = result['content'] print MyDialog.my_dict pass
def add_proejct(self,data={},mem_data={},mod_data={}): project_id = 0 #添加项目 method = 'Project.add' content = data result = lib_post(method,content) if 500 == result['status_code']: return (False,result['content']) if 200 == result['status_code'] and 0 == result['content']['is_success']: project_id = result['content']['id'] else: return (False,u'项目添加失败') #添加项目成员 #{'project_id':0,'admin_id':0} if 0<len(mem_data['admin_id']): for admin_id in mem_data['admin_id']: method = 'Projectmem.add' content = {'project_id':project_id,'admin_id':admin_id} result = lib_post(method,mem_data) if 500 == result['status_code']: return (False,result['content']) if 200 == result['status_code'] and 0 == result['content']['is_success']: pass else: return (False,u'添加项目成员失败') #添加项目模块 if 0<len(mod_data['name']): for name in mod_data['name']: mod_data['project_id'] = project_id method = 'Projectmodule.add' content = {'project_id':project_id,'name':name} result = lib_post(method, content) if 500 == result['status_code']: return (False,result['content']) if 200 == result['status_code'] and 0 == result['content']['is_success']: pass else: return (False,u'添加项目模块失败') return (True,u'添加成功')
def get_dict(self): method = "Map.get_map" content = {} result = lib_post(method, content) if 500 == result["status_code"]: return (False, "参数错误") elif 200 == result["status_code"]: return (True, result["content"]) return (False, "其他错误")
def get_right(self, role_id): method = "Role.get_info" content = {"id": role_id} result = lib_post(method, content) if 500 == result["status_code"]: return (False, "参数错误") elif 200 == result["status_code"]: return (True, result["content"]) return (False, "其他错误")
def get_dict(self): method = 'Map.get_map' content = {} result = lib_post(method,content) if 500 == result['status_code']: return (False,'参数错误') elif 200 == result['status_code']: return (True,result['content']) return (False,'其他错误')
def add_positionhr(self,data={}): method = 'Positionhr.add' content = data result = lib_post(method,content) if 500 == result['status_code']: return (False,result['content']) if 200 == result['status_code'] and 0 == result['content']['is_success']: return (True,u'添加成功') return (False,u'添加失败')
def add_positionhr(self, data={}): method = "Positionhr.add" content = data result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: return (True, u"添加成功") return (False, u"添加失败")
def add_proejct(self, data={}, mem_data={}, mod_data={}): project_id = 0 # 添加项目 method = "Project.add" content = data result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: project_id = result["content"]["id"] else: return (False, u"项目添加失败") # 添加项目成员 # {'project_id':0,'admin_id':0} if 0 < len(mem_data["admin_id"]): for admin_id in mem_data["admin_id"]: method = "Projectmem.add" content = {"project_id": project_id, "admin_id": admin_id} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"添加项目成员失败") # 添加项目模块 if 0 < len(mod_data["name"]): for name in mod_data["name"]: mod_data["project_id"] = project_id method = "Projectmodule.add" content = {"project_id": project_id, "name": name} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"添加项目模块失败") return (True, u"添加成功")
def get_positionhr_one_by_id(self, id): method = "Positionhr.get_info" content = {"id": id} try: result = lib_post(method, content) except: return (False, u"查询异常") if 200 == result["status_code"]: return (True, result["content"]) return (False, u"查询失败")
def get_resource(self): method = "Resource.get_list" content = {"order": {"id": "asc"}} re_list = [] result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"]: if 0 < int(str(result["content"]["record_count"])): return (True, result["content"]) return (False, "")
def delete_positionhr(self, where={}): method = "Positionhr.delete" content = {} content["where"] = where result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: return (True, u"成功删除") return (False, u"删除失败")
def get_resource_where(self, where={}): method = "Resource.get_list" content = {"where": where} re_list = [] result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"]: if 0 < int(str(result["content"]["record_count"])): return (True, result["content"]) return (False, "")
def get_project_mod(self, project_id=0): re_list = [] method = "Projectmodule.get_list" content = {"where": {"project_id": project_id}, "page_size": 20} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 < result["content"]["record_count"]: rows = result["content"]["record_count"] for row in range(0, rows - 1): re_list.append(result["content"]["list"][row]["name"]) return re_list
def login(self,user_name='',passwd=''): if ''==user_name or '' == passwd: return ('',False,0) method = 'Admin.login' content = {'admin_name':urllib.quote(user_name.encode('utf-8')),'passwd':urllib.quote(passwd.encode('utf-8'))} result = lib_post(method, content) if 500 == result['status_code']: return (result['content'],False,0) if 200 == result['status_code'] and 0 == result['content']['is_success']: admin_id = result['content']['id'] return (u'成功登录',True,admin_id) return (u'用户名或者密码错误!',False,0)
def update_admin_passwd(self, data={}): method = "Admin.update_passwd" content = {} content = data try: result = lib_post(method, content) except: return (False, u"更新异常") if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: return (True, u"成功修改") return (False, u"修改失败")
def get_project_mod_name_by_project_id(self, project_id=0): method = "Projectmodule.get_list" content = {"where": {"project_id": project_id}} re_list = [] try: result = lib_post(method, content) except: return (False, u"查询失败") if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 < result["content"]["record_count"]: rows = int(str(result["content"]["record_count"])) for row in (0, rows - 1): re_list.append(result["content"]["list"][row]["name"]) return (True, re_list)
def get_resource_name(self): method = 'Resource.get_list' content = {'order':{'id':'asc'}} re_list = [] result = lib_post(method,content) if 500 == result['status_code']: return (False,result['content']) if 200 == result['status_code']: if 0< int(str(result['content']['record_count'])): rows = int(str(result['content']['record_count'])) for i in range(0,rows-1): re_list.append(result['content']['list'][i]['source_name']) return (True,re_list) return (False,'') pass
def update_positionhr(self, data={}, where={}): method = "Positionhr.update" content = {} content["data"] = data content["where"] = where try: result = lib_post(method, content) except: return (False, u"更新异常") if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: return (True, u"成功修改") return (False, u"修改失败")
def get_resource_name(self): method = "Resource.get_list" content = {"order": {"id": "asc"}} re_list = [] result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"]: if 0 < int(str(result["content"]["record_count"])): rows = int(str(result["content"]["record_count"])) for i in range(0, rows - 1): re_list.append(result["content"]["list"][i]["source_name"]) return (True, re_list) return (False, "") pass
def get_number(self,module_index=0): cur_prefix = Dict.prefix_list[module_index] number = '' max_num = 1 method = '%s.get_list'%Dict.module_list[module_index] content={'page_size':1} result = lib_post(method,content) if 500 == result['status_code']: lib_log(0,result['content']) return 'error' if 200 == result['status_code']: if 0 < int(result['content']['record_count']): max_num = int(result['content']['list'][0]['id']) max_num += 1 number = '%06d'%max_num return '%s%s'%(cur_prefix,number)
def get_number(self, module_index=0): cur_prefix = Dict.prefix_list[module_index] number = "" max_num = 1 method = "%s.get_list" % Dict.module_list[module_index] content = {"page_size": 1} result = lib_post(method, content) if 500 == result["status_code"]: lib_log(0, result["content"]) return "error" if 200 == result["status_code"]: if 0 < int(result["content"]["record_count"]): max_num = int(result["content"]["list"][0]["id"]) max_num += 1 number = "%06d" % max_num return "%s%s" % (cur_prefix, number)
def action_select(self): keyword = unicode(self.txt_keyword.text().toUtf8(),'utf8','ignore').encode('utf8') #keyword = '测试' #unicode(self.txt_keyword.text().toUtf8(),'utf8','ignore').encode('utf8') #keyword = unicode(str(keyword)) #keyword = urllib.quote(keyword.encode('utf-8')) method = 'Project.get_list' content = {'page_size':20,'where':{'name':['like','$'+urllib.quote(keyword)+'$']}} result = lib_post(method, content) row_count = 0 if 200 == result['status_code']: cur_row_count = self.MyTable.rowCount() self.MyTable.setRowCount(0) self.MyTable.clearContents() for i in range(0,cur_row_count): self.MyTable.removeRow(i) row_count = int(result['content']['record_count']) self.MyTable.setRowCount(int(result['content']['record_count'])) for i in range(0, row_count): #编号 newItem = QTableWidgetItem(result['content']['list'][i]['number']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 0, newItem) #项目名称 newItem = QTableWidgetItem(result['content']['list'][i]['name']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 1, newItem) #创建人 newItem = QTableWidgetItem(result['content']['list'][i]['create']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 2, newItem) #最后更新日期 newItem = QTableWidgetItem(lib.timestamp_datetime(result['content']['list'][i]['last_time'])) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 3, newItem) #项目描述 newItem = QTableWidgetItem(result['content']['list'][i]['description']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 4, newItem)
def get_my_bug(self,admin_id=0): if 0 == admin_id: return (500,None,u'参数不正确') method = 'Bug.get_self_bug' content = {'admin_id':urllib.quote(admin_id.encode('utf-8'))} result = lib_post(method, content) if 500 == result['status_code']: return (500,None,result['content']) elif 200 == result['status_code'] and 0 == result['content']['is_success']: return (200,0,u'严重错误') elif 200 == result['status_code'] and 1 == result['content']['is_success']: return (200,1,u'一般错误') elif 200 == result['status_code'] and -1 == result['content']['is_success']: return (200,-1,u'没有错误') else: return (200,None,u'查询失败') pass
def login(self, user_name="", passwd=""): if "" == user_name or "" == passwd: return ("", False, 0) method = "Admin.login" content = { "admin_name": urllib.quote(user_name.encode("utf-8")), "passwd": urllib.quote(passwd.encode("utf-8")), } result = lib_post(method, content) if 500 == result["status_code"]: return (result["content"], False, 0) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: admin_id = result["content"]["id"] role_id = result["content"]["role_id"] part_id = result["content"]["part_id"] return (u"成功登录", True, admin_id, role_id, part_id) return (u"用户名或者密码错误!", False, 0)
def get_project_mod_by_project_id(self, project_id=0): method = "Projectmodule.get_list" content = {"where": {"project_id": project_id}} re_list = {} try: result = lib_post(method, content) except: return (False, u"查询失败") if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 < result["content"]["record_count"]: rows = int(str(result["content"]["record_count"])) for row in range(0, rows): key = str(result["content"]["list"][row]["name"]) id = result["content"]["list"][row]["id"] re_list[key] = id return (True, re_list) return (False, {}) pass
def get_my_bug(self, admin_id=0): if 0 == admin_id: return (500, None, u"参数不正确") method = "Bug.get_self_bug" content = {"admin_id": urllib.quote(admin_id.encode("utf-8"))} result = lib_post(method, content) if 500 == result["status_code"]: return (500, None, result["content"]) elif 200 == result["status_code"] and 0 == result["content"]["is_success"]: return (200, 0, u"严重错误") elif 200 == result["status_code"] and 1 == result["content"]["is_success"]: return (200, 1, u"一般错误") elif 200 == result["status_code"] and -1 == result["content"]["is_success"]: return (200, -1, u"没有错误") else: return (200, None, u"查询失败") pass
def init_data_project(self): method = 'Project.get_list' content = {'page_size':20} result = lib_post(method, content) rows = int(result['content']['record_count']) self.MyTable = QTableWidget(rows, 5) self.MyTable.setHorizontalHeaderLabels([u'编号',u'项目名称',u'创建人',u'最后更新日期',u'项目描述']) #调整列宽度 self.MyTable.setColumnWidth(0,100)#编号 self.MyTable.setColumnWidth(1,200)#项目名称 self.MyTable.setColumnWidth(2,100)#创建人 self.MyTable.setColumnWidth(3,150)#最后更新时间 self.MyTable.setColumnWidth(4,1000)#项目描述 if 200 == result['status_code']: for i in range(0, int(result['content']['record_count'])): #编号 newItem = QTableWidgetItem(result['content']['list'][i]['number']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 0, newItem) #项目名称 newItem = QTableWidgetItem(result['content']['list'][i]['name']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 1, newItem) #创建人 newItem = QTableWidgetItem(result['content']['list'][i]['create']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 2, newItem) #最后更新日期 newItem = QTableWidgetItem(lib.timestamp_datetime(result['content']['list'][i]['last_time'])) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 3, newItem) #项目描述 newItem = QTableWidgetItem(result['content']['list'][i]['description']) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, 4, newItem)
def change_table(self, index=0): #MyDialog.table_cur_index = str(self.com_list.currentText()) if index>=0: MyDialog.table_cur_index = index else: MyDialog.table_cur_index = int(self.com_list.currentText()) i =j=0 #情况内容 self.MyTable.clear() self.MyTable.setColumnCount(len(self.table_list[Dict.module_list[MyDialog.table_cur_index]])) self.MyTable.setHorizontalHeaderLabels(self.table_list[Dict.module_list[MyDialog.table_cur_index]]) #设置列宽度 for width in MyDialog.table_width_list[Dict.module_list[MyDialog.table_cur_index]]: self.MyTable.setColumnWidth(i, MyDialog.table_width_list[Dict.module_list[MyDialog.table_cur_index]].__getitem__(i)) i += 1 #绑定数据 method = Dict.module_list[MyDialog.table_cur_index]+'.get_list' content = {'page_size':10} result = lib_post(method, content) if 200 == result['status_code']: rows = int(result['content']['record_count']) i = 0 if rows >10: rows = 10 self.MyTable.setRowCount(rows) for i in range(0, rows): j = 0 for field in MyDialog.table_field_list[Dict.module_list[MyDialog.table_cur_index]]: itemValue = lib_format(MyDialog.table_format_list[Dict.module_list[MyDialog.table_cur_index]][j], result['content']['list'][i][field], MyDialog.my_dict) newItem = QTableWidgetItem(itemValue) #newItem.setText(itemValue) newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.MyTable.setItem(i, j, newItem) j += 1 i += 1
pass else: self.re_data.remove(self.data[unicode(checkbox.text())]) pass pass def text(self): tmp_list = [] for i in self.re_data: tmp_list.append(str(i)) return ','.join(tmp_list) if __name__ == '__main__': app = QtGui.QApplication([]) data = {} method = 'Resource.get_list' content={'order':{'id':'asc'}} result = lib_post(method,content) rows = int(result['content']['record_count']) for i in range(0,rows-1): key = result['content']['list'][i]['source_name'] id = result['content']['list'][i]['id'] data[key] = id pass check_data = [] check_data.append(2) check_data.append(4) window = MulCheckedBox(None,data,check_data) window.show() sys.exit(app.exec_())
def update_project(self, data={}, where={}, mem_data={}, mod_data={}): method = "Project.update" content = {} content["data"] = data content["where"] = where try: result = lib_post(method, content) except: return (False, u"更新异常") if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"修改项目失败") # return (True,u'成功修改') # 检查项目成员 ##查询旧的项目成员数据 status, old_project_mem = self.get_project_mem_by_project_id(mem_data["project_id"]) if status: # 获取新旧列表的交集,此集合为不变元素 inersection = list(set(mem_data["admin_id"]).intersection(set(old_project_mem))) # 获取旧集合和交集的差集(所得结果删除的项目成员) need_delete = list(set(old_project_mem).difference(set(inersection))) # 调用删除 if 0 < len(need_delete): if 1 == len(need_delete): where_str = str(need_delete[0]) else: tmp_list = need_delete need_delete = [] for item in tmp_list: need_delete.append(str(item)) where_str = ",".join(need_delete) method = "Projectmem.delete" content = {"admin_id": ["in", where_str], "project_id": mem_data["project_id"]} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"删除项目成员失败") # 获取新集合与交集的差集(所得结果为要新增的项目成员) need_add = list(set(mem_data["admin_id"]).difference(set(inersection))) if 0 < len(need_add): method = "Projectmem.add" for item in need_add: content = {"project_id": mem_data["project_id"], "admin_id": item} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"添加项目成员失败") # 检查项目模块 ##查询旧的项目模块 status, old_project_mod = self.get_project_mod_name_by_project_id(mod_data["project_id"]) if status: tmp_list = [] for item in old_project_mod: tmp_list.append(urllib.quote(str(item))) old_project_mod = tmp_list # 获取新旧列表的交集,此集合为不变元素 inersection = list(set(mod_data["name"]).intersection(set(old_project_mod))) # 获取旧集合和交集的差集(所得结果删除的项目模块) need_delete = list(set(old_project_mod).difference(set(inersection))) # 调用删除 if 0 < len(need_delete): if 1 == len(need_delete): where_str = str(need_delete[0]) else: tmp_list = need_delete need_delete = [] for item in tmp_list: need_delete.append(str(item)) where_str = ",".join(need_delete) method = "Projectmodule.delete" content = {"name": ["in", where_str], "project_id": mod_data["project_id"]} result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"删除项目模块失败") # 获取新集合与交集的差集(所得结果为要新增的项目模块) need_add = list(set(mod_data["name"]).difference(set(inersection))) content = {"project_id": mem_data["project_id"], "name": item} if 0 < len(need_add): method = "Projectmodule.add" for item in need_add: result = lib_post(method, content) if 500 == result["status_code"]: return (False, result["content"]) if 200 == result["status_code"] and 0 == result["content"]["is_success"]: pass else: return (False, u"添加项目模块失败") return (True, u"成功修改")