Exemplo n.º 1
0
 def get(self):
     args = self.parser.parse_args()
     page = args.get('page', None)
     if page is None:
         return ResponseClass.warn(ResponseCode.FORMAT_ERROR)
     if g.user.role == conf.USER_ROLE_ADMIN:
         session = AppUtils.get_session()
         try:
             items = session.query(Item).order_by(desc(Item.id)).offset(
                 page * 10).limit(10).all()
             data = []
             for item in items:
                 item_dict = AppUtils.serialize(item)
                 data.append(item_dict)
             return ResponseClass.ok_with_data(data)
         except Exception as e:
             pass
         finally:
             session.close()
     else:
         session = AppUtils.get_session()
         try:
             items = session.query(Item).filter_by(isOn=True).order_by(
                 Item.name).offset(page * 10).limit(10).all()
             data = []
             for item in items:
                 item_dict = AppUtils.serialize(item)
                 data.append(item_dict)
             return ResponseClass.ok_with_data(data)
         except Exception as e:
             pass
         finally:
             session.close()
Exemplo n.º 2
0
 def get(self):
     args = self.parser.parse_args()
     page = args.get('page', None)
     if page is None:
         return ResponseClass.warn(ResponseCode.FORMAT_ERROR)
     session = AppUtils.get_session()
     try:
         repository_items = session.query(Repository).filter_by(
             user_id=g.user.id).order_by(
                 conf.database.desc(Repository.create_date)).offset(
                     page * 10).limit(10).all()
         data = []
         for repository_item in repository_items:
             item_data = AppUtils.serialize(repository_item.item)
             item_data['repo_id'] = repository_item.id
             data.append(item_data)
         return ResponseClass.ok_with_data(data)
     except Exception as e:
         pass
     finally:
         session.close()