mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* fixes #965: intermittent bug during consolidation of notifications * fixes #863: better visibility for input validation errors * fixes #375: re-evaluate affiliation requests on email change * fixes #741: remove data quality validation for superusers * fixes #587: customizable pagination in django admin * fixes #923: Prevent deletion of a last technical contact if there is an existing netixlan object * better search #23 (first pass) * black format * haystack test config to run_tests.py remove old django_init.py test settings * black format * haystack test config fixes * #23 better search (pt.2) * rate limit distance queries (#23) rate limiting based on query filters * settings controlled blocking of distance filter for unauthenticated / unverified users (#23) * fix distance filter throttling with api key auth (#23) * fix anon user access check on distance queries * search index and performance tweaks * fix org_id not set in search results * org id to int Co-authored-by: Stefan Pratter <stefan@20c.com>
30 lines
649 B
Python
30 lines
649 B
Python
from contextlib import contextmanager
|
|
import contextvars
|
|
|
|
# stores current request in a thread safe context aware
|
|
# manner.
|
|
_current_request = contextvars.ContextVar("current_request")
|
|
|
|
|
|
@contextmanager
|
|
def current_request(request=None):
|
|
|
|
"""
|
|
Will yield the current request, if there is one.
|
|
|
|
To se the current request for the context pass it to
|
|
the request parameter.
|
|
"""
|
|
|
|
if request:
|
|
token = _current_request.set(request)
|
|
else:
|
|
token = None
|
|
try:
|
|
yield _current_request.get()
|
|
except LookupError:
|
|
yield None
|
|
finally:
|
|
if token:
|
|
_current_request.reset(token)
|