[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Source code for google.appengine.ext.ndb.django_middleware
## Copyright 2008 The ndb Authors. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License."""Django middleware for NDB."""__author__='James A. Morrison'from.importeventloop,tasklets
[docs]classNdbDjangoMiddleware(object):"""Django middleware for NDB. To use NDB with django, add 'ndb.NdbDjangoMiddleware', to the MIDDLEWARE_CLASSES entry in your Django settings.py file. Or, if you are using the ndb version from the SDK, use 'google.appengine.ext.ndb.NdbDjangoMiddleware', It's best to insert it in front of any other middleware classes, since some other middleware may make datastore calls and those won't be handled properly if that middleware is invoked before this middleware. See http://docs.djangoproject.com/en/dev/topics/http/middleware/. """
[docs]defprocess_request(self,unused_request):"""Called by Django before deciding which view to execute."""# Compare to the first half of toplevel() in context.py.tasklets._state.clear_all_pending()# Create and install a new context.ctx=tasklets.make_default_context()tasklets.set_context(ctx)
@staticmethoddef_finish():# Compare to the finally clause in toplevel() in context.py.ctx=tasklets.get_context()tasklets.set_context(None)ctx.flush().check_success()eventloop.run()# Ensure writes are flushed, etc.
[docs]defprocess_response(self,request,response):"""Called by Django just before returning a response."""self._finish()returnresponse
[docs]defprocess_exception(self,unused_request,unused_exception):"""Called by Django when a view raises an exception."""self._finish()returnNone
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]