Example #1
0
def episode(request, episode):

    podcast = episode.podcast

    podcast = check_restrictions(podcast)

    user = request.user

    if not podcast:
        raise Http404

    if user.is_authenticated():

        is_fav = FavoriteEpisode.objects.filter(user=user, episode=episode)\
                                        .exists()

        # pre-populate data for fetch_data
        podcasts_dict = {podcast.get_id(): podcast}
        episodes_dict = {episode.id.hex: episode}

        has_history = EpisodeHistoryEntry.objects.filter(user=user,
                                                         episode=episode)\
                                                 .exists()

        played_parts = EpisodeHeatmap(podcast, episode, user, episode.duration)

        devices = {c.id.hex: c for c in user.client_set.all()}
        can_flattr = user.profile.settings.get_wksetting(
            FLATTR_TOKEN) and episode.flattr_url

    else:
        has_history = False
        is_fav = False
        played_parts = None
        devices = {}
        can_flattr = False

    is_publisher = check_publisher_permission(user, podcast)

    prev = None  #podcast.get_episode_before(episode)
    next = None  #podcast.get_episode_after(episode)

    return render(
        request, 'episode.html', {
            'episode': episode,
            'podcast': podcast,
            'prev': prev,
            'next': next,
            'has_history': has_history,
            'is_favorite': is_fav,
            'played_parts': played_parts,
            'actions': EPISODE_ACTION_TYPES,
            'devices': devices,
            'can_flattr': can_flattr,
            'is_publisher': is_publisher,
        })
Example #2
0
def episode(request, episode):

    podcast = episode.podcast

    podcast = check_restrictions(podcast)

    user = request.user

    if not podcast:
        raise Http404

    if user.is_authenticated():

        is_fav = FavoriteEpisode.objects.filter(user=user, episode=episode)\
                                        .exists()

        # pre-populate data for fetch_data
        podcasts_dict = {podcast.get_id(): podcast}
        episodes_dict = {episode.id.hex: episode}

        has_history = EpisodeHistoryEntry.objects.filter(user=user,
                                                         episode=episode)\
                                                 .exists()

        played_parts = EpisodeHeatmap(podcast, episode, user, episode.duration)

        devices = {c.id.hex: c for c in user.client_set.all()}
        can_flattr = user.profile.settings.get_wksetting(FLATTR_TOKEN) and episode.flattr_url

    else:
        has_history = False
        is_fav = False
        played_parts = None
        devices = {}
        can_flattr = False

    is_publisher = check_publisher_permission(user, podcast)

    prev = None #podcast.get_episode_before(episode)
    next = None #podcast.get_episode_after(episode)

    return render(request, 'episode.html', {
        'episode': episode,
        'podcast': podcast,
        'prev': prev,
        'next': next,
        'has_history': has_history,
        'is_favorite': is_fav,
        'played_parts': played_parts,
        'actions': EPISODE_ACTION_TYPES,
        'devices': devices,
        'can_flattr': can_flattr,
        'is_publisher': is_publisher,
    })
Example #3
0
def episode(request, episode):

    podcast = podcast_by_id(episode.podcast)

    podcast = check_restrictions(podcast)

    user = request.user

    if not podcast:
        raise Http404

    if user.is_authenticated():

        episode_state = episode_state_for_user_episode(user, episode)
        is_fav = episode_state.is_favorite()


        # pre-populate data for fetch_data
        podcasts_dict = {podcast.get_id(): podcast}
        episodes_dict = {episode._id: episode}

        has_history = bool(list(episode_state.get_history_entries()))

        played_parts = EpisodeHeatmap(podcast.get_id(),
                episode._id, user._id, duration=episode.duration)

        devices = dict( (d.id, d.name) for d in user.devices )
        can_flattr = user.get_wksetting(FLATTR_TOKEN) and episode.flattr_url

    else:
        has_history = False
        is_fav = False
        played_parts = None
        devices = {}
        can_flattr = False

    is_publisher = check_publisher_permission(user, podcast)

    prev = podcast.get_episode_before(episode)
    next = podcast.get_episode_after(episode)

    return render(request, 'episode.html', {
        'episode': episode,
        'podcast': podcast,
        'prev': prev,
        'next': next,
        'has_history': has_history,
        'is_favorite': is_fav,
        'played_parts': played_parts,
        'actions': EPISODE_ACTION_TYPES,
        'devices': devices,
        'can_flattr': can_flattr,
        'is_publisher': is_publisher,
    })
