Commits

Jakub Zalewski committed 795eb76

first!

Comments (0)

Files changed (4)

+Django-Readonly 
+=============
+
+Put your website into read-only mode for maintanance. It blocks any POST requests and signs users out. 
+It doesn't lock any database transactions (check out https://github.com/streeter/django-db-readonly for that).
+
+
+ * http://pypi.python.org/pypi/django-readonly/
+ * https://bitbucket.org/zalew/django-readonly/
+ 
+ Usage
+ -----
+ 
+ * ``pip install django-readonly``
+ * settings.py: add ``'readonly.middleware.ReadOnlyMiddleware',`` to ``MIDDLEWARE_CLASSES``
+ * settings.py: READ_ONLY = True
+ * template: ``{% if request.read_only %}<p>Website is currently in read-only mode.</p>{% endif %}``
+  

readonly/__init__.py

+VERSION = (0, 1, 0)
+DEV_STATUS = '3 - Alpha'

readonly/middleware.py

+#!/usr/bin/env python
+# encoding: utf-8
+from django.conf import settings
+from django.contrib.auth import logout
+
+
+class ReadOnlyMiddleware:
+
+    def process_request(self, request):
+        if getattr(settings, 'READ_ONLY', False):
+            if request.user.is_authenticated():
+                logout(request)
+            if request.method == 'POST':
+                request.POST = {}
+            request.read_only = True
+        return None
+#!/usr/bin/env python
+# encoding: utf-8
+import os
+from setuptools import setup, find_packages
+from readonly import VERSION, DEV_STATUS
+
+setup(
+    name='django-readonly',
+    version='.'.join(map(str, VERSION)),
+    description='Put website in read-only mode for maintenance.',
+    long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
+    keywords='django readonly',
+    author='Jakub Zalewski',
+    author_email='zalew7@gmail.com',
+    url='https://bitbucket.org/zalew/django-readonly',
+    license='public domain',
+    packages=find_packages(),
+    zip_safe=False,
+    package_data={
+        'readonly': [],
+    },
+    classifiers=[
+        'Development Status :: %s' % DEV_STATUS,
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: Public Domain',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Framework :: Django',
+    ],
+      install_requires=[
+        'django',
+    ],
+)