Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed Jan 15, 2023
2 parents e3fae67 + d3e4c07 commit 623c3c2
Show file tree
Hide file tree
Showing 27 changed files with 356 additions and 611 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ After switching to Wagtail, the documentation has to be updated. Stay tuned 😄
- Video support - not as sophisticated as image / audio support, but it works 🤗
- Comments via [django-fluent-comments](https://github.com/django-fluent/django-fluent-comments)
and a build in moderating spam filter
- Full-text search via [django-watson](https://github.com/etianen/django-watson)

## Deployment

Expand Down
2 changes: 1 addition & 1 deletion cast/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Just another blogging / podcasting package
"""
__version__ = "0.2.1"
__version__ = "0.2.2"
162 changes: 0 additions & 162 deletions cast/access_log.py

This file was deleted.

12 changes: 3 additions & 9 deletions cast/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from rest_framework import serializers

from ..models import Audio, Request, Video

from ..models import Audio, Video

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -31,13 +30,8 @@ class AudioPodloveSerializer(serializers.HyperlinkedModelSerializer):
audio = serializers.ListField()
chapters = serializers.ListField()
duration = serializers.CharField(source="duration_str")
link = serializers.URLField(source="episode_url")

class Meta:
model = Audio
fields = ("title", "subtitle", "audio", "duration", "chapters")


class RequestSerializer(serializers.ModelSerializer):
class Meta:
model = Request
fields = "__all__"
fields = ("title", "subtitle", "audio", "duration", "chapters", "link")
2 changes: 0 additions & 2 deletions cast/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
views.AudioPodloveDetailView.as_view(),
name="audio_podlove_detail",
),
# request
path("request/", views.RequestListView.as_view(), name="request_list"),
# comment training data
path("comment_training_data/", views.CommentTrainingDataView.as_view(), name="comment-training-data"),
]
45 changes: 13 additions & 32 deletions cast/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
from django.http import JsonResponse
from django.urls import reverse
from django.views.generic import CreateView
from rest_framework import generics, status
from rest_framework import generics
from rest_framework.decorators import api_view
from rest_framework.pagination import PageNumberPagination
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.serializers import ListSerializer
from rest_framework.views import APIView

from ..forms import VideoForm
from ..models import Audio, Request, SpamFilter, Video
from .serializers import (
AudioPodloveSerializer,
AudioSerializer,
RequestSerializer,
VideoSerializer,
)
from ..models import Audio, SpamFilter, Video
from .serializers import AudioPodloveSerializer, AudioSerializer, VideoSerializer
from .viewmixins import AddRequestUserMixin, FileUploadResponseMixin

logger = logging.getLogger(__name__)
Expand All @@ -37,7 +31,6 @@ def api_root(request):
# ("galleries", request.build_absolute_uri(reverse("cast:api:gallery_list"))),
("videos", request.build_absolute_uri(reverse("cast:api:video_list"))),
("audios", request.build_absolute_uri(reverse("cast:api:audio_list"))),
("requests", request.build_absolute_uri(reverse("cast:api:request_list"))),
("comment_training_data", request.build_absolute_uri(reverse("cast:api:comment-training-data"))),
)
return Response(OrderedDict(root_api_urls))
Expand Down Expand Up @@ -93,28 +86,16 @@ class AudioPodloveDetailView(generics.RetrieveAPIView):
queryset = Audio.objects.all()
serializer_class = AudioPodloveSerializer


class RequestListView(generics.ListCreateAPIView):
queryset = Request.objects.all().order_by("-timestamp")
serializer_class = RequestSerializer
pagination_class = StandardResultsSetPagination
permission_classes = (IsAuthenticated,)

def create(self, request, *args, **kwargs):
"""Allow for bulk create via many=True."""
serializer = self.get_serializer(data=request.data, many=isinstance(request.data, list))
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

def perform_create(self, serializer):
"""Use bulk_create for request lists, normal model serializer otherwise."""
if isinstance(serializer, ListSerializer):
requests = [Request(**d) for d in serializer.validated_data]
Request.objects.bulk_create(requests)
else:
serializer.save()
def retrieve(self, request, *args, **kwargs):
instance = self.get_object()
if (episode_id := request.query_params.get("episode_id")) is not None:
try:
episode_id = int(episode_id)
instance.set_episode_id(episode_id)
except (ValueError, TypeError):
pass
serializer = self.get_serializer(instance)
return Response(serializer.data)


class CommentTrainingDataView(APIView):
Expand Down
26 changes: 24 additions & 2 deletions cast/blocks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from itertools import chain, islice, tee

from django.utils.functional import cached_property

from wagtail.core.blocks import ChooserBlock, ListBlock
from django.utils.safestring import mark_safe
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name
from wagtail.core.blocks import (
CharBlock,
ChooserBlock,
ListBlock,
StructBlock,
TextBlock,
)


def previous_and_next(iterable):
Expand Down Expand Up @@ -58,3 +67,16 @@ def widget(self):

def get_form_state(self, value):
return self.widget.get_value_data(value)


class CodeBlock(StructBlock):
language = CharBlock(help_text="The language of the code block")
source = TextBlock(rows=8, help_text="The source code of the block")

def render_basic(self, value, context=None):
if value:
lexer = get_lexer_by_name(value["language"], stripall=True)
highlighted = highlight(value["source"], lexer, HtmlFormatter())
return mark_safe(highlighted)
else:
return ""
58 changes: 0 additions & 58 deletions cast/management/commands/access_log_import.py

This file was deleted.

2 changes: 0 additions & 2 deletions cast/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .itunes import ItunesArtWork
from .moderation import SpamFilter
from .pages import Blog, HomePage, Post, sync_media_ids
from .request import Request
from .video import Video, get_video_dimensions

__all__ = [
Expand All @@ -19,7 +18,6 @@
ItunesArtWork,
Post,
sync_media_ids,
Request,
SpamFilter,
Video,
get_video_dimensions,
Expand Down
Loading

0 comments on commit 623c3c2

Please sign in to comment.