예제 #1
0
파일: views.py 프로젝트: vctrshn/pinecast
def site_episode(req, podcast_slug, episode_id):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)
    episode = get_object_or_404(PodcastEpisode,
                                podcast=site.podcast,
                                id=episode_id)
    return _srender(req, site, 'episode.html', {'episode': episode})
예제 #2
0
파일: views.py 프로젝트: vctrshn/pinecast
def site_home(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)
    episodes = pod.get_episodes()
    paginator = Paginator(episodes, SITE_EPISODES_PER_PAGE)
    try:
        pager = paginator.page(req.GET.get('page'))
    except PageNotAnInteger:
        pager = paginator.page(1)
    except EmptyPage:
        return redirect('site_home', podcast_slug=pod.slug)
    return _srender(req, site, 'home.html', {'pager': pager})
예제 #3
0
파일: views.py 프로젝트: Pinecast/pinecast
def favicon(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    us = UserSettings.get_from_user(pod.owner)
    if not minimum(us.plan, FEATURE_MIN_SITE_FAVICON):
        return redirect('https://pinecast.com/static/img/favicon.png')

    site = get_object_or_404(models.Site, podcast=pod)

    if not site.favicon_url:
        return redirect('https://pinecast.com/static/img/favicon.png')

    return redirect(site.favicon_url)
예제 #4
0
파일: views.py 프로젝트: Pinecast/pinecast
def site_home(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)
    episodes = pod.get_episodes()
    paginator = Paginator(episodes, SITE_EPISODES_PER_PAGE)
    try:
        pager = paginator.page(req.GET.get('page'))
    except PageNotAnInteger:
        pager = paginator.page(1)
    except EmptyPage:
        return redirect('site_home', podcast_slug=pod.slug)
    return _srender(req, site, 'home.html', {'pager': pager})
예제 #5
0
파일: views.py 프로젝트: vctrshn/pinecast
def favicon(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    us = UserSettings.get_from_user(pod.owner)
    if not minimum(us.plan, FEATURE_MIN_SITE_FAVICON):
        return redirect('https://pinecast.com/static/img/favicon.png')

    site = get_object_or_404(models.Site, podcast=pod)

    if not site.favicon_url:
        return redirect('https://pinecast.com/static/img/favicon.png')

    return redirect(site.favicon_url)
예제 #6
0
파일: views.py 프로젝트: vctrshn/pinecast
def site_blog(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)
    posts = site.siteblogpost_set.filter(
        publish__lt=datetime.datetime.now()).order_by('-publish')
    paginator = Paginator(posts, 5)
    try:
        pager = paginator.page(req.GET.get('page'))
    except PageNotAnInteger:
        pager = paginator.page(1)
    except EmptyPage:
        return redirect('site_home', podcast_slug=pod.slug)
    return _srender(req, site, 'blog.html', {'pager': pager})
예제 #7
0
파일: views.py 프로젝트: Pinecast/pinecast
def site_blog(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)
    posts = site.siteblogpost_set.filter(
        publish__lt=datetime.datetime.now()).order_by('-publish')
    paginator = Paginator(posts, 5)
    try:
        pager = paginator.page(req.GET.get('page'))
    except PageNotAnInteger:
        pager = paginator.page(1)
    except EmptyPage:
        return redirect('site_home', podcast_slug=pod.slug)
    return _srender(req, site, 'blog.html', {'pager': pager})
예제 #8
0
파일: views.py 프로젝트: vctrshn/pinecast
def ep_comment_box(req, podcast_slug, episode_id):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    if not UserSettings.user_meets_plan(pod.owner,
                                        plans.FEATURE_MIN_COMMENT_BOX):
        raise Http404()
    ep = get_object_or_404(PodcastEpisode, podcast=pod, id=episode_id)
    if not req.POST:
        return _pmrender(req, 'feedback/comment_episode.html', {
            'podcast': pod,
            'episode': ep
        })

    try:
        if not _validate_recaptcha(req):
            raise Exception('Invalid ReCAPTCHA')

        ip = analyze.get_request_ip(req)
        f = Feedback(podcast=pod,
                     episode=ep,
                     sender=req.POST.get('email'),
                     message=req.POST.get('message'),
                     sender_ip=ip)
        f.save()
        send_notification_email(
            pod.owner, ugettext('[Pinecast] You got some feedback!'),
            'Go check the Feedback page of %s--an episode on %s--to see what was written.\n\n'
            'https://pinecast.com%s' %
            (ep.title, pod.name,
             reverse('podcast_episode',
                     podcast_slug=podcast_slug,
                     episode_id=str(ep.id)) + '#tab-feedback'))
        NotificationHook.trigger_notification(podcast=pod,
                                              trigger_type='feedback',
                                              data={
                                                  'episode':
                                                  ep,
                                                  'content':
                                                  req.POST.get('message'),
                                                  'sender':
                                                  req.POST.get('email')
                                              })
    except Exception:
        return _pmrender(req, 'feedback/comment_episode.html', {
            'podcast': pod,
            'episode': ep,
            'error': True,
            'default': req.POST
        })

    return _pmrender(req, 'feedback/thanks.html', {'podcast': pod})
예제 #9
0
def subscriptions(req):
    if not req.session.get('pay_session'):
        return redirect('tip_jar_login')

    tip_user = get_object_or_404(TipUser, id=req.session['pay_session'])
    ctx = {'tip_user': tip_user}
    return _pmrender(req, 'payments/tip_jar/subscriptions.html', ctx)
예제 #10
0
def tip_flow(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    us = UserSettings.get_from_user(pod.owner)
    if not us.stripe_payout_managed_account:
        if pod.homepage:
            return redirect(pod.homepage)
        else:
            raise Http404()

    recurring_tip = None
    pay_session = req.session.get('pay_session')
    tipper = None
    if pay_session:
        tipper = TipUser.objects.get(id=pay_session, verified=True)
        try:
            recurring_tip = RecurringTip.objects.get(
                podcast=pod, tipper=tipper, deactivated=False)
        except Exception as e:
            pass

    ctx = {'error': req.GET.get('error'),
           'recurring_tip': recurring_tip,
           'podcast': pod,
           'tipper': tipper}

    return _pmrender(req, 'payments/tip_jar/main.html', ctx)
예제 #11
0
def send_tip(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)

    try:
        amount = int(float(req.POST.get('amount')) / 100.0) * 100
        if amount < 100:
            return {'error': ugettext('Tips less than $1 are not allowed.')}
    except Exception:
        return HttpResponse(status=400)

    tip_type = req.POST.get('type')

    owner_us = UserSettings.get_from_user(pod.owner)
    if owner_us.plan == PLAN_DEMO and tip_type == 'subscribe':
        return {'error': ugettext('You cannot have recurring tips for free podcasts.')}

    if amount > PLAN_TIP_LIMITS[owner_us.plan]:
        return {'error': ugettext('That tip is too large for %s') % pod.name}


    if tip_type == 'charge':
        return _send_one_time_tip(req, pod, owner_us, amount)
    elif tip_type == 'subscribe':
        return _auth_subscription(req, pod, amount)
    else:
        return HttpResponse(status=400)
예제 #12
0
def subscriptions(req):
    if not req.session.get('pay_session'):
        return redirect('tip_jar_login')

    tip_user = get_object_or_404(TipUser, id=req.session['pay_session'])
    ctx = {'tip_user': tip_user}
    return _pmrender(req, 'payments/tip_jar/subscriptions.html', ctx)
예제 #13
0
def tip_flow(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    us = UserSettings.get_from_user(pod.owner)
    if not us.stripe_payout_managed_account:
        if pod.homepage:
            return redirect(pod.homepage)
        else:
            raise Http404()

    recurring_tip = None
    pay_session = req.session.get('pay_session')
    tipper = None
    if pay_session:
        tipper = TipUser.objects.get(id=pay_session, verified=True)
        try:
            recurring_tip = RecurringTip.objects.get(
                podcast=pod, tipper=tipper, deactivated=False)
        except Exception as e:
            pass

    ctx = {'error': req.GET.get('error'),
           'recurring_tip': recurring_tip,
           'podcast': pod,
           'tipper': tipper}

    return _pmrender(req, 'payments/tip_jar/main.html', ctx)
예제 #14
0
def send_tip(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)

    try:
        amount = int(float(req.POST.get('amount')) / 100.0) * 100
        if amount < 100:
            return {'error': ugettext('Tips less than $1 are not allowed.')}
    except Exception:
        return HttpResponse(status=400)

    tip_type = req.POST.get('type')

    owner_us = UserSettings.get_from_user(pod.owner)
    if owner_us.plan == PLAN_DEMO and tip_type == 'subscribe':
        return {'error': ugettext('You cannot have recurring tips for free podcasts.')}

    if amount > PLAN_TIP_LIMITS[owner_us.plan]:
        return {'error': ugettext('That tip is too large for %s') % pod.name}


    if tip_type == 'charge':
        return _send_one_time_tip(req, pod, owner_us, amount)
    elif tip_type == 'subscribe':
        return _auth_subscription(req, pod, amount)
    else:
        return HttpResponse(status=400)
예제 #15
0
def test_notification(req):
    podcast = _get_podcast(req, id=req.POST.get('podcast'))
    notification = get_object_or_404(NotificationHook, podcast=podcast, id=req.POST.get('id'))

    notification.send_test()

    return redirect(reverse('podcast_dashboard', podcast_slug=podcast.slug) + '?notification_sent=true#settings,notifications')
예제 #16
0
def edit_blog_post(req, podcast_slug, post_slug):
    site = get_site(req, podcast_slug)
    post = get_object_or_404(SiteBlogPost, site=site, slug=post_slug)

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/blog/page_edit.html', {
            'site': site,
            'post': post
        })
    try:
        naive_publish = datetime.datetime.strptime(
            req.POST.get('publish', '').split('.')[0],
            '%Y-%m-%dT%H:%M:%S')  # 2015-07-09T12:00
        adjusted_publish = naive_publish - UserSettings.get_from_user(
            req.user).get_tz_delta()
        post.title = req.POST.get('title')
        post.slug = req.POST.get('slug')
        post.body = req.POST.get('body')
        post.publish = adjusted_publish
        post.disable_comments = req.POST.get('disable_comments') == 'true'
        post.save()
    except Exception as e:
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/blog/page_edit.html', data)
    else:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) +
            '#site,blog')
