(request, uid)
return ajax_success(html=results, msg="success")
Return a feed populated with posts similar to the one in the request.
Return a feed populated with posts similar to the one in the request.
Return a feed populated with posts similar to the one in the request .
def similar_posts(request, uid):
    """
    Return a feed populated with posts similar to the one in the request.
    """

    post = Post.objects.filter(uid=uid).first()
    if not post:
        ajax_error(msg='Post does not exist.')

    template_name = 'widgets/similar_posts.html'
    cache_key = f"{const.SIMILAR_CACHE_KEY}-{post.uid}"
    results = cache.get(cache_key)

    if results is None:
        logger.debug("Setting similar posts cache.")
        # Do a more like this search on post
        similar = search.more_like_this(uid=post.uid)
        # Render template with posts
        tmpl = loader.get_template(template_name)
        context = dict(results=similar)
        results = tmpl.render(context)

        # Expire in one week if results exists, one hour if not.
        expire = 3600 * 24 * 7 if len(similar) > 1 else 3600
        cache.set(cache_key, results, expire)

    return ajax_success(html=results, msg="success")
def similar_posts ( request , uid ) : post = Post . objects . filter ( uid = uid ) . first ( ) if not post : ajax_error ( msg = 'Post does not exist.' ) template_name = 'widgets/similar_posts.html' cache_key = f"{const.SIMILAR_CACHE_KEY}-{post.uid}" results = cache . get ( cache_key ) if results is None : logger . debug ( "Setting similar posts cache." ) # Do a more like this search on post similar = search . more_like_this ( uid = post . uid ) # Render template with posts tmpl = loader . get_template ( template_name ) context = dict ( results = similar ) results = tmpl . render ( context ) # Expire in one week if results exists, one hour if not. expire = 3600 * 24 * 7 if len ( similar ) > 1 else 3600 cache . set ( cache_key , results , expire ) return ajax_success ( html = results , msg = "success" )