def slotAddType(self): #权限检查 #if not ims.model.dbSysUser.g_current_user.is_enable_write_all():return item = self.ui.treeWidget.currentItem() if item == None:return itemData = self.__getItemIdDepth__(item) if itemData == None : return if itemData[1] == 1: #如果深度为1,则父类别id为0 parentid = 0 else: #否则求父节点的类别id item_parent = item.parent() data_parent = self.__getItemIdDepth__(item_parent) if itemData == None: return parentid = data_parent[0] #获取类别名称 text = QInputDialog.getText(self, u'新增类别',u'请输入一个新的类别名称') if not text[1]: return if text[0]=="": return newtype = ArticleType() newtype.text = u'%s'%text[0] newtype.parentid = parentid #执行数据库操作 if not dbArticleType().insert(newtype): QMessageBox.critical(self, u'出错了',u'添加类别失败,请重试') else: self.__updateArticleTree()
def slotAddType1(self): if not ims.model.dbSysUser.g_current_user.is_enable_write_all():return #msg = QMessageBox.information(self, u'input', u'input') text = QInputDialog.getText(self, QString(u"新增类别名" ), QString(u"请输入一个类别名称") , QLineEdit.Normal); if text[0] == '': return newtype = ArticleType() newtype.text = unicode(text[0]) #print newtype.text newtype.parentid = 0 if not dbArticleType().insert(newtype): QMessageBox.warning(self, u'error', u'添加类别1失败') self.__initType1list()
def slotAddType2(self): if not ims.model.dbSysUser.g_current_user.is_enable_write_all():return '''先获取父类别id''' res = self.ui.comboBox_type1.itemData(self.ui.comboBox_type1.currentIndex()).toInt() if not res[1]: print 'invadate combobox item data' return parentid = int(res[0]) #msg = QMessageBox.information(self, u'input', u'input') text = QInputDialog.getText(self, QString(u"新增类别名" ), QString(u"请输入一个类别名称") , QLineEdit.Normal); if text[0] == '':return newtype = ArticleType() newtype.text = unicode(text[0]) newtype.parentid = parentid if not dbArticleType().insert(newtype): QMessageBox.warning(self, u'doo', u'添加类别失败') self.__initType2list()
def ImportArticleType(filepath): if filepath==None or len(filepath)==0: return False book = xlrd.open_workbook(filepath) sheet = book.sheet_by_index(0) if sheet is None: return False headers = ['类别'] if sheet.ncols!=0 or sheet.cell_value(0, 0)!='类别': raise Exception("cols must be 1count and contain type'文件列数要求为1,并且只有一列<类别>") return type1set = set() typeslist2 = [] for row in range(1, sheet.nrows): for col in range(sheet.ncols): print sheet.cell_value(row,col) types = sheet.cell_value(row,col) t1t2 = types.split('-') if len(t1t2)!= 2: raise Exception("invadate type") return if(t1t2[0]==''): raise Exception("invadate type1") return type1set.add(t1t2[0]) db = dbArticleType() for text in type1set: typeinfo = ArticleType() typeinfo.parentid = 0 typeinfo.text=text db.insert(typeinfo) for row in range(1,sheet.nrows): for col in range(sheet.ncols): print sheet.cell_value(row,col) types = sheet.cell_value(row,col) t1t2 = types.split('-') if len(t1t2)!= 2: break parent_type = db.getArticleTypeInfoByTypeName(t1t2[0]) if parent_type is None: raise Exception("invadate parent type") return type = ArticleType() type.parentid= parent_type.id type.text=t1t2[1] typeslist2.append(type) for item in typeslist2: db.insert(item)