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_by_id(thing_id) elif thing_type == 'Episode': thing = episode_by_id(thing_id) else: raise NotImplemented(_("Can't flattr a '%s'") % thing_type) if not thing.flattr_url: return False, _('No Payment URL available') try: success, msg = flattr.flattr_url(thing.flattr_url) if settings.FLATTR_MYGPO_THING: flattr.flattr_url(settings.FLATTR_MYGPO_THING) except Exception as ex: raise flattr_thing.retry(exc=ex) return success, msg
def get(self, request): user = request.user site = RequestSite(request) flattr = Flattr(user, site.domain, request.is_secure()) url = request.build_absolute_uri() token = flattr.process_retrieved_code(url) if token: messages.success(request, _('Authentication successful')) update_flattr_settings(user, token) else: messages.error(request, _('Authentication failed. Try again later')) return HttpResponseRedirect(reverse('account') + '#flattr')
def get(self, request): user = request.user site = RequestSite(request) flattr = Flattr(user, site.domain, request.is_secure()) url = request.build_absolute_uri() token = flattr.process_retrieved_code(url) if token: messages.success(request, _('Authentication successful')) settings = user.profile.settings settings.set_wksetting(FLATTR_TOKEN, token) settings.save() else: messages.error(request, _('Authentication failed. Try again later')) return HttpResponseRedirect(reverse('account') + '#flattr')
def flattr_thing(user_id, thing_id, domain, is_secure, thing_type): """ Task to flattr a thing """ user = User.objects.get(pk=user_id) 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: return False, _('No Payment URL available') try: success, msg = flattr.flattr_url(thing.flattr_url) if settings.FLATTR_MYGPO_THING: flattr.flattr_url(settings.FLATTR_MYGPO_THING) except Exception as ex: raise flattr_thing.retry(exc=ex) if success: HistoryEntry.objects.create( timestamp=datetime.utcnow(), podcast=podcast, episode=episode, user=user, client=None, action=HistoryEntry.FLATTR, ) return success, msg
def list_show(request, plist, owner): is_own = owner == request.user site = RequestSite(request) objs = [entry.content_object for entry in plist.entries.all()] max_subscribers = max([p.subscriber_count() for p in objs] + [0]) thing = plist.get_flattr_thing(site.domain, owner.username) flattr = Flattr(owner, site.domain, request.is_secure()) flattr_autosubmit = flattr.get_autosubmit_url(thing) return render(request, 'list.html', { 'podcastlist': plist, 'max_subscribers': max_subscribers, 'owner': owner, 'flattr_autosubmit': flattr_autosubmit, 'domain': site.domain, 'is_own': is_own, })
def list_show(request, plist, owner): is_own = owner == request.user site = RequestSite(request) objs = [entry.content_object for entry in plist.entries.all()] max_subscribers = max([p.subscriber_count() for p in objs] + [0]) thing = plist.get_flattr_thing(site.domain, owner.username) flattr = Flattr(owner, site.domain, request.is_secure()) flattr_autosubmit = flattr.get_autosubmit_url(thing) return render( request, 'list.html', { 'podcastlist': plist, 'max_subscribers': max_subscribers, 'owner': owner, 'flattr_autosubmit': flattr_autosubmit, 'domain': site.domain, 'is_own': is_own, })
def list_show(request, plist, owner): is_own = owner == request.user site = RequestSite(request) plist = proxy_object(plist) podcasts = list(podcasts_groups_by_id(plist.podcasts)) plist.podcasts = podcasts max_subscribers = max([p.subscriber_count() for p in podcasts] + [0]) thing = plist.get_flattr_thing(site.domain, owner.username) flattr = Flattr(owner, site.domain, request.is_secure()) flattr_autosubmit = flattr.get_autosubmit_url(thing) return render(request, 'list.html', { 'podcastlist': plist, 'max_subscribers': max_subscribers, 'owner': owner, 'flattr_autosubmit': flattr_autosubmit, 'domain': site.domain, 'is_own': is_own, })
def account(request): if request.method == 'GET': site = RequestSite(request) flattr = Flattr(request.user, site.domain, request.is_secure()) userpage_token = request.user.profile.get_token('userpage_token') profile_form = ProfileForm({ 'twitter': request.user.profile.twitter, 'about': request.user.profile.about, }) form = UserAccountForm({ 'email': request.user.email, 'public': request.user.profile.settings.get_wksetting(PUBLIC_SUB_USER) }) flattr_form = FlattrForm({ 'enable': request.user.profile.settings.get_wksetting(FLATTR_AUTO), 'token': request.user.profile.settings.get_wksetting(FLATTR_TOKEN), 'flattr_mygpo': request.user.profile.settings.get_wksetting(FLATTR_MYGPO), 'username': request.user.profile.settings.get_wksetting(FLATTR_USERNAME), }) return render( request, 'account.html', { 'site': site, 'form': form, 'profile_form': profile_form, 'flattr_form': flattr_form, 'flattr': flattr, 'userpage_token': userpage_token, }) try: form = UserAccountForm(request.POST) if not form.is_valid(): raise ValueError( _('Oops! Something went wrong. Please double-check the data you entered.' )) if form.cleaned_data['password_current']: if not request.user.check_password( form.cleaned_data['password_current']): raise ValueError('Current password is incorrect') request.user.set_password(form.cleaned_data['password1']) request.user.email = form.cleaned_data['email'] try: request.user.save() except Exception as ex: # TODO: which exception? messages.error(request, str(ex)) messages.success(request, 'Account updated') except (ValueError, ValidationError) as e: messages.error(request, str(e)) return render(request, 'account.html', { 'form': form, })