Changeset - 0160f03c25ee
[Not reviewed]
0 1 0
Brett Smith (brett) - 7 years ago 2017-02-03 16:02:33
brett@sfconservancy.org
blog: Remove unnecessary kwargs manipulation from custom_index.

I don't know if this code is left over from previous versions or what, but
it's not doing anything now. custom_index doesn't pass kwargs to anything
else, so there's no need to fiddle with the dict so much.
1 file changed with 1 insertions and 10 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/blog/views.py
Show inline comments
...
 
@@ -12,30 +12,26 @@ def OR_filter(field_name, objs):
 
    from django.db.models import Q
 
    return reduce(lambda x, y: x | y,
 
                  [Q(**{field_name: x.id}) for x in objs])
 

	
 
def last_name(person):
 
    return person.formal_name.rpartition(' ')[2]
 

	
 
def custom_index(request, queryset, *args, **kwargs):
 
    """Blog list view that allows scrolling and also shows an index by
 
    year.
 
    """
 

	
 
    kwargs = kwargs.copy()
 
    kwargs['extra_context'] = kwargs.get('extra_context', {}).copy()
 
    extra_context = kwargs['extra_context']
 

	
 
    extra_context = kwargs.get('extra_context', {}).copy()
 
    date_field = kwargs['date_field']
 
    del kwargs['date_field']
 

	
 
    if not kwargs.get('allow_future', False):
 
        queryset = queryset.filter(**{'%s__lte' % date_field: datetime.now()})
 

	
 
    authors = []
 
    if 'author' in request.GET:
 
        authors = [get_object_or_404(Person, username=author)
 
                   for author in request.GET.getlist('author')]
 
        extra_context['authors'] = authors
 
        queryset = queryset.filter(OR_filter('author', authors))
 

	
 
    tags = []
...
 
@@ -45,31 +41,26 @@ def custom_index(request, queryset, *args, **kwargs):
 
        extra_context['tags'] = tags
 
        queryset = queryset.filter(OR_filter('tags', tags))
 

	
 
    if authors or tags:
 
        query_string = '&'.join(['author=%s' % a.username for a in authors]
 
                                + ['tag=%s' % t.slug for t in tags])
 
        extra_context['query_string'] = query_string
 

	
 
    else:
 
        date_list = queryset.dates(date_field, 'year')
 
        extra_context['date_list'] = date_list
 

	
 
    # return object_list(request, queryset, *args, **kwargs)
 
    kwargs['queryset'] = queryset
 
    kwargs['extra_context'] = extra_context
 

	
 
    paginate_by = kwargs.get('paginate_by', 6)  # Show 6 news items per page, by default
 
    paginator = Paginator(queryset, paginate_by)
 

	
 
    page = request.GET.get('page')
 

	
 
    try:
 
        blog_entries = paginator.page(page)
 
    except PageNotAnInteger:
 
        # If page is not an integer, deliver first page.
 
        blog_entries = paginator.page(1)
 
    except EmptyPage:
 
        # If page is out of range (e.g. 9999), deliver last page of results.
 
        blog_entries = paginator.page(paginator.num_pages)
 

	
 
    extra_context['blog_entries'] = blog_entries
0 comments (0 inline, 0 general)