Example #4
0
def episode(request, episode):

    podcast = episode.podcast

    podcast = check_restrictions(podcast)

    user = request.user

    if not podcast:
        raise Http404

    if user.is_authenticated:

        is_fav = FavoriteEpisode.objects.filter(user=user,
                                                episode=episode).exists()

        # pre-populate data for fetch_data
        podcasts_dict = {podcast.get_id(): podcast}
        episodes_dict = {episode.id.hex: episode}

        has_history = EpisodeHistoryEntry.objects.filter(
            user=user, episode=episode).exists()

        devices = {c.id.hex: c for c in user.client_set.all()}

    else:
        has_history = False
        is_fav = False
        devices = {}

    is_publisher = check_publisher_permission(user, podcast)

    prev = None  # podcast.get_episode_before(episode)
    next = None  # podcast.get_episode_after(episode)

    return render(
        request,
        'episode.html',
        {
            'episode': episode,
            'podcast': podcast,
            'prev': prev,
            'next': next,
            'has_history': has_history,
            'is_favorite': is_fav,
            'actions': EPISODE_ACTION_TYPES,
            'devices': devices,
            'is_publisher': is_publisher,
        },
    )
Example #5
0
def episode(request, episode):

    podcast = episode.podcast

    podcast = check_restrictions(podcast)

    user = request.user

    if not podcast:
        raise Http404

    if user.is_authenticated:

        is_fav = FavoriteEpisode.objects.filter(user=user, episode=episode).exists()

        # pre-populate data for fetch_data
        podcasts_dict = {podcast.get_id(): podcast}
        episodes_dict = {episode.id.hex: episode}

        has_history = EpisodeHistoryEntry.objects.filter(
            user=user, episode=episode
        ).exists()

        devices = {c.id.hex: c for c in user.client_set.all()}

    else:
        has_history = False
        is_fav = False
        devices = {}

    is_publisher = check_publisher_permission(user, podcast)

    prev = None  # podcast.get_episode_before(episode)
    next = None  # podcast.get_episode_after(episode)

    return render(
        request,
        'episode.html',
        {
            'episode': episode,
            'podcast': podcast,
            'prev': prev,
            'next': next,
            'has_history': has_history,
            'is_favorite': is_fav,
            'actions': EPISODE_ACTION_TYPES,
            'devices': devices,
            'is_publisher': is_publisher,
        },
    )
Example #6
0
def show(request, podcast):
    """ Shows a podcast detail page """

    podcast = check_restrictions(podcast)

    current_site = RequestSite(request)
    num_episodes = 20
    episodes = episode_list(podcast, request.user, limit=num_episodes)
    user = request.user

    # TODO: move into EpisodeList (?) class
    listeners = [e.listeners for e in episodes if e.listeners is not None]
    max_listeners = max(listeners, default=0)

    episode = None

    if episodes:
        episode = episodes[0]
        episodes = episodes[1:]

    if podcast.group:
        group = podcast.group
        rel_podcasts = group.podcast_set.exclude(pk=podcast.pk)
    else:
        rel_podcasts = []

    tags = get_tags(podcast, user)
    has_tagged = any(t['is_own'] for t in tags)

    if user.is_authenticated():
        subscribed_devices = Client.objects.filter(
            subscription__user=user,
            subscription__podcast=podcast,
        )

        subscribe_targets = get_subscribe_targets(podcast, user)

        has_history = HistoryEntry.objects.filter(user=user, podcast=podcast)\
                                          .exists()
        can_flattr = (user.profile.settings.get_wksetting(FLATTR_TOKEN) and
                      podcast.flattr_url)

    else:
        has_history = False
        subscribed_devices = []
        subscribe_targets = []
        can_flattr = False

    is_publisher = check_publisher_permission(user, podcast)

    episodes_total = podcast.episode_count or 0
    num_pages = episodes_total / num_episodes
    page_list = get_page_list(1, num_pages, 1, 15)

    return render(request, 'podcast.html', {
        'tags': tags,
        'has_tagged': has_tagged,
        'url': current_site,
        'has_history': has_history,
        'podcast': podcast,
        'devices': subscribed_devices,
        'related_podcasts': rel_podcasts,
        'can_subscribe': len(subscribe_targets) > 0,
        'subscribe_targets': subscribe_targets,
        'episode': episode,
        'episodes': episodes,
        'max_listeners': max_listeners,
        'can_flattr': can_flattr,
        'is_publisher': is_publisher,
        'page_list': page_list,
        'current_page': 1,
    })
