def doIt(self): title = unicode(self.newDoc.titleLine.text()) authors = unicode(self.newDoc.authorsLine.text()) tags = unicode(self.newDoc.tagsLine.text()) year = unicode(self.newDoc.yearLine.text()) doi = unicode(self.newDoc.doiLine.text()) file = unicode(self.newDoc.documentLine.text()) # input sanatation y, ok = self.newDoc.yearLine.text().toInt() if not ok: msg = "You must enter a year!" response = QMessageBox.question(self.parent, "Error", msg, QMessageBox.Ok) if response == QMessageBox.Ok: # yes, this cannot fail, but if we don't do this qt will return False # garbagecollect away the floor under the messageboxes feet return False # a well whatever just in case import string import random chars = string.letters + string.digits randomFilename = "" for i in range(8): randomFilename = randomFilename + random.choice(chars) if file == "": commentFileName = randomFilename else: # use the pdf name # strip the directory and append the 8 random chars # .txt is appended later and it is put in a different directory commentFileName = file while True: startidx = commentFileName.find(str("/")) if startidx == -1: break commentFileName = commentFileName[startidx + 1 :] commentFileName += randomFilename addToDB(title, authors, tags, year, file, commentFileName, doi) self.indexNewFile(title, authors, tags, file) self.dialog.close() self.parent.populateTable() return True
def doIt(self): row = self.parent.infoTable.selectedItems()[0].row() doc = self.parent.infoTable.item(row, 0).data(Qt.UserRole).toPyObject() oldFile = doc.localFile commentFileName = doc.commentFile doc.delete() title = unicode(self.newDoc.titleLine.text()) authors = unicode(self.newDoc.authorsLine.text()) tags = unicode(self.newDoc.tagsLine.text()) year = unicode(self.newDoc.yearLine.text()) doi = unicode(self.newDoc.doiLine.text()) file = unicode(self.newDoc.documentLine.text()) # input sanatation y, ok = self.newDoc.yearLine.text().toInt() if not ok: msg = "You must enter a year!" response = QMessageBox.question(self.parent, "Error", msg, QMessageBox.Ok) if response == QMessageBox.Ok: # yes, this cannot fail, but if we don't do this qt will return False # garbagecollect away the floor under the messageboxes feet return False # a well whatever just in case addToDB(title, authors, tags, year, file, commentFileName, doi) if oldFile != file: if oldFile != "": # there is an old now invalid file in the whoosh index pass # TODO: remove from index if file != "": # there is a new file to be added to index self.indexNewFile(title, authors, tags, file) self.dialog.close() self.parent.populateTable() return True