Skip to content
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
10 changes: 5 additions & 5 deletions backend/api/conferences/schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from api.context import Info
from api.conferences.types import Conference
import strawberry
import strawberry_django

from conferences.models import Conference as ConferenceModel
from conferences import models


@strawberry.type
class ConferenceQuery:
@strawberry.field
def conference(self, info: Info, code: str) -> Conference:
return ConferenceModel.objects.prefetch_related("durations").get(code=code)
@strawberry_django.field
def conference(self, code: str) -> Conference:
return models.Conference.objects.filter(code=code)
32 changes: 19 additions & 13 deletions backend/api/conferences/tests/test_query_talk.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,29 @@ def test_abstract_shows_keynote_description(graphql_client, user):
}


def test_fetch_schedule_talk(simple_schedule_item, graphql_client, user):
def test_fetch_schedule_talk(
simple_schedule_item, graphql_client, user, django_assert_num_queries
):
graphql_client.force_login(user)

schedule_item = simple_schedule_item
response = graphql_client.query(
"""query($slug: String!, $code: String!) {
conference(code: $code) {
talk(slug: $slug) {
youtubeVideoId
userHasSpot
hasSpacesLeft
spacesLeft
with django_assert_num_queries(4):
response = graphql_client.query(
"""query($slug: String!, $code: String!) {
conference(code: $code) {
talk(slug: $slug) {
youtubeVideoId
userHasSpot
hasSpacesLeft
spacesLeft
}
}
}
}""",
variables={"slug": schedule_item.slug, "code": schedule_item.conference.code},
)
}""",
variables={
"slug": schedule_item.slug,
"code": schedule_item.conference.code,
},
)

assert response["data"]["conference"]["talk"] == {
"youtubeVideoId": "AbCdEfGhIjK",
Expand Down
103 changes: 19 additions & 84 deletions backend/api/conferences/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from api.context import Info
from django.db.models import Case, When, Value, IntegerField
from django.db.models import Prefetch
from participants.models import Participant as ParticipantModel
from datetime import datetime
from api.participants.types import Participant
Expand Down Expand Up @@ -139,27 +137,31 @@ def youtube_video_id(self) -> str | None:
return schedule_item.youtube_video_id if schedule_item else None


@strawberry.type
@strawberry_django.type(conference_models.Conference)
class Conference:
id: strawberry.ID
id: strawberry.auto

name: str = strawberry.field(resolver=make_localized_resolver("name"))
introduction: str = strawberry.field(
resolver=make_localized_resolver("introduction")
name: str = strawberry_django.field(
resolver=make_localized_resolver("name"), only=["name"]
)
introduction: str = strawberry_django.field(
resolver=make_localized_resolver("introduction"), only=["introduction"]
)
code: str
hostname: str
code: strawberry.auto
hostname: strawberry.auto
start: datetime
end: datetime
map: Map | None = strawberry.field(resolver=resolve_map)

pretix_event_url: str
pretix_event_url: strawberry.auto

@strawberry.field
@strawberry_django.field(
only=["pretix_organizer_id", "pretix_event_id"],
)
def voucher(self, info: Info, code: str) -> Voucher | None:
return get_voucher(self, code)

@strawberry.field
@strawberry_django.field(only=["timezone"])
def timezone(self, info: Info) -> str:
return str(self.timezone)

Expand Down Expand Up @@ -207,9 +209,7 @@ def topics(self, info: Info) -> list[Topic]:
def languages(self, info: Info) -> list[Language]:
return self.languages.all()

@strawberry.field
def durations(self, info: Info) -> list["Duration"]:
return self.durations.all()
durations: list["Duration"]

@strawberry.field
def submission_types(self, info: Info) -> list[SubmissionType]:
Expand Down Expand Up @@ -272,9 +272,9 @@ def talks(self, info: Info) -> list[ScheduleItem]:
.all()
)

@strawberry.field
@strawberry_django.field
def talk(self, info: Info, slug: str) -> ScheduleItem | None:
return self.schedule_items.filter(slug=slug).prefetch_related("rooms").first()
return self.schedule_items.filter(slug=slug)

@strawberry.field
def ranking(self, info: Info, topic: strawberry.ID) -> RankRequest | None:
Expand All @@ -296,74 +296,9 @@ def ranking(self, info: Info, topic: strawberry.ID) -> RankRequest | None:
stats=rank_request.stats.all(),
)