예제 #17
0
def delete_page(req, podcast_slug, page_slug):
    site = get_site(req, podcast_slug)
    page = get_object_or_404(SitePage, site=site, slug=page_slug)
    page.delete()

    return redirect(
        reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#site')
예제 #18
0
def network_dashboard(req, network_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])

    net_podcasts = net.podcast_set.all()
    pod_map = {str(p.id): p for p in net_podcasts}

    top_episodes_data = analytics_query.get_top_episodes([str(p.id) for p in net_podcasts])

    top_episodes = []
    for ep_id, count in sorted(top_episodes_data.items(), key=lambda x: -1 * x[1])[:75]:
        try:
            episode = PodcastEpisode.objects.get(id=ep_id)
        except PodcastEpisode.DoesNotExist:
            continue
        top_episodes.append({
            'count': count,
            'episode': episode,
            'podcast': pod_map[str(episode.podcast_id)],
        })

    upcoming_episodes = PodcastEpisode.objects.filter(
        podcast__in=net_podcasts,
        publish__gt=round_now())

    return _pmrender(req,
                     'dashboard/network/page_dash.html',
                     {'error': req.GET.get('error'),
                      'network': net,
                      'net_podcasts': net_podcasts,
                      'net_podcasts_map': pod_map,
                      'top_episodes': top_episodes,
                      'upcoming_episodes': list(upcoming_episodes)})
