forked from devdaydresden/devday_website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addresses devdaydresden#219, devdaydresden#220 and devdaydresden#221 but needs more customizing
- Loading branch information
Showing
4 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from rest_framework import serializers, viewsets | ||
from rest_framework.relations import HyperlinkedRelatedField, SlugRelatedField | ||
from speaker.models import PublishedSpeaker | ||
|
||
|
||
class PublishedSpeakerSerializer(serializers.ModelSerializer): | ||
event = SlugRelatedField(slug_field="slug", read_only=True) | ||
talk_set = HyperlinkedRelatedField( | ||
many=True, view_name="talk-detail", read_only=True, lookup_field="slug" | ||
) | ||
|
||
class Meta: | ||
model = PublishedSpeaker | ||
fields = [ | ||
"url", | ||
"name", | ||
"twitter_handle", | ||
"short_biography", | ||
"slug", | ||
"event", | ||
"portrait", | ||
"thumbnail", | ||
"talk_set", | ||
] | ||
extra_kwargs = {"url": {"view_name": "speaker-detail", "lookup_field": "slug"}} | ||
|
||
|
||
class PublishedSpeakerViewSet(viewsets.ReadOnlyModelViewSet): | ||
serializer_class = PublishedSpeakerSerializer | ||
lookup_field = "slug" | ||
|
||
def get_queryset(self): | ||
qs = PublishedSpeaker.objects.order_by("name") | ||
event = self.request.query_params.get("event", None) | ||
speaker = self.request.query_params.get("speaker", None) | ||
if event: | ||
qs = qs.filter(event__slug=event) | ||
if speaker: | ||
qs = qs.filter(slug=speaker) | ||
return qs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
from rest_framework import serializers, viewsets | ||
from rest_framework.relations import StringRelatedField | ||
|
||
from rest_framework import filters, serializers, viewsets | ||
from rest_framework.relations import HyperlinkedRelatedField, SlugRelatedField | ||
from talk.models import Talk | ||
|
||
|
||
class SessionSerializer(serializers.ModelSerializer): | ||
event = StringRelatedField() | ||
published_speaker = StringRelatedField() | ||
event = SlugRelatedField(slug_field="slug", read_only=True) | ||
published_speaker = HyperlinkedRelatedField( | ||
read_only=True, view_name="speaker-detail", lookup_field="slug" | ||
) | ||
|
||
class Meta: | ||
model = Talk | ||
fields = ['url', 'title', 'abstract', 'published_speaker', 'event'] | ||
fields = ["url", "title", "abstract", "published_speaker", "event"] | ||
extra_kwargs = {"url": {"lookup_field": "slug"}} | ||
|
||
|
||
class SessionViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = Talk.objects.filter(published_speaker__isnull=False) | ||
queryset = Talk.objects.filter(published_speaker__isnull=False).order_by( | ||
"-event__start_time", "title", "published_speaker__name" | ||
) | ||
serializer_class = SessionSerializer | ||
lookup_field = "slug" | ||
|
||
def get_queryset(self): | ||
qs = super().get_queryset() | ||
event_slug = self.request.query_params.get("event", None) | ||
if event_slug: | ||
qs = qs.filter(event__slug=event_slug) | ||
return qs |