def get(self, request, **kwargs): """ request.GET['type']: 0 if additional articles, 1 if related articles """ uuid = request.GET.get('uuid') try: skip, limit = int(request.GET.get('skip', 0)), int(request.GET.get('limit', 3)) articles_type = int(request.GET.get('type', 0)) except ValueError: return HttpResponse(json.dumps({'success': False, 'reason': 'Incorrect skip/limit/type values'}), content_type='application/javascript') if not uuid: raise Http404 if articles_type == 0: # additional articles articles = update_articles_for_template(cluster_articles(uuid)[skip:skip+limit]) else: # related articles articles = update_articles_for_template(similar_articles(uuid, limit=limit, skip=skip)) return HttpResponse(json.dumps({'success': True, 'articles': articles}), content_type='application/javascript')
def get_context_data(self, **kwargs): context = super(ArticleDetailView, self).get_context_data(**kwargs) uuid = kwargs.get('uuid') article = get_single_article(uuid) if not article: raise Http404 additional_articles = update_articles_for_template( cluster_articles(solr_mongo_searcher(), uuid)) related_articles = update_articles_for_template( similar_articles(get_solr(), uuid, limit=10)) context.update({ 'article': article, 'article_json': json.dumps(article), 'additional_articles': additional_articles, 'related_articles': related_articles }) return context
def get(self, request, **kwargs): """ request.GET['type']: 0 if additional articles, 1 if related articles """ uuid = request.GET.get('uuid') try: skip, limit = int(request.GET.get('skip', 0)), int( request.GET.get('limit', 3)) articles_type = int(request.GET.get('type', 0)) except ValueError: return HttpResponse(json.dumps({ 'success': False, 'reason': 'Incorrect skip/limit/type values' }), content_type='application/javascript') if not uuid: raise Http404 if articles_type == 0: # additional articles articles = update_articles_for_template( cluster_articles(uuid)[skip:skip + limit]) else: # related articles articles = update_articles_for_template( similar_articles(uuid, limit=limit, skip=skip)) return HttpResponse(json.dumps({ 'success': True, 'articles': articles }), content_type='application/javascript')