From bea1f0cfd5f521aa5221346be06151b0e04311c8 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 5 Oct 2019 18:00:19 +0300 Subject: [PATCH] Initial commit --- .gitignore | 6 ++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 26 ++++++++++++++++++++++++++ marshmallow_pageinfo/__init__.py | 19 +++++++++++++++++++ requirements.txt | 1 + setup.py | 21 +++++++++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 marshmallow_pageinfo/__init__.py create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d47b31a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea + +.venv +/build +/dist +*.egg* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ae03a7f --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..68f0b14 --- /dev/null +++ b/README.md @@ -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), + } +``` diff --git a/marshmallow_pageinfo/__init__.py b/marshmallow_pageinfo/__init__.py new file mode 100644 index 0000000..caf8d38 --- /dev/null +++ b/marshmallow_pageinfo/__init__.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a734fd1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +marshmallow==3.2.1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9ee0655 --- /dev/null +++ b/setup.py @@ -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'] + )