Exemplo n.º 1
0
    def post(self, *args, **kwargs):
        result = utils.init_response_data()
        try:
            sku = self.get_argument("sku","")
            name = self.get_argument("name","")
            sort = self.get_argument("sort",0)
            image = self.get_argument("image","")
            show_code = self.get_argument("show_code","")
            show_name = self.get_argument("show_name","")
            enable_flag = self.get_argument("enable_flag",1)
            on_sale_flag = self.get_argument("on_sale_flag",1)
            origin_price = self.get_argument("origin_price",0.0)
            price = self.get_argument("price",0.0)
            type = self.get_argument("type", "")
            desc = self.get_argument("desc","")

            add_time = datetime.datetime.now()

            if type == "":
                raise Exception("类型不能为空")

            query_params = dict(
                type = type,
            )
            if not self.model.is_exists(query_params):

                obj = self.model.create(dict(sku=sku,name=name,sort=sort,image=image,show_code=show_code,show_name=show_name,
                                    enable_flag=enable_flag,on_sale_flag=on_sale_flag,origin_price=origin_price,
                                    price=price,type=type,desc=desc,add_time=add_time))
                obj = utils.dump(obj)
                result["data"] = obj
        except Exception, e:
            result = utils.reset_response_data(0, str(e))
Exemplo n.º 2
0
 def search_list(self, page=1, page_size=10):
     query_params = {}
     coll = self.get_coll()
     length = coll.find(query_params).count()
     pager = utils.count_page(length, page, page_size)
     cr = coll.find(query_params).sort("add_date", -1).limit(
         pager['page_size']).skip(pager['skip'])
     objs = [utils.dump(obj) for obj in cr]
     return objs, pager
Exemplo n.º 3
0
 def update(self, query_params, update_params):
     coll = self.get_coll()
     obj = coll.find_one(query_params)
     if obj:
         obj.update(update_params)
         ret = coll.save(obj)
     else:
         obj = {}
     return utils.dump(obj)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 def get_show_products(self, show_code):
     result = {}
     show_products = utils.dump(self.get_coll().find({
         "show_code": show_code,
         "enable_flag": 1
     }))
     result['show_products'] = sorted(show_products,
                                      key=lambda x: x['sort'],
                                      reverse=True)
     if len(result['show_products']) != 0:
         result['show_code'] = show_code
         result['show_name'] = result['show_products'][0]['show_name']
     return result
Exemplo n.º 6
0
 def list(self, query_list={"enable_flag": 1}, page=1, page_size=15):
     length = self.get_coll().find(query_list).count()
     pager = utils.count_page(length, page, page_size)
     list = self.get_coll().aggregate([{
         "$match": query_list
     }, {
         "$sort": {
             "add_time": -1
         }
     }, {
         "$skip": pager['skip']
     }, {
         "$limit": pager['page_size']
     }])
     return utils.dump(list), pager
Exemplo n.º 7
0
    def post(self):
        result = utils.init_response_data()
        try:
            self.check_request_params(self.mp_require_params)
            request_params = self.format_request_params()
            exec("""request_params = self.mp_default_params.update(%s)""" %
                 request_params)
            request_params = self.mp_default_params

            query_params = {}
            for key in self.query_params:
                query_params.update({
                    key: request_params[key],
                })

            if query_params == {} or not self.model.is_exists(query_params):
                obj = self.model.create(**request_params)
                result = utils.dump(obj)
        except Exception, e:
            result = utils.reset_response_data(0, str(e))
Exemplo n.º 8
0
 def search(self, query_params):
     coll = self.get_coll()
     obj = coll.find_one(query_params)
     obj = utils.dump(obj)
     return obj
Exemplo n.º 9
0
 def create(self, **obj):
     coll = self.get_coll()
     curr_time = datetime.datetime.now()
     obj["add_time"] = str(curr_time)
     coll.insert_one(obj)
     return utils.dump(obj)