mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 21:49:16 +02:00
See #190: API and serializers to manage import requests
This commit is contained in:
parent
a443f9431e
commit
9767c8f415
9 changed files with 186 additions and 11 deletions
|
@ -2,10 +2,10 @@ from rest_framework import serializers
|
|||
|
||||
|
||||
class Action(object):
|
||||
def __init__(self, name, allow_all=False, filters=None):
|
||||
def __init__(self, name, allow_all=False, qs_filter=None):
|
||||
self.name = name
|
||||
self.allow_all = allow_all
|
||||
self.filters = filters or {}
|
||||
self.qs_filter = qs_filter
|
||||
|
||||
def __repr__(self):
|
||||
return "<Action {}>".format(self.name)
|
||||
|
@ -65,7 +65,6 @@ class ActionSerializer(serializers.Serializer):
|
|||
"You cannot apply this action on all objects"
|
||||
)
|
||||
final_filters = data.get("filters", {}) or {}
|
||||
final_filters.update(data["action"].filters)
|
||||
if self.filterset_class and final_filters:
|
||||
qs_filterset = self.filterset_class(final_filters, queryset=data["objects"])
|
||||
try:
|
||||
|
@ -74,6 +73,9 @@ class ActionSerializer(serializers.Serializer):
|
|||
raise serializers.ValidationError("Invalid filters")
|
||||
data["objects"] = qs_filterset.qs
|
||||
|
||||
if data["action"].qs_filter:
|
||||
data["objects"] = data["action"].qs_filter(data["objects"])
|
||||
|
||||
data["count"] = data["objects"].count()
|
||||
if data["count"] < 1:
|
||||
raise serializers.ValidationError("No object matching your request")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue