示例#1
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Delete:
         # Pas de confirmation, pas de sauvegarde : on est des oufs !
         ids = [item.data(Qt.UserRole) for item in self.selectedItems()]
         Session.query(Recipe).filter(Recipe.id.in_(ids)).delete('fetch')
         self.reload()
     elif event.key() == Qt.Key_N:
         self.editRecipe(None)
     else:
         super(RecipesWidget, self).keyPressEvent(event)
示例#2
0
文件: recipes.py 项目: madjar/re-eat
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Delete:
         # Pas de confirmation, pas de sauvegarde : on est des oufs !
         ids = [item.data(Qt.UserRole) for item in self.selectedItems()]
         Session.query(Recipe).filter(Recipe.id.in_(ids)).delete('fetch')
         self.reload()
     elif event.key() == Qt.Key_N:
         self.editRecipe(None)
     else:
         super(RecipesWidget, self).keyPressEvent(event)
示例#3
0
    def test_remove_recipe(self):
        rw = RecipesWidget()
        self.assertEqual(len(rw.selectedItems()), 0)
        before = Session.query(Recipe).count()

        rw.item(0).setSelected(True)
        rw.item(3).setSelected(True)
        QTest.keyClick(rw, Qt.Key_Delete)

        self.assertEqual(Session.query(Recipe).count(), before - 2)
        self.assertEqual(rw.count(), before - 2)
示例#4
0
    def test_remove_recipe(self):
        rw = RecipesWidget()
        self.assertEqual(len(rw.selectedItems()), 0)
        before = Session.query(Recipe).count()

        rw.item(0).setSelected(True)
        rw.item(3).setSelected(True)
        QTest.keyClick(rw, Qt.Key_Delete)

        self.assertEqual(Session.query(Recipe).count(), before - 2)
        self.assertEqual(rw.count(), before - 2)
示例#5
0
文件: meals.py 项目: madjar/re-eat
 def get_meal(self, date, index):
     try:
         meal = (Session.query(Meal).filter(
             and_(Meal.date == date, Meal.index == index)).one())
     except NoResultFound:
         meal = Meal(date, index)
         Session.add(meal)
     return meal
示例#6
0
文件: meals.py 项目: madjar/re-eat
 def get_meal(self, date, index):
     try:
         meal = (Session.query(Meal).
                 filter(and_(Meal.date == date, Meal.index == index))
                 .one())
     except NoResultFound:
         meal = Meal(date, index)
         Session.add(meal)
     return meal
示例#7
0
文件: tags.py 项目: madjar/re-eat
 def reload(self):
     tags = Session.query(Tag.name, Tag.id).all()
     self.tagsdict = dict(tags)
     self.availableTags = self.tagsdict.keys()
     for i in xrange(self.listWidget.count()):
         tag = self.listWidget.item(i).text()
         if tag in self.availableTags:
             self.availableTags.remove(tag)
     self.lineEdit.completer().model().setStringList(self.availableTags)
示例#8
0
 def reload(self):
     tags = Session.query(Tag.name, Tag.id).all()
     self.tagsdict = dict(tags)
     self.availableTags = self.tagsdict.keys()
     for i in xrange(self.listWidget.count()):
         tag = self.listWidget.item(i).text()
         if tag in self.availableTags:
             self.availableTags.remove(tag)
     self.lineEdit.completer().model().setStringList(self.availableTags)
示例#9
0
    def test_getting_the_entered_tags(self):
        tw = TagsWidget()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        expected = [t.id for t in Session.query(Tag.id)
                                         .filter(Tag.name == u'lourd')
                                         .all()]
        self.assertEqual(tw.tags(), expected)
示例#10
0
    def test_getting_the_entered_tags(self):
        tw = TagsWidget()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        expected = [
            t.id
            for t in Session.query(Tag.id).filter(Tag.name == u'lourd').all()
        ]
        self.assertEqual(tw.tags(), expected)
示例#11
0
文件: meals.py 项目: madjar/re-eat
 def add_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.append(recipe)
     self.widgets[(date, index)].addRecipe(recipe)
示例#12
0
文件: recipes.py 项目: madjar/re-eat
 def doubleClick(self, item):
     recipe = Session.query(Recipe).get(item.data(Qt.UserRole))
     self.editRecipe(recipe)
示例#13
0
文件: recipes.py 项目: madjar/re-eat
def get_recipes(tags=()):
    recipes = Session.query(Recipe)
    for t in tags:
        recipes = recipes.filter(Recipe.tags.any(Tag.id == t))
    return recipes.all()
示例#14
0
文件: meals.py 项目: madjar/re-eat
 def add_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.append(recipe)
     self.widgets[(date, index)].addRecipe(recipe)
示例#15
0
文件: meals.py 项目: madjar/re-eat
 def remove_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.remove(recipe)
     self.widgets[(date, index)].removeRecipe(recipe)
示例#16
0
 def doubleClick(self, item):
     recipe = Session.query(Recipe).get(item.data(Qt.UserRole))
     self.editRecipe(recipe)
示例#17
0
def get_recipes(tags=()):
    recipes = Session.query(Recipe)
    for t in tags:
        recipes = recipes.filter(Recipe.tags.any(Tag.id == t))
    return recipes.all()
示例#18
0
文件: meals.py 项目: madjar/re-eat
 def _meals_in_range(self):
     return (Session.query(Meal).options(joinedload('recipes')).filter(
         and_(self.fro <= Meal.date, Meal.date < self.to)).all())
示例#19
0
文件: meals.py 项目: madjar/re-eat
 def remove_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.remove(recipe)
     self.widgets[(date, index)].removeRecipe(recipe)
示例#20
0
文件: meals.py 项目: madjar/re-eat
 def _meals_in_range(self):
     return (Session.query(Meal).options(joinedload('recipes'))
             .filter(and_(self.fro <= Meal.date, Meal.date < self.to))
             .all())