# Path: maple/utils.py
# class AuthMethodView(MethodView):
#     decorators = (login_required, )
# 
# Path: maple/storage/db.py
# class Bucket(ModelUserMixin, db.Model):
#     __tablename__ = 'bucket'
# 
#     name = db.Column(db.String(108), nullable=False, unique=True)
#     description = db.Column(db.String(1024), default='default')
# 
#     def get_root_path(self, path, create=False):
#         filepath = self.rootpath
#         for name in path.split("/"):
#             if name == "":
#                 continue
#             childpath = filepath.child_paths.filter_by(
#                 name=name,
#                 bucket_id=self.id,
#             ).first()
#             if not childpath and not create:
#                 return
# 
#             if not childpath and create:
#                 childpath = FilePath(
#                     name=name,
#                     bucket_id=self.id,
#                     parent_id=filepath.id,
#                 )
#                 childpath.save()
#             filepath = childpath
#         return filepath
# 
#     @property
#     def rootpath(self):
#         filepath = self.paths.filter_by(name="/").first()
#         if not filepath:
#             filepath = FilePath(name="/", bucket_id=self.id)
#             filepath.save()
#         return filepath
# 
#     @property
#     def abspath(self):
#         return os.path.join(config.UPLOAD_FOLDER, self.name)
# 
#     @property
#     def relpath(self):
#         return os.path.join(self.name)
# 
#     def __repr__(self):
#         return '<Bucket %r>' % self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: maple/storage/serializer.py
# class BucketSerializer(Serializer):
#     class Meta:
#         exclude = ["paths"]
# 
# Path: maple/utils.py
# def check_params(keys, req=None):
#     '''
#     only check is not NULL
#     '''
#     def _check_params(func):
#         @wraps(func)
#         def decorator(*args, **kwargs):
#             if req is not None:
#                 request_data = req
#             else:
#                 request_data = request.data
#             for key in keys:
#                 if not request_data.get(key):
#                     return HTTP.BAD_REQUEST(message='{0} required'.format(key))
#             return func(*args, **kwargs)
# 
#         return decorator
# 
#     return _check_params
# 
# def filter_maybe(request_data, columns, params=None):
#     if params is None:
#         params = dict()
#     is_dict = isinstance(columns, dict)
#     for column in columns:
#         value = request_data.get(column)
#         if not value:
#             continue
#         key = column if not is_dict else columns.get(column, column)
# 
#         if key in ["created_at__gte", "created_at__lte"]:
#             value = datetime.strptime(value, '%Y-%m-%d')
#         params.update({key: value})
#     return params
# 
# def update_maybe(ins, request_data, columns):
#     for column in columns:
#         value = request_data.get(column)
#         if value:
#             setattr(ins, column, value)
#     return ins


from flask import request
from flask_maple.response import HTTP
from maple.utils import AuthMethodView
from maple.storage.db import Bucket
from maple.storage.serializer import BucketSerializer
from maple.utils import check_params, filter_maybe, update_maybe
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ********************************************************************************
# Copyright © 2019 jianglin
# File Name: bucket.py
# Author: jianglin
# Email: mail@honmaple.com
# Created: 2019-05-13 16:36:36 (CST)
# Last Update: Monday 2019-09-23 17:11:18 (CST)
#          By:
# Description:
# ********************************************************************************


class BucketListView(AuthMethodView):
    def get(self):
        data = request.data
        user = request.user
        page, number = self.pageinfo


# Path: maple/utils.py
# class AuthMethodView(MethodView):
#     decorators = (login_required, )
# 
# Path: maple/storage/db.py
# class Bucket(ModelUserMixin, db.Model):
#     __tablename__ = 'bucket'
# 
#     name = db.Column(db.String(108), nullable=False, unique=True)
#     description = db.Column(db.String(1024), default='default')
# 
#     def get_root_path(self, path, create=False):
#         filepath = self.rootpath
#         for name in path.split("/"):
#             if name == "":
#                 continue
#             childpath = filepath.child_paths.filter_by(
#                 name=name,
#                 bucket_id=self.id,
#             ).first()
#             if not childpath and not create:
#                 return
# 
#             if not childpath and create:
#                 childpath = FilePath(
#                     name=name,
#                     bucket_id=self.id,
#                     parent_id=filepath.id,
#                 )
#                 childpath.save()
#             filepath = childpath
#         return filepath
# 
#     @property
#     def rootpath(self):
#         filepath = self.paths.filter_by(name="/").first()
#         if not filepath:
#             filepath = FilePath(name="/", bucket_id=self.id)
#             filepath.save()
#         return filepath
# 
#     @property
#     def abspath(self):
#         return os.path.join(config.UPLOAD_FOLDER, self.name)
# 
#     @property
#     def relpath(self):
#         return os.path.join(self.name)
# 
#     def __repr__(self):
#         return '<Bucket %r>' % self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: maple/storage/serializer.py
# class BucketSerializer(Serializer):
#     class Meta:
#         exclude = ["paths"]
# 
# Path: maple/utils.py
# def check_params(keys, req=None):
#     '''
#     only check is not NULL
#     '''
#     def _check_params(func):
#         @wraps(func)
#         def decorator(*args, **kwargs):
#             if req is not None:
#                 request_data = req
#             else:
#                 request_data = request.data
#             for key in keys:
#                 if not request_data.get(key):
#                     return HTTP.BAD_REQUEST(message='{0} required'.format(key))
#             return func(*args, **kwargs)
# 
#         return decorator
# 
#     return _check_params
# 
# def filter_maybe(request_data, columns, params=None):
#     if params is None:
#         params = dict()
#     is_dict = isinstance(columns, dict)
#     for column in columns:
#         value = request_data.get(column)
#         if not value:
#             continue
#         key = column if not is_dict else columns.get(column, column)
# 
#         if key in ["created_at__gte", "created_at__lte"]:
#             value = datetime.strptime(value, '%Y-%m-%d')
#         params.update({key: value})
#     return params
# 
# def update_maybe(ins, request_data, columns):
#     for column in columns:
#         value = request_data.get(column)
#         if value:
#             setattr(ins, column, value)
#     return ins


# Path: maple/storage/api/bucket.py
from flask import request
from flask_maple.response import HTTP
from maple.utils import AuthMethodView
from maple.storage.db import Bucket
from maple.storage.serializer import BucketSerializer
from maple.utils import check_params, filter_maybe, update_maybe

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ********************************************************************************
# Copyright © 2019 jianglin
# File Name: bucket.py
# Author: jianglin
# Email: mail@honmaple.com
# Created: 2019-05-13 16:36:36 (CST)
# Last Update: Monday 2019-09-23 17:11:18 (CST)
#          By:
# Description:
# ********************************************************************************


class BucketListView(AuthMethodView):
    def get(self):
        data = request.data
        user = request.user
        page, number = self.pageinfo


        params = filter_maybe(data, {"name": "name__contains"})