Skip to content

Commit

Permalink
Add a new http API for CCIP APP events data.
Browse files Browse the repository at this point in the history
  • Loading branch information
xingularity committed May 5, 2018
1 parent 8d9d280 commit 9d5a1e4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Empty file added __init__.py
Empty file.
Empty file added src/__init__.py
Empty file.
73 changes: 73 additions & 0 deletions src/events/api_proposals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from proposals.models import TalkProposal
from events.models import KeynoteEvent, ProposedTalkEvent, CustomEvent
# from django.core import serializers
from django.http import JsonResponse
import datetime as dt
import pytz


def get_ccip_events_json(request):
import pprint
pprint.pprint(list(ProposedTalkEvent.objects.values())[0])
proposed_talk_events = ProposedTalkEvent.objects.select_related('proposal__submitter')

json_data_list = list()
for event in proposed_talk_events:
json_dict = dict()
json_dict['speaker'] = dict()
json_dict['speaker']['bio'] = event.proposal.submitter.bio
json_dict['speaker']['name'] = event.proposal.submitter.speaker_name
json_dict['speaker']['avatar'] = event.proposal.submitter.get_photo_url()
# json_dict['speaker']['avatar'] = request.build_absolute_uri(event.proposal.submitter.photo.url)
json_dict['subject'] = event.proposal.title
json_dict['summary'] = event.proposal.abstract
json_dict['type'] = ''
json_dict['room'] = event.location[-2:].upper()
json_dict['start'] = event.begin_time.value.isoformat()
json_dict['end'] = event.end_time.value.isoformat()
json_dict['id'] = event.proposal.id
json_data_list.append(json_dict)
print(json_dict)

# Keynote #1
json_dict = dict()
json_dict['speaker'] = dict()
json_dict['speaker']['bio'] = ''
json_dict['speaker']['name'] = '陳昇瑋'
json_dict['speaker']['avatar'] = 'https://tw.pycon.org/2018/static/images/default_head.png'
# json_dict['speaker']['avatar'] = request.build_absolute_uri(event.proposal.submitter.photo.url)
json_dict['subject'] = ''
json_dict['summary'] = ''
json_dict['type'] = ''
json_dict['room'] = 'R0'
json_dict['start'] = dt.datetime(2018, 6, 1, 9, 20, 0, tzinfo=pytz.FixedOffset(8*60)).isoformat()
json_dict['end'] = dt.datetime(2018, 6, 1, 10, 20, 0, tzinfo=pytz.FixedOffset(8*60)).isoformat()
json_dict['id'] = 1
json_data_list.append(json_dict)

# Keynote #2
json_dict = dict()
json_dict['speaker'] = dict()
json_dict['speaker']['bio'] = """
Katie has worn many different hats over the years. She has been a software developer for many languages, systems administrator for multiple operating systems, and speaker on many different topics.
When she’s not changing the world, she enjoys making tapestries, cooking, and seeing just how well various application stacks handle emoji.
"""
json_dict['speaker']['name'] = 'Katie McLaughlin'
json_dict['speaker']['avatar'] = 'https://tw.pycon.org/2018/static/pycontw-2018/assets/keynotes/katie.jpg'
# json_dict['speaker']['avatar'] = request.build_absolute_uri(event.proposal.submitter.photo.url)
json_dict['subject'] = 'Communication strategies beyond the Basic Multilingual Plane'
json_dict['summary'] = """
The standardisation of the universal character set has paved the way for the ability for data to be freely transferred between computers around the world. However, the most volatile part of this standard is still causing prolific issues with miscommunication between humans.
In this keynote, Katie McLaughlin will share knowledge from her years of research and contributions to this field and rant about emoji for a bit.
"""
json_dict['type'] = ''
json_dict['room'] = 'R0'
json_dict['start'] = dt.datetime(2018, 6, 1, 9, 10, 0, tzinfo=pytz.FixedOffset(8*60)).isoformat()
json_dict['end'] = dt.datetime(2018, 6, 1, 10, 10, 0, tzinfo=pytz.FixedOffset(8*60)).isoformat()
json_dict['id'] = 2
json_data_list.append(json_dict)

# pprint.pprint(json_dict)
return JsonResponse(json_data_list, safe=False)
4 changes: 4 additions & 0 deletions src/events/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf.urls import url
from django.views.generic import RedirectView
from events.api_proposals import get_ccip_events_json

from . import views

Expand All @@ -16,4 +17,7 @@

# Backward compatibility to the static events page.
url(r'^talk/$', RedirectView.as_view(pattern_name='events_talk_list')),

# API for CCIP
url(r'^ccip-json/$', get_ccip_events_json),
]

0 comments on commit 9d5a1e4

Please sign in to comment.