Example #1
0
 def post(self):
     args = self.parser.parse_args()
     if not (args['url'] and args['format'] and args['shop_id']):
         abort(400, message="url, format and shop_id are required.")
     if not url_check(args['url']):
         abort(400, message="url should be a proper URL string.")
     if not format_check(args['format']):
         abort(400, message="format should be yml or excel.")
     shop_exists = db.session.query(exists().where(Shop.id == args['shop_id'])).scalar()
     if not shop_exists:
         abort(404, message="shop with id={} doesn't exist".format(args['shop_id']))
     pricelist = Pricelist(url=args['url'], format=args['format'], shop_id=args['shop_id'])
     db.session.add(pricelist)
     db.session.commit()
     return {'result': 'OK'}, 200
Example #2
0
 def put(self, id):
     args = self.parser.parse_args()
     pricelist = db.session.query(Pricelist).filter(Pricelist.id == id).first()
     if not (args['url'] and args['format'] and args['shop_id']):
         abort(400, message="url, format and shop_id are required.")
     if not url_check(args['url']):
         abort(400, message="url should be a proper URL string.")
     if not format_check(args['format']):
         abort(400, message="format should be yml or excel.")
     shop_exists = db.session.query(exists().where(Shop.id == args['shop_id'])).scalar()
     if not shop_exists:
         abort(404, message="shop with id={} doesn't exist".format(args['shop_id']))
     pricelists = list(db.session.query(Pricelist).filter(Pricelist.shop_id == pricelist.shop_id))
     if args['shop_id'] != pricelist.shop_id and len(pricelists) == 1:
         abort(400, message="can't move the shop's last pricelist")
     pricelist.url = args['url']
     pricelist.format = args['format']
     pricelist.shop_id = args['shop_id']
     db.session.add(pricelist)
     db.session.commit()
     return {'result': 'OK'}, 200