2019-03-18 22:38:22 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
import graphene
|
2019-03-11 19:26:36 +00:00
|
|
|
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 22:38:22 +00:00
|
|
|
Url,
|
|
|
|
UrlType,
|
|
|
|
)
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventTypeNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = EventType
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
filter_fields = {"name": ["iexact"]}
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventLocationNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = EventLocation
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
filter_fields = {"name": ["iexact"], "camp__slug": ["iexact"]}
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventTrackNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = EventTrack
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
filter_fields = {"name": ["iexact"], "camp__slug": ["iexact"]}
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventInstanceNode(DjangoObjectType):
|
|
|
|
|
2019-03-18 22:38:22 +00:00
|
|
|
start = graphene.Int(description="When this instance of the event starts. In posix time.")
|
|
|
|
end = graphene.Int(description="When this instance of the event ends. In posix time.")
|
|
|
|
|
2019-03-11 19:26:36 +00:00
|
|
|
class Meta:
|
|
|
|
model = EventInstance
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
only_fields = ("event", "start", "end", "location")
|
2019-03-11 19:26:36 +00:00
|
|
|
filter_fields = {
|
2019-03-18 22:38:22 +00:00
|
|
|
"event__title": ["iexact"],
|
|
|
|
"event__track__camp__slug": ["iexact"],
|
2019-03-11 19:26:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 22:38:22 +00:00
|
|
|
def resolve_start(self, info, **kwargs):
|
|
|
|
return time.mktime(self.when.lower.timetuple())
|
|
|
|
|
|
|
|
def resolve_end(self, info, **kwargs):
|
|
|
|
return time.mktime(self.when.upper.timetuple())
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SpeakerNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = Speaker
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
only_fields = ("id", "name", "biography", "slug", "camp", "events")
|
|
|
|
filter_fields = {"name": ["iexact"], "camp__slug": ["iexact"]}
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = Event
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
filter_fields = {"title": ["iexact"], "track__camp__slug": ["iexact"]}
|
2019-03-11 19:26:36 +00:00
|
|
|
|
|
|
|
|
2019-03-18 21:11:33 +00:00
|
|
|
class UrlNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = Url
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
|
|
|
only_fields = ("url", "urltype")
|
2019-03-18 21:11:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UrlTypeNode(DjangoObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = UrlType
|
2019-03-18 22:38:22 +00:00
|
|
|
interfaces = (relay.Node,)
|
2019-03-18 21:11:33 +00:00
|
|
|
|
|
|
|
|
2019-03-11 19:26:36 +00:00
|
|
|
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)
|