def get_vips(args, token=None): if token is None or not is_stuff(token): return abort(403) if 'name' in args: return Vip.objects(Q(name=args['name'])) return None
def create_sales_record(count, seller_id, book_id, purchaser_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() if book is None: return {'message': 'Missing parameter book, or book id is wrong.'} if book.remaining < count: return {'message': 'This book is not enough'} price = book.price seller = Account.objects(id=seller_id).first() if seller is None: return {'message': 'Missing parameter seller, or seller id is wrong.'} try: purchaser = Vip.objects(id=purchaser_id).first() except ValidationError: purchaser = None if purchaser is not None: price *= 0.8 book.remaining -= count book.sales += count book.save() sales_record = SalesRecord( count=count, price=price, book=book, seller=seller, purchaser=purchaser, ).save() return {'id': sales_record.id, 'success': 1}
def get_vips(args, token=None): if token is None or not is_stuff(token): return abort(403) if 'name' in args: return Vip.objects(Q(name=args['name'])) return None
def create_sales_record(count, seller_id, book_id, purchaser_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() if book is None: return {'message': 'Missing parameter book, or book id is wrong.'} if book.remaining < count: return {'message': 'This book is not enough'} price = book.price seller = Account.objects(id=seller_id).first() if seller is None: return {'message': 'Missing parameter seller, or seller id is wrong.'} try: purchaser = Vip.objects(id=purchaser_id).first() except ValidationError: purchaser = None if purchaser is not None: price *= 0.8 book.remaining -= count book.sales += count book.save() sales_record = SalesRecord( count=count, price=price, book=book, seller=seller, purchaser=purchaser, ).save() return { 'id': sales_record.id, 'success': 1 }
def get_all_accounts(token=None): if token is None or not is_stuff(token): return abort(403) if is_admin(token): condition = Q(username__ne='root') else: condition = Q(username__ne='root') & Q(role='stuff') accounts = Account.objects(condition) return accounts
def get_all_accounts(token=None): if token is None or not is_stuff(token): return abort(403) if is_admin(token): condition = Q(username__ne='root') else: condition = Q(username__ne='root') & Q(role='stuff') accounts = Account.objects(condition) return accounts
def get_account_by_id(account_id, token=None): if token is None or not is_stuff(token): return abort(403) condition = Q(id=account_id) if is_admin(token) and not is_root(token): condition &= Q(username__ne='root') elif not is_root(token): condition = Q(username__ne='root') & Q(role='stuff') account = Account.objects(condition).first() return account
def get_account_by_id(account_id, token=None): if token is None or not is_stuff(token): return abort(403) condition = Q(id=account_id) if is_admin(token) and not is_root(token): condition &= Q(username__ne='root') elif not is_root(token): condition = Q(username__ne='root') & Q(role='stuff') account = Account.objects(condition).first() return account
def create_book_type(name, token=None): if token is None or not is_stuff(token): return abort(403) if Type.objects(name=name).first() is not None: return {'message': 'This type has been exist'} book_type = Type(name=name).save() return { 'id': book_type.id, 'success': 1, }
def create_book_type(name, token=None): if token is None or not is_stuff(token): return abort(403) if Type.objects(name=name).first() is not None: return {'message': 'This type has been exist'} book_type = Type(name=name).save() return { 'id': book_type.id, 'success': 1, }
def get_accounts(args, token=None): if token is None or not is_stuff(token): return abort(403) if is_admin(token): condition = Q(username__ne='root') else: condition = Q(username__ne='root') & Q(role='stuff') if 'username' in args: condition &= Q(username=args['username']) if 'nickname' in args: condition &= Q(nickname=args['nickname']) accounts = Account.objects(condition) return accounts
def get_accounts(args, token=None): if token is None or not is_stuff(token): return abort(403) if is_admin(token): condition = Q(username__ne='root') else: condition = Q(username__ne='root') & Q(role='stuff') if 'username' in args: condition &= Q(username=args['username']) if 'nickname' in args: condition &= Q(nickname=args['nickname']) accounts = Account.objects(condition) return accounts
def get_book_types(args, token=None): if token is None or not is_stuff(token): return abort(403) condition = None if 'id' in args: condition = Q(id=args['id']) if 'name' in args: if condition is None: condition = Q(name=args['name']) else: condition &= Q(name=args['name']) types = Type.objects(condition) return types
def get_book_types(args, token=None): if token is None or not is_stuff(token): return abort(403) condition = None if 'id' in args: condition = Q(id=args['id']) if 'name' in args: if condition is None: condition = Q(name=args['name']) else: condition &= Q(name=args['name']) types = Type.objects(condition) return types
def create_vip(username, nickname, phone, token=None): if token is None or not is_stuff(token): return abort(403) if phone is None: phone = "" if Vip.objects(username=username).first() is not None: return {'message': 'The vip\'s name has been used'} vip = Vip( username=username, nickname=nickname, phone=phone, ).save() return { 'id': vip.id, 'success': 1, }
def create_vip(username, nickname, phone, token=None): if token is None or not is_stuff(token): return abort(403) if phone is None: phone = "" if Vip.objects(username=username).first() is not None: return {'message': 'The vip\'s name has been used'} vip = Vip( username=username, nickname=nickname, phone=phone, ).save() return { 'id': vip.id, 'success': 1, }
def get_all_vips(token=None): if token is None or not is_stuff(token): return abort(403) vips = Vip.objects() return vips
def get_sales_records_by_vip(vip_id, token=None): if token is None or not is_stuff(token): return abort(403) vip = Vip.objects(id=vip_id).first() sales_records = SalesRecord.objects(purchaser=vip) return sales_records
def get_book_by_id(book_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() return book
def get_all_books(token=None): if token is None or not is_stuff(token): return abort(403) books = Book.objects() return books
def get_book_by_id(book_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() return book
def get_sales_records_by_account(account_id, token=None): if token is None or not is_stuff(token): return abort(403) account = Account.objects(id=account_id).first() sales_records = SalesRecord.objects(seller=account) return sales_records
def rm_vip(book_id, token=None): if token is None or not is_stuff(token): return abort(403) vip = Vip.objects(id=book_id) vip.delete() return {'success': 1}
def get_books_by_type(type_id, token=None): if token is None or not is_stuff(token): return abort(403) the_type = Type.objects(id=type_id).first() books = Book.objects(type__in=[the_type]) return books
def rm_vip(book_id, token=None): if token is None or not is_stuff(token): return abort(403) vip = Vip.objects(id=book_id) vip.delete() return {'success': 1}
def get_all_books(token=None): if token is None or not is_stuff(token): return abort(403) books = Book.objects() return books
def get_books_by_type(type_id, token=None): if token is None or not is_stuff(token): return abort(403) the_type = Type.objects(id=type_id).first() books = Book.objects(type__in=[the_type]) return books
def get_all_vips(token=None): if token is None or not is_stuff(token): return abort(403) vips = Vip.objects() return vips
def get_sales_records_by_book(book_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() sales_records = SalesRecord.objects(book=book) return sales_records
def get_sales_records_by_account(account_id, token=None): if token is None or not is_stuff(token): return abort(403) account = Account.objects(id=account_id).first() sales_records = SalesRecord.objects(seller=account) return sales_records
def get_all_types(token=None): if token is None or not is_stuff(token): return abort(403) types = Type.objects() return types
def get_sales_records_by_book(book_id, token=None): if token is None or not is_stuff(token): return abort(403) book = Book.objects(id=book_id).first() sales_records = SalesRecord.objects(book=book) return sales_records
def get_sales_records_by_vip(vip_id, token=None): if token is None or not is_stuff(token): return abort(403) vip = Vip.objects(id=vip_id).first() sales_records = SalesRecord.objects(purchaser=vip) return sales_records
def get_all_types(token=None): if token is None or not is_stuff(token): return abort(403) types = Type.objects() return types