mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 14:59:26 +02:00
Blacked the code
This commit is contained in:
parent
b6fc0051fa
commit
62ca3bd736
279 changed files with 8861 additions and 9527 deletions
|
@ -15,42 +15,42 @@ class PlaylistTrackSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = models.PlaylistTrack
|
||||
fields = ('id', 'track', 'playlist', 'index', 'creation_date')
|
||||
fields = ("id", "track", "playlist", "index", "creation_date")
|
||||
|
||||
|
||||
class PlaylistTrackWriteSerializer(serializers.ModelSerializer):
|
||||
index = serializers.IntegerField(
|
||||
required=False, min_value=0, allow_null=True)
|
||||
index = serializers.IntegerField(required=False, min_value=0, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = models.PlaylistTrack
|
||||
fields = ('id', 'track', 'playlist', 'index')
|
||||
fields = ("id", "track", "playlist", "index")
|
||||
|
||||
def validate_playlist(self, value):
|
||||
if self.context.get('request'):
|
||||
if self.context.get("request"):
|
||||
# validate proper ownership on the playlist
|
||||
if self.context['request'].user != value.user:
|
||||
if self.context["request"].user != value.user:
|
||||
raise serializers.ValidationError(
|
||||
'You do not have the permission to edit this playlist')
|
||||
"You do not have the permission to edit this playlist"
|
||||
)
|
||||
existing = value.playlist_tracks.count()
|
||||
max_tracks = preferences.get('playlists__max_tracks')
|
||||
max_tracks = preferences.get("playlists__max_tracks")
|
||||
if existing >= max_tracks:
|
||||
raise serializers.ValidationError(
|
||||
'Playlist has reached the maximum of {} tracks'.format(
|
||||
max_tracks))
|
||||
"Playlist has reached the maximum of {} tracks".format(max_tracks)
|
||||
)
|
||||
return value
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, validated_data):
|
||||
index = validated_data.pop('index', None)
|
||||
index = validated_data.pop("index", None)
|
||||
instance = super().create(validated_data)
|
||||
instance.playlist.insert(instance, index)
|
||||
return instance
|
||||
|
||||
@transaction.atomic
|
||||
def update(self, instance, validated_data):
|
||||
update_index = 'index' in validated_data
|
||||
index = validated_data.pop('index', None)
|
||||
update_index = "index" in validated_data
|
||||
index = validated_data.pop("index", None)
|
||||
super().update(instance, validated_data)
|
||||
if update_index:
|
||||
instance.playlist.insert(instance, index)
|
||||
|
@ -71,17 +71,15 @@ class PlaylistSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = models.Playlist
|
||||
fields = (
|
||||
'id',
|
||||
'name',
|
||||
'tracks_count',
|
||||
'user',
|
||||
'modification_date',
|
||||
'creation_date',
|
||||
'privacy_level',)
|
||||
read_only_fields = [
|
||||
'id',
|
||||
'modification_date',
|
||||
'creation_date',]
|
||||
"id",
|
||||
"name",
|
||||
"tracks_count",
|
||||
"user",
|
||||
"modification_date",
|
||||
"creation_date",
|
||||
"privacy_level",
|
||||
)
|
||||
read_only_fields = ["id", "modification_date", "creation_date"]
|
||||
|
||||
def get_tracks_count(self, obj):
|
||||
try:
|
||||
|
@ -93,4 +91,5 @@ class PlaylistSerializer(serializers.ModelSerializer):
|
|||
|
||||
class PlaylistAddManySerializer(serializers.Serializer):
|
||||
tracks = serializers.PrimaryKeyRelatedField(
|
||||
many=True, queryset=Track.objects.for_nested_serialization())
|
||||
many=True, queryset=Track.objects.for_nested_serialization()
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue