Files
@ f6bbcc7ee328
Branch filter:
Location: website/www/conservancy/apps/blog/urls.py - annotation
f6bbcc7ee328
2.9 KiB
text/x-python
Just quit it with this relative import stuff.
While I think these relative imports seem to be valid for the running
application, I am having trouble with the django-admin applications
regarding them. I don't see this syntactic sugar as absolutely
essential, so I'm just going to change it now.
While I think these relative imports seem to be valid for the running
application, I am having trouble with the django-admin applications
regarding them. I don't see this syntactic sugar as absolutely
essential, so I'm just going to change it now.
2bf594b86cb1 f6bbcc7ee328 f7e45da6ddc8 8e6ea8ad71bf f6bbcc7ee328 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 8e6ea8ad71bf 8e6ea8ad71bf f7e45da6ddc8 0b530f1139c6 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf c7d4309149a8 fb16e1127dd4 c7d4309149a8 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf c7d4309149a8 | from django.conf.urls import patterns, url, include
from conservancy.apps.blog.models import Entry, EntryTag # relative import
from conservancy.apps.staff.models import Person
from datetime import datetime
from conservancy.apps.blog.views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView
extra_context = {}
info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
'extra_context': extra_context,
}
# urlpatterns = patterns('django.views.generic.date_based',
urlpatterns = patterns('',
# (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')),
# (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', 'archive_day', info_dict),
# (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict),
# (r'^(?P<year>\d{4})/$', 'archive_year', dict(info_dict,
# make_object_list=True)),
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', BlogDateDetailView.as_view(**info_dict)),
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', BlogDayArchiveView.as_view(**info_dict)),
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', BlogMonthArchiveView.as_view(**info_dict)),
(r'^(?P<year>\d{4})/$', BlogYearArchiveView.as_view(**info_dict)),
)
urlpatterns += patterns('conservancy.apps.blog.views',
(r'^/?$', 'custom_index', dict(info_dict, paginate_by=4)),
(r'^query/$', 'query'),
)
# Code to display authors and tags on each blog page
def all_tags_by_use_amount():
"""Returns all tags with an added 'cnt' attribute (how many times used)
Also sorts the tags so most-used tags appear first.
"""
# tally use amount
retval = []
current = None
for obj in EntryTag.objects.filter(entry__pub_date__lte=datetime.now(),
entry__isnull=False).order_by('label'):
if current is not None and obj.id == current.id:
current.cnt += 1
else:
if current is not None:
retval.append(current)
current = obj
current.cnt = 1
if current is not None:
retval.append(current)
# sort and return
retval.sort(key=lambda x: -x.cnt)
return retval
def all_authors():
return sorted(Person.objects.filter(entry__isnull=False).distinct(),
key=last_name)
def all_year_list():
return Entry.objects.dates('pub_date', 'year')
# The functions are passed to the context uncalled so they will be
# called for each web request. If we want to only make these database
# queries a single time when a web server process begins, call both
# functions below (i.e. make both lines below end in '()')
extra_context['all_authors'] = all_authors
extra_context['all_tags'] = all_tags_by_use_amount
extra_context['all_year_list'] = all_year_list
|