Login

Managing Google AppEngine datastore maintenance

Author:
cvedovini
Posted:
June 30, 2010
Language:
Python
Version:
Not specified
Tags:
decorator readonly appengine maintenance capabilities datastore
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

  1. Google AppEngine Login Decorator by cmcavoy 7 years, 4 months ago
  2. ImageField for Google App Engine by davepeck 5 years, 9 months ago
  3. Using Google Apps Premium infrastructure for user management by tommy 7 years, 1 month ago
  4. cache_page that does nothing by peterbe 6 years ago
  5. Memento by manelvf 4 years, 7 months ago

Comments

Please login first before commenting.