Skip to content
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
merged 2 commits into from
Dec 22, 2017
Merged

Conversation

chosak
Copy link
Member

@chosak chosak commented Dec 20, 2017

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 (likely regcore.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 returns None. 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.

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 (likely `regcore.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 Apache 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 returns
`None`. 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.
@chosak chosak merged commit 1c9c356 into master Dec 22, 2017
@chosak chosak deleted the regcore-with-python branch December 22, 2017 17:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants