Browse Source

Move `latest` generic view to separate view

This should fix problem with datetime.datetime.utcnow() evaluation
caching in queryset.
pull/1/head
Hidden Z 14 years ago
parent
commit
d7d032d940
  1. 0
      pyi2phosts/latest/__init__.py
  2. 5
      pyi2phosts/latest/urls.py
  3. 24
      pyi2phosts/latest/views.py
  4. 18
      pyi2phosts/urls.py

0
pyi2phosts/latest/__init__.py

5
pyi2phosts/latest/urls.py

@ -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

@ -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,
}
)

18
pyi2phosts/urls.py

@ -1,4 +1,3 @@
import datetime
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template from django.views.generic.simple import direct_to_template
from django.views.generic.list_detail import object_list 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('', urlpatterns = patterns('',
url(r'^$', direct_to_template, { url(r'^$', direct_to_template, {
'template': 'index.html', 'template': 'index.html',
@ -58,8 +42,8 @@ urlpatterns = patterns('',
}, name='index'), }, name='index'),
url(r'^faq/$', object_list, extsources, name='faq'), url(r'^faq/$', object_list, extsources, name='faq'),
url(r'^browse/$', object_list, browse_hosts, name='browse'), 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'^search/$', include('pyi2phosts.search.urls')),
(r'^postkey/', include('pyi2phosts.postkey.urls')), (r'^postkey/', include('pyi2phosts.postkey.urls')),
(r'^jump/', include('pyi2phosts.jump.urls')), (r'^jump/', include('pyi2phosts.jump.urls')),

Loading…
Cancel
Save