Beispiel #1
0
def post(post_id, _request=request):

    # TODO: make this crap reusable
    response = requests.get('http://localhost:5000/api/post/{}'.format(post_id))

    if response.status_code == 404:
        return base.page_not_found()

    elif response.status_code != 200:
        return response.content

    import json
    pst = json.loads(response.content.decode('utf-8'))
    return render_template('post.html', **{'post': pst})
Beispiel #2
0
def post(slug, _request=request):

    try:
        pst = Post.objects(slug=slug)[0]
    except IndexError:
        return base.page_not_found()

    related_tag = random.choice(pst.tags)
    related_posts = Post.objects(tags=related_tag, id__ne=pst.id)[0:6]
    related_posts = related_posts if len(related_posts) >= 3 else []
    title = '{} - Last Minute Gifts'.format(pst.title.capitalize())
    meta_description = '{}, and hundreds more gifts from our hand-picked list on LastMinGift.com. ' \
                       'Fast shipping available for last-minute gifts.'.format(pst.title)

    return render_template('post.html',
                           post=pst,
                           title=title,
                           related_tag=related_tag,
                           related_posts=related_posts,
                           meta_description=meta_description,
                           meta_image=pst.thumbnail_url)