def is_exist(self, id, column='_id', is_objectid=True): if is_objectid: items = self.get_coll().find_one( {column: utils.create_objectid(id)}) else: items = self.get_coll().find_one({column: id}) return items != None
def delete(self): result = utils.init_response_data() try: ids = json.loads(self.get_argument("ids")) _ids = [utils.create_objectid(id) for id in ids] for _id in _ids: self.model.delete(_id=_id) except Exception, e: result = utils.reset_response_data(0, str(e))
def get(self): result = utils.init_response_data() try: product_id = self.get_argument("product_id","") product = self.coll.find_one({"_id":utils.create_objectid(product_id)}) result["data"] = utils.dump(product) except Exception as e: result = utils.reset_response_data(0,unicode(e)) self.finish(result)
def get_user_id(self): token = self.get_argument('access_token', None) if not token: auth_header = self.request.headers.get('Authorization', None) if not auth_header: raise Exception('This resource need a authorization token') token = auth_header[7:] redis_tool = Redis.RedisTool() user_id = redis_tool.get(token) return utils.create_objectid(user_id)
def get(self): result = utils.init_response_data() try: id = self.get_argument("id") _id = utils.create_objectid(id) ret = self.model.search({"_id": _id}) if ret: result["data"] = ret else: result["data"] = {} except Exception, e: result = utils.reset_response_data(0, str(e))
def get(self): result = utils.init_response_data() product_id = self.get_argument("product_id", "") try: if not self.model.is_exist(product_id): raise ValueError(u"该商品不存在") result['data'] = self.coll.find_one( {"_id": utils.create_objectid(product_id)}) result['mode'] = '' except Exception as e: result['alert'] = 1 result = utils.reset_response_data(0, unicode(e)) self.render("admin/product/product-edit.html", result=result)
def get(self): result = utils.init_response_data() product_id = self.get_argument("product_id", "") try: if not self.model.is_exist(product_id): raise ValueError(u"该商品不存在") self.model.edit({ "enable_flag": 0, "_id": utils.create_objectid(product_id) }) result['data'], result['pager'] = self.model.list() result['mode'] = '' except Exception as e: result = utils.reset_response_data(0, unicode(e)) result['alert'] = 1 self.render("admin/product/product-list.html", result=result, search='')
def put(self): result = utils.init_response_data() try: id = self.get_argument("id") _id = utils.create_objectid(id) address = self.get_argument("address", "") self.check_request_params(self.mp_require_params) request_params = self.format_request_params() update_params = {} exec("""update_params.update(%s)""" % request_params) self.check_update_params(update_params) update_params["_id"] = _id del update_params["id"] ret = self.model.update(query_params={"_id": _id}, update_params=update_params) result['data'] = ret except Exception, e: result = utils.reset_response_data(0, str(e))