<commit_before>from functools import wraps, partial
from datetime import datetime

from django.urls import reverse
from django.http import HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.sites.requests import RequestSite
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.views.decorators.vary import vary_on_cookie
from django.views.decorators.cache import never_cache, cache_control
from django.shortcuts import get_object_or_404
from django.contrib.contenttypes.models import ContentType

from mygpo.podcasts.models import Podcast, PodcastGroup, Episode, Tag
from mygpo.users.models import SubscriptionException
from mygpo.subscriptions.models import Subscription
from mygpo.subscriptions import (
    subscribe as subscribe_podcast,
    unsubscribe as unsubscribe_podcast,
    subscribe_all as subscribe_podcast_all,
    unsubscribe_all as unsubscribe_podcast_all,
    get_subscribe_targets
)
from mygpo.history.models import HistoryEntry
from mygpo.core.tasks import flattr_thing
from mygpo.utils import normalize_feed_url
from mygpo.users.settings import PUBLIC_SUB_PODCAST, FLATTR_TOKEN
from mygpo.publisher.utils import check_publisher_permission
from mygpo.usersettings.models import UserSettings
from mygpo.users.models import Client
from mygpo.web.forms import SyncForm
from mygpo.decorators import allowed_methods
from mygpo.web.utils import get_podcast_link_target, get_page_list, \
    check_restrictions

import logging
logger = logging.getLogger(__name__)


@vary_on_cookie
@cache_control(private=True)
@allowed_methods(['GET'])
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 = []<commit_msg>Don't exclude current podcast from related podcasts<commit_after>from functools import wraps, partial
from datetime import datetime

from django.urls import reverse
from django.http import HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.sites.requests import RequestSite
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.views.decorators.vary import vary_on_cookie
from django.views.decorators.cache import never_cache, cache_control
from django.shortcuts import get_object_or_404
from django.contrib.contenttypes.models import ContentType

from mygpo.podcasts.models import Podcast, PodcastGroup, Episode, Tag
from mygpo.users.models import SubscriptionException
from mygpo.subscriptions.models import Subscription
from mygpo.subscriptions import (
    subscribe as subscribe_podcast,
    unsubscribe as unsubscribe_podcast,
    subscribe_all as subscribe_podcast_all,
    unsubscribe_all as unsubscribe_podcast_all,
    get_subscribe_targets
)
from mygpo.history.models import HistoryEntry
from mygpo.core.tasks import flattr_thing
from mygpo.utils import normalize_feed_url
from mygpo.users.settings import PUBLIC_SUB_PODCAST, FLATTR_TOKEN
from mygpo.publisher.utils import check_publisher_permission
from mygpo.usersettings.models import UserSettings
from mygpo.users.models import Client
from mygpo.web.forms import SyncForm
from mygpo.decorators import allowed_methods
from mygpo.web.utils import get_podcast_link_target, get_page_list, \
    check_restrictions

import logging
logger = logging.getLogger(__name__)


@vary_on_cookie
@cache_control(private=True)
@allowed_methods(['GET'])
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()
        can_flattr = (user.profile.settings.get_wksetting(FLATTR_TOKEN) and
                      podcast.flattr_url)

    else:
        has_history = False
        subscribed_devices = []
{'fraction_non_alphanumeric': 0.06505788358062939, 'fraction_numerical': 0.0035871514756236752, 'mean_word_length': 3.9547657512116317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6488700', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1739, 'n_words': 452}