Example #1
0
def gifts(tag, _request=request):

    # Check if there is a category for this; if not, use tags
    tags = [tag]
    category = None
    try:
        category = Category.objects.get(slug=tag)
        tags = category.tags
    except DoesNotExist:
        pass

    category_name = tag.title()

    posts = Post.objects(tags__in=tags)
    featured_posts = Post.objects(tags__in=['featured'])
    if category:
        title = '{} for {}'.format(category.title, date.today().year)
    else:
        title = 'Last Minute {} Gifts for {}'.format(category_name, date.today().year)
    h1 = category.title if category else '{} Gift Guide'.format(category_name)
    meta_description = 'Find perfect {} gifts and hundreds more from our hand-picked list on LastMinGift.com. ' \
                       'Fast shipping available for last-minute gifts.'.format(category_name)
    return render_template('gallery.html',
                           posts=list(posts),
                           featured_posts=list(featured_posts),
                           category=category,
                           tag=category_name,
                           title=title,
                           h1=h1,
                           meta_description=meta_description,
                           meta_image=posts[0].thumbnail_url if posts else '')
Example #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)