示例#1
0
def subscribe(request):
    blog = resolve_address(request)
    if not blog:
        return not_found(request)

    subscribe_message = ""
    if request.method == "POST":
        if request.POST.get("email", "") and not request.POST.get("name", ""):
            email = request.POST.get("email", "")
            subscriber_dupe = Subscriber.objects.filter(blog=blog,
                                                        email_address=email)
            if not subscriber_dupe:
                validate_subscriber_email(email, blog)
                subscribe_message = "You've been subscribed! \ʕ •ᴥ•ʔ/"
            else:
                subscribe_message = "You are already subscribed."

    all_posts = blog.post_set.filter(publish=True).order_by('-published_date')

    return render(
        request, 'subscribe.html', {
            'blog': blog,
            'root': blog.useful_domain(),
            'subscribe_message': subscribe_message
        })
示例#2
0
def feed(request):
    blog = resolve_address(request)

    if not blog:
        raise Http404("Blog does not exist")

    all_posts = blog.post_set.filter(publish=True,
                                     is_page=False).order_by('-published_date')

    fg = FeedGenerator()
    fg.id(blog.useful_domain())
    fg.author({'name': blog.subdomain, 'email': 'hidden'})
    fg.title(blog.title)
    fg.subtitle(blog.meta_description
                or clean_text(unmark(blog.content)[:160]) or blog.title)
    fg.link(href=f"{blog.useful_domain()}/", rel='alternate')

    for post in all_posts:
        fe = fg.add_entry()
        fe.id(f"{blog.useful_domain()}/{post.slug}/")
        fe.title(post.title)
        fe.author({'name': blog.subdomain, 'email': 'hidden'})
        fe.link(href=f"{blog.useful_domain()}/{post.slug}/")
        fe.content(clean_text(mistune.html(post.content)), type="html")
        fe.published(post.published_date)
        fe.updated(post.published_date)

    if request.GET.get('type') == 'rss':
        fg.link(href=f"{blog.useful_domain()}/feed/?type=rss", rel='self')
        rssfeed = fg.rss_str(pretty=True)
        return HttpResponse(rssfeed, content_type='application/rss+xml')
    else:
        fg.link(href=f"{blog.useful_domain()}/feed/", rel='self')
        atomfeed = fg.atom_str(pretty=True)
        return HttpResponse(atomfeed, content_type='application/atom+xml')
示例#3
0
def confirm_subscription(request):
    blog = resolve_address(request)
    if not blog:
        return not_found(request)

    email = request.GET.get("email", "")
    token = hashlib.md5(
        f'{email} {blog.subdomain} {timezone.now().strftime("%B %Y")}'.encode(
        )).hexdigest()
    if token == request.GET.get("token", ""):
        Subscriber.objects.get_or_create(blog=blog, email_address=email)

        return HttpResponse(
            f"<p>You've been subscribed to <a href='{blog.useful_domain()}'>{blog.title}</a>. \ʕ •ᴥ•ʔ/</p>"
        )

    return HttpResponse(
        "Something went wrong. Try subscribing again. ʕノ•ᴥ•ʔノ ︵ ┻━┻")
示例#4
0
def confirm_subscription(request):
    blog = resolve_address(request)
    if not blog:
        return not_found(request)

    email = request.GET.get("email", "")
    token = hashlib.md5(
        f'{email} {blog.subdomain} {timezone.now().strftime("%B %Y")}'.encode(
        )).hexdigest()
    if token == request.GET.get("token", ""):
        Subscriber.objects.get_or_create(blog=blog, email_address=email)

        return HttpResponse(f'''
            <p style='text-align: center; padding-top: 30%'>
                Your subscription to
                <a href="{blog.useful_domain()}">{blog.title}</a>
                has been confirmed. \ʕ •ᴥ•ʔ/
            </p>
            ''')

    return HttpResponse(
        "Something went wrong. Try subscribing again. ʕノ•ᴥ•ʔノ ︵ ┻━┻")
示例#5
0
def feed(request):
    address_info = resolve_address(request)
    if not address_info:
        return redirect('/')

    blog = address_info['blog']
    root = address_info['root']

    all_posts = blog.post_set.filter(publish=True,
                                     is_page=False).order_by('-published_date')

    fg = FeedGenerator()
    fg.id(f'http://{root}/')
    fg.author({'name': blog.subdomain, 'email': 'hidden'})
    fg.title(blog.title)
    if blog.content:
        fg.subtitle(clean_text(unmark(blog.content)[:160]))
    else:
        fg.subtitle(blog.title)
    fg.link(href=f"http://{root}/", rel='alternate')

    for post in all_posts:
        fe = fg.add_entry()
        fe.id(f"http://{root}/{post.slug}/")
        fe.title(post.title)
        fe.author({'name': blog.subdomain, 'email': 'hidden'})
        fe.link(href=f"http://{root}/{post.slug}/")
        fe.content(clean_text(mistune.html(post.content)), type="html")
        fe.published(post.published_date)
        fe.updated(post.published_date)

    if request.GET.get('type') == 'rss':
        fg.link(href=f"http://{root}/feed/?type=rss", rel='self')
        rssfeed = fg.rss_str(pretty=True)
        return HttpResponse(rssfeed, content_type='application/rss+xml')
    else:
        fg.link(href=f"http://{root}/feed/", rel='self')
        atomfeed = fg.atom_str(pretty=True)
        return HttpResponse(atomfeed, content_type='application/atom+xml')