Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from toirl/feature/issue2
Browse files Browse the repository at this point in the history
Sort news items in descending order based on its date and id.
  • Loading branch information
toirl committed Jan 5, 2016
2 parents b7e0f40 + b1318a2 commit 204ded8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ringo_news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@

def get_news(request):
"""Returns a list of News items which are attached to the current
user of the request. If the user marks the news as read, the news
willl get detached form the user and is not listed anymore."""
user of the request. The news are sorted by the date of the news.
Recent news comes before older news. News with the same date are
ordered by their internal id in descendig order. If the user marks
the news as read, the news willl get detached form the user and is
not listed anymore."""

# Custom sort function with will sort the new based on their date
# and id.
def compare(b, a):
return cmp(a.date, b.date) or cmp(a.id, b.id)

if not request.user:
return []
else:
request.user.news.sort(compare)
return request.user.news


Expand Down

0 comments on commit 204ded8

Please sign in to comment.