Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating docs, adding notes on using gevent

  • Loading branch information...
commit 347a102d06a479adc1beaad57ca9517d1e8f9fe5 1 parent 8a5494a
@coleifer authored
View
2  docs/admin.rst
@@ -344,7 +344,7 @@ file uploads.
class PhotoAdmin(ModelAdmin):
columns = ['image', 'thumb']
- def get_form(self):
+ def get_form(self, adding=False):
class PhotoForm(Form):
image = HiddenField()
image_file = FileField(u'Image file')
View
3  docs/api.rst
@@ -232,11 +232,12 @@ Exposing Models with the ModelAdmin
:rtype: The model instance with the given pk, raising a ``DoesNotExist``
in the event the model instance does not exist.
- .. py:method:: get_form()
+ .. py:method:: get_form([adding=False])
Provides a useful extension point in the event you want to define custom
fields or custom validation behavior.
+ :param boolean adding: indicates whether adding a new instance or editing existing
:rtype: A `wtf-peewee <http://github.com/coleifer/wtf-peewee>`_ Form subclass that
will be used when adding or editing model instances in the admin.
View
54 docs/gevent.rst
@@ -0,0 +1,54 @@
+.. _gevent:
+
+Using gevent
+============
+
+If you would like to serve your flask application using gevent, there are two small
+settings you will need to add.
+
+Database configuration
+----------------------
+
+Instruct peewee to store connection information in a thread local:
+
+.. code-block:: python
+
+ # app configuration
+ DATABASE = {
+ 'name': 'my_db',
+ 'engine': 'peewee.PostgresqlDatabase',
+ 'user': 'postgres',
+ 'threadlocals': True, # <-- this
+ }
+
+
+Monkey-patch the thread module
+------------------------------
+
+Some time before instantiating a :py:class:`Database` object (and preferrably at
+the very "beginning" of your code) you will want to `monkey-patch <http://www.gevent.org/gevent.monkey.html>`_
+the standard library thread module:
+
+.. code-block:: python
+
+ from gevent import monkey; monkey.patch_thread()
+
+If you want to patch everything (recommended):
+
+.. code-block:: python
+
+ from gevent import monkey; monkey.patch_all()
+
+.. note:: Remember to monkey-patch before initializing your app
+
+
+Rationale
+---------
+
+flask-peewee opens a connection-per-request. Flask stores things, like "per-request"
+information, in a special object called a `context local <http://flask.pocoo.org/docs/reqcontext/>`_.
+Flask will ensure that this works even in a greened environment. Peewee does not
+automatically work in a "greened" environment, and stores connection state on the
+database instance in a local. Peewee can use a thread local instead, which ensures
+connections are not shared across threads. When using peewee with gevent, it is
+necessary to make this "threadlocal" a "greenlet local" by monkeypatching the thread module.
View
6 docs/index.rst
@@ -8,7 +8,7 @@ flask-peewee
Welcome to the flask-peewee documentation!
-provides a layer of integration between the `flask <http://flask.pocoo.org/>`_
+provides a layer of integration between the `flask <http://flask.pocoo.org/>`_
web framework and the `peewee orm <http://peewee.rtfd.org/>`_.
Contents:
@@ -16,7 +16,7 @@ Contents:
.. toctree::
:maxdepth: 2
:glob:
-
+
installation
getting-started
database
@@ -24,6 +24,7 @@ Contents:
auth
rest-api
utils
+ gevent
API in depth:
@@ -39,4 +40,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
-
Please sign in to comment.
Something went wrong with that request. Please try again.