Ejemplo n.º 1
0
def get_mind_graph_article_list(request):

    l1_tag = request.GET['label1']
    l2_tag = request.GET['label2']
    l3_tag = request.GET['label3']

    try:
        time = timezone.datetime.strptime(request.GET[time],
                                          "%Y-%m-%d %H:%M:%S")
    except:
        time = timezone.now()

    days_interval = timedelta(days=3)

    articles = Article.objects.filter(article_tags__level1_tag=l1_tag,
                                      article_tags__level2_tag=l2_tag,
                                      article_tags__level3_tag=l3_tag,
                                      publish_time__lt=time,
                                      publish_time__gt=time -
                                      days_interval).order_by('-publish_time')

    json_dict_data = []

    for article in articles:
        json_dict_data.append(get_article_dict(article))

    return JsonResponse(get_json_dict(data={'articles': json_dict_data}))
Ejemplo n.º 2
0
def get_article_list(request):
    """
    {
      'articles': [ARTICLE, ...]
    }
    """

    ONE_PAGE_SIZE = 10

    section = request.GET.get('section', "")
    page = int(request.GET.get('page', 0))

    json_dict = get_json_dict(data={})
    json_dict['data']['articles'] = []

    if section == "":
        articles = Article.objects.all().order_by(
            '-publish_time')[ONE_PAGE_SIZE * page:ONE_PAGE_SIZE * (page + 1)]
    else:
        articles = Article.objects.filter(section__name=section).order_by(
            '-publish_time')[ONE_PAGE_SIZE * page:ONE_PAGE_SIZE * (page + 1)]

    for article in articles:
        json_dict['data']['articles'].append(get_article_dict(article))

    return JsonResponse(json_dict)
Ejemplo n.º 3
0
def search_for_article(request):

    if settings.DEBUG:
        article_ids = [
            51540, 51541, 51542, 51543, 51544, 51545, 51546, 51547, 51548,
            51549, 51550, 51551, 51552, 51553, 51554, 51555, 51556, 51557,
            51558, 51559
        ]
    else:
        keyword = request.GET['keyword']
        try:
            page = int(request.GET['page'])
        except:
            page = 0

        search_engine = SearchEngine("10.144.5.124", "8983")
        article_ids = search_engine.query(keyword, page)

    json_dict = get_json_dict(data={})
    json_dict['data']['articles'] = []

    for article_id in article_ids:
        try:
            article = Article.objects.get(id=article_id)
            json_dict['data']['articles'].append(get_article_dict(article))
        except:
            pass

    return JsonResponse(json_dict)
Ejemplo n.º 4
0
def get_article_content(request):
    article_id = request.GET['id']

    article = Article.objects.get(id=article_id)
    json_dict = get_json_dict(data={})
    json_dict['data']['article'] = get_article_dict(article)

    return JsonResponse(json_dict)
Ejemplo n.º 5
0
def get_similar_articles(request):

    article_id = request.GET["id"]
    search_engine = SearchEngine("10.144.5.124", "8983")
    suggested_article_ids = search_engine.morelikethis(article_id)

    json_dict = get_json_dict(data={'articles': []})

    for suggested_article_id in suggested_article_ids:
        try:
            article = Article.objects.get(id=suggested_article_id)
            json_dict['data']['articles'].append(get_article_dict(article))
        except:
            pass
    return JsonResponse(json_dict)
Ejemplo n.º 6
0
def get_article_content(request):
    article_id = request.GET['id']

    article = Article.objects.get(id=article_id)
    json_dict = get_json_dict(data={})
    json_dict['data']['article'] = get_article_dict(article)

    if request.user.is_authenticated:
        account = request.user.account
        account.score += 1
        account.save()
        action = Action(type="read_article",
                        value="article_id:{0}".format(article_id),
                        account=account)
        action.save()

    return JsonResponse(json_dict)
Ejemplo n.º 7
0
def get_article_list(request):
    """
    {
      'articles': [ARTICLE, ...]
    }
    """

    ONE_PAGE_SIZE = 10

    section = request.GET['section']
    page = int(request.GET.get('page', 0))

    json_dict = get_json_dict(data={})
    json_dict['data']['articles'] = []

    for article in Article.objects.filter(
            section__name=section)[ONE_PAGE_SIZE * page:ONE_PAGE_SIZE *
                                   (page + 1)]:
        json_dict['data']['articles'].append(get_article_dict(article))

    return JsonResponse(json_dict)