<commit_before>from datetime import datetime

from django.utils.translation import ugettext as _
from django.conf import settings

from mygpo.podcasts.models import Podcast, Episode
from mygpo.celery import celery
from mygpo.history.models import HistoryEntry
from mygpo.data.feeddownloader import PodcastUpdater
from mygpo.utils import get_timestamp
from mygpo.users.models import EpisodeAction
from mygpo.flattr import Flattr
from mygpo.db.couchdb.episode_state import episode_state_for_user_episode, \
         add_episode_actions


@celery.task(max_retries=5, default_retry_delay=60)
def flattr_thing(user, thing_id, domain, is_secure, thing_type):
    """ Task to flattr a thing """

    flattr = Flattr(user, domain, is_secure)

    if thing_type == 'Podcast':
        thing = Podcast.objects.get(id=thing_id)
        episode, podcast = None, thing

    elif thing_type == 'Episode':
        thing = Episode.objects.get(id=thing_id).select_related('podcast')
        episode, podcast = thing, thing.podcast

    else:
        raise NotImplemented(_("Can't flattr a '%s'") % thing_type)


    if not thing.flattr_url:<commit_msg>[Flattr] fix bug when flattring episode<commit_after>from datetime import datetime

from django.utils.translation import ugettext as _
from django.conf import settings

from mygpo.podcasts.models import Podcast, Episode
from mygpo.celery import celery
from mygpo.history.models import HistoryEntry
from mygpo.data.feeddownloader import PodcastUpdater
from mygpo.utils import get_timestamp
from mygpo.users.models import EpisodeAction
from mygpo.flattr import Flattr
from mygpo.db.couchdb.episode_state import episode_state_for_user_episode, \
         add_episode_actions


@celery.task(max_retries=5, default_retry_delay=60)
def flattr_thing(user, thing_id, domain, is_secure, thing_type):
    """ Task to flattr a thing """

    flattr = Flattr(user, domain, is_secure)

    if thing_type == 'Podcast':
        thing = Podcast.objects.get(id=thing_id)
        episode, podcast = None, thing

    elif thing_type == 'Episode':
        query = Episode.objects.filter(id=thing_id).select_related('podcast')
        thing = query.get()
        episode, podcast = thing, thing.podcast

    else:
        raise NotImplemented(_("Can't flattr a '%s'") % thing_type)


    if not thing.flattr_url:
{'fraction_non_alphanumeric': 0.08516129032258064, 'fraction_numerical': 0.0025806451612903226, 'mean_word_length': 4.262443438914027, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1505558', 'n_tokens_mistral': 746, 'n_tokens_neox': 724, 'n_words': 190}