Exemplo n.º 1
0
 def add_2_articles(self):
     self.add_2_categories()
     s = self.session()
     a1 = Article(u'This is content of article 1', Category.find_by_name(s, u'c1'), u'Title of c1')
     a2 = Article(u'This is content of article 2', Category.find_by_name(s, u'c2'), u'Title of c2')
     s.add_all([a1, a2])
     s.commit()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
 def _show_article_list(self, window):
     from ljn.Model import Category
     from ljn.Repository import get_session
     id = self._get_selected_category_id(window)
     if id is not None:
         msg = ' (%s)' % Category.find_by_id(get_session(), id).name
     else:
         msg = ''
     window.list_dock_pane.setWindowTitle("Article List" + msg)
     window.list_layout.setCurrentWidget(window.article_list)
Exemplo n.º 4
0
    def _del_category(self):
        items = self.selectedItems()
        if not items:
            return

        category = items[0].category
        msg = 'Delete "%s"?' % category.name
        btn = QMessageBox.question(self, 'Delete category', msg, QMessageBox.Yes | QMessageBox.No)
        if btn == QMessageBox.No:
            return

        s = get_session()
        s.delete(Category.find_by_id(s, category.id))
        s.commit()
        self.update_categories()
Exemplo n.º 5
0
    def update_articles(self, category_id=None):
        self.clear()
        self.addItem('..')

        if category_id is None:
            category_id = self.category_id

        if category_id is None:
            return

        self.category_id = category_id
        category = Category.find_by_id(get_session(), category_id)

        if category is not None:
            for a in category.articles:
                self.addItem(ArticleItem(a))
Exemplo n.º 6
0
    def _rename_category(self):
        items = self.selectedItems()
        if not items:
            return

        category = items[0].category
        text, result = QInputDialog.getText(self, 'Rename category', 'New category name:', text=category.name)
        if not result:
            return

        text = str(text)
        if not text or text == category.name:
            return

        s = get_session()
        c = Category.find_by_id(s, category.id)
        c.name = text
        s.commit()
        self.update_categories()
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def update_categories(self):
     self.clear()
     for c in Category.all(get_session()):
         self.addItem(CategoryItem(c))