1 from datetime
import datetime
3 from django
.utils
.translation
import ugettext
as _
5 from mygpo
.cel
import celery
6 from mygpo
.data
.feeddownloader
import PodcastUpdater
7 from mygpo
.utils
import get_timestamp
8 from mygpo
.users
.models
import EpisodeAction
9 from mygpo
.flattr
import Flattr
10 from mygpo
.db
.couchdb
.podcast
import podcast_by_id
11 from mygpo
.db
.couchdb
.episode
import episode_by_id
12 from mygpo
.db
.couchdb
.episode_state
import episode_state_for_user_episode
, \
16 @celery.task(max_retries
=5, default_retry_delay
=60)
17 def flattr_thing(user
, thing_id
, domain
, thing_type
):
18 """ Task to flattr a thing """
20 flattr
= Flattr(user
, domain
)
22 if thing_type
== 'Podcast':
23 thing
= podcast_by_id(thing_id
)
25 elif thing_type
== 'Episode':
26 thing
= episode_by_id(thing_id
)
29 raise NotImplemented(_("Can't flattr a '%s'") % thing_type
)
32 if not thing
.flattr_url
:
33 return False, _('No Payment URL available')
36 success
, msg
= flattr
.flattr_url(thing
.flattr_url
)
38 except Exception as ex
:
39 raise flattr_thing
.retry(exc
=ex
)
44 def auto_flattr_episode(user
, episode_id
):
45 success
, msg
= flattr_thing(user
, episode_id
, None, 'Episode')
50 episode
= episode_by_id(episode_id
)
51 state
= episode_state_for_user_episode(user
, episode
)
53 action
= EpisodeAction()
54 action
.action
= 'flattr'
55 add_episode_actions(state
, [action
])