summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-05-15 07:50:41 +0000
committerCoprDistGit <infra@openeuler.org>2023-05-15 07:50:41 +0000
commit4c8139461c6903e147c7bbff33151e1e71b6aa48 (patch)
tree373d1851ecafb1d951bddb3ac6d6f7740d08c85a
parent0c6379e92ea784a60c636b070b0a44076e259532 (diff)
automatic import of python-air-drf-relation
-rw-r--r--.gitignore1
-rw-r--r--python-air-drf-relation.spec765
-rw-r--r--sources1
3 files changed, 767 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..bb45ab1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/air_drf_relation-0.5.7.tar.gz
diff --git a/python-air-drf-relation.spec b/python-air-drf-relation.spec
new file mode 100644
index 0000000..161bb32
--- /dev/null
+++ b/python-air-drf-relation.spec
@@ -0,0 +1,765 @@
+%global _empty_manifest_terminate_build 0
+Name: python-air-drf-relation
+Version: 0.5.7
+Release: 1
+Summary: Improved interaction with DRF relations.
+License: MIT
+URL: https://github.com/bubaley/air-drf-relation
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/d5/9d/8d7023545f52570c45d05b963ce0505ce0df3440c3342288f99ba350fe6f/air_drf_relation-0.5.7.tar.gz
+BuildArch: noarch
+
+
+%description
+**AIR-DRF-RELATION**
+
+# Table of Contents
+
+1. [Instalation](#instalation)
+2. [About](#about)
+3. [AirRelatedField](#airrelatedfield)
+ 1. [pk_only](#pk_only)
+ 2. [hidden](#hidden)
+4. [AirModelSerializer](#airmodelserializer)
+ 1. [user](#user)
+ 2. [extra_kwargs](#extra_kwargs)
+ 3. [hidden_fields](#hidden_fields)
+ 4. [Kwargs by actions](#kwargs-by-actions)
+ 1. [action_read_only_fields](#action_read_only_fields)
+ 2. [action_hidden_fields](#action_hidden_fields)
+ 3. [action_extra_kwargs](#action_extra_kwargs)
+ 4. [Priority extra_kwargs](#priority-extra_kwargs)
+ 5. [Filter nested querysets](#filter-nested-querysets)
+
+# Instalation
+
+`$ pip install air-drf-relation`
+
+# About
+
+`air-drf-relation` adds flexibility and convenience in working with ModelSerializer.
+
+# AirRelatedField
+
+Used to extend the functionality of the `PrimaryKeyRelatedField`
+
+```python
+class BookSerializer(ModelSerializer):
+ # author = PrimaryKeyRelatedField(queryset=Author.objects) - default usage
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(CitySerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+`AirRelatedField` allows you to get not only pk but also an object with pk, which will be searched.
+```json
+{
+ "name": "demo",
+ "author": {
+ "id": 1
+ },
+ "city": 1
+}
+```
+## pk_only
+Automatically AirRelatedField returns a serialized object. If you only want to use pk, you must specify the `pk_only` key.
+
+```python
+author = AirRelatedField(AuthorSerializer, pk_only=True)
+```
+
+## hidden
+Hidden fields are not used for serialization and validation. The data will be returned without fields. Usually used together in `AirModelSerializer`
+
+```python
+author = AirRelatedField(AuthorSerializer, hidden=True)
+```
+
+## Important
+You cannot use `hidden` and `pk_only` in ModelSerializer and with extra_kwargs
+
+# AirModelSerializer
+
+Used to extend the functionality of the `ModelSerializer`
+
+```python
+class BookSerializer(AirModelSerializer): # full example
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+ hidden_fields = ()
+ read_only_fields = () # default read_only_fields
+ extra_kwargs = {} # default extra_kwargs with support custom keys
+ action_read_only_fields = {
+ 'create': {},
+ '_': {} # used for other actions
+ },
+ action_hidden_fields = {
+ 'create': (),
+ '_': ()
+ }
+ action_extra_kwargs = {
+ 'list': {},
+ '_': {}
+ }
+ nested_save_fields = ()
+```
+
+## user
+User is automatically put from the `request` if available. You can also set the user manually.
+
+```python
+class DemoSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name')
+
+ validate_name(self, value):
+ if not self.user:
+ return None
+ return value
+```
+Manually set user.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, user=request.user)
+```
+
+## extra_kwargs
+Extends the standard work with `extra_kwargs` by adding work with additional attributes. You can also transfer `extra_kwargs` manually.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ extra_kwargs = {
+ 'author': {'pk_only': True},
+ 'name': {'hidden': True}
+ }
+```
+## hidden_fields
+Hides fields for validation and seralization.
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ hidden_fields = ('name', 'author')
+```
+## Kwargs by actions
+Kwargs by actions is used only when the event. You can pass acions separated by `,`.
+For events that don't match, you can use `_` key. It is used if action **is passed**.
+Action is set automatically from the ViewSet, or it can be passed manually.
+
+```python
+class DemoViewSet(ModelViewSet):
+ queryset = Demo.objects.all()
+ serializer_class = DemoSerializer
+
+ def perform_create(serializer, request):
+ action = serializer.action # action is 'create'
+ serializer.save()
+
+ @action(methods=['POST'], detail=False)
+ def demo_action(self, request):
+ serializer = self.get_serializer_class()
+ action = serializer.action # action is 'demo_action'
+```
+
+Manually set action.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, action='custom_action')
+action = serializer.action # action is 'custom_action'
+```
+
+### action_read_only_fields
+Sets `read_only_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_read_only_fields = {
+ 'create,update': ('name', 'author')
+ }
+```
+
+### action_hidden_fields
+Sets `hidden_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_hidden_fields = {
+ 'custom_action': ('author', ),
+ '_': ('id', )
+ }
+```
+
+### action_extra_kwargs
+Expand `extra_kwargs` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer, pk_only=True, null=True)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_extra_kwargs = {
+ 'create,custom_update': {
+ 'author': {'pk_only': False, 'null'=True}
+ }
+ }
+```
+
+## Priority extra_kwargs
+Below are the priorities of the extra_kwargs extension in ascending order
+1. extra_kwargs `in Meta`
+2. hidden_fields
+3. action_hidden_fields
+4. action_read_only_fields
+5. action_extra_kwargs
+6. extra_kwargs `manually transmitted`
+
+## Filter nested querysets
+AirModelSerializer allows you to filter the queryset by nested fields.
+```python
+class BookSerializer(AirModelSerializer):
+ city = AirRelatedField(CitySerializer, queryset_function_name='custom_filter')
+
+ def queryset_author(self, queryset):
+ return queryset.filter(active=True, created_by=self.user)
+
+ def filter_city_by_active(self, queryset):
+ return queryset.filter(active=True)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+%package -n python3-air-drf-relation
+Summary: Improved interaction with DRF relations.
+Provides: python-air-drf-relation
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-air-drf-relation
+**AIR-DRF-RELATION**
+
+# Table of Contents
+
+1. [Instalation](#instalation)
+2. [About](#about)
+3. [AirRelatedField](#airrelatedfield)
+ 1. [pk_only](#pk_only)
+ 2. [hidden](#hidden)
+4. [AirModelSerializer](#airmodelserializer)
+ 1. [user](#user)
+ 2. [extra_kwargs](#extra_kwargs)
+ 3. [hidden_fields](#hidden_fields)
+ 4. [Kwargs by actions](#kwargs-by-actions)
+ 1. [action_read_only_fields](#action_read_only_fields)
+ 2. [action_hidden_fields](#action_hidden_fields)
+ 3. [action_extra_kwargs](#action_extra_kwargs)
+ 4. [Priority extra_kwargs](#priority-extra_kwargs)
+ 5. [Filter nested querysets](#filter-nested-querysets)
+
+# Instalation
+
+`$ pip install air-drf-relation`
+
+# About
+
+`air-drf-relation` adds flexibility and convenience in working with ModelSerializer.
+
+# AirRelatedField
+
+Used to extend the functionality of the `PrimaryKeyRelatedField`
+
+```python
+class BookSerializer(ModelSerializer):
+ # author = PrimaryKeyRelatedField(queryset=Author.objects) - default usage
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(CitySerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+`AirRelatedField` allows you to get not only pk but also an object with pk, which will be searched.
+```json
+{
+ "name": "demo",
+ "author": {
+ "id": 1
+ },
+ "city": 1
+}
+```
+## pk_only
+Automatically AirRelatedField returns a serialized object. If you only want to use pk, you must specify the `pk_only` key.
+
+```python
+author = AirRelatedField(AuthorSerializer, pk_only=True)
+```
+
+## hidden
+Hidden fields are not used for serialization and validation. The data will be returned without fields. Usually used together in `AirModelSerializer`
+
+```python
+author = AirRelatedField(AuthorSerializer, hidden=True)
+```
+
+## Important
+You cannot use `hidden` and `pk_only` in ModelSerializer and with extra_kwargs
+
+# AirModelSerializer
+
+Used to extend the functionality of the `ModelSerializer`
+
+```python
+class BookSerializer(AirModelSerializer): # full example
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+ hidden_fields = ()
+ read_only_fields = () # default read_only_fields
+ extra_kwargs = {} # default extra_kwargs with support custom keys
+ action_read_only_fields = {
+ 'create': {},
+ '_': {} # used for other actions
+ },
+ action_hidden_fields = {
+ 'create': (),
+ '_': ()
+ }
+ action_extra_kwargs = {
+ 'list': {},
+ '_': {}
+ }
+ nested_save_fields = ()
+```
+
+## user
+User is automatically put from the `request` if available. You can also set the user manually.
+
+```python
+class DemoSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name')
+
+ validate_name(self, value):
+ if not self.user:
+ return None
+ return value
+```
+Manually set user.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, user=request.user)
+```
+
+## extra_kwargs
+Extends the standard work with `extra_kwargs` by adding work with additional attributes. You can also transfer `extra_kwargs` manually.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ extra_kwargs = {
+ 'author': {'pk_only': True},
+ 'name': {'hidden': True}
+ }
+```
+## hidden_fields
+Hides fields for validation and seralization.
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ hidden_fields = ('name', 'author')
+```
+## Kwargs by actions
+Kwargs by actions is used only when the event. You can pass acions separated by `,`.
+For events that don't match, you can use `_` key. It is used if action **is passed**.
+Action is set automatically from the ViewSet, or it can be passed manually.
+
+```python
+class DemoViewSet(ModelViewSet):
+ queryset = Demo.objects.all()
+ serializer_class = DemoSerializer
+
+ def perform_create(serializer, request):
+ action = serializer.action # action is 'create'
+ serializer.save()
+
+ @action(methods=['POST'], detail=False)
+ def demo_action(self, request):
+ serializer = self.get_serializer_class()
+ action = serializer.action # action is 'demo_action'
+```
+
+Manually set action.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, action='custom_action')
+action = serializer.action # action is 'custom_action'
+```
+
+### action_read_only_fields
+Sets `read_only_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_read_only_fields = {
+ 'create,update': ('name', 'author')
+ }
+```
+
+### action_hidden_fields
+Sets `hidden_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_hidden_fields = {
+ 'custom_action': ('author', ),
+ '_': ('id', )
+ }
+```
+
+### action_extra_kwargs
+Expand `extra_kwargs` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer, pk_only=True, null=True)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_extra_kwargs = {
+ 'create,custom_update': {
+ 'author': {'pk_only': False, 'null'=True}
+ }
+ }
+```
+
+## Priority extra_kwargs
+Below are the priorities of the extra_kwargs extension in ascending order
+1. extra_kwargs `in Meta`
+2. hidden_fields
+3. action_hidden_fields
+4. action_read_only_fields
+5. action_extra_kwargs
+6. extra_kwargs `manually transmitted`
+
+## Filter nested querysets
+AirModelSerializer allows you to filter the queryset by nested fields.
+```python
+class BookSerializer(AirModelSerializer):
+ city = AirRelatedField(CitySerializer, queryset_function_name='custom_filter')
+
+ def queryset_author(self, queryset):
+ return queryset.filter(active=True, created_by=self.user)
+
+ def filter_city_by_active(self, queryset):
+ return queryset.filter(active=True)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+%package help
+Summary: Development documents and examples for air-drf-relation
+Provides: python3-air-drf-relation-doc
+%description help
+**AIR-DRF-RELATION**
+
+# Table of Contents
+
+1. [Instalation](#instalation)
+2. [About](#about)
+3. [AirRelatedField](#airrelatedfield)
+ 1. [pk_only](#pk_only)
+ 2. [hidden](#hidden)
+4. [AirModelSerializer](#airmodelserializer)
+ 1. [user](#user)
+ 2. [extra_kwargs](#extra_kwargs)
+ 3. [hidden_fields](#hidden_fields)
+ 4. [Kwargs by actions](#kwargs-by-actions)
+ 1. [action_read_only_fields](#action_read_only_fields)
+ 2. [action_hidden_fields](#action_hidden_fields)
+ 3. [action_extra_kwargs](#action_extra_kwargs)
+ 4. [Priority extra_kwargs](#priority-extra_kwargs)
+ 5. [Filter nested querysets](#filter-nested-querysets)
+
+# Instalation
+
+`$ pip install air-drf-relation`
+
+# About
+
+`air-drf-relation` adds flexibility and convenience in working with ModelSerializer.
+
+# AirRelatedField
+
+Used to extend the functionality of the `PrimaryKeyRelatedField`
+
+```python
+class BookSerializer(ModelSerializer):
+ # author = PrimaryKeyRelatedField(queryset=Author.objects) - default usage
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(CitySerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+`AirRelatedField` allows you to get not only pk but also an object with pk, which will be searched.
+```json
+{
+ "name": "demo",
+ "author": {
+ "id": 1
+ },
+ "city": 1
+}
+```
+## pk_only
+Automatically AirRelatedField returns a serialized object. If you only want to use pk, you must specify the `pk_only` key.
+
+```python
+author = AirRelatedField(AuthorSerializer, pk_only=True)
+```
+
+## hidden
+Hidden fields are not used for serialization and validation. The data will be returned without fields. Usually used together in `AirModelSerializer`
+
+```python
+author = AirRelatedField(AuthorSerializer, hidden=True)
+```
+
+## Important
+You cannot use `hidden` and `pk_only` in ModelSerializer and with extra_kwargs
+
+# AirModelSerializer
+
+Used to extend the functionality of the `ModelSerializer`
+
+```python
+class BookSerializer(AirModelSerializer): # full example
+ author = AirRelatedField(AuthorSerializer)
+ city = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+ hidden_fields = ()
+ read_only_fields = () # default read_only_fields
+ extra_kwargs = {} # default extra_kwargs with support custom keys
+ action_read_only_fields = {
+ 'create': {},
+ '_': {} # used for other actions
+ },
+ action_hidden_fields = {
+ 'create': (),
+ '_': ()
+ }
+ action_extra_kwargs = {
+ 'list': {},
+ '_': {}
+ }
+ nested_save_fields = ()
+```
+
+## user
+User is automatically put from the `request` if available. You can also set the user manually.
+
+```python
+class DemoSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name')
+
+ validate_name(self, value):
+ if not self.user:
+ return None
+ return value
+```
+Manually set user.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, user=request.user)
+```
+
+## extra_kwargs
+Extends the standard work with `extra_kwargs` by adding work with additional attributes. You can also transfer `extra_kwargs` manually.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ extra_kwargs = {
+ 'author': {'pk_only': True},
+ 'name': {'hidden': True}
+ }
+```
+## hidden_fields
+Hides fields for validation and seralization.
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ hidden_fields = ('name', 'author')
+```
+## Kwargs by actions
+Kwargs by actions is used only when the event. You can pass acions separated by `,`.
+For events that don't match, you can use `_` key. It is used if action **is passed**.
+Action is set automatically from the ViewSet, or it can be passed manually.
+
+```python
+class DemoViewSet(ModelViewSet):
+ queryset = Demo.objects.all()
+ serializer_class = DemoSerializer
+
+ def perform_create(serializer, request):
+ action = serializer.action # action is 'create'
+ serializer.save()
+
+ @action(methods=['POST'], detail=False)
+ def demo_action(self, request):
+ serializer = self.get_serializer_class()
+ action = serializer.action # action is 'demo_action'
+```
+
+Manually set action.
+```python
+serializer = DemoSerializer(data={'name': 'demo'}, action='custom_action')
+action = serializer.action # action is 'custom_action'
+```
+
+### action_read_only_fields
+Sets `read_only_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_read_only_fields = {
+ 'create,update': ('name', 'author')
+ }
+```
+
+### action_hidden_fields
+Sets `hidden_fields` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_hidden_fields = {
+ 'custom_action': ('author', ),
+ '_': ('id', )
+ }
+```
+
+### action_extra_kwargs
+Expand `extra_kwargs` by action in serializer.
+
+```python
+class BookSerializer(AirModelSerializer):
+ author = AirRelatedField(AuthorSerializer, pk_only=True, null=True)
+
+ class Meta:
+ fields = ('id', 'name', 'author')
+ action_extra_kwargs = {
+ 'create,custom_update': {
+ 'author': {'pk_only': False, 'null'=True}
+ }
+ }
+```
+
+## Priority extra_kwargs
+Below are the priorities of the extra_kwargs extension in ascending order
+1. extra_kwargs `in Meta`
+2. hidden_fields
+3. action_hidden_fields
+4. action_read_only_fields
+5. action_extra_kwargs
+6. extra_kwargs `manually transmitted`
+
+## Filter nested querysets
+AirModelSerializer allows you to filter the queryset by nested fields.
+```python
+class BookSerializer(AirModelSerializer):
+ city = AirRelatedField(CitySerializer, queryset_function_name='custom_filter')
+
+ def queryset_author(self, queryset):
+ return queryset.filter(active=True, created_by=self.user)
+
+ def filter_city_by_active(self, queryset):
+ return queryset.filter(active=True)
+
+ class Meta:
+ model = Book
+ fields = ('uuid', 'name', 'author', 'city')
+```
+
+%prep
+%autosetup -n air-drf-relation-0.5.7
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-air-drf-relation -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Mon May 15 2023 Python_Bot <Python_Bot@openeuler.org> - 0.5.7-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..b50eef8
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+9c5964f42757d9dcfffdfb10cc5c839f air_drf_relation-0.5.7.tar.gz