예제 #19
0
def get_site(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    if (pod.owner != req.user and
        not Network.objects.filter(
            deactivated=False, members__in=[req.user], podcast__in=[pod]).count()):
        raise Http404()
    return pod.site
예제 #20
0
def network_add_member(req, network_id):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            members__in=[req.user])

    try:
        user = User.objects.get(email=req.POST.get('email'))
    except User.DoesNotExist:
        return redirect(
            reverse('network_dashboard', network_id=network_id) +
            '?error=udne#members,add-member')

    net.members.add(user)
    net.save()
    pinecast.email.send_notification_email(
        user,
        ugettext('[Pinecast] You have been added to "%s"') % net.name,
        ugettext('''
We are emailing you to let you know that you were added to the network
"%s". No action is required on your part. If you log in to Pinecast,
you will now have read and write access to all of the podcasts in the
network, and will be able to add your own podcasts to the network.
        ''') % net.name)

    return redirect(
        reverse('network_dashboard', network_id=net.id) + '#members')
예제 #21
0
def podcast_episode_publish_now(req, podcast_slug, episode_id):
    pod = get_podcast(req, podcast_slug)
    ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod)

    ep.publish = datetime.datetime.now()
    ep.save()

    return redirect('podcast_episode', podcast_slug=pod.slug, episode_id=str(ep.id))
