def _del_article(self): items = self.selectedItems() if not items: return article = items[0].article msg = 'Delete "%s"?' % article.title btn = QMessageBox.question(self, 'Delete article', msg, QMessageBox.Yes | QMessageBox.No) if btn == QMessageBox.No: return s = get_session() s.delete(Article.find_by_id(s, article.id)) s.commit() self.update_articles()
def add_test_data(): from ljn.Model import Category s = session_maker() if not len(Category.all(s)): s.add(Category(u'c1')) s.add(Category(u'c2')) if not len(Article.all(s)): s.add(Article('this is content 1', Category.find_by_name(s, u'c1'), u'title of a1')) s.add(Article('this is content 2', Category.find_by_name(s, u'c1'), u'title of a2')) s.add(Article('this is content 3', Category.find_by_name(s, u'c2'), u'title of a3')) article = Category.find_by_name(s, u'c1').articles[0] if not len(article.new_words): w = Word('is') article.new_words.append(ArticleNewWord(article, w, 'is')) s.commit()
def _rename_article(self): items = self.selectedItems() if not items: return article = items[0].article text, result = QInputDialog.getText(self, 'Rename article', 'New article title:', text=article.title) if not result: return text = str(text) if not text or text == article.title: return s = get_session() a = Article.find_by_id(s, article.id) a.title = text s.commit() self.update_articles()
def testArticleNewWord(self): self.add_2_articles() s = self.session() a1, a2 = Article.all(s) w1 = Word('this') w2 = Word('that') a1.new_words.append(ArticleNewWord(a1, w1, 'This')) a1.new_words.append(ArticleNewWord(a1, w1, 'this')) a1.new_words.append(ArticleNewWord(a1, w2, 'that')) s.commit() self.assertEqual(len(w1.article_new_words), 2) self.assertEqual(len(w2.article_new_words), 1) self.assertEqual(len(a1.new_words), 3) self.assertEqual(len(a2.new_words), 0) s.delete(a1) s.commit() self.assertEqual(len(w1.article_new_words), 0) self.assertEqual(len(w2.article_new_words), 0)
def testCategory(self): s = self.session() s.add(Category(u'c1')) self.assertEqual(1, len(s.query(Category).all())) c = Category.find_by_name(s, u'c1') self.assertEqual(c.name, u'c1') self.assertEqual(len(c.articles), 0) s.commit() s.add(Article(u'ac', c, u'at')) s.commit() self.assertIsNotNone(c.create_date) self.assertEqual(len(c.articles), 1) s.delete(c) s.commit() self.assertEqual(len(Article.all(s)), 0)
def _refresh(self): article = Article.find_by_id(get_session(), self.article_id) self.new_words = list(article.new_words) self.highlight.rehighlight() self.onArticleLoaded.emit(self.article_id)
def open_article(self, window, article_id): from ljn.Model import Article from ljn.Repository import get_session window.article_browser.setFocus() window.article_browser.set_article(Article.find_by_id(get_session(), article_id))