<commit_before>Pylons support
==============

You can very easily interface Mongokit with Pylons. This tutorial explains how to do this.
Note that there's a lot of way to do the same thing. If you found another better solution,
please contact me, I'll update this tutorial.

Write you all models in ``model/``.  In the ``model/__init__.py``, import all the module
you want to register and then add them to a list called `register_models`.

Example of ``model/__init__.py``::

    from blog import Blog
    from blogpost import BlogPost

    register_models = [Blog, BlogPost]

Then go to the ``lib/app_globals.py`` and edit this file so it look like this::

    from pylons import config
    from <appname>.models import register_models
    from mongokit import *

    class Globals(object):

        """Globals acts as a container for objects available throughout the
        life of the application

        """

        def __init__(self):
            """One instance of Globals is created during application
            initialization and is available during requests via the
            'app_globals' variable

            """
            self.connection = Connection(
              host = config['db_host'],
              port = int(config['db_port']),
            )
            self.db = self.connection[config['db_name']]
            self.connection.register(register_models)


In this file, we create the connection (optionaly the db if we use only on) and then
we register all our models.

Now, you can access to the connection via the pylons.config :

    config['pylons.app_globals'].connection

A more convenient way is to add the connection to the BaseController so you can access
it just with ``self.connection``. The file ``lib/base.py`` has to look like this::

    from pylons.controllers import WSGIController
    from pylons.templating import render_mako as render
    from pylons import config
    import pylons
<commit_msg>Fix typo in doc/pylons.txt<commit_after>Pylons support
==============

You can very easily interface Mongokit with Pylons. This tutorial explains how to do this.
Note that there's a lot of way to do the same thing. If you found another better solution,
please contact me, I'll update this tutorial.

Write you all models in ``model/``.  In the ``model/__init__.py``, import all the module
you want to register and then add them to a list called `register_models`.

Example of ``model/__init__.py``::

    from blog import Blog
    from blogpost import BlogPost

    register_models = [Blog, BlogPost]

Then go to the ``lib/app_globals.py`` and edit this file so it look like this::

    from pylons import config
    from <appname>.models import register_models
    from mongokit import *

    class Globals(object):

        """Globals acts as a container for objects available throughout the
        life of the application

        """

        def __init__(self):
            """One instance of Globals is created during application
            initialization and is available during requests via the
            'app_globals' variable

            """
            self.connection = Connection(
              host = config['db_host'],
              port = int(config['db_port']),
            )
            self.db = self.connection[config['db_name']]
            self.connection.register(register_models)


In this file, we create the connection (optionally the db if we use only on) and then
we register all our models.

Now, you can access to the connection via the pylons.config :

    config['pylons.app_globals'].connection

A more convenient way is to add the connection to the BaseController so you can access
it just with ``self.connection``. The file ``lib/base.py`` has to look like this::

    from pylons.controllers import WSGIController
    from pylons.templating import render_mako as render
    from pylons import config
    import pylons

{'fraction_non_alphanumeric': 0.07479508196721311, 'fraction_numerical': 0.0, 'mean_word_length': 2.9444444444444446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7079189', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1002, 'n_words': 461}