예제 #22
0
파일: views.py 프로젝트: Pinecast/pinecast
def podcast_episode_publish_now(req, podcast_slug, episode_id):
    pod = get_podcast(req, podcast_slug)
    ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod)

    ep.publish = datetime.datetime.now()
    ep.save()

    return redirect('podcast_episode', podcast_slug=pod.slug, episode_id=str(ep.id))
예제 #23
0
def get_site(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    if (pod.owner != req.user
            and not Network.objects.filter(deactivated=False,
                                           members__in=[req.user],
                                           podcast__in=[pod]).count()):
        raise Http404()
    return pod.site
예제 #24
0
파일: views.py 프로젝트: Pinecast/pinecast
def player(req, episode_id):
    ep = get_object_or_404(PodcastEpisode, id=episode_id)
    resp = render(req, 'player.html', {'episode': ep})

    # If the user is not a demo user, allow the player to be used outside the app.
    if UserSettings.user_meets_plan(ep.podcast.owner, plans.FEATURE_MIN_PLAYER):
        resp.xframe_options_exempt = True
    return resp
예제 #25
0
파일: views.py 프로젝트: Pinecast/pinecast
def listen(req, episode_id):
    ep = get_object_or_404(PodcastEpisode, id=episode_id)
    if req.method == 'GET':
        analytics_log.write_listen(
            ep=ep,
            source='embed' if req.GET.get('embed') else 'direct',
            req=req)

    return redirect(_asset(ep.audio_url))
예제 #26
0
def listen(req, episode_id):
    ep = get_object_or_404(PodcastEpisode, id=episode_id)
    if req.method == 'GET':
        analytics_log.write_listen(
            ep=ep,
            source='embed' if req.GET.get('embed') else 'direct',
            req=req)

    return redirect(_asset(ep.audio_url))
예제 #27
0
파일: views.py 프로젝트: Pinecast/pinecast
def delete_podcast(req, podcast_slug):
    # This doesn't use `get_podcast` because only the owner may delete the podcast
    pod = get_object_or_404(Podcast, slug=podcast_slug, owner=req.user)

    for tip in pod.recurring_tips.all():
        tip.cancel()

    pod.delete()
    return redirect('dashboard')
예제 #28
0
def remove_blog_post(req, podcast_slug):
    site = get_site(req, podcast_slug)
    post = get_object_or_404(SiteBlogPost,
                             site=site,
                             slug=req.POST.get('slug'))

    post.delete()
    return redirect(
        reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#site,blog')
예제 #29
0
def delete_podcast(req, podcast_slug):
    # This doesn't use `get_podcast` because only the owner may delete the podcast
    pod = get_object_or_404(Podcast, slug=podcast_slug, owner=req.user)

    for tip in pod.recurring_tips.all():
        tip.cancel()

    pod.delete()
    return redirect('dashboard')
예제 #30
0
def network_remove_podcast(req, network_id, podcast_slug):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])
    pod = get_object_or_404(Podcast, slug=podcast_slug, networks__in=[net])

    # We don't need to confirm if the user is the owner.
    if pod.owner == req.user:
        pod.networks.remove(net)
        pod.save()
        return redirect('network_dashboard', network_id=net.id)

    if req.user != net.owner:
        raise Http404()


    pod.networks.remove(net)
    pod.save()

    return redirect('network_dashboard', network_id=net.id)
예제 #31
0
def player(req, episode_id):
    ep = get_object_or_404(PodcastEpisode, id=episode_id)
    resp = render(req, 'player.html', {'episode': ep})

    # If the user is not a demo user, allow the player to be used outside the app.
    if UserSettings.user_meets_plan(ep.podcast.owner,
                                    plans.FEATURE_MIN_PLAYER):
        resp.xframe_options_exempt = True
    return resp
예제 #32
0
def import_progress(req, podcast_slug):
    p = get_object_or_404(Podcast, slug=podcast_slug, owner=req.user)
    ids = req.GET.get('ids')
    reqs = AssetImportRequest.objects.filter(id__in=ids.split(','))
    total = reqs.count()
    return {
        'elems': {x.id: x.get_json_payload() for x in reqs},
        'status': sum(1.0 for r in reqs if r.resolved) / total * 100.0,
    }
예제 #33
0
def network_deactivate(req, network_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, owner=req.user)

    if req.POST.get('confirm') != 'doit':
        return redirect('dashboard')

    net.deactivated = True
    net.save()

    return redirect('dashboard')
