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)
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)
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
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
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)
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)
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)
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)
def doubleClick(self, item): recipe = Session.query(Recipe).get(item.data(Qt.UserRole)) self.editRecipe(recipe)
def get_recipes(tags=()): recipes = Session.query(Recipe) for t in tags: recipes = recipes.filter(Recipe.tags.any(Tag.id == t)) return recipes.all()
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)
def _meals_in_range(self): return (Session.query(Meal).options(joinedload('recipes')).filter( and_(self.fro <= Meal.date, Meal.date < self.to)).all())
def _meals_in_range(self): return (Session.query(Meal).options(joinedload('recipes')) .filter(and_(self.fro <= Meal.date, Meal.date < self.to)) .all())