{ "info": { "author": "Henri Hulski", "author_email": "henri.hulski@gazeta.pl", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "more.pony: Pony ORM integration in Morepath\n===========================================\n\nThis package provides Morepath integration for the Pony_\nObject-Relational Mapper library.\n\nThis package binds the database session to the request so\nyou can interact with the database in your App directly\nwithout using ``db_session``.\n\n\nQuick start\n-----------\n\nInstall ``more.pony``:\n\n.. code-block:: console\n\n $ pip install -U more.pony\n\nExtend your App class from PonyApp:\n\n.. code-block:: python\n\n from more.pony import PonyApp\n\n class App(PonyApp):\n pass\n\n\nCreate your model:\n\n.. code-block:: python\n\n from pony.orm import Database, PrimaryKey, Optional\n\n db = Database()\n\n\n class Document(db.Entity):\n _table_ = 'document'\n\n id = PrimaryKey(int, auto=True)\n title = Optional(str)\n content = Optional(str)\n\n def update(self, payload={}):\n self.set(**payload)\n\n def remove(self):\n self.delete()\n\n\nSetup the database in your start script:\n\n.. code-block:: python\n\n import morepath\n\n from .app import App\n from .model import db\n\n\n def run():\n db.bind(provider='sqlite', filename='app.db', create_db=True)\n db.generate_mapping(create_tables=True)\n\n morepath.autoscan()\n morepath.run(App())\n\n\nNow you can use the model in your path:\n\n.. code-block:: python\n\n from .app import App\n from .model import Document\n\n\n @App.path(model=Document, path='documents/{id}')\n def get_document(request, id=0):\n return Document[id]\n\nAnd in your view:\n\n.. code-block:: python\n\n from .app import App\n from .model import Document\n\n\n @App.json(model=Document)\n def document_default(self, request):\n return {\n 'id': self.id,\n 'title': self.title,\n 'content': self.content,\n 'link': request.link(self)\n }\n\n\n @App.json(model=Document, request_method='PUT')\n def document_update(self, request):\n self.update(request.json)\n\n\n @App.json(model=Document, request_method='DELETE')\n def document_remove(self, request):\n self.remove()\n\n\nSettings\n--------\n\nYou can set the arguments which are passed to ``db_session``\nin the ``pony`` section of your settings.\n\nThe default settings are:\n\n.. code-block:: python\n\n @App.setting_section(section='pony')\n def get_pony_settings():\n return {\n 'allowed_exceptions': [],\n 'immediate': False,\n 'retry': 0,\n 'retry_exceptions': [TransactionError],\n 'serializable': False,\n 'strict': False\n }\n\nMore information about the arguments you find in the `Pony API documentation`_.\n\nYou can also use the ``database`` settings section for your database setup,\nwhich allows you to use different setups for production, development and\ntesting environments.\n\nJust create create an App for each environment and load specific\nsettings files:\n\n.. code-block:: python\n\n class App(PonyApp):\n pass\n\n with open('settings/default.yml') as defaults:\n defaults_dict = yaml.load(defaults)\n\n App.init_settings(defaults_dict)\n\n\n class ProductionApp(App):\n pass\n\n\n with open('settings/production.yml') as settings:\n settings_dict = yaml.load(settings)\n\n ProductionApp.init_settings(settings_dict)\n\n\n class TestApp(App):\n pass\n\n\n with open('settings/test.yml') as settings:\n settings_dict = yaml.load(settings)\n\n TestApp.init_settings(settings_dict)\n\nThe database configuration in the YAML settings\nfiles, depending on the database you use, could\nlook something like:\n\n.. code-block:: yaml\n\n database:\n provider: sqlite\n filename: app.db\n create_db: true\n\nIn your start script you setup the database and load\nthe App according to the ``RUN_ENV`` environment variable:\n\n.. code-block:: python\n\n import os\n import morepath\n\n from .app import App, ProductionApp, TestApp\n from .model import db\n\n\n def setup_db(app):\n db_params = app.settings.database.__dict__.copy()\n db.bind(**db_params)\n db.generate_mapping(create_tables=True)\n\n def run():\n morepath.autoscan()\n\n if os.getenv('RUN_ENV') == 'production':\n ProductionApp.commit()\n app = ProductionApp()\n elif os.getenv('RUN_ENV') == 'test':\n TestApp.commit()\n app = TestApp()\n else:\n App.commit()\n app = App()\n\n setup_db(app)\n morepath.run(app)\n\nDetail about the database configuration you find\nin the `PonyOrm documentation`_.\n\n\nSide effects\n------------\n\nIf you want to trigger side effects (like sending an email or\nwriting to filesystem) on database commits you can emit a signal\nin the ``@request.after`` of the view which triggers the side effects.\n\nLike this the side effects will be triggered just before the\ndatabase session gets committed and only if it wasn't rolled back.\n\nThis example uses `more.emit`_:\n\n.. code-block:: python\n\n @App.json(model=Document, request_method='PUT')\n def document_update(self, request):\n self.update(request.json)\n\n @request.after\n def after(response):\n request.app.signal.emit('document_updated', self, request)\n\nAltenatively you can use in your model the PonyORM\n`after_insert()`_, `after_update()`_ or `after_delete()`_\nentity-hooks.\nThis makes sure that the side effect is triggered\n**after** the database session has committed.\n\nThe drawback is that you don't have easy access to the\nrequest or app in the model.\n\n\n.. _Pony: https://ponyorm.com\n.. _Pony API documentation:\n https://docs.ponyorm.com/api_reference.html#transactions-db-session\n.. _PonyOrm documentation: https://docs.ponyorm.com/api_reference.html#database\n.. _more.emit: https://github.com/morepath/more.emit\n.. _after_insert(): https://docs.ponyorm.com/api_reference.html#after_insert\n.. _after_update(): https://docs.ponyorm.com/api_reference.html#after_update\n.. _after_delete(): https://docs.ponyorm.com/api_reference.html#after_delete\n\n\nCHANGES\n=======\n\n0.2 (2017-07-20)\n----------------\n\n- Upgrade PonyORM to 0.7.2.\n- Use a dictonary for passing parameters to db.bind in examples and tests.\n\n\n0.1 (2017-04-22)\n----------------\n\n- Initial public release.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/morepath/more.pony", "keywords": "morepath Pony ORM PonyORM", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "more.pony", "package_url": "https://pypi.org/project/more.pony/", "platform": "", "project_url": "https://pypi.org/project/more.pony/", "project_urls": { "Homepage": "https://github.com/morepath/more.pony" }, "release_url": "https://pypi.org/project/more.pony/0.2/", "requires_dist": null, "requires_python": "", "summary": "Pony ORM integration in Morepath", "version": "0.2" }, "last_serial": 3037699, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "13addd96553e9d1451a8c9207240a866", "sha256": "8c9bab8ea4c08c27861b9150f047ff09b8debc947a8ff264272993bd77a6bb96" }, "downloads": -1, "filename": "more.pony-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "13addd96553e9d1451a8c9207240a866", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8445, "upload_time": "2017-04-22T15:13:07", "url": "https://files.pythonhosted.org/packages/17/0c/3e8772df56b7d5a42cd2be577979c8b37d090ddf326abe49088347af9027/more.pony-0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "414f3c54c7195de98685de5f839957e9", "sha256": "527f43f3ad402c26fa5b714647f0382637832e764d4f41478fb18ad32e985fc7" }, "downloads": -1, "filename": "more.pony-0.1.tar.gz", "has_sig": false, "md5_digest": "414f3c54c7195de98685de5f839957e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6282, "upload_time": "2017-04-22T15:13:10", "url": "https://files.pythonhosted.org/packages/65/54/f16100698281176c0f6143cbb7f54f7e2ac3320f071603b698cd91ad5e1c/more.pony-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "74e2576cf0c7678a46362ed14a9cd3cc", "sha256": "3ff97e9c9fe638ed83e3bf7720ecae34784f259243cb4ff1664c4a689dc30f3c" }, "downloads": -1, "filename": "more.pony-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "74e2576cf0c7678a46362ed14a9cd3cc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8587, "upload_time": "2017-07-20T19:53:59", "url": "https://files.pythonhosted.org/packages/7c/0e/c428556c93ed801af9fa7326def5ed072b23ff9ab37f715346996c759bb8/more.pony-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "07bea6d60bdfe8f8e438ca24e97202fc", "sha256": "acc4d0183357bf26ee650baf908c057a70985001d23ef98c9ba8a0eadb8f3c0c" }, "downloads": -1, "filename": "more.pony-0.2.tar.gz", "has_sig": false, "md5_digest": "07bea6d60bdfe8f8e438ca24e97202fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6350, "upload_time": "2017-07-20T19:53:57", "url": "https://files.pythonhosted.org/packages/93/b4/1dd8ac8025aa3cc7713236a73c30de4b14ea78637636a66f1784052321ae/more.pony-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "74e2576cf0c7678a46362ed14a9cd3cc", "sha256": "3ff97e9c9fe638ed83e3bf7720ecae34784f259243cb4ff1664c4a689dc30f3c" }, "downloads": -1, "filename": "more.pony-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "74e2576cf0c7678a46362ed14a9cd3cc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8587, "upload_time": "2017-07-20T19:53:59", "url": "https://files.pythonhosted.org/packages/7c/0e/c428556c93ed801af9fa7326def5ed072b23ff9ab37f715346996c759bb8/more.pony-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "07bea6d60bdfe8f8e438ca24e97202fc", "sha256": "acc4d0183357bf26ee650baf908c057a70985001d23ef98c9ba8a0eadb8f3c0c" }, "downloads": -1, "filename": "more.pony-0.2.tar.gz", "has_sig": false, "md5_digest": "07bea6d60bdfe8f8e438ca24e97202fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6350, "upload_time": "2017-07-20T19:53:57", "url": "https://files.pythonhosted.org/packages/93/b4/1dd8ac8025aa3cc7713236a73c30de4b14ea78637636a66f1784052321ae/more.pony-0.2.tar.gz" } ] }