예제 #34
0
def import_progress(req, podcast_slug):
    p = get_object_or_404(Podcast, slug=podcast_slug, owner=req.user)
    ids = req.GET.get('ids')
    reqs = AssetImportRequest.objects.filter(id__in=ids.split(','))
    total = reqs.count()
    return {
        'elems': {x.id: x.get_json_payload()
                  for x in reqs},
        'status': sum(1.0 for r in reqs if r.resolved) / total * 100.0,
    }
예제 #35
0
파일: views.py 프로젝트: Pinecast/pinecast
def ep_comment_box(req, podcast_slug, episode_id):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    if not UserSettings.user_meets_plan(pod.owner, plans.FEATURE_MIN_COMMENT_BOX):
        raise Http404()
    ep = get_object_or_404(PodcastEpisode, podcast=pod, id=episode_id)
    if not req.POST:
        return _pmrender(req, 'feedback/comment_episode.html', {'podcast': pod, 'episode': ep})

    try:
        if not _validate_recaptcha(req):
            raise Exception('Invalid ReCAPTCHA')

        ip = analyze.get_request_ip(req)
        f = Feedback(
            podcast=pod,
            episode=ep,
            sender=req.POST.get('email'),
            message=req.POST.get('message'),
            sender_ip=ip
        )
        f.save()
        send_notification_email(
            pod.owner,
            ugettext('[Pinecast] You got some feedback!'),
            'Go check the Feedback page of %s--an episode on %s--to see what was written.\n\n'
            'https://pinecast.com%s' %
            (ep.title,
             pod.name,
             reverse('podcast_episode',
                     podcast_slug=podcast_slug,
                     episode_id=str(ep.id)) +
             '#tab-feedback')
        )
        NotificationHook.trigger_notification(
            podcast=pod,
            trigger_type='feedback',
            data={'episode': ep, 'content': req.POST.get('message'), 'sender': req.POST.get('email')})
    except Exception:
        return _pmrender(req, 'feedback/comment_episode.html',
                         {'podcast': pod, 'episode': ep, 'error': True, 'default': req.POST})

    return _pmrender(req, 'feedback/thanks.html', {'podcast': pod})
예제 #36
0
def network_remove_member(req, network_id, member_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])
    user = get_object_or_404(User, id=member_id)

    if not net.members.filter(username=user.username).count():
        raise Http404()

    # We don't need to confirm if the user is the owner.
    if net.owner == user:
        return redirect('network_dashboard', network_id=net.id)

    pods = Podcast.objects.filter(owner=user, networks__in=[net])

    for pod in pods:
        pod.networks.remove(net)
        pod.save()
    net.members.remove(user)
    net.save()

    return redirect(reverse('network_dashboard', network_id=net.id) + '#members')
예제 #37
0
def network_remove_podcast(req, network_id, podcast_slug):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            members__in=[req.user])
    pod = get_object_or_404(Podcast, slug=podcast_slug, networks__in=[net])

    # We don't need to confirm if the user is the owner.
    if pod.owner == req.user:
        pod.networks.remove(net)
        pod.save()
        return redirect('network_dashboard', network_id=net.id)

    if req.user != net.owner:
        raise Http404()

    pod.networks.remove(net)
    pod.save()

    return redirect('network_dashboard', network_id=net.id)
예제 #38
0
def network_edit(req, network_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])

    try:
        net.name = req.POST.get('name')
        net.image_url = signer.unsign(req.POST.get('image-url')) if req.POST.get('image-url') else None
        net.save()
    except Exception as e:
        # TODO: maybe handle this better?
        pass

    return redirect('network_dashboard', network_id=net.id)
예제 #39
0
def network_deactivate(req, network_id):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            owner=req.user)

    if req.POST.get('confirm') != 'doit':
        return redirect('dashboard')

    net.deactivated = True
    net.save()

    return redirect('dashboard')
예제 #40
0
def network_add_show(req, network_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])
    slug = req.POST.get('slug')
    try:
        pod = Podcast.objects.get(slug=slug)
    except Podcast.DoesNotExist:
        return redirect(reverse('network_dashboard', network_id=net.id) + '?error=aslg#shows,add-show')
    else:
        if pod.owner != req.user:
            return redirect(reverse('network_dashboard', network_id=net.id) + '?error=nown#shows,add-show')
        pod.networks.add(net)
        pod.save()
    return redirect('network_dashboard', network_id=net.id)
