- Author:
- cvedovini
- Posted:
- June 30, 2010
- Language:
- Python
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
This code defines a decorator that inform users of your site when the Google AppEngine data store is in read-only mode during maintenance periods.
Use it as a decorator on your views that require write access to the data store.
@requires_datastore_write
def update(request):
...
Create a maintenance.html
Django template (or change the name in the code) with the message that the user will see, something like:
This application is currently in maintenance mode and some operations are temporarily unavailable.
Thanks for trying back later. Sorry for the inconvenience.
1 2 3 4 5 6 7 8 9 10 11 12 13 | def requires_datastore_write(view):
def newview(request, *args, **kwargs):
from google.appengine.api import capabilities
datastore_write_enabled = capabilities.CapabilitySet('datastore_v3', capabilities=['write']).is_enabled()
if datastore_write_enabled:
return view(request, *args, **kwargs)
else:
from django.shortcuts import render_to_response
from django.template import RequestContext
return render_to_response('maintenance.html', context_instance=RequestContext(request))
return newview
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.