forked from claytondaley/drf-keyed-list
-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
313 additions
and
79 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
<!-- | ||
For general questions please use the Discussions section of the project: | ||
https://github.com/bihealth/varfish-server/discussions | ||
For bug reports and feature requests please open a ticket using the templates! | ||
--> | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
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,28 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
<!-- | ||
For general questions please use the Discussions section of the project: | ||
https://github.com/bihealth/varfish-server/discussions | ||
For bug reports and feature requests please open a ticket using the templates! | ||
--> | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
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,14 @@ | ||
<!-- | ||
NOTE | ||
NOTE In most cases, you should create an issue first, and only then | ||
NOTE a pull request. Please see the contribution guidelines for | ||
NOTE further information. In particular related to conventional | ||
NOTE commit messages. | ||
NOTE | ||
The title should have the following format: | ||
<type>: description (#<issue>) | ||
--> |
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,18 @@ | ||
name: PR | ||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- reopened | ||
- edited | ||
- synchronize | ||
|
||
jobs: | ||
title-format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: amannn/action-semantic-pull-request@v3.4.0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
validateSingleCommit: true |
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,81 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches_ignore: [] | ||
|
||
jobs: | ||
cancel-previous: | ||
runs-on: ubuntu-latest | ||
if: github.ref != 'refs/heads/main' | ||
steps: | ||
- uses: khan/pull-request-workflow-cancel@1.0.0 | ||
with: | ||
workflows: "main.yml" | ||
env: | ||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | ||
|
||
linting: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.11" | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
lfs: true | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "${{ matrix.python-version }}" | ||
|
||
- name: Install dependencies | ||
run: | | ||
make dev-deps | ||
pip install -e . | ||
- name: Run lintings | ||
run: | | ||
make lint | ||
testing: | ||
runs-on: ubuntu-latest | ||
needs: linting | ||
strategy: | ||
matrix: | ||
django-version: | ||
- ">=3.0,<4.0" | ||
- ">=4.0,<5.0" | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
lfs: true | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "${{ matrix.python-version }}" | ||
|
||
- name: Install Django dependency | ||
run: | | ||
pip install "Django${{ matrix.django-version }}" | ||
- name: Install this library via pip | ||
run: | | ||
pip install -e . | ||
- name: "No tests yet :(" | ||
run: | | ||
# make test |
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,41 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
name: release-please | ||
|
||
jobs: | ||
release-please: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- uses: GoogleCloudPlatform/release-please-action@v2 | ||
id: release | ||
with: | ||
release-type: python | ||
package-name: drf-keyed-list-bihealth | ||
|
||
- uses: actions/checkout@v2 | ||
if: ${{ steps.release.outputs.release_created }} | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
if: ${{ steps.release.outputs.release_created }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Build package | ||
if: ${{ steps.release.outputs.release_created }} | ||
run: | | ||
python -m pip install --upgrade pip | ||
python setup.py sdist | ||
- name: Publish to PyPI | ||
if: ${{ steps.release.outputs.release_created }} | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_TOKEN }} |
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 |
---|---|---|
|
@@ -104,4 +104,4 @@ venv.bak/ | |
.mypy_cache/ | ||
|
||
# JetBrains | ||
.idea | ||
.idea |
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,42 @@ | ||
DIRS := drf_keyed_list | ||
|
||
.PHONY: all | ||
all: | ||
|
||
.PHONY: dev-deps | ||
dev-deps: | ||
pip install black==23.7.0 isort==5.12.0 flake8 | ||
|
||
.PHONY: format | ||
format: black isort | ||
|
||
.PHONY: isort | ||
isort: | ||
isort --force-sort-within-sections --profile=black $(DIRS) | ||
|
||
.PHONY: black | ||
black: | ||
black --line-length 100 $(DIRS) | ||
|
||
.PHONY: lint | ||
lint: check-black check-isort flake8 | ||
|
||
.PHONY: check-black | ||
check-black: | ||
black --check --diff --line-length 100 $(DIRS) | ||
|
||
.PHONY: check-isort | ||
check-isort: | ||
isort --force-sort-within-sections --profile=black --check $(DIRS) | ||
|
||
.PHONY: flake8 | ||
flake8: | ||
flake8 $(DIRS) | ||
|
||
.PHONY: test | ||
test: | ||
cd example-project | ||
python manage.py test djangoplugins | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
python manage.py syncplugins |
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,11 +1,11 @@ | ||
__title__ = 'DRF Keyed List' | ||
__version__ = '0.0.2' | ||
__author__ = 'Clayton Daley III' | ||
__license__ = 'Apache 2.0' | ||
__copyright__ = 'Copyright 2018 Clayton Daley' | ||
__title__ = "DRF Keyed List" | ||
__version__ = "0.0.2" | ||
__author__ = "Clayton Daley III" | ||
__license__ = "Apache 2.0" | ||
__copyright__ = "Copyright 2018 Clayton Daley" | ||
|
||
# Version synonym | ||
VERSION = __version__ | ||
|
||
|
||
from .serializers import KeyedListSerializer | ||
from .serializers import KeyedListSerializer # noqa: F401,E402 |
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,43 +1,37 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
from rest_framework.serializers import ListSerializer | ||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.fields import SkipField | ||
from rest_framework.serializers import ListSerializer | ||
from rest_framework.settings import api_settings | ||
|
||
|
||
class KeyedListSerializer(ListSerializer): | ||
default_error_messages = { | ||
'not_a_dict': _('Expected a dict of items but got type "{input_type}".'), | ||
'empty': _('This dict may not be empty.') | ||
"not_a_dict": _('Expected a dict of items but got type "{input_type}".'), | ||
"empty": _("This dict may not be empty."), | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
meta = getattr(self.child, 'Meta', None) | ||
assert hasattr(meta, 'keyed_list_serializer_field'), \ | ||
"Must provide a field name at keyed_list_serializer_field when using KeyedListSerializer" | ||
meta = getattr(self.child, "Meta", None) | ||
assert hasattr( | ||
meta, "keyed_list_serializer_field" | ||
), "Must provide a field name at keyed_list_serializer_field when using KeyedListSerializer" | ||
self._keyed_field = meta.keyed_list_serializer_field | ||
|
||
def to_internal_value(self, data): | ||
if not isinstance(data, dict): | ||
message = self.error_messages['not_a_dict'].format( | ||
input_type=type(data).__name__ | ||
) | ||
raise ValidationError({ | ||
api_settings.NON_FIELD_ERRORS_KEY: [message] | ||
}, code='not_a_dict') | ||
message = self.error_messages["not_a_dict"].format(input_type=type(data).__name__) | ||
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: [message]}, code="not_a_dict") | ||
if not self.allow_empty and len(data) == 0: | ||
if self.parent and self.partial: | ||
raise SkipField() | ||
|
||
message = self.error_messages['empty'] | ||
raise ValidationError({ | ||
api_settings.NON_FIELD_ERRORS_KEY: [message] | ||
}, code='empty') | ||
message = self.error_messages["empty"] | ||
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: [message]}, code="empty") | ||
data = [{**v, **{self._keyed_field: k}} for k, v in data.items()] | ||
return super().to_internal_value(data) | ||
|
||
def to_representation(self, data): | ||
response = super().to_representation(data) | ||
return {v.pop(self._keyed_field): v for v in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
[metadata] | ||
license_file = LICENSE.md | ||
description-file = README.md | ||
|
||
[flake8] | ||
exclude = | ||
.*.py | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9 | ||
ignore = E203, E266, E501, W503 | ||
max-line-length = 100 | ||
application_import_names = mycmsproject | ||
import-order-style = google |
Oops, something went wrong.