예제 #41
0
파일: views.py 프로젝트: vctrshn/pinecast
def sitemap(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)

    output = '''<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    '''

    pages = pod.podcastepisode_set.all().count()
    for i in range(pages):
        output += '''
        <url>
            <loc>{url}</loc>
            <changefreq>weekly</changefreq>
        </url>
        '''.format(
            url='%s?page=%d' %
            (_subdomain_reverse('site_home', podcast_slug=pod.slug), i + 1))

    output += '''
    <url><loc>{url}</loc></url>
    '''.format(url=_subdomain_reverse('site_blog', podcast_slug=pod.slug))

    for episode in pod.podcastepisode_set.all():
        output += '''
        <url><loc>{url}</loc></url>
        '''.format(url=_subdomain_reverse(
            'site_episode', podcast_slug=pod.slug, episode_id=str(episode.id)))

    for post in site.siteblogpost_set.all():
        output += '''
        <url><loc>{url}</loc></url>
        '''.format(url=_subdomain_reverse(
            'site_post', podcast_slug=pod.slug, post_slug=post.slug))

    output += '</urlset>'

    return HttpResponse(output, content_type='application/xml')
예제 #42
0
def podcast_episode(req, podcast_slug, episode_id):
    pod = get_podcast(req, podcast_slug)
    ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod)

    total_listens = analytics_query.total_listens(pod, episode=ep)

    data = {
        'error': 'error' in req.GET,
        'podcast': pod,
        'episode': ep,
        'analytics': {'total_listens': total_listens},
        'feedback': Feedback.objects.filter(podcast=pod, episode=ep).order_by('-created'),
    }
    return _pmrender(req, 'dashboard/episode/page_episode.html', data)
예제 #43
0
def delete_comment(req, podcast_slug, comment_id):
    pod = get_podcast(req, podcast_slug)
    comment = get_object_or_404(Feedback, podcast=pod, id=comment_id)

    ep = comment.episode
    comment.delete()
    if ep:
        return redirect(
            reverse('podcast_episode', podcast_slug=podcast_slug, episode_id=str(ep.id)) + '#tab-feedback'
        )
    else:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#tab-feedback'
        )
예제 #44
0
파일: views.py 프로젝트: Pinecast/pinecast
def delete_comment(req, podcast_slug, comment_id):
    pod = get_podcast(req, podcast_slug)
    comment = get_object_or_404(Feedback, podcast=pod, id=comment_id)

    ep = comment.episode
    comment.delete()
    if ep:
        return redirect(
            reverse('podcast_episode', podcast_slug=podcast_slug, episode_id=str(ep.id)) + '#tab-feedback'
        )
    else:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#tab-feedback'
        )
예제 #45
0
파일: views.py 프로젝트: Pinecast/pinecast
def podcast_episode(req, podcast_slug, episode_id):
    pod = get_podcast(req, podcast_slug)
    ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod)

    total_listens = analytics_query.total_listens(pod, episode_id=str(ep.id))

    data = {
        'error': 'error' in req.GET,
        'podcast': pod,
        'episode': ep,
        'analytics': {'total_listens': total_listens},
        'feedback': Feedback.objects.filter(podcast=pod, episode=ep).order_by('-created'),
    }
    return _pmrender(req, 'dashboard/episode/page_episode.html', data)
예제 #46
0
파일: views.py 프로젝트: Pinecast/pinecast
def sitemap(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    site = get_object_or_404(models.Site, podcast=pod)

    output = '''<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    '''

    pages = pod.podcastepisode_set.all().count()
    for i in range(pages):
        output += '''
        <url>
            <loc>{url}</loc>
            <changefreq>weekly</changefreq>
        </url>
        '''.format(url='%s?page=%d' % (
            _subdomain_reverse('site_home', podcast_slug=pod.slug),
            i + 1))

    output += '''
    <url><loc>{url}</loc></url>
    '''.format(url=_subdomain_reverse('site_blog', podcast_slug=pod.slug))

    for episode in pod.podcastepisode_set.all():
        output += '''
        <url><loc>{url}</loc></url>
        '''.format(url=_subdomain_reverse('site_episode', podcast_slug=pod.slug, episode_id=str(episode.id)))

    for post in site.siteblogpost_set.all():
        output += '''
        <url><loc>{url}</loc></url>
        '''.format(url=_subdomain_reverse('site_post', podcast_slug=pod.slug, post_slug=post.slug))


    output += '</urlset>'

    return HttpResponse(output, content_type='application/xml')
예제 #47
0
def network_remove_member(req, network_id, member_id):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            members__in=[req.user])
    user = get_object_or_404(User, id=member_id)

    if not net.members.filter(username=user.username).count():
        raise Http404()

    # We don't need to confirm if the user is the owner.
    if net.owner == user:
        return redirect('network_dashboard', network_id=net.id)

    pods = Podcast.objects.filter(owner=user, networks__in=[net])

    for pod in pods:
        pod.networks.remove(net)
        pod.save()
    net.members.remove(user)
    net.save()

    return redirect(
        reverse('network_dashboard', network_id=net.id) + '#members')
