Ejemplo n.º 1
0
def class_2(request):
    # print "class_2 ......"
    try:
        current_page = request.GET.get('p')
        user_name = request.session.get('user_name')
        # rec_db = MongoOperator('localhost', 27017, 'AgriRecSys', 'news')
        # db_ans = rec_db.find({"class_name": "病虫害"})
        db_ans = page.objects.filter(class_name='水果病虫害防治')
        data = {}
        ans_list = []
        count = 0
        for i, news in enumerate(db_ans, 0):
            content = str(news.content['content0'])
            ans_list.append({
                "news": news,
                "news_id": news.id,
                'content': content

                # "href": "#href_id%d" % (i),
                # "content_id": "href_id%d" % (i),

                # "click_id": "ajax_id_%d" % (i),
                # "ajax_id": "#ajax_id_%d" % (i),
            })
            count += 1
        page_obj = Pagination(count, current_page)
        data_list = ans_list[page_obj.start():page_obj.end()]
        data["user_name"] = user_name
    except:
        return index(request)
    return render(request,
                  ROOT_URL + "/recommend_templates/templates/class_2.html", {
                      'data': data_list,
                      'page_obj': page_obj
                  })
Ejemplo n.º 2
0
def test(request):
    print("class_1 ......")
    try:
        current_page = request.GET.get('p')
        user_name = request.session.get('user_name')
        rec_db = MongoOperator('localhost', 27017, 'AgriRecSys', 'news')
        db_ans = rec_db.find({"class_name": "病虫害"})
        data = {}
        ans_list = []
        count = 0
        for i, news in enumerate(list(db_ans), 0):
            ans_list.append({
                "news": news,
                "news_id": str(news["_id"]),

                #"href": "#href_id%d" % (i),
                #"content_id": "href_id%d" % (i),

                #"click_id": "ajax_id_%d" % (i),
                #"ajax_id": "#ajax_id_%d" % (i),
            })
            count += 1
        page_obj = Pagination(count, current_page)
        data_list = ans_list[page_obj.start():page_obj.end()]
        data["user_name"] = user_name
    except:
        return index(request)
    return render(request,
                  ROOT_URL + "/recommend_templates/templates/test.html", {
                      'data': data_list,
                      'page_obj': page_obj
                  })