...
 
Commits (3)
[bumpversion]
current_version = 0.6.0
current_version = 0.7.0
[bumpversion:file:VERSION]
from datetime import date, datetime
from enum import Enum
import pytz
from django.conf import settings
from django.db import models
from django.db.models import Exists, OuterRef
from django.urls import reverse
from django.utils.timezone import now
from taggit.managers import TaggableManager
from mptt.models import MPTTModel, TreeForeignKey, TreeManyToManyField
from taggit.managers import TaggableManager
from core.models import Role, RoleMixin, SoftDeleteModel
from enum import Enum
import pytz
PUBLICATION_LIMIT_7D = '7d'
PUBLICATION_LIMITS = ((PUBLICATION_LIMIT_7D, 'GEMA ±7 Tage Ausstrahlung'),)
......
lohrothek-backend (0.7.0-1) unstable; urgency=medium
* New upstream release
-- Konrad Mohrfeldt <konrad@moppi> Sun, 06 Oct 2019 22:34:43 +0200
lohrothek-backend (0.6.0-1) unstable; urgency=medium
* New upstream release
......
......@@ -3,17 +3,24 @@ from django.utils.timezone import now
from django_filters import rest_framework as filters
from django_filters import CharFilter
from taggit.forms import TagField
from taggit.models import Tag
from audiothek.models import Audiofile, RadioReport
from program.models import Broadcast, RadioProgram
class TagFilter(CharFilter):
class HasTagFilter(CharFilter):
field_class = TagField
def __init__(self, *args, **kwargs):
kwargs.setdefault('lookup_expr', 'in')
super().__init__(*args, **kwargs)
super().__init__(*args, field_name='tags__slug', distinct=True, **kwargs)
class TagFilter(filters.FilterSet):
class Meta:
model = Tag
fields = tuple()
class BroadcastFilter(filters.FilterSet):
......@@ -40,7 +47,7 @@ class ReportFilter(filters.FilterSet):
series = filters.ModelChoiceFilter(
queryset=RadioProgram.objects.all(), method='filter_series', label='Sendereihe')
is_available = filters.BooleanFilter(method='filter_available', label='Verfügbar')
tags = TagFilter(field_name='tags__slug', distinct=True)
tags = HasTagFilter()
omit = filters.NumberFilter(field_name='id', exclude=True)
keywords = filters.CharFilter(method='filter_keywords', label='Stichworte')
......
from taggit.models import Tag
from rest_framework import serializers
from rest_framework.reverse import reverse
......@@ -62,17 +63,35 @@ class ProgramSerializer(serializers.ModelSerializer):
fields = ('id', 'name', 'description', 'teaser', 'cover_image',)
class MinimalTagSerializer(serializers.ModelSerializer):
class Meta:
model = Tag
fields = ('name', 'slug')
class TagSerializer(MinimalTagSerializer):
weight = serializers.SerializerMethodField()
def get_weight(self, obj):
# TODO: calculate weight based on how often this tag
# was used on any model within $time_frame and
# a float between 0 and 1
# (0 == not used, 1 == only used tag)
return 0
class Meta:
model = Tag
fields = ('name', 'slug', 'weight')
class ReportSerializer(serializers.ModelSerializer):
audio = AudiofileSerializer(source='audiofiles', many=True)
license = LicenseSerializer(required=False)
tags = serializers.SerializerMethodField()
tags = MinimalTagSerializer(many=True)
publication = serializers.SerializerMethodField()
broadcast_ids = serializers.PrimaryKeyRelatedField(source='broadcasts',
read_only=True, many=True)
def get_tags(self, obj):
return {tag.slug: str(tag) for tag in obj.tags.all()}
def get_publication(self, obj):
return {
'start': obj.publication_time,
......
......@@ -3,13 +3,14 @@ from django.urls import include, path
from rest_framework.routers import DefaultRouter
from rest_api.frontend.views import BroadcastViewSet, ProgramViewSet, RenderImageView, \
ReportViewSet, StreamAudiofileView
ReportViewSet, StreamAudiofileView, TagViewSet
router = DefaultRouter(trailing_slash=settings.APPEND_SLASH)
router.register(r'broadcasts', BroadcastViewSet)
router.register(r'recordings', ReportViewSet)
router.register(r'series', ProgramViewSet)
router.register(r'tags', TagViewSet)
urlpatterns = [
path('', include(router.urls)),
......
......@@ -4,15 +4,16 @@ from django.views.generic import View
from imagekit import ImageSpec
from imagekit.cachefiles import ImageCacheFile
from imagekit.processors import ResizeToFill
from taggit.models import Tag
from rest_framework import viewsets
from audiothek.models import Audiofile, RadioReport
from core.http import HttpResponseSendfile
from core.models import Image
from program.models import Broadcast, RadioProgram
from rest_api.frontend.filters import BroadcastFilter, ReportFilter
from rest_api.frontend.filters import BroadcastFilter, ReportFilter, TagFilter
from rest_api.frontend.serializers import BroadcastSerializer, ProgramSerializer, \
ReportSerializer
ReportSerializer, TagSerializer
SUPPORTED_IMAGE_RENDER_FORMATS = ('PNG', 'JPEG', 'WEBP')
......@@ -75,6 +76,12 @@ class ReportViewSet(viewsets.ReadOnlyModelViewSet):
filterset_class = ReportFilter
class TagViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Tag.objects.all()
serializer_class = TagSerializer
filterset_class = TagFilter
class StreamAudiofileView(View):
def get_audiofile(self):
return get_object_or_404(Audiofile, pk=self.kwargs.get('pk'))
......