def get(_, lang, event_id): if lang == 'ja': cached_event = Cache.get('api_event_' + str(event_id)) if cached_event is None: event = Topic.get_event_published_by_id(event_id) if event is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = EventSerializer(event).data Cache.set('api_event_' + str(event_id), res) else: res = cached_event elif lang == 'en': cached_event_en = Cache.get('api_event_en_' + str(event_id)) if cached_event_en is None: event = TopicEn.get_event_published_by_id(event_id) if event is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = EventEnSerializer(event).data Cache.set('api_event_en_' + str(event_id), res) else: res = cached_event_en else: return JsonResponse({ 'message': 'Not Found' }, status=404) return JsonResponse(res, safe=False)
def get(_, lang): if lang == 'ja': cached_groups = Cache.get('api_groups') if cached_groups is None: res = GroupSerializer(Group.get_all(), many=True).data Cache.set('api_groups', res) else: res = cached_groups elif lang == 'en': try: cached_groups_en = Cache.get('api_groups_en') except: cached_groups_en = None if cached_groups_en is None: res = GroupEnSerializer(Group.get_all(), many=True).data Cache.set('api_groups_en', res) else: res = cached_groups_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang, topic_id): if lang == 'ja': cached_topic = Cache.get('api_topic_' + str(topic_id)) if cached_topic is None: topic = Topic.get_topic_published_by_id(topic_id) if topic is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = TopicSerializer(topic).data Cache.set('api_topic_' + str(topic_id), res) else: res = cached_topic elif lang == 'en': cached_topic_en = Cache.get('api_topic_en_' + str(topic_id)) if cached_topic_en is None: topic = TopicEn.get_topic_published_by_id(topic_id) if topic is None: return JsonResponse({ 'message': 'Not Found' }, status=404) res = TopicEnSerializer(topic).data Cache.set('api_topic_en_' + str(topic_id), res) else: res = cached_topic_en else: return JsonResponse({ 'message': 'Not Found' }, status=404) return JsonResponse(res, safe=False)
def get(_, lang): if lang == 'ja': cached_topics = Cache.get('api_topics') if cached_topics is None: res = TopicsSerializer( Topic.get_topic_published_all(), many=True).data Cache.set('api_topics', res) else: res = cached_topics elif lang == 'en': cached_topics_en = Cache.get('api_topics_en') if cached_topics_en is None: res = TopicsEnSerializer( TopicEn.get_topic_published_all(), many=True).data Cache.set('api_topics_en', res) else: res = cached_topics_en else: return JsonResponse({ 'message': 'Not Found' }, status=404) return JsonResponse(res, safe=False)
def get(_, lang, video_id): if lang == 'ja': cached_video = Cache.get('api_video_' + str(video_id)) if cached_video is None: video = Video.get_published_by_id(video_id) if video is None: return JsonResponse({'message': 'Not Found'}, status=404) res = VideoSerializer(video).data Cache.set('api_video_' + str(video_id), res) else: res = cached_video elif lang == 'en': cached_video_en = Cache.get('api_video_en_' + str(video_id)) if cached_video_en is None: video = VideoEn.get_published_by_id(video_id) if video is None: return JsonResponse({'message': 'Not Found'}, status=404) res = VideoEnSerializer(video).data Cache.set('api_video_en_' + str(video_id), res) else: res = cached_video_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang, video_id): if lang == 'ja': cached_video_topics = Cache.get('api_video_topics_' + str(video_id)) if cached_video_topics is None: res = TopicsSerializer(Topic.objects.filter( post_type='topic', video__id=video_id, status=1, published_at__lt=datetime.now()), many=True, read_only=True).data Cache.set('api_video_topics_' + str(video_id), res) else: res = cached_video_topics elif lang == 'en': cached_video_topics_en = Cache.get('api_video_topics_en_' + str(video_id)) if cached_video_topics_en is None: res = TopicsEnSerializer(TopicEn.objects.filter( post_type='topic', video__id=video_id, status=1, published_at__lt=datetime.now()), many=True, read_only=True).data Cache.set('api_video_topics_en_' + str(video_id), res) else: res = cached_video_topics_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang): if lang == 'ja': cached_videos = Cache.get('api_videos_all') if cached_videos is None: res = VideosSerializer(Video.get_published_all(), many=True).data Cache.set('api_videos_all', res) else: res = cached_videos elif lang == 'en': cached_videos_en = Cache.get('api_videos_en_all') if cached_videos_en is None: res = VideosEnSerializer(VideoEn.get_published_all(), many=True).data Cache.set('api_videos_en_all', res) else: res = cached_videos_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang, category_id): if lang == 'ja': cached_videos = Cache.get('api_videos_' + str(category_id)) if cached_videos is None: res = VideosSerializer(Video.get_by_category_id(category_id), many=True).data Cache.set('api_videos_' + str(category_id), res) else: res = cached_videos elif lang == 'en': cached_videos_en = Cache.get('api_videos_en_' + str(category_id)) if cached_videos_en is None: res = VideosEnSerializer( VideoEn.get_by_category_id(category_id), many=True).data Cache.set('api_videos_en_' + str(category_id), res) else: res = cached_videos_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang, introduction_id): if lang == 'ja': cached_introduction = Cache.get('api_introduction_' + str(introduction_id)) if cached_introduction is None: introduction = Introduction.get_published_by_id( introduction_id) if introduction is None: return JsonResponse({'message': 'Not Found'}, status=404) res = IntroductionSerializer(introduction).data Cache.set('api_introduction_' + str(introduction_id), res) else: res = cached_introduction elif lang == 'en': try: cached_introduction_en = Cache.get('api_introduction_en_' + str(introduction_id)) except: cached_introduction_en = None if cached_introduction_en is None: introduction = IntroductionEn.get_published_by_id( introduction_id) if introduction is None: return JsonResponse({'message': 'Not Found'}, status=404) res = IntroductionEnSerializer(introduction).data Cache.set('api_introduction_en_' + str(introduction_id), res) else: res = cached_introduction_en else: return JsonResponse({'message': 'Not Found'}, status=404) return JsonResponse(res, safe=False)
def get(_, lang): if lang == 'ja': cached_home_events = Cache.get('api_home_events') if cached_home_events is None: events_res = EventsSerializer( Topic.get_event_home_published_all(), many=True).data Cache.set('api_home_events', events_res) else: events_res = cached_home_events cached_home_topics = Cache.get('api_home_topics') if cached_home_topics is None: topics_res = TopicsSerializer( Topic.get_topic_home_published_all(), many=True).data Cache.set('api_home_topics', topics_res) else: topics_res = cached_home_topics elif lang == 'en': cached_home_categories_en = Cache.get('api_home_categories_en') if cached_home_categories_en is None: events_res = EventsEnSerializer( TopicEn.get_event_home_published_all(), many=True).data Cache.set('api_categories_en', events_res) else: events_res = cached_home_categories_en cached_home_topics_en = Cache.get('api_home_topics_en') if cached_home_topics_en is None: topics_res = TopicsEnSerializer( TopicEn.get_topic_home_published_all(), many=True).data Cache.set('api_home_topics_en', topics_res) else: topics_res = cached_home_topics_en else: return JsonResponse({ 'message': 'Not Found' }, status=404) return JsonResponse({ 'events': events_res, 'topics': topics_res, }, safe=False)