Example #7
0
def show(request, podcast):
    """ Shows a podcast detail page """

    podcast = check_restrictions(podcast)

    current_site = RequestSite(request)
    num_episodes = 20
    episodes = episode_list(podcast, request.user, limit=num_episodes)
    user = request.user

    # TODO: move into EpisodeList (?) class
    listeners = [e.listeners for e in episodes if e.listeners is not None]
    max_listeners = max(listeners, default=0)

    episode = None

    if episodes:
        episode = episodes[0]
        episodes = episodes[1:]

    if podcast.group:
        group = podcast.group
        rel_podcasts = group.podcast_set.all()
    else:
        rel_podcasts = []

    tags = get_tags(podcast, user)
    has_tagged = any(t['is_own'] for t in tags)

    if user.is_authenticated:
        subscribed_devices = Client.objects.filter(
            subscription__user=user, subscription__podcast=podcast)

        subscribe_targets = get_subscribe_targets(podcast, user)

        has_history = HistoryEntry.objects.filter(user=user,
                                                  podcast=podcast).exists()

    else:
        has_history = False
        subscribed_devices = []
        subscribe_targets = []

    is_publisher = check_publisher_permission(user, podcast)

    episodes_total = podcast.episode_count or 0
    num_pages = episodes_total / num_episodes
    page_list = get_page_list(1, num_pages, 1, 15)

    return render(
        request,
        'podcast.html',
        {
            'tags': tags,
            'has_tagged': has_tagged,
            'url': current_site,
            'has_history': has_history,
            'podcast': podcast,
            'devices': subscribed_devices,
            'related_podcasts': rel_podcasts,
            'can_subscribe': len(subscribe_targets) > 0,
            'subscribe_targets': subscribe_targets,
            'episode': episode,
            'episodes': episodes,
            'max_listeners': max_listeners,
            'is_publisher': is_publisher,
            'page_list': page_list,
            'current_page': 1,
        },
    )
Example #8
0
def show(request, podcast):
    """ Shows a podcast detail page """

    podcast = check_restrictions(podcast)

    current_site = RequestSite(request)
    num_episodes = 20
    episodes = episode_list(podcast, request.user, limit=num_episodes)
    user = request.user

    max_listeners = max([e.listeners for e in episodes] + [0])

    episode = None

    if episodes:
        episode = episodes[0]
        episodes = episodes[1:]

    if podcast.group:
        group = PodcastGroup.get(podcast.group)
        rel_podcasts = filter(lambda x: x != podcast, group.podcasts)
    else:
        rel_podcasts = []

    tags, has_tagged = get_tags(podcast, user)

    if user.is_authenticated():
        state = podcast_state_for_user_podcast(user, podcast)
        subscribed_devices = state.get_subscribed_device_ids()
        subscribed_devices = user.get_devices(subscribed_devices)

        subscribe_targets = podcast.subscribe_targets(user)

        has_history = bool(state.actions)
        is_public = state.settings.get('public_subscription', True)
        can_flattr = request.user.get_wksetting(FLATTR_TOKEN) and podcast.flattr_url

    else:
        has_history = False
        is_public = False
        subscribed_devices = []
        subscribe_targets = []
        can_flattr = False

    is_publisher = check_publisher_permission(user, podcast)

    episodes_total = podcast.episode_count or 0
    num_pages = episodes_total / num_episodes
    page_list = get_page_list(1, num_pages, 1, 15)

    return render(request, 'podcast.html', {
        'tags': tags,
        'has_tagged': has_tagged,
        'url': current_site,
        'has_history': has_history,
        'podcast': podcast,
        'is_public': is_public,
        'devices': subscribed_devices,
        'related_podcasts': rel_podcasts,
        'can_subscribe': len(subscribe_targets) > 0,
        'subscribe_targets': subscribe_targets,
        'episode': episode,
        'episodes': episodes,
        'max_listeners': max_listeners,
        'can_flattr': can_flattr,
        'is_publisher': is_publisher,
        'page_list': page_list,
        'current_page': 1,
    })