Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Initial Speakers Endpoint #273

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions devday/devday/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

from devday.views import SendEmailView, exception_test_view
from rest_framework import routers

from speaker.api_views import SpeakerViewSet
from talk.api_views import SessionViewSet
from twitterfeed.views import TwitterwallView

admin.autodiscover()

router = routers.DefaultRouter()
router.register(r"sessions", SessionViewSet)
router.register(r"speakers", SpeakerViewSet)

urlpatterns = [
url(r"^api/", include(router.urls)),
Expand Down
31 changes: 31 additions & 0 deletions devday/speaker/api_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rest_framework import serializers, viewsets

from speaker.models import Speaker


class SpeakerSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.CharField(source="slug")
image = serializers.ImageField(source="public_image", use_url=True, allow_null=False, allow_empty_file=False)

class Meta:
model = Speaker
fields = ["id", "url", "name", "short_biography", "position", "image"]
lookup_field = "slug"
extra_kwargs = {
"url": {'lookup_field': 'slug'}
}

def to_representation(self, instance):
representation = super().to_representation(instance)

# TODO Jens: This probably can be solved more elegantly with a mixin.
if not representation["image"]:
representation["image"] = ""

return representation


class SpeakerViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Speaker.objects.all()
serializer_class = SpeakerSerializer
lookup_field = "slug"
15 changes: 12 additions & 3 deletions devday/talk/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
from talk.models import Talk


class SessionSerializer(serializers.ModelSerializer):
class SessionSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.CharField(source="slug")
description = serializers.CharField(source="abstract")

# TODO Jens: Replace 'event' and 'speakers' with proper nested relationships once their endpoints are done.
event = StringRelatedField()
published_speaker = StringRelatedField()
published_speakers = StringRelatedField(many=True)

class Meta:
model = Talk
fields = ["url", "title", "abstract", "published_speakers", "event"]
fields = ["id", "url", "title", "description", "published_speakers", "event"]
lookup_field = "slug"
extra_kwargs = {
"url": {'lookup_field': 'slug'}
}


class SessionViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Talk.objects.filter(published_speakers__isnull=False)
serializer_class = SessionSerializer
lookup_field = 'slug'