예제 #48
0
def network_edit(req, network_id):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            members__in=[req.user])

    try:
        net.name = req.POST.get('name')
        net.image_url = signer.unsign(
            req.POST.get('image-url')) if req.POST.get('image-url') else None
        net.save()
    except Exception as e:
        # TODO: maybe handle this better?
        pass

    return redirect('network_dashboard', network_id=net.id)
예제 #49
0
def import_result(req):
    p = get_object_or_404(AssetImportRequest,
                          access_token=req.POST.get('token'),
                          id=req.POST.get('id'))

    if req.POST.get('failed'):
        p.failure_message = req.POST.get('error')
        p.save()
        return {'success': True}

    try:
        p.resolve(req.POST.get('url'))
    except Exception as e:
        return HttpResponseBadRequest(str(e))

    return {'success': True}
예제 #50
0
파일: views.py 프로젝트: Pinecast/pinecast
def network_listen_history(req):
    net = get_object_or_404(Network, id=req.GET.get("network_id"), members__in=[req.user])

    pods = net.podcast_set.all()

    f = (
        Format(req, "listen")
        .select(episode_f="count")
        .last_thirty()
        .interval()
        .group("podcast")
        .where(podcast=[str(p.id) for p in pods])
    )

    return f.format_intervals(
        labels_map={str(p.id): p.name for p in pods}, extra_data={str(p.id): {"slug": p.slug} for p in pods}
    )
예제 #51
0
def _get_podcast(req, **kwargs):
    podcast = get_object_or_404(Podcast, **kwargs)
    us = UserSettings.get_from_user(podcast.owner)
    if not minimum(us.plan, FEATURE_MIN_NOTIFICATIONS):
        raise HttpResponseForbidden()

    if req.user.is_staff:
        return podcast

    if req.user == podcast.owner:
        return podcast

    pods = Network.objects.filter(deactivated=False, members__in=[req.user], podcast__in=[podcast])
    if not pods.count():
        raise Http404()

    return podcast
예제 #52
0
def import_result(req):
    p = get_object_or_404(AssetImportRequest,
                          access_token=req.POST.get('token'),
                          id=req.POST.get('id'))

    if req.POST.get('failed'):
        p.failure_message = req.POST.get('error')
        p.failed = True
        p.save()
        return {'success': True}

    try:
        p.resolve(req.POST.get('url'))
    except Exception as e:
        return HttpResponseBadRequest(str(e))

    return {'success': True}
예제 #53
0
def edit_page(req, podcast_slug, page_slug):
    site = get_site(req, podcast_slug)
    page = get_object_or_404(SitePage, site=site, slug=page_slug)

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/pages/page_edit.html', {
            'site': site,
            'page': page
        })
    try:
        page.title = req.POST.get('title')
        page.body = SitePage.get_body_from_req(req, page.page_type)
        page.save()
    except Exception as e:
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/pages/page_edit.html', data)
    else:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#site')
예제 #54
0
def confirm_sub(req, podcast_slug):
    if not validate_confirmation(req):
        return _pmrender(req, 'payments/tip_jar/bad_link.html', ctx)

    pod = get_object_or_404(Podcast, slug=podcast_slug)

    try:
        amount = int(req.GET.get('amount'))
    except ValueError:
        return HttpResponse(status=400)
    email = req.GET.get('email')
    token = req.GET.get('token')

    try:
        result = _finish_sub(req, pod, amount, email, token)
        if result:
            return redirect('tip_jar_subs')
    except Exception:
        return HttpResponse(status=400)
