Пример #1
0
    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)