Example #1
0
 def save(cls, obj):
     try:
         session.add(obj)
         session.commit()
     except Exception:
         session.rollback()
         raise
Example #2
0
 def remove(cls, obj):
     try:
         session.delete(obj)
         session.commit()
     except Exception:
         session.rollback()
         raise
Example #3
0
 def update(cls, obj, **kwargs):
     try:
         for key, value in kwargs.items():
             setattr(obj, key, value)
         session.commit()
     except Exception:
         session.rollback()
         raise
Example #4
0
 def get_gifts(self, giver_id):
     try:
         dreams = self.model.query.filter_by(giver_id=giver_id, is_fulfilled=False).all()
         session.commit()
     except Exception:
         session.rollback()
         raise
     return dreams
Example #5
0
 def get_all(self, user_id):
     try:
         dreams = self.model.query.filter_by(owner_id=user_id).all()
         session.commit()
     except Exception:
         session.rollback()
         raise
     return dreams
Example #6
0
 def get_unfulfilled_dreams(self, user_id):
     try:
         dreams = self.model.query.filter_by(owner_id=user_id, is_fulfilled=False).all()
         session.commit()
     except Exception:
         session.rollback()
         raise
     return dreams
Example #7
0
 def get_gift(self, giver_id, dream_id):
     try:
         gift = self.model.query.filter_by(id=dream_id, giver_id=giver_id, is_fulfilled=False).first()
         session.commit()
     except Exception:
         session.rollback()
         raise
     return gift
Example #8
0
 def get_by_id_only(self, dream_id):
     try:
         dream = self.model.query.filter_by(id=dream_id).first()
         if not dream:
             raise Exception('Not found this dream')
         session.commit()
     except Exception:
         session.rollback()
         raise
     return dream