Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix top k policy #476

Merged
merged 6 commits into from
Nov 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions apps/core/views/viewsets/article.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time
import datetime

from django.core.paginator import Paginator as DjangoPaginator
from django.db import models
from django.http import Http404
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext
from rest_framework import (
Expand Down Expand Up @@ -479,10 +480,13 @@ def recent(self, request, *args, **kwargs):

@decorators.action(detail=False, methods=["get"])
def top(self, request):
# The most recent article at the top
top_articles = Article.objects.exclude(topped_at__isnull=True).order_by(
"-topped_at", "-pk"
current_date = datetime.datetime.combine(
timezone.now().date(), datetime.time.min, datetime.timezone.utc
)
# get the articles that are created_at within a week and order by hit_count
top_articles = Article.objects.filter(
created_at__gte=current_date - datetime.timedelta(days=7)
).order_by("-hit_count", "-pk")

search_keyword = request.query_params.get("main_search__contains")
if search_keyword:
Expand Down
Loading