Skip to content
This repository
Browse code

Updating docs, adding notes on using gevent

  • Loading branch information...
commit 347a102d06a479adc1beaad57ca9517d1e8f9fe5 1 parent 8a5494a
Charles Leifer authored August 13, 2012
2  docs/admin.rst
Source Rendered
@@ -344,7 +344,7 @@ file uploads.
344 344
     class PhotoAdmin(ModelAdmin):
345 345
         columns = ['image', 'thumb']
346 346
 
347  
-        def get_form(self):
  347
+        def get_form(self, adding=False):
348 348
             class PhotoForm(Form):
349 349
                 image = HiddenField()
350 350
                 image_file = FileField(u'Image file')
3  docs/api.rst
Source Rendered
@@ -232,11 +232,12 @@ Exposing Models with the ModelAdmin
232 232
         :rtype: The model instance with the given pk, raising a ``DoesNotExist``
233 233
                 in the event the model instance does not exist.
234 234
 
235  
-    .. py:method:: get_form()
  235
+    .. py:method:: get_form([adding=False])
236 236
 
237 237
         Provides a useful extension point in the event you want to define custom
238 238
         fields or custom validation behavior.
239 239
 
  240
+        :param boolean adding: indicates whether adding a new instance or editing existing
240 241
         :rtype: A `wtf-peewee <http://github.com/coleifer/wtf-peewee>`_ Form subclass that
241 242
                 will be used when adding or editing model instances in the admin.
242 243
 
54  docs/gevent.rst
Source Rendered
... ...
@@ -0,0 +1,54 @@
  1
+.. _gevent:
  2
+
  3
+Using gevent
  4
+============
  5
+
  6
+If you would like to serve your flask application using gevent, there are two small
  7
+settings you will need to add.
  8
+
  9
+Database configuration
  10
+----------------------
  11
+
  12
+Instruct peewee to store connection information in a thread local:
  13
+
  14
+.. code-block:: python
  15
+
  16
+    # app configuration
  17
+    DATABASE = {
  18
+        'name': 'my_db',
  19
+        'engine': 'peewee.PostgresqlDatabase',
  20
+        'user': 'postgres',
  21
+        'threadlocals': True, # <-- this
  22
+    }
  23
+
  24
+
  25
+Monkey-patch the thread module
  26
+------------------------------
  27
+
  28
+Some time before instantiating a :py:class:`Database` object (and preferrably at
  29
+the very "beginning" of your code) you will want to `monkey-patch <http://www.gevent.org/gevent.monkey.html>`_
  30
+the standard library thread module:
  31
+
  32
+.. code-block:: python
  33
+
  34
+    from gevent import monkey; monkey.patch_thread()
  35
+
  36
+If you want to patch everything (recommended):
  37
+
  38
+.. code-block:: python
  39
+
  40
+    from gevent import monkey; monkey.patch_all()
  41
+
  42
+.. note:: Remember to monkey-patch before initializing your app
  43
+
  44
+
  45
+Rationale
  46
+---------
  47
+
  48
+flask-peewee opens a connection-per-request.  Flask stores things, like "per-request"
  49
+information, in a special object called a `context local <http://flask.pocoo.org/docs/reqcontext/>`_.
  50
+Flask will ensure that this works even in a greened environment.  Peewee does not
  51
+automatically work in a "greened" environment, and stores connection state on the
  52
+database instance in a local.  Peewee can use a thread local instead, which ensures
  53
+connections are not shared across threads.  When using peewee with gevent, it is
  54
+necessary to make this "threadlocal" a "greenlet local" by monkeypatching the thread module.
6  docs/index.rst
Source Rendered
@@ -8,7 +8,7 @@ flask-peewee
8 8
 
9 9
 Welcome to the flask-peewee documentation!
10 10
 
11  
-provides a layer of integration between the `flask <http://flask.pocoo.org/>`_ 
  11
+provides a layer of integration between the `flask <http://flask.pocoo.org/>`_
12 12
 web framework and the `peewee orm <http://peewee.rtfd.org/>`_.
13 13
 
14 14
 Contents:
@@ -16,7 +16,7 @@ Contents:
16 16
 .. toctree::
17 17
    :maxdepth: 2
18 18
    :glob:
19  
-   
  19
+
20 20
    installation
21 21
    getting-started
22 22
    database
@@ -24,6 +24,7 @@ Contents:
24 24
    auth
25 25
    rest-api
26 26
    utils
  27
+   gevent
27 28
 
28 29
 API in depth:
29 30
 
@@ -39,4 +40,3 @@ Indices and tables
39 40
 * :ref:`genindex`
40 41
 * :ref:`modindex`
41 42
 * :ref:`search`
42  
-

0 notes on commit 347a102

Please sign in to comment.
Something went wrong with that request. Please try again.