def add_blog_post(req, podcast_slug): site = get_site(req, podcast_slug) if not payment_plans.minimum( UserSettings.get_from_user(site.podcast.owner).plan, payment_plans.FEATURE_MIN_BLOG): raise Http404() data = {'site': site} if not req.POST: return _pmrender(req, 'dashboard/sites/blog/page_new.html', data) 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 = SiteBlogPost( site=site, title=req.POST.get('title'), slug=req.POST.get('slug'), body=req.POST.get('body'), publish=adjusted_publish ) post.save() except Exception as e: print e data.update(error=True, default=req.POST) return _pmrender(req, 'dashboard/sites/blog/page_new.html', data) else: return redirect('site_manage_blog', podcast_slug=podcast_slug)
def edit_site(req, podcast_slug): site = get_site(req, podcast_slug) data = { 'site': site, 'themes': Site.SITE_THEMES, } if not req.POST: return _pmrender(req, 'dashboard/sites/page_edit.html', data) try: site.theme = req.POST.get('theme') site.cover_image_url = signer.unsign(req.POST.get('cover-url')) if req.POST.get('cover-url') else None site.logo_url = signer.unsign(req.POST.get('logo-url')) if req.POST.get('logo-url') else None site.analytics_id = req.POST.get('analytics_id') site.itunes_url = req.POST.get('itunes_url') site.stitcher_url = req.POST.get('stitcher_url') site.save() except Exception as e: print e data.update(error=True, default=req.POST) return _pmrender(req, 'dashboard/sites/page_edit.html', data) else: return redirect('site_options', podcast_slug=podcast_slug)
def new_site(req, podcast_slug): pod = get_podcast(req, podcast_slug) if not payment_plans.minimum( UserSettings.get_from_user(pod.owner).plan, payment_plans.FEATURE_MIN_SITES): raise Http404() data = { 'podcast': pod, 'themes': Site.SITE_THEMES, } if not req.POST: return _pmrender(req, 'dashboard/sites/page_new.html', data) try: site = Site( podcast=pod, theme=req.POST.get('theme'), cover_image_url=signer.unsign(req.POST.get('cover-url')) if req.POST.get('cover-url') else None, logo_url=signer.unsign(req.POST.get('logo-url')) if req.POST.get('logo-url') else None, analytics_id=req.POST.get('analytics_id'), itunes_url=req.POST.get('itunes_url'), stitcher_url=req.POST.get('stitcher_url') ) site.save() except Exception as e: print e data.update(error=True, default=req.POST) return _pmrender(req, 'dashboard/sites/page_new.html', data) else: return redirect('site_options', podcast_slug=podcast_slug)
def new_network(req): uset = UserSettings.get_from_user(req.user) if not plans.minimum(uset.plan, plans.FEATURE_MIN_NETWORK): return _pmrender(req, 'dashboard/network/page_new_upgrade.html') if not req.POST: return _pmrender(req, 'dashboard/network/page_new.html') try: net = Network( name=req.POST.get('name'), owner=req.user, image_url=signer.unsign(req.POST.get('image-url')) if req.POST.get('image-url') else None ) net.save() net.members.add(req.user) net.save() except Exception as e: print e return _pmrender(req, 'dashboard/network/page_new.html', {'error': ugettext('Error while saving network details'), 'default': req.POST}) return redirect('network_dashboard', network_id=net.id)
def network_add_show(req, network_id): net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user]) if req.POST: slug = req.POST.get('slug') try: pod = Podcast.objects.get(slug=slug) except Podcast.DoesNotExist: return _pmrender(req, 'dashboard/network/page_add_show.html', {'network': net, 'error': ugettext('No podcast with the slug "%s" was found') % slug}) else: if pod.owner != req.user: return _pmrender(req, 'dashboard/network/page_add_show.html', {'network': net, 'error': ugettext('You must be the owner of a podcast to add it to a network')}) pod.networks.add(net) pod.save() return redirect('network_dashboard', network_id=net.id) return _pmrender(req, 'dashboard/network/page_add_show.html', {'network': net})
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]) if not req.POST: return _pmrender(req, 'dashboard/network/page_remove_member.html', {'network': net, 'member': user, 'pods': pods}) if req.POST.get('confirm') != 'doit': return redirect('network_dashboard', network_id=net.id) for pod in pods: pod.networks.remove(net) pod.save() net.members.remove(user) net.save() return redirect('network_dashboard', network_id=net.id)
def network_edit(req, network_id): net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user]) if not req.POST: return _pmrender(req, 'dashboard/network/page_edit.html', {'network': net}) 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: print e return _pmrender(req, 'dashboard/network/page_edit.html', {'network': net, 'error': ugettext('Error while saving network details'), 'default': req.POST}) return redirect('network_dashboard', network_id=net.id)
def manage_blog(req, podcast_slug): site = get_site(req, podcast_slug) if not payment_plans.minimum( UserSettings.get_from_user(site.podcast.owner).plan, payment_plans.FEATURE_MIN_BLOG): raise Http404() return _pmrender(req, 'dashboard/sites/blog/page_manage.html', {'site': site, 'posts': site.siteblogpost_set.all().order_by('-publish')})
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.save() except Exception as e: print 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)
def network_dashboard(req, network_id): net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user]) ame = ugettext('No user with that email address was found') if req.GET.get('add_member_error') == 'dne' else None added_member = req.GET.get('added_member', 'false') == 'true' podcasts = net.podcast_set.all() return _pmrender(req, 'dashboard/network/page_dash.html', {'network': net, 'net_podcasts': podcasts, 'add_member_error': ame, 'add_member_success': added_member})
def network_deactivate(req, network_id): net = get_object_or_404(Network, deactivated=False, id=network_id, owner=req.user) if not req.POST: return _pmrender(req, 'dashboard/network/page_deactivate.html', {'network': net}) if req.POST.get('confirm') != 'doit': return redirect('dashboard') net.deactivated = True net.save() return redirect('dashboard')
def delete_site(req, podcast_slug): site = get_site(req, podcast_slug) data = {'site': site} if not req.POST: return _pmrender(req, 'dashboard/sites/page_delete.html', data) elif req.POST.get('slug') != podcast_slug: return redirect('site_options', podcast_slug=podcast_slug) site.delete() return redirect( reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#tab-site' )
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() if not req.POST: return _pmrender(req, 'dashboard/network/page_remove_podcast.html', {'network': net, 'podcast': pod}) if req.POST.get('confirm') != 'doit': return redirect('network_dashboard', network_id=net.id) pod.networks.remove(net) pod.save() return redirect('network_dashboard', network_id=net.id)
def site_options(req, podcast_slug): site = get_site(req, podcast_slug) return _pmrender(req, 'dashboard/sites/page_site.html', {'site': site, 'error': req.GET.get('error')})