2023-10-05 08:17:55 +00:00
|
|
|
# Copyright (C) 2008 Bradley M. Kuhn <bkuhn@ebb.org>
|
|
|
|
# Copyright (C) 2006, 2007 Software Freedom Law Center, Inc.
|
|
|
|
#
|
|
|
|
# This software's license gives you freedom; you can copy, convey,
|
|
|
|
# propogate, redistribute and/or modify this program under the terms of
|
|
|
|
# the GNU Affero General Public License (AGPL) as published by the Free
|
|
|
|
# Software Foundation (FSF), either version 3 of the License, or (at your
|
|
|
|
# option) any later version of the AGPL published by the FSF.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program in a file in the toplevel directory called
|
|
|
|
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
from datetime import datetime
|
2023-10-05 11:07:34 +00:00
|
|
|
from functools import reduce
|
2024-02-23 04:00:42 +00:00
|
|
|
from operator import or_
|
2023-10-05 08:17:55 +00:00
|
|
|
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
|
2024-04-25 05:32:24 +00:00
|
|
|
from .models import Cast, CastTag, Podcast
|
|
|
|
|
|
|
|
|
|
|
|
def podcasts(request):
|
|
|
|
podcasts = Podcast.objects.all()
|
|
|
|
return render(request, 'podjango/podcasts.html', {'podcasts': podcasts})
|
2023-10-05 08:17:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def OR_filter(field_name, objs):
|
|
|
|
from django.db.models import Q
|
2024-02-23 04:00:42 +00:00
|
|
|
return reduce(or_,
|
2023-10-05 08:17:55 +00:00
|
|
|
[Q(**{field_name: x.id}) for x in objs])
|
|
|
|
|
2024-02-23 04:02:04 +00:00
|
|
|
|
2023-10-05 08:17:55 +00:00
|
|
|
def last_name(person):
|
|
|
|
return person.formal_name.rpartition(' ')[2]
|
|
|
|
|
2024-02-23 04:02:04 +00:00
|
|
|
|
2024-04-25 05:32:24 +00:00
|
|
|
def custom_index(request, podcast_slug, *args, **kwargs):
|
2023-10-05 08:17:55 +00:00
|
|
|
"""Cast list view that allows scrolling and also shows an index by
|
|
|
|
year.
|
|
|
|
"""
|
|
|
|
|
2024-04-25 05:32:24 +00:00
|
|
|
podcast = get_object_or_404(Podcast, slug=podcast_slug)
|
2023-10-05 08:17:55 +00:00
|
|
|
kwargs = kwargs.copy()
|
|
|
|
kwargs['extra_context'] = kwargs.get('extra_context', {}).copy()
|
|
|
|
extra_context = kwargs['extra_context']
|
|
|
|
|
|
|
|
date_field = kwargs['date_field']
|
|
|
|
del kwargs['date_field']
|
|
|
|
|
|
|
|
if not kwargs.get('allow_future', False):
|
2024-04-25 05:32:24 +00:00
|
|
|
queryset = Cast.objects.filter(
|
|
|
|
podcast=podcast,
|
|
|
|
**{'%s__lte' % date_field: datetime.now()},
|
|
|
|
)
|
2023-10-05 08:17:55 +00:00
|
|
|
|
|
|
|
tags = []
|
|
|
|
if 'tag' in request.GET:
|
|
|
|
tags = [get_object_or_404(CastTag, slug=tag)
|
|
|
|
for tag in request.GET.getlist('tag')]
|
|
|
|
extra_context['tags'] = tags
|
2024-04-25 05:32:24 +00:00
|
|
|
queryset = queryset.filter(OR_filter('tags', tags), podcast=podcast)
|
2023-10-05 08:17:55 +00:00
|
|
|
|
2024-04-25 05:32:24 +00:00
|
|
|
if tags:
|
|
|
|
query_string = '&'.join('tag=%s' % t.slug for t in tags)
|
2023-10-05 08:17:55 +00:00
|
|
|
extra_context['query_string'] = query_string
|
|
|
|
|
|
|
|
else:
|
|
|
|
date_list = queryset.dates(date_field, 'year')
|
|
|
|
extra_context['date_list'] = date_list
|
|
|
|
|
2024-04-25 05:32:24 +00:00
|
|
|
return render(request, 'podjango/cast_list.html', {'podcast': podcast,
|
|
|
|
'object_list': queryset,
|
|
|
|
'tags': tags})
|