mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-24 10:03:48 +03:00
Compare commits
2 Commits
debdf53927
...
5bc8cd523a
Author | SHA1 | Date | |
---|---|---|---|
5bc8cd523a | |||
63311d1d26 |
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import elastic_transport
|
||||||
import structlog
|
import structlog
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
@ -91,7 +92,9 @@ def get_queryset(self):
|
||||||
):
|
):
|
||||||
return self.filter(BaseFileItem.objects.none())
|
return self.filter(BaseFileItem.objects.none())
|
||||||
return self.filter(
|
return self.filter(
|
||||||
BaseFileItem.objects.filter(user=self.request.user, parent__isnull=True)
|
BaseFileItem.objects.cache().filter(
|
||||||
|
user=self.request.user, parent__isnull=True
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -313,18 +316,25 @@ def on_completion(self, uploaded_file, request):
|
||||||
}
|
}
|
||||||
prepared = False
|
prepared = False
|
||||||
if prepared and uploaded_file.size <= request.user.left_file_upload:
|
if prepared and uploaded_file.size <= request.user.left_file_upload:
|
||||||
f = File.objects.create(
|
try:
|
||||||
user=request.user,
|
f = File.objects.create(
|
||||||
file_obj=uploaded_file,
|
user=request.user,
|
||||||
name=uploaded_file.name,
|
file_obj=uploaded_file,
|
||||||
parent=folder,
|
name=uploaded_file.name,
|
||||||
)
|
parent=folder,
|
||||||
request.user.left_file_upload -= uploaded_file.size
|
)
|
||||||
request.user.save()
|
request.user.left_file_upload -= uploaded_file.size
|
||||||
self.message = {
|
request.user.save()
|
||||||
"message": f"File {f.file.name.split('/')[-1]} successfully uploaded",
|
self.message = {
|
||||||
"status": True,
|
"message": f"File {f.file.name.split('/')[-1]} successfully uploaded",
|
||||||
}
|
"status": True,
|
||||||
|
}
|
||||||
|
except elastic_transport.ConnectionError:
|
||||||
|
self.message = {
|
||||||
|
"message": "Service is down, please try again later or contact support",
|
||||||
|
"status": False,
|
||||||
|
}
|
||||||
|
logger.error("Elasticsearch is down")
|
||||||
elif prepared:
|
elif prepared:
|
||||||
self.message = {
|
self.message = {
|
||||||
"message": "File is too large, please increase disk space",
|
"message": "File is too large, please increase disk space",
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
class AuthorSerializer(serializers.ModelSerializer):
|
class AuthorSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Author
|
model = Author
|
||||||
fields = ["name", "slug", "link", "image_cropped"]
|
fields = ["name", "slug", "image_cropped"]
|
||||||
|
|
||||||
|
|
||||||
class AlbumSerializer(serializers.ModelSerializer):
|
class AlbumSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Album
|
model = Album
|
||||||
fields = ["name", "slug", "link", "image_cropped"]
|
fields = ["name", "slug", "image_cropped"]
|
||||||
|
|
||||||
|
|
||||||
class SongSerializer(serializers.ModelSerializer):
|
class SongSerializer(serializers.ModelSerializer):
|
||||||
|
@ -32,10 +32,12 @@ class SongSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
@extend_schema_field(serializers.BooleanField)
|
@extend_schema_field(serializers.BooleanField)
|
||||||
def get_liked(self, obj):
|
def get_liked(self, obj):
|
||||||
if self.context["request"].user.is_authenticated:
|
if "request" in self.context:
|
||||||
return SongUserRating.objects.filter(
|
if self.context["request"].user.is_authenticated:
|
||||||
song=obj, user=self.context["request"].user, like=True
|
return SongUserRating.objects.filter(
|
||||||
).exists()
|
song=obj, user=self.context["request"].user, like=True
|
||||||
|
).exists()
|
||||||
|
return None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Song
|
model = Song
|
||||||
|
@ -59,18 +61,30 @@ class Meta:
|
||||||
|
|
||||||
|
|
||||||
class ListSongSerializer(SetUserModelSerializer):
|
class ListSongSerializer(SetUserModelSerializer):
|
||||||
album = serializers.CharField(source="album.name", read_only=True)
|
album = AlbumSerializer(read_only=True)
|
||||||
|
authors = AuthorSerializer(many=True, read_only=True)
|
||||||
liked = serializers.SerializerMethodField(method_name="get_liked")
|
liked = serializers.SerializerMethodField(method_name="get_liked")
|
||||||
|
|
||||||
@extend_schema_field(serializers.BooleanField)
|
@extend_schema_field(serializers.BooleanField)
|
||||||
def get_liked(self, obj):
|
def get_liked(self, obj):
|
||||||
if "likes" in self.context:
|
if "likes" in self.context:
|
||||||
return self.context["likes"]
|
return self.context["likes"]
|
||||||
return obj.id in self.context["likes_ids"]
|
if "likes_ids" in self.context:
|
||||||
|
return obj.id in self.context["likes_ids"]
|
||||||
|
return None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Song
|
model = Song
|
||||||
fields = ["name", "slug", "file", "image_cropped", "length", "album", "liked"]
|
fields = [
|
||||||
|
"name",
|
||||||
|
"slug",
|
||||||
|
"file",
|
||||||
|
"image_cropped",
|
||||||
|
"length",
|
||||||
|
"album",
|
||||||
|
"authors",
|
||||||
|
"liked",
|
||||||
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"slug": {"read_only": True},
|
"slug": {"read_only": True},
|
||||||
"image_cropped": {"read_only": True},
|
"image_cropped": {"read_only": True},
|
||||||
|
|
|
@ -48,7 +48,8 @@ def process_file(path, user_id):
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def load_ym_file_meta(track, user_id):
|
def load_ym_file_meta(track, user_id):
|
||||||
return yandex.load_file_meta(track, user_id)
|
yb = yandex.load_file_meta(track, user_id)
|
||||||
|
return yb
|
||||||
|
|
||||||
|
|
||||||
@shared_task()
|
@shared_task()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user