1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-09 14:28:03 +00:00
py-i2phosts/pyi2phosts/latest/views.py

31 lines
1009 B
Python
Raw Normal View History

import datetime
from django.conf import settings
from pyi2phosts.postkey.models import i2phost
2015-10-26 18:45:39 +00:00
from pyi2phosts.lib.generic import LocalObjectList
def get_latest():
2015-10-26 18:55:35 +00:00
now_date = datetime.datetime.utcnow()
start_date = now_date - datetime.timedelta(days=settings.LATEST_DAY_COUNT)
qs = i2phost.objects.filter(activated=True,
date_added__range=(start_date, now_date)).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT]
return qs
2015-10-26 18:45:39 +00:00
class LatestHostsListsView(LocalObjectList):
2015-10-26 18:55:35 +00:00
""" Renders list of latest active hosts added """
2015-10-26 18:55:35 +00:00
def get_context_data(self, **kwargs):
context = super(LatestHostsListsView, self).get_context_data(**kwargs)
context.update({
'title': settings.SITE_NAME,
'day_count': settings.LATEST_DAY_COUNT,
'hosts_count': settings.LATEST_HOSTS_COUNT
})
return context
2015-10-26 18:55:35 +00:00
queryset = get_latest()
template_name = 'latest.html'
context_object_name = 'host_list'
paginate_by = 40