This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
Pull from regulations-core with Python, not HTTP #845
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes it possible for regulations-site to pull content from a regulations-core API running in the same Django instance by directly making Python calls instead of using HTTP requests.
By defining the Django setting
EREGS_REGCORE_URLS
and setting it to the path to your regulations-core URLconf (likelyregcore.urls
), the API will, instead of using HTTP to make requests, just call the Django views directly.When running in the same Django installation as regulations-core this saves time and reduces load on the web server.
If this setting is not defined then behavior falls back to the current method of using HTTP requests based on the
EREGS_API_BASE
environment variable.The best way to test this in action is to observe that if you run the Django debug server with this setting, you won't see any requests to the regcore API when making regsite requests.
I've added several unit tests that attempt to cover this change. Behavior should be similar to the current HTTP-based approach. If the Django view returns a 404 or raises an
Http404
then the API returnsNone
. If the view raises an exception, then the API will pass that along. Otherwise, the view just passes back the JSON content of the regcore view response as if it had been retrieved via HTTP.