def podcast_dashboard(req, podcast_slug): pod = get_podcast(req, podcast_slug) with analytics_query.AsyncContext() as async_ctx: total_listens = analytics_query.total_listens(pod, async_ctx) total_listens_this_week = analytics_query.total_listens_this_week(pod, async_ctx) subscribers = analytics_query.total_subscribers(pod, async_ctx) listens = total_listens() data = { 'podcast': pod, 'episodes': pod.podcastepisode_set.order_by('-publish'), 'analytics': { 'total_listens': listens, 'total_listens_this_week': total_listens_this_week(), 'subscribers': subscribers(), }, 'next_milestone': next(x for x in MILESTONES if x > listens), 'previous_milestone': [x for x in MILESTONES if x <= listens][-1] if listens else 0, 'hit_first_milestone': listens > MILESTONES[1], # The first "real" milestone 'is_still_importing': pod.is_still_importing(), } owner_uset = UserSettings.get_from_user(pod.owner) if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX): data['feedback'] = Feedback.objects.filter(podcast=pod, episode=None).order_by('-created') return _pmrender(req, 'dashboard/podcast/page_podcast.html', data)
def podcast_dashboard(req, podcast_slug): pod = get_podcast(req, podcast_slug) tz = UserSettings.get_from_user(req.user).tz_offset total_listens = analytics_query.total_listens(pod) total_listens_this_week = analytics_query.total_listens_this_week(pod, tz) subscribers = analytics_query.total_subscribers(pod) data = { 'podcast': pod, 'episodes': pod.podcastepisode_set.order_by('-publish'), 'analytics': { 'total_listens': total_listens, 'total_listens_this_week': total_listens_this_week, 'subscribers': subscribers, }, 'next_milestone': next(x for x in constants.MILESTONES if x > total_listens), 'previous_milestone': [x for x in constants.MILESTONES if x <= total_listens][-1] if total_listens > 0 else 0, 'hit_first_milestone': total_listens > constants.MILESTONES[1], # The first "real" milestone 'is_still_importing': pod.is_still_importing(), 'site': None, 'LOCALES': constants.locales, 'SITE_PAGE_TYPES': SitePage.PAGE_TYPES, 'SITE_THEMES': Site.SITE_THEMES, 'N_DESTINATIONS': NotificationHook.DESTINATIONS, 'N_TRIGGERS': NotificationHook.TRIGGERS, } try: data['site'] = pod.site except Site.DoesNotExist: pass owner_uset = UserSettings.get_from_user(pod.owner) if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX): all_feedback = Feedback.objects.filter(podcast=pod) data['feedback_all'] = all_feedback data['feedback'] = all_feedback.filter(episode=None).order_by('-created') data['feedback_episodes'] = (all_feedback.exclude(episode=None) .annotate(Count('episode', distinct=True)) .select_related('episode')) if payment_plans.minimum(owner_uset.plan, payment_plans.PLAN_PRO): sparkline_data = analytics_query.get_episode_sparklines(pod, tz) data['sparklines'] = sparkline_data if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_NOTIFICATIONS): data['notifications'] = NotificationHook.objects.filter(podcast=pod) if req.GET.get('notification_sent'): data['notification_sent'] = True if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COLLABORATORS): data['collab_error'] = req.GET.get('collaberr') return _pmrender(req, 'dashboard/podcast/page_podcast.html', data)
def podcast_episode(req, podcast_slug, episode_id): pod = get_podcast(req, podcast_slug) ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod) total_listens = analytics_query.total_listens(pod, episode_id=str(ep.id)) data = { 'error': 'error' in req.GET, 'podcast': pod, 'episode': ep, 'analytics': {'total_listens': total_listens}, 'feedback': Feedback.objects.filter(podcast=pod, episode=ep).order_by('-created'), } return _pmrender(req, 'dashboard/episode/page_episode.html', data)
def podcast_episode(req, podcast_slug, episode_id): pod = get_podcast(req, podcast_slug) ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod) total_listens = analytics_query.total_listens(pod, episode=ep) data = { 'error': 'error' in req.GET, 'podcast': pod, 'episode': ep, 'analytics': {'total_listens': total_listens}, 'feedback': Feedback.objects.filter(podcast=pod, episode=ep).order_by('-created'), } return _pmrender(req, 'dashboard/episode/page_episode.html', data)
def podcast_dashboard(req, podcast_slug): pod = get_podcast(req, podcast_slug) tz = UserSettings.get_from_user(req.user).tz_offset total_listens = analytics_query.total_listens(pod) total_listens_this_week = analytics_query.total_listens_this_week(pod, tz) subscribers = analytics_query.total_subscribers(pod) def pop_until_lt(arr, field, comp, max=-1): count = 0 while arr: if getattr(arr[0], field) >= comp: yield arr.pop(0) else: return if max > 0: count += 1 if count == max: break if not arr: return if max > 0: ignored = 0 while arr: if getattr(arr[0], field) >= comp: ignored += 1 arr.pop(0) else: break if ignored: yield ignored data = { 'podcast': pod, 'episodes': pod.podcastepisode_set.order_by('-publish'), 'analytics': { 'total_listens': total_listens, 'total_listens_this_week': total_listens_this_week, 'subscribers': subscribers, }, 'next_milestone': next(x for x in constants.MILESTONES if x > total_listens), 'previous_milestone': [x for x in constants.MILESTONES if x <= total_listens][-1] if total_listens else 0, 'hit_first_milestone': total_listens > constants.MILESTONES[1], # The first "real" milestone 'is_still_importing': pod.is_still_importing(), 'site': None, 'LOCALES': constants.locales, 'PODCAST_CATEGORIES': json.dumps(list(CATEGORIES)), 'SITE_THEMES': Site.SITE_THEMES, 'N_DESTINATIONS': NotificationHook.DESTINATIONS, 'N_TRIGGERS': NotificationHook.TRIGGERS, 'pop_until_lt': pop_until_lt, } try: data['site'] = pod.site except Site.DoesNotExist: pass owner_uset = UserSettings.get_from_user(pod.owner) if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX): all_feedback = Feedback.objects.filter(podcast=pod) data['feedback_all'] = all_feedback data['feedback'] = all_feedback.filter(episode=None).order_by('-created') data['feedback_episodes'] = all_feedback.exclude(episode=None).annotate( Count('episode', distinct=True)) if payment_plans.minimum(owner_uset.plan, payment_plans.PLAN_PRO): sparkline_data = analytics_query.get_episode_sparklines(pod, tz) data['sparklines'] = sparkline_data if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_NOTIFICATIONS): data['notifications'] = NotificationHook.objects.filter(podcast=pod) if req.GET.get('notification_sent'): data['notification_sent'] = True return _pmrender(req, 'dashboard/podcast/page_podcast.html', data)