Initial commit
This commit is contained in:
commit
bea1f0cfd5
6 changed files with 94 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.idea
|
||||||
|
|
||||||
|
.venv
|
||||||
|
/build
|
||||||
|
/dist
|
||||||
|
*.egg*
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 IceTemple
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
26
README.md
Normal file
26
README.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# marshmallow_pageinfo
|
||||||
|
|
||||||
|
Page info marshmallow schema for api
|
||||||
|
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
`pip install -U marshmallow_pageinfo`
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
from marshmallow_pageinfo import PAGE_INFO_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
|
@controller.route('/', methods=['GET'])
|
||||||
|
def get_todo():
|
||||||
|
page_info = PAGE_INFO_SCHEMA.load(request.args)
|
||||||
|
pagination = todo_q.paginate(page_info['page'], page_info['per_page'])
|
||||||
|
return {
|
||||||
|
'todos': TODO_SCHEMA.dump(pagination.items),
|
||||||
|
'pageInfo': PAGE_INFO_SCHEMA.dump(pagination),
|
||||||
|
}
|
||||||
|
```
|
19
marshmallow_pageinfo/__init__.py
Normal file
19
marshmallow_pageinfo/__init__.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from marshmallow import Schema, fields, EXCLUDE
|
||||||
|
|
||||||
|
__all__ = ('PAGE_INFO_SCHEMA', 'PageInfoSchema',)
|
||||||
|
|
||||||
|
|
||||||
|
class PageInfoSchema(Schema):
|
||||||
|
page = fields.Integer(missing=1)
|
||||||
|
per_page = fields.Integer(data_key='perPage', missing=10)
|
||||||
|
total = fields.Integer()
|
||||||
|
pages = fields.Integer(data_key='totalPages')
|
||||||
|
has_next = fields.Boolean(data_key='hasNext')
|
||||||
|
has_prev = fields.Boolean(data_key='hasPrev')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
dump_only = ('total', 'pages', 'has_next', 'has_prev')
|
||||||
|
|
||||||
|
|
||||||
|
PAGE_INFO_SCHEMA = PageInfoSchema()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
marshmallow==3.2.1
|
21
setup.py
Normal file
21
setup.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
with open('README.md', 'r') as f:
|
||||||
|
readme = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
setup(
|
||||||
|
name='marshmallow_pageinfo',
|
||||||
|
version='1.0.0',
|
||||||
|
author='Dmitriy Pleshevskiy',
|
||||||
|
author_email='dmitriy@ideascup.me',
|
||||||
|
description='Page info marshmallow schema for api',
|
||||||
|
long_description=readme,
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
|
package_data={'': ['LICENSE', 'README.md']},
|
||||||
|
include_package_data=True,
|
||||||
|
license='MIT',
|
||||||
|
packages=['marshmallow_pageinfo']
|
||||||
|
)
|
Reference in a new issue