From a04eb0b9780f4660de90a0e2d54c133c30ccd842 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sun, 11 Dec 2016 22:45:53 -0500 Subject: [PATCH 1/3] better pagination docs + fix docs generation + better version management --- docs/conf.py | 4 ++-- docs/index.rst | 16 +++++++++++++--- examples/biggerapp/app.py | 3 ++- examples/biggerapp/views.py | 10 ++++++++++ flask_mongoengine/__init__.py | 13 +++++++++++++ setup.py | 17 ++++++++++++++++- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 44c46d7f..91e0c20b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,9 +49,9 @@ # import flask_mongoengine # The short X.Y version. -version = flask_mongoengine.get_version() +version = flask_mongoengine.__version__ # The full version, including alpha/beta/rc tags. -release = flask_mongoengine.get_version() +release = flask_mongoengine.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index acba4d93..1017140b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -107,9 +107,17 @@ has_prev, next_num, prev_num. In the template:: - {% macro render_pagination(pagination, endpoint) %} + {# Display a page of todos #} + + + {# Macro for creating navigation links #} + {% macro render_navigation(pagination, endpoint) %} {% endmacro %} + {{ render_navigation(paginated_todos, 'view_todos') }} + MongoEngine and WTForms ======================= diff --git a/examples/biggerapp/app.py b/examples/biggerapp/app.py index 76d3161e..badb7afe 100644 --- a/examples/biggerapp/app.py +++ b/examples/biggerapp/app.py @@ -28,8 +28,9 @@ DebugToolbarExtension(app) -from views import index +from views import index, pagination app.add_url_rule('/', view_func=index) +app.add_url_rule('/pagination', view_func=pagination) if __name__ == "__main__": app.run(host="0.0.0.0", port=4000) diff --git a/examples/biggerapp/views.py b/examples/biggerapp/views.py index 87334938..31317fd2 100644 --- a/examples/biggerapp/views.py +++ b/examples/biggerapp/views.py @@ -10,3 +10,13 @@ def index(): todos = list(Todo.objects[:10]) todos = Todo.objects.all() return flask.render_template('index.html', todos=todos) + +def pagination(): + Todo.objects().delete() + for i in range(10): + Todo(title='Simple todo {}'.format(i), text="12345678910").save() # Insert + + page_num = int(flask.request.args.get('page') or 1) + todos_page = Todo.objects.paginate(page=page_num, per_page=3) + + return flask.render_template('pagination.html', todos_page=todos_page) diff --git a/flask_mongoengine/__init__.py b/flask_mongoengine/__init__.py index 68210758..6c15894e 100644 --- a/flask_mongoengine/__init__.py +++ b/flask_mongoengine/__init__.py @@ -16,6 +16,19 @@ from .wtf import WtfBaseField +VERSION = (0, 9, 0) + + +def get_version(): + """Return the VERSION as a string, e.g. for VERSION == (0, 9, 0), + return '0.9.0'. + """ + return '.'.join(map(str, VERSION)) + + +__version__ = get_version() + + def _patch_base_field(obj, name): """ If the object submitted has a class whose base class is diff --git a/setup.py b/setup.py index c23b34dd..de2318ea 100644 --- a/setup.py +++ b/setup.py @@ -15,11 +15,26 @@ except: pass + +def get_version(version_tuple): + """Return the version tuple as a string, e.g. for (0, 10, 7), + return '0.10.7'. + """ + return '.'.join(map(str, version_tuple)) + + +# Dirty hack to get version number from flask_monogengine/__init__.py - we +# can't import it as it depends on PyMongo and PyMongo isn't installed until +# this file is read +init = os.path.join(os.path.dirname(__file__), 'flask_mongoengine', '__init__.py') +version_line = list(filter(lambda l: l.startswith('VERSION'), open(init)))[0] +version = get_version(eval(version_line.split('=')[-1])) + test_requirements = ['coverage', 'nose', 'rednose'] setup( name='flask-mongoengine', - version='0.9.0', + version=version, url='https://github.com/mongoengine/flask-mongoengine', license='BSD', author='Ross Lawley', From 4ed867c21188e0acbe2faf4b66b471f2093ec1dc Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sun, 11 Dec 2016 22:46:09 -0500 Subject: [PATCH 2/3] add missing file --- examples/biggerapp/templates/pagination.html | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/biggerapp/templates/pagination.html diff --git a/examples/biggerapp/templates/pagination.html b/examples/biggerapp/templates/pagination.html new file mode 100644 index 00000000..13de34a2 --- /dev/null +++ b/examples/biggerapp/templates/pagination.html @@ -0,0 +1,35 @@ +{% extends "layout.html" %} + +{# Macro for creating navigation links #} +{% macro render_navigation(pagination, endpoint) %} + +{% endmacro %} + +{% block body %} + +
+
    + {% for todo in todos_page.items %} +
  • {{ todo.title }}
  • + {% endfor %} +
+
+ + + + +{% endblock %} From 9b2fd78d16a54cd9ef7acab0f19cbef16fc97a8c Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sun, 11 Dec 2016 22:49:46 -0500 Subject: [PATCH 3/3] add a link to the pagination page --- examples/biggerapp/templates/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/biggerapp/templates/index.html b/examples/biggerapp/templates/index.html index afc06320..71dcf4f4 100644 --- a/examples/biggerapp/templates/index.html +++ b/examples/biggerapp/templates/index.html @@ -8,4 +8,6 @@

{{ todo.title }}

{% else %} Unbelievable. No todos here so far Add one {% endfor %} +
+ See pagination {% endblock %}