github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/server/block/operation/commodity.py (about) 1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 from operation import Base 4 from db.example.commodity import CommodityDB 5 6 class CommodityOp(Base): 7 def __init__(self): 8 super(CommodityOp, self).__init__() 9 self.exampledb = CommodityDB() 10 11 def create(self, name='', describe='', original_price='', real_price='', commodity_type='', file_path='', **kwargs): 12 kwargs = { 13 'name': name, 14 'describe': describe, 15 'original_price': float(original_price), 16 'real_price': float(real_price), 17 'commodity_type': commodity_type, 18 'file_path': file_path 19 } 20 self.exampledb.create(**kwargs) 21 22 def update(self, id='', name='', describe='', original_price='', real_price='', commodity_type='', file_path='', **kwargs): 23 kwargs = { 24 'name': name, 25 'describe': describe, 26 'original_price': float(original_price), 27 'real_price': float(real_price), 28 'commodity_type': commodity_type, 29 'file_path': file_path 30 } 31 self.exampledb.update(id, **kwargs) 32 33 def lists(self, offset=0, limit=1000, id='', name='', **kwargs): 34 filters = { 35 'offset': offset, 36 'limit': limit 37 } 38 if id: 39 filters.update({"id": id}) 40 if name: 41 filters.update({"name": name}) 42 43 order_list = self.exampledb.lists(offset, limit, **filters) 44 return order_list