Пример #1
0
def dashboard(request):
    try:
        topics_list = DSPConnectorV12.get_topics()['topics']
        selected_topic = random.choice(topics_list)
        hot_news = DSPConnectorV12.search_news(
            selected_topic['topic_id'])['news'][:4]
        top_influencers = DSPConnectorV12.get_audiences(
            selected_topic['topic_id'])['audiences'][:4]
    except DSPConnectorException as e:
        messages.error(request, e.message)
        topics_list = {}
        selected_topic = 'No themes'
        context = {'selected_topic': selected_topic, 'topics': topics_list}
        return render(request, 'dashboard/theme.html', context)

    hot_tags = [t[0] for t in Profile.get_hot_tags(30)]
    last_members = Profile.get_last_n_members(3)
    context = {
        'selected_topic': selected_topic,
        'topics': topics_list,
        'last_members': last_members,
        'hot_tags': hot_tags,
        'json_hot_tags': json.dumps(hot_tags),
        'hot_news': hot_news,
        'top_influencers': top_influencers
    }
    return render(request, 'dashboard/dashboard.html', context)
Пример #2
0
def get_audiences(request, topic_id):
    try:
        audiences = DSPConnectorV12.get_audiences(topic_id)
    except DSPConnectorException:
        audiences = {}
    return JsonResponse({'status': 'ok', 'result': audiences}, status=200)