-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
168 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
default_install_hook_types: [pre-commit, commit-msg] | ||
default_language_version: | ||
python: python3 | ||
exclude: (/migrations/|manage.py|docs/source/conf.py) | ||
repos: | ||
- repo: https://github.com/base-angewandte/pre-commit-hooks | ||
rev: py3.7 | ||
rev: 1.1.1-py3.7 | ||
hooks: | ||
- id: base-hooks | ||
- id: base-commit-msg-hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,42 @@ | ||
import logging | ||
|
||
from rest_framework.exceptions import APIException | ||
from rest_framework.views import exception_handler | ||
|
||
default_app_config = 'api.apps.ApiConfig' | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PermanentRedirect(APIException): | ||
# TODO: in the current version rest_framework.status has a status.HTTP_307_TEMPORARY_REDIRECT, but it is missing a | ||
# status.HTTP_308_PERMANENT_REDIRECT, which is available in a newer version of rest_framework. Update this, | ||
# as soon as rest_framework is updated. | ||
# status_code = status.HTTP_308_PERMANENT_REDIRECT | ||
status_code = 308 | ||
default_detail = 'This resource has moved' | ||
default_code = 'permanent_redirect' | ||
|
||
def __init__(self, detail=None, to=None): | ||
if to is None: | ||
raise TypeError("PermanentRedirect is missing required argument 'to'") | ||
self.to = to | ||
if detail is None: | ||
detail = self.default_detail | ||
super().__init__(detail) | ||
|
||
|
||
def portfolio_exception_handler(exc, context): | ||
# Call REST framework's default exception handler first, | ||
# to get the standard error response. | ||
response = exception_handler(exc, context) | ||
|
||
if isinstance(exc, PermanentRedirect): | ||
pk = context['kwargs']['pk'] | ||
old_path = context['request']._request.path | ||
new_path = old_path.replace(pk, exc.to) | ||
response.data['to'] = new_path | ||
# TODO: update to response.headers['Location'] once django is updated to >= 3.2 | ||
response['Location'] = new_path | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.2.28 on 2022-11-21 10:14 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0018_auto_20220422_0809'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='entry', | ||
name='data', | ||
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters