bornhack-website/src/program/schema.py

116 lines
2.9 KiB
Python
Raw Normal View History

2019-03-18 21:11:33 +00:00
from django.db.models import Q
from graphene import relay
from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from .models import (
Event,
EventType,
EventLocation,
EventTrack,
EventInstance,
Speaker,
2019-03-18 21:11:33 +00:00
Url, UrlType)
class EventTypeNode(DjangoObjectType):
class Meta:
model = EventType
interfaces = (relay.Node, )
filter_fields = {
'name': ['iexact'],
}
class EventLocationNode(DjangoObjectType):
class Meta:
model = EventLocation
interfaces = (relay.Node, )
filter_fields = {
'name': ['iexact'],
2019-03-18 21:11:33 +00:00
'camp__slug': ['iexact'],
}
class EventTrackNode(DjangoObjectType):
class Meta:
model = EventTrack
interfaces = (relay.Node, )
filter_fields = {
'name': ['iexact'],
2019-03-18 21:11:33 +00:00
'camp__slug': ['iexact'],
}
class EventInstanceNode(DjangoObjectType):
class Meta:
model = EventInstance
interfaces = (relay.Node, )
filter_fields = {
'event__title': ['iexact'],
2019-03-18 21:11:33 +00:00
'event__track__camp__slug': ['iexact'],
}
def resolve_when(self, info):
# We need to resolve this ourselves, graphene-django isn't smart enough
return [self.when.lower, self.when.upper]
class SpeakerNode(DjangoObjectType):
class Meta:
model = Speaker
interfaces = (relay.Node, )
2019-03-18 21:11:33 +00:00
only_fields = ('id', 'name', 'biography', 'slug', 'camp', 'events',)
filter_fields = {
'name': ['iexact'],
2019-03-18 21:11:33 +00:00
'camp__slug': ['iexact'],
}
class EventNode(DjangoObjectType):
class Meta:
model = Event
interfaces = (relay.Node, )
filter_fields = {
'title': ['iexact'],
'track__camp__slug': ['iexact'],
}
2019-03-18 21:11:33 +00:00
class UrlNode(DjangoObjectType):
class Meta:
model = Url
interfaces = (relay.Node, )
only_fields = ('url', 'urltype',)
class UrlTypeNode(DjangoObjectType):
class Meta:
model = UrlType
interfaces = (relay.Node, )
class ProgramQuery(object):
event_type = relay.Node.Field(EventTypeNode)
all_event_types = DjangoFilterConnectionField(EventTypeNode)
event_location = relay.Node.Field(EventLocationNode)
all_event_locations = DjangoFilterConnectionField(EventLocationNode)
event_track = relay.Node.Field(EventTrackNode)
all_event_tracks = DjangoFilterConnectionField(EventTrackNode)
event_instance = relay.Node.Field(EventInstanceNode)
all_event_instances = DjangoFilterConnectionField(EventInstanceNode)
event = relay.Node.Field(EventNode)
all_events = DjangoFilterConnectionField(EventNode)
speaker = relay.Node.Field(SpeakerNode)
all_speakers = DjangoFilterConnectionField(SpeakerNode)
2019-03-18 21:11:33 +00:00
url = relay.Node.Field(UrlNode)
url_type = relay.Node.Field(UrlTypeNode)