Esempio n. 1
0
def new_cards(request):
    # serves the What's New page - this function returns the first page of results for all sources for
    # cards uploaded in the last two weeks

    # initialise results dict, 2 weeks time delta, and the dsl search
    results = {}
    days = 14
    s = Card.objects.filter(
        date__range=[timezone.now() - timedelta(
            days=days), timezone.now()]).order_by("-date", )

    # for each source, query elasticsearch for the requested cards, and attach it to the results dict if we have any hits
    for source in Source.objects.all():
        result = search_new(s, source.id)
        if result["qty"] > 0:
            results[source.id] = result

    return render(request, "cardpicker/new.html", {"sources": results})
Esempio n. 2
0
def new_cards(request):
    # serves the What's New page - this function returns the first page of results for all sources for 
    # cards uploaded in the last two weeks

    # initialise results dict, 2 weeks time delta, and the dsl search
    results = {}
    days = 14
    s = CardSearch \
        .search() \
        .filter('range', date={'from': datetime.now() - timedelta(days=days), 'to': datetime.now()}) \
        .sort({'date': {'order': 'desc'}})

    # for each source, query elasticsearch for the requested cards, and attach it to the results dict if we have any hits
    for source in Source.objects.all():
        result = search_new(s, source.id)
        if result['qty'] > 0:
            results[source.id] = result
    
    return render(request, 'cardpicker/new.html', {"sources": results})
Esempio n. 3
0
def search_new_page(request):
    # triggers when the user clicks 'load more' on the What's New page
    # this function takes the current page number and source from the frontend and returns the next page
    # extract specified source and page from post request
    source = request.POST.get("source")
    page = int(request.POST.get("page"))

    # initialise results dict, 2 weeks time delta, and the dsl search
    results = {}
    days = 14
    s = Card.objects.filter(
        date__range=[timezone.now() - timedelta(
            days=days), timezone.now()]).order_by("-date", )

    # query elasticsearch for the requested cards and attach it to the results dict if we have any hits
    result = search_new(s, source, page)
    if result["qty"] > 0:
        results[source] = result

    return JsonResponse({"sources": results}, safe=False)
Esempio n. 4
0
def search_new_page(request):
    # triggers when the user clicks 'load more' on the What's New page
    # this function takes the current page number and source from the frontend and returns the next page
    # extract specified source and page from post request
    source = request.POST.get('source')
    page = int(request.POST.get('page'))

    # initialise results dict, 2 weeks time delta, and the dsl search
    results = {}
    days = 14
    s = CardSearch \
        .search() \
        .filter('range', date={'from': datetime.now() - timedelta(days=days), 'to': datetime.now()}) \
        .sort({'date': {'order': 'desc'}})

    # query elasticsearch for the requested cards and attach it to the results dict if we have any hits
    result = search_new(s, source, page)
    if result['qty'] > 0:
        results[source] = result

    return JsonResponse({"sources": results}, safe=False)