def delete(self): """multi delete """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 # TODO: use function if not hasattr(g, 'user'): return omitError('CE_NOT_EXIST', 'not login yet'), 400 r = g.user if r is None: return omitError('CE_NOT_EXIST'), 400 if r.login != superuser: return omitError('CE_UNAUTHORIZED', 'permission deny'), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 _r = [] for id in ids: id = inputs.natural(id) # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() r.isdel = True _r.append(r) try: for v in _r: db.session.merge(v) db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self): """multi delete """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: db.session.rollback() return omitError( ErrorMsg='user id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = grp.query.filter(grp.id == id).scalar() if r is None: db.session.rollback() return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 db.session.delete(r) try: db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self, id): requestArgsSet = set((col) for col in request.args) if not ExtraParamsIsValid(requestArgsSet): return omitError(ErrorMsg=repr(set( (col) for col in request.args))), 400 try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: db.session.rollback() return omitError( ErrorMsg='user id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id).scalar() if r is None: db.session.rollback() return omitError('CE_NOT_EXIST', 'admin id {} not found'.format(id)), 400 db.session.delete(r) try: db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return message, 400 return message, 204
def delete(self): """multi delete @api {delete} /rest/objects/ipaddrs delete IP address items. @apiName DelIpAddrs @apiVersion 0.0.1 @apiGroup objects @apiPermission registered user @apiDescription todo validation @apiParam {String{..255}} [ids] the items id seperate with common @apiExample Example usage: curl -X DELETE -v -b $COOKIES -H "Content-Type:application/json" http://localhost/rest/objects/ipaddrs?id=1,2,3 ================================================ HTTP/1.0 204 NO CONTENT @apiError CE_INVALID_PARAM invalid parameter @api {delete} /rest/objects/ipaddrs @apiErrorExample {json} we use invalid parameter pages curl -X DELETE -v -b $COOKIES -H "Content-Type:application/json" http://localhost/rest/objects/pages?id=1,2,3 ================================================ HTTP/1.0 400 BAD REQUEST { "errorId": 2001, "message": "param `ipaddrs` not found" } @apiError CE_NOT_EXIST item not found @api {delete} /rest/objects/ipaddr @apiErrorExample {json} we use not exist id curl -X DELETE -v -b $COOKIES -H "Content-Type:application/json" http://localhost/rest/objects/pages?id=7,8,9 ================================================ HTTP/1.0 400 BAD REQUEST { "errorId": 2003, "message": "id 7 not found" } """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: db.session.rollback() return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id).scalar() if r is None: db.session.rollback() return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 db.session.delete(r) try: db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self): """multi delete @api {delete} /rest/customer/businesses Delete items @apiName DelCustomerBusiness @apiVersion 0.0.3 @apiGroup customer @apiPermission registered user @apiDescription todo validation @apiParam {String{..254}} [ids] the items id seperate with common @apiExample {curl} Example usage: curl -X DELETE -v -b $COOKIES -H "Content-Type:application/json" http://localhost/rest/customer/businesses?id=1,2,3 HTTP/1.0 204 NO CONTENT @apiError CE_INVALID_PARAM invalid parameter HTTP/1.0 400 BAD REQUEST { "errorId": 2001, "message": "param `businesses` not found" } @apiError CE_NOT_EXIST item not found HTTP/1.0 400 BAD REQUEST { "errorId": 2003, "message": "id 7 not found" } """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 _details = [] _pics = [] _deals = [] _r = [] for id in ids: id = inputs.natural(id) # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() r.isdel = True _r.append(r) # must have d = detail.query.filter(detail.business_id == id, detail.isdel == False).scalar() d.isdel = True _details.append(d) p = pics.query.filter(pics.business_id == id, pics.isdel == False).all() _pics += p __deals = deals.query.filter(deals.business_id == id, deals.isdel == False).all() _deals += __deals try: for v in _deals: db.session.delete(v) for v in _pics: db.session.delete(v) for v in _r: db.session.merge(v) for v in _details: db.session.merge(v) db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self): """multi delete delete comments by comment id @api {delete} /rest/customer/comments delete comments by id @apiVersion 0.0.5 @apiName DeleteCommentsById @apiGroup campaign @apiPermission registered user @apiParam {String{..254}} [comments] the items id seperate with common @apiDescription todo certificate with cookies / oauth 2.0<br /> todo long/lat validation<br /> todo metadata for counter of registerd devices<br /> todo error / success return code in api @apiExample {curl} Example usage: curl -X DELETE -H "mTag: xx" -H "Content-Type:application/json" http://localhost/rest/customer/comments?comments=1,2 """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 _r = [] for id in ids: try: id = inputs.natural(id) except Exception as error: return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 r.isdel = True _r.append(r) _rates = [] for __r in _r: ___r = rates.query.filter(rates.user_id == __r.user_id, rates.business_id == __r.business_id, rates.isdel == False).scalar() if ___r is None: return omitError( 'CE_NOT_EXIST', 'user_id {}, business_id {} are duplicate'.format( __r.user_id, __r.business_id)), 400 ___r.isdel = True _rates.append(___r) try: for v in _r: db.session.merge(v) for v in _rates: db.session.merge(v) db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self, business_id): """delete devices by device id under business id @api {delete} /rest/pushno/unreg/:id registed devices under business id @apiVersion 0.0.4 @apiName DeleteDevicesByBusinessId @apiGroup pushno @apiPermission registered user @apiParam {Number} id business id @apiParam {String{..254}} [pushnos] the items id seperate with common @apiDescription todo certificate with cookies / oauth 2.0<br /> todo long/lat validation<br /> todo metadata for counter of registerd devices<br /> todo error / success return code in api @apiExample {curl} Example usage: curl -X DELETE -H "mTag: xx" -H "Content-Type:application/json" http://localhost/rest/pushno/unreg/1?pushnos=4 """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 r = business.query.filter(business.id == business_id, business.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 _r = [] for id in ids: try: id = inputs.natural(id) except Exception as error: return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.business_id == business_id, obj.id == id, obj.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 r.isdel = True _r.append(r) try: for v in _r: db.session.merge(v) db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 return '', 204
def delete(self): """multi delete """ """delete images @api {delete} /rest/pic/gallery delete image with ids @apiVersion 0.0.5 @apiName DeleteImages @apiGroup business @apiPermission registered user @apiDescription todo certificate with cookies / oauth 2.0<br /> todo long/lat validation<br /> todo metadata for counter of registerd devices<br /> todo error / success return code in api @apiParam {Number} pics pics's id @apiParam {String={customer}} type upload type @apiDescription todo certificate with cookies / oauth 2.0<br /> todo long/lat validation<br /> todo metadata for counter of registerd devices<br /> todo error / success return code in api @apiExample {curl} Example usage: curl -X DELETE -H "mTag: xx" -H "Content-Type:application/json" http://localhost/rest/pic/gallery?pics=7,8&type=customer """ try: ids = request.args.get(__heads__).split(',') except Exception as error: return omitError( ErrorMsg='param `{}` not found'.format(__heads__)), 400 type = request.args.get('type') if type not in PIC_ALLOWED_TYPE: logger.debug('%s not in PIC_ALLOWED_TYPE', type) type = None if not type: return omitError('CE_INVALID_PARAM', 'not found'), 400 for id in ids: try: id = inputs.natural(id) except Exception as error: return omitError(ErrorMsg='id `{}` not int'.format(id)), 400 # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() if r is None: return omitError('CE_NOT_EXIST', 'id {} not found'.format(id)), 400 _r = [] _filenames = [] for id in ids: id = inputs.natural(id) # it could als cascade delete `online` user r = obj.query.filter(obj.id == id, obj.isdel == False).scalar() _r.append(r) pic_path = os.path.join(STATIC_ROOT, PIC_PREFIX, type, str(r.business_id), r.path) _filenames.append(pic_path) try: for v in _r: db.session.delete(v) db.session.flush() db.session.commit() except Exception as error: logger.warning('session commit error(%s)', error) db.session.rollback() return omitError(ErrorMsg=repr(error)), 400 for v in _filenames: try: os.remove(v) except OSError: pass return '', 204