@strawberry.field
@strawberry_django.field
def days(self, info: Info) -> list[Day]:
days = list(
self.days.order_by("day")
.prefetch_related(
"slots",
"slots__day",
"slots__day__added_rooms",
"slots__day__added_rooms__room",
Prefetch(
"slots__items",
queryset=(
ScheduleItemModel.objects.for_conference(self.id)
.annotate(
order=Case(
When(type="custom", then=Value(1)),
When(type="break", then=Value(1)),
When(type="talk", then=Value(2)),
When(type="panel", then=Value(3)),
default=Value(4),
output_field=IntegerField(),
)
)
.order_by("order")
.prefetch_related(
"audience_level",
"language",
"rooms",
"additional_speakers",
"additional_speakers__user",
"language",
"submission",
"submission__type",
"submission__tags",
"submission__duration",
"submission__audience_level",
"submission__speaker",
"submission__languages",
"submission__schedule_items",
"keynote",
"keynote__schedule_items",
"keynote__schedule_items__rooms",
"keynote__schedule_items__slot",
"keynote__schedule_items__slot__day",
"keynote__speakers",
"keynote__speakers__user",
)
),
),
)
.all()
)
all_speakers = [
speaker.id
for day in days
for slot in day.slots.all()
for item in slot.items.all()
for speaker in item.speakers
]
info.context._participants_data = {
participant.user_id: participant
for participant in ParticipantModel.objects.for_conference(self.id)
.filter(user_id__in=all_speakers)
.prefetch_related("user")
.all()
}

return days
return self.days.all()

@strawberry.field
def current_day(self, info: Info) -> Day | None:
Expand Down
18 changes: 10 additions & 8 deletions backend/api/schedule/types/day.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
from schedule.models import ScheduleItem as ScheduleItemModel
from api.schedule.types.schedule_item import ScheduleItem
from django.utils import timezone
from datetime import date, timedelta
from datetime import timedelta
from api.schedule.types.day_room import DayRoom
from api.schedule.types.slot import ScheduleSlot
import strawberry
import strawberry_django
from schedule import models


@strawberry.type
@strawberry_django.type(models.Day)
class Day:
id: strawberry.ID
day: date
id: strawberry.auto
day: strawberry.auto

@strawberry.field
def random_events(self, limit: int = 4) -> list[ScheduleItem]:
Expand All @@ -31,13 +33,13 @@ def random_events(self, limit: int = 4) -> list[ScheduleItem]:
.order_by("?")[:limit]
)

@strawberry.field
@strawberry_django.field
def slots(
self, info: Info, room: strawberry.ID | None = None
) -> list[ScheduleSlot]:
if room:
return list(self.slots.filter(items__rooms__id=room))
return list(self.slots.all())
return self.slots.filter(items__rooms__id=room)
return self.slots.all()

@strawberry.field
def running_events(self, info: Info) -> list[ScheduleItem]:
Expand All @@ -59,7 +61,7 @@ def running_events(self, info: Info) -> list[ScheduleItem]:

return [item for item in current_slot.items.all()]

@strawberry.field
@strawberry_django.field(prefetch_related=["added_rooms__room"])
def rooms(self) -> list[DayRoom]:
added_rooms = self.added_rooms.all()
return [
Expand Down
8 changes: 5 additions & 3 deletions backend/api/schedule/types/room.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import strawberry
import strawberry_django
from schedule import models


@strawberry.type
@strawberry_django.type(models.Room)
class Room:
id: strawberry.ID
name: str
id: strawberry.auto
name: strawberry.auto
type: str
Loading
Loading