示例#1
0
 def get_number_of_pictures_per_username(self, username):
     number_of = []
     with SafeSession() as safe_session:
         try:
             number_of = safe_session.get_session().query(Picture).filter_by(username=username).count()
         except (SQLAlchemyError, DBAPIError) as e:
             raise DBException(str(e))
     return number_of
示例#2
0
 def get_paths_by_username(self, username):
     path_list = []
     with SafeSession() as safe_session:
         try:
             path_list = safe_session.get_session().query(Picture).filter_by(username=username).all()
         except (SQLAlchemyError, DBAPIError) as e:
             raise DBException(str(e))
     return path_list
示例#3
0
 def get_mapping(self, username):
     mapping_list = []
     with SafeSession() as safe_session:
         try:
             mapping_list = safe_session.get_session().query(WidgetUser).filter_by(username=username).all()
         except (SQLAlchemyError, DBAPIError) as e:
             raise DBException(str(e))
     return mapping_list
示例#4
0
 def get_all_user(self):
     users = []
     with SafeSession() as safe_session:
         try:
             users = safe_session.get_session().query(User).all()
         except (SQLAlchemyError, DBAPIError) as e:
             raise DBException(str(e))
     return users
示例#5
0
 def get_user_by_username(self, username):
     assigned_user = None
     with SafeSession() as safe_session:
             try:
                 assigned_user = safe_session.get_session().query(User).filter_by(username=username).first()
             except (SQLAlchemyError, DBAPIError) as e:
                 raise DBException(str(e))
     return assigned_user
示例#6
0
 def get_base_url(self, widget):
     url = None
     with SafeSession() as safe_session:
             try:
                 widget = safe_session.get_session().query(Widget).filter_by(widget=widget).first()
                 if widget:
                     url = widget.base_url
             except (SQLAlchemyError, DBAPIError) as e:
                 raise DBException(str(e))
     return url
示例#7
0
 def does_widget_exists(self, widget_name):
     result = False
     with SafeSession() as safe_session:
             try:
                 widget = safe_session.get_session().query(Widget).filter_by(widget=widget_name).first()
                 if widget:
                     result = True
             except (SQLAlchemyError, DBAPIError) as e:
                 raise DBException(str(e))
     return result
示例#8
0
 def get_widgets(self):
     widgets = []
     with SafeSession() as safe_session:
         try:
             tuple_widgets = safe_session.get_session().query(Widget.widget).all()
             for item in tuple_widgets:
                 widgets.append(item[0])
         except (SQLAlchemyError, DBAPIError) as e:
             raise DBException(str(e))
     return widgets
示例#9
0
 def insert_user(self, username, prename, name):
     with SafeSession() as safe_session:
         try:
             if safe_session.get_session().query(User).filter_by(username=username).first() is None:
                 user = User(username=username, prename=prename, name=name)
                 safe_session.add(user)
                 safe_session.commit()
                 return True
             else:
                 return False
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
示例#10
0
 def delete_user_by_username(self, username):
     with SafeSession() as safe_session:
         try:
             user_to_delete = safe_session.get_session().query(User).filter_by(username=username).first()
             if user_to_delete:
                 safe_session.delete(user_to_delete)
                 safe_session.commit()
                 return True
             else:
                 return False
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
示例#11
0
 def delete(self, identifier):
     success = False
     with SafeSession() as safe_session:
         try:
             mapping_to_delete = safe_session.get_session().query(WidgetUser).filter_by(identifier=identifier).first()
             if mapping_to_delete:
                 safe_session.delete(mapping_to_delete)
                 safe_session.commit()
                 success =  True
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
     return success
示例#12
0
 def delete_widget(self, widget):
     with SafeSession() as safe_session:
         try:
             widget_to_delete = safe_session.get_session().query(Widget).filter_by(widget=widget).first()
             if widget_to_delete:
                 safe_session.delete(widget_to_delete)
                 safe_session.commit()
                 return True
             else:
                 return False
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
示例#13
0
 def add_picture(self, username, image_path):
     with SafeSession() as safe_session:
         try:
             user = safe_session.get_session().query(User).filter_by(username=username).first()
             if user:
                 picture = Picture(username=user.username, image_path=image_path)
                 safe_session.add(picture)
                 safe_session.commit()
                 return True
             else:
                 return False
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
示例#14
0
 def add_widget(self, widget, base_url):
     ret = None
     with SafeSession() as safe_session:
         try:
             if safe_session.get_session().query(Widget).filter_by(widget=widget).first() is None:
                 widget = Widget(widget=widget, base_url=base_url)
                 safe_session.add(widget)
                 safe_session.commit()
                 ret = True
             else:
                 ret = False
         except (SQLAlchemyError, DBAPIError) as e:
             safe_session.rollback()
             raise DBException(str)
     return ret
示例#15
0
 def update(self, widget, username, position, context):  # TODO refactor lazy implementation
     identifier = username + str(position)
     self.delete(identifier)
     success = False
     with SafeSession() as safe_session:
         try:
             if WidgetDao().does_widget_exists(widget):
                 widget_user = WidgetUser(identifier=identifier,widget=widget,
                                          username=username, position=position, context=context)
                 safe_session.add(widget_user)
                 safe_session.commit()
                 success = True
         except (SQLAlchemyError, DBAPIError, DBException) as e:
             safe_session.rollback()
             raise DBException(str)
     return success