{ "info": { "author": "Chris Streeter", "author_email": "pypi@chrisstreeter.com", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Topic :: Software Development" ], "description": "About\n-----\n\nA way to globally disable writes to your database. This works by\ninserting a cursor wrapper between Django's ``CursorWrapper`` and the\ndatabase connection's cursor wrapper.\n\nInstallation\n------------\n\nThe library is hosted on\n`PyPi `_, so you can\ngrab it there with::\n\n pip install django-db-readonly\n\nThen add ``readonly`` to your ``INSTALLED_APPS``.::\n\n INSTALLED_APPS = (\n # ...\n 'readonly',\n # ...\n )\n\nUsage\n-----\n\nYou need to add this line to your ``settings.py`` to make the database read-only:\n\n::\n\n # Set to False to allow writes\n SITE_READ_ONLY = True\n\nWhen you do this, any write action to your databases will generate an\nexception. You should catch this exception and deal with it somehow. Or\nlet Django display an `error 500\npage `_.\nThe exception you will want to catch is\n``readonly.exceptions.DatabaseWriteDenied`` which inherits from\n``django.db.utils.DatabaseError``.\n\nThere is also a middleware class that will handle the exceptions and\nattempt to handle them as explained below. To enable the middleware, add the following line to your\n``settings.py``:\n\n::\n\n MIDDLEWARE_CLASSES = (\n # ...\n 'readonly.middleware.DatabaseReadOnlyMiddleware',\n # ...\n )\n\nThis will then catch ``DatabaseWriteDenied`` exceptions. If the request is a POST request, we\nwill redirect the user to the same URL, but as a GET request. If the\nrequest is not a POST (ie. a GET), we will just display a\n``HttpResponse`` with text telling the user the site is in read-only\nmode.\n\nIn addition, the middleware class can add an error-type message using\nthe ``django.contrib.messages`` module. Add:\n\n::\n\n # Enable\n DB_READ_ONLY_MIDDLEWARE_MESSAGE = True\n\nto your ``settings.py`` and then on POST requests that generate a\n``DatabaseWriteDenied`` exception, we will add an error message\ninforming the user that the site is in read-only mode.\n\nFor additional messaging, there is a context processor that adds\n``SITE_READ_ONLY`` into the context. Add the following line in your\n``settings.py``:\n\n::\n\n TEMPLATE_CONTEXT_PROCESSORS = (\n # ...\n 'readonly.context_processors.readonly',\n # ...\n )\n\nAnd use it as you would any boolean in the template, e.g.\n``{% if SITE_READ_ONLY %} We're down for maintenance. {% endif %}``\n\nTesting\n-------\n\nThere aren't any tests included, yet. Run it at your own risk.\n\nCaveats\n-------\n\nThis will work with `Django Debug\nToolbar `_. In fact,\nI was inspired by `DDT's sql\npanel `_\nwhen writing this app.\n\nHowever, in order for both DDT *and* django-db-readonly to work, you\nneed to make sure that you have ``readonly`` before ``debug_toolbar`` in\nyour ``INSTALLED_APPS``. Otherwise, you are responsible for debugging\nwhat is going on. Of course, I'm not sure why you'd be running DDT in\nproduction and running django-db-readonly in development, but whatever,\nI'm not you.\n\nMore generally, if you have any other apps that modifies either\n``django.db.backends.util.CursorWrapper`` or\n``django.db.backends.util.CursorDebugWrapper``, you need to make sure\nthat ``readonly`` is placed *before* of those apps in\n``INSTALLED_APPS``.\n\nThe Nitty Gritty\n----------------\n\nHow does this do what it does? Well, django-db-readonly sits between\nDjango's own cursor wrapper at ``django.db.backends.util.CursorWrapper``\nand the database specific cursor at\n``django.db.backends.*.base.*CursorWrapper``. It overrides two specific\nmethods: ``execute`` and ``executemany``. If the site is in read-only\nmode, then the SQL is examined to see if it contains any write actions\n(defined in ``readonly.ReadOnlyCursorWrapper.SQL_WRITE_BLACKLIST``). If\na write is detected, an exception is raised.\n\nLicense\n-------\n\nUses the `MIT `_ license.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/streeter/django-db-readonly", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "ambition-django-db-readonly", "package_url": "https://pypi.org/project/ambition-django-db-readonly/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/ambition-django-db-readonly/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/streeter/django-db-readonly" }, "release_url": "https://pypi.org/project/ambition-django-db-readonly/1.0.1/", "requires_dist": null, "requires_python": null, "summary": "Add a global database read-only setting.", "version": "1.0.1" }, "last_serial": 2562309, "releases": { "1.0.1": [] }, "urls": [] }