mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-02 01:44:40 +00:00
pyi2phosts/urls.py: use separate functions to get dates
We need to get current date and start date every time when /latest/ requested. Before this dates were evaluated only at webserver startup so newly added and activated hosts weren't can be appeared in /latest/.
This commit is contained in:
parent
48ce4ba473
commit
3c193bcdc3
@ -12,6 +12,12 @@ from pyi2phosts.extsources.models import ExternalSource
|
|||||||
from pyi2phosts.postkey.models import i2phost
|
from pyi2phosts.postkey.models import i2phost
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
|
def now_date():
|
||||||
|
return datetime.datetime.utcnow()
|
||||||
|
|
||||||
|
def start_date():
|
||||||
|
return now_date() - datetime.timedelta(days=settings.LATEST_DAY_COUNT)
|
||||||
|
|
||||||
extsources = {
|
extsources = {
|
||||||
'queryset': ExternalSource.objects.filter(active=True),
|
'queryset': ExternalSource.objects.filter(active=True),
|
||||||
'template_name': 'faq.html',
|
'template_name': 'faq.html',
|
||||||
@ -31,11 +37,9 @@ browse_hosts = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
now_date = datetime.datetime.utcnow()
|
|
||||||
start_date = now_date - datetime.timedelta(days=settings.LATEST_DAY_COUNT)
|
|
||||||
latest_hosts = {
|
latest_hosts = {
|
||||||
'queryset': i2phost.objects.filter(activated=True,
|
'queryset': i2phost.objects.filter(activated=True,
|
||||||
date_added__range=(start_date, now_date)).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT],
|
date_added__range=(start_date(), now_date())).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT],
|
||||||
'template_name': 'latest.html',
|
'template_name': 'latest.html',
|
||||||
'template_object_name': 'host',
|
'template_object_name': 'host',
|
||||||
'paginate_by': 40,
|
'paginate_by': 40,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user