Files
@ 2b709f61e022
Branch filter:
Location: website/conservancy/blog/urls.py - annotation
2b709f61e022
2.2 KiB
text/x-python
Make bin/deploy abort if there's an error with `git push`
For example, your push failed because there's upstream changes.
For example, your push failed because there's upstream changes.
8e6ea8ad71bf b7e2ce2a4d44 33833e3a3390 b7e2ce2a4d44 b7e2ce2a4d44 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 47a30a750ad1 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf b2a006f49ce1 33833e3a3390 33833e3a3390 33833e3a3390 33833e3a3390 33833e3a3390 33833e3a3390 b2a006f49ce1 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 datetime import datetime
from django.urls import path
from ..staff.models import Person
from .models import Entry, EntryTag
from .views import (
BlogDateDetailView,
BlogDayArchiveView,
BlogMonthArchiveView,
BlogYearArchiveView,
custom_index,
last_name,
query,
)
extra_context = {}
info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
'extra_context': extra_context,
}
urlpatterns = [
path('<int:year>/<month>/<int:day>/<slug:slug>/', BlogDateDetailView.as_view(**info_dict)),
path('<int:year>/<month>/<int:day>/', BlogDayArchiveView.as_view(**info_dict)),
path('<int:year>/<month>/', BlogMonthArchiveView.as_view(**info_dict)),
path('<int:year>/', BlogYearArchiveView.as_view(**info_dict)),
path('', custom_index, dict(info_dict, paginate_by=4)),
path('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
|