예제 #55
0
def confirm_sub(req, podcast_slug):
    if not validate_confirmation(req):
        return _pmrender(req, 'payments/tip_jar/bad_link.html', ctx)

    pod = get_object_or_404(Podcast, slug=podcast_slug)

    try:
        amount = int(req.GET.get('amount'))
    except ValueError:
        return HttpResponse(status=400)
    email = req.GET.get('email')
    token = req.GET.get('token')

    try:
        result = _finish_sub(req, pod, amount, email, token)
        if result:
            return redirect('tip_jar_subs')
    except Exception:
        return HttpResponse(status=400)
예제 #56
0
def edit_blog_post(req, podcast_slug, post_slug):
    site = get_site(req, podcast_slug)
    post = get_object_or_404(SiteBlogPost, site=site, slug=post_slug)

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/blog/page_edit.html', {'site': site, 'post': post})
    try:
        naive_publish = datetime.datetime.strptime(req.POST.get('publish'), '%Y-%m-%dT%H:%M') # 2015-07-09T12:00
        adjusted_publish = naive_publish - UserSettings.get_from_user(req.user).get_tz_delta()
        post.title = req.POST.get('title')
        post.slug = req.POST.get('slug')
        post.body = req.POST.get('body')
        post.publish = adjusted_publish
        post.disable_comments = req.POST.get('disable_comments') == 'true'
        post.save()
    except Exception as e:
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/blog/page_edit.html', data)
    else:
        return redirect('site_manage_blog', podcast_slug=podcast_slug)
예제 #57
0
파일: views.py 프로젝트: Pinecast/pinecast
def get_episodes(req):
    pod_slug = req.GET.get('podcast')
    network = req.GET.get('network_id')
    start_date = req.GET.get('start_date')

    if not pod_slug and not network:
        return []

    pods = set()
    if pod_slug:
        pods.add(get_podcast(req, pod_slug))

    if network:
        net = get_object_or_404(Network, id=network, members__in=[req.user])
        pods = pods | set(net.podcast_set.all())

    if not pods:
        return []

    query = PodcastEpisode.objects.filter(
        podcast__in=list(pods),
        publish__lt=datetime.datetime.now(),
        awaiting_import=False
    )
    if start_date:
        try:
            parsed_date = datetime.datetime.strptime(start_date, '%Y-%m-%dT%H:%M:%S')
        except ValueError:
            raise Http404()
        query = query.filter(publish__gte=parsed_date)

    uset = UserSettings.get_from_user(req.user)
    tz_delta = uset.get_tz_delta()
    return [
        {'id': ep.id,
         'title': ep.title,
         'podcastSlug': ep.podcast.slug,
         'publish': (ep.publish + tz_delta).strftime('%Y-%m-%dT%H:%M:%S')} for
        ep in
        sorted(query, key=lambda x: x.publish)
    ]
예제 #58
0
파일: views.py 프로젝트: Pinecast/pinecast
def edit_podcast_episode(req, podcast_slug, episode_id):
    pod = get_podcast(req, podcast_slug)
    ep = get_object_or_404(PodcastEpisode, id=episode_id, podcast=pod)

    try:
        publish_parsed = datetime.datetime.strptime(req.POST.get('publish').split('.')[0], ISO_FORMAT)

        ep.title = req.POST.get('title')
        ep.subtitle = req.POST.get('subtitle')
        ep.publish = publish_parsed
        ep.description = req.POST.get('description')
        ep.duration = int(req.POST.get('duration-hours')) * 3600 + int(req.POST.get('duration-minutes')) * 60 + int(req.POST.get('duration-seconds'))

        ep.audio_url = signer.unsign(req.POST.get('audio-url'))
        ep.audio_size = int(req.POST.get('audio-url-size'))
        ep.audio_type = req.POST.get('audio-url-type')

        image_url = req.POST.get('image-url')
        if image_url:
            ep.image_url = signer.unsign(req.POST.get('image-url'))
        else:
            ep.image_url = pod.cover_image

        ep.copyright = req.POST.get('copyright')
        ep.license = req.POST.get('license')

        ep.explicit_override = req.POST.get('explicit_override')

        ep.set_flair(req.POST, no_save=True)
        ep.save()

        ep.delete_feedback_prompt()
        if req.POST.get('feedback_prompt'):
            prompt = EpisodeFeedbackPrompt(episode=ep, prompt=req.POST.get('feedback_prompt'))
            prompt.save()

    except Exception as e:
        return redirect(reverse('podcast_episode', podcast_slug=pod.slug, episode_id=str(ep.id)) + '?error=true#edit')
    return redirect('podcast_episode', podcast_slug=pod.slug, episode_id=str(ep.id))