A simple Django app to fetch and parse data from Dataporten.
Project description
Django-dataporten is a simple Django app to fetch data from dataporten and connect it to a user.
Quick start
Add “dataporten” to your INSTALLED_APPS setting like this
INSTALLED_APPS = [
...
'dataporten',
]
Run python manage.py migrate to create the dataporten proxy models.
3. In your settings.py file, add the variable DATAPORTEN_TOKEN_FUNCTION, which
should be a dotted path to the function that will retrieve user tokens.
The function should accept a User
and return a str
.
Here is a python3.6/3.7 example that will work if you use django-allauth:
def allauth_token(user: User) -> str:
return SocialToken.objects.get(
account__user=user,
account__provider='dataporten',
).token
4. Add the dataporten middleware. This middleware adds a dataporten
attribute to request.user
for users with an associated
dataporten SocialToken
object. Take care to place it after
django.contrib.auth.middleware.AuthenticationMiddleware
.
MIDDLEWARE = (
# Other middleware...
'django.contrib.auth.middleware.AuthenticationMiddleware',
# Other middleware...
# Adds dataporten API information to request.user.dataporten
# Needs to be placed after any authentication middleware, as this
# requires inspection of request.user
'dataporten.middleware.DataportenGroupsMiddleware',
# Other middleware...
)
5. Optionally, enable caching for API queries. Take care to create the directory
set in DATAPORTEN_CACHE_PATH
before starting the Django server.
# Cache requests to the dataporten API
DATAPORTEN_CACHE_REQUESTS = True
# Where to save the sqlite3 cache backend
DATAPORTEN_CACHE_PATH = 'tmp/'
Run tests
export DJANGO_SETTINGS_MODULE=dataporten.settings
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_dataporten-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e58991d5ae9fc8f12b9e6fdfb21b6308a070de34a97ab4a30c1a37a65c690e0b |
|
MD5 | c24e137debbe018d0bb568b58b3ffe14 |
|
BLAKE2b-256 | 3b6719de120cafaf59e041f1bec5a0869a2a021fde39446b22845b64c3688727 |