mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-02 01:44:40 +00:00
Move latest
generic view to separate view
This should fix problem with datetime.datetime.utcnow() evaluation caching in queryset.
This commit is contained in:
parent
efa9397a9c
commit
d7d032d940
0
pyi2phosts/latest/__init__.py
Normal file
0
pyi2phosts/latest/__init__.py
Normal file
5
pyi2phosts/latest/urls.py
Normal file
5
pyi2phosts/latest/urls.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('pyi2phosts.latest.views',
|
||||
url(r'^$', 'latest', name='latest'),
|
||||
)
|
24
pyi2phosts/latest/views.py
Normal file
24
pyi2phosts/latest/views.py
Normal file
@ -0,0 +1,24 @@
|
||||
import datetime
|
||||
|
||||
from django.views.generic import list_detail
|
||||
|
||||
import settings
|
||||
from pyi2phosts.postkey.models import i2phost
|
||||
|
||||
def latest(request):
|
||||
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 list_detail.object_list(
|
||||
request = request,
|
||||
queryset = qs,
|
||||
template_name = 'latest.html',
|
||||
template_object_name = 'host',
|
||||
paginate_by = 40,
|
||||
extra_context = {
|
||||
'title': settings.SITE_NAME,
|
||||
'day_count': settings.LATEST_DAY_COUNT,
|
||||
'hosts_count': settings.LATEST_HOSTS_COUNT,
|
||||
}
|
||||
)
|
@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
from django.conf.urls.defaults import *
|
||||
from django.views.generic.simple import direct_to_template
|
||||
from django.views.generic.list_detail import object_list
|
||||
@ -31,21 +30,6 @@ browse_hosts = {
|
||||
}
|
||||
}
|
||||
|
||||
now_date = datetime.datetime.utcnow()
|
||||
start_date = now_date - datetime.timedelta(days=settings.LATEST_DAY_COUNT)
|
||||
latest_hosts = {
|
||||
'queryset': i2phost.objects.filter(activated=True,
|
||||
date_added__range=(start_date, now_date)).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT],
|
||||
'template_name': 'latest.html',
|
||||
'template_object_name': 'host',
|
||||
'paginate_by': 40,
|
||||
'extra_context': {
|
||||
'title': settings.SITE_NAME,
|
||||
'day_count': settings.LATEST_DAY_COUNT,
|
||||
'hosts_count': settings.LATEST_HOSTS_COUNT,
|
||||
}
|
||||
}
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', direct_to_template, {
|
||||
'template': 'index.html',
|
||||
@ -58,8 +42,8 @@ urlpatterns = patterns('',
|
||||
}, name='index'),
|
||||
url(r'^faq/$', object_list, extsources, name='faq'),
|
||||
url(r'^browse/$', object_list, browse_hosts, name='browse'),
|
||||
url(r'^latest/$', object_list, latest_hosts, name='latest'),
|
||||
|
||||
(r'^latest/$', include('pyi2phosts.latest.urls')),
|
||||
(r'^search/$', include('pyi2phosts.search.urls')),
|
||||
(r'^postkey/', include('pyi2phosts.postkey.urls')),
|
||||
(r'^jump/', include('pyi2phosts.jump.urls')),
|
||||
|
Loading…
x
Reference in New Issue
Block a user