On 19/07/16 05:16, Rishi Gupta wrote:
Hi django-developers,
(1) Middleware error framework.
Zulip has some exception middleware to allow 40x errors to be returned
to the user from anywhere within the view code via raising a special
exception, which we’ve found to be a really nice, convenient
programming style. With this model, validation code called anywhere
from within a view can pass nice, clear user-facing errors up to the
frontend. You can do this by writing something like:
I did something like this [actually, the code was handed to me by Matt
Schinckel]... which I use in django-nap.
It's HtppResponse melded with Exception so you can raise it.
I submitted it for consideration some time ago, and it was rejected
because it bound source and action too tightly.
However, it looks like your solution doesn't suffer from this shortcoming.
As was mentioned by Tim, I think this can readily grow outside django,
until it's matured.
(2) High level logging for database queries.
We've currently monkey-patched a system to add the following
information to our log lines:
... 52ms (db: 4ms/8q) /url ...
Some years back I wrote some middleware to do just this.... originally
logging the count / total time, and later sending it to the browser in a
cookie with a 0 time to live.
Currently there isn't a great way to do this "natively"; Django’s
database cursors either logs the whole query (in DEBUG mode) or
nothing at all.
In debug mode the queries [and their execution times] are kept on the
connection.
import time
class CookieDebugMiddleware(object):
'''Show query counts, times, and view timing in Cookies'''
def process_request(self, request):
request.start_time = time.time()
def process_response(self, request, response):
response.set_cookie('QueryCount', '%d (%s s)' % (
len(connection.queries),
sum([float(q['time']) for q in connection.queries])
), max_age=0)
response.set_cookie('ViewTime', '%s s' % (time.time() -
request.start_time), max_age=0)
return response
--
Curtis
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/ff91610e-9a8e-2c8a-554b-ca2c880de95b%40tinbrain.net.
For more options, visit https://groups.google.com/d/optout.