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/>.
#
2023-10-19 22:52:39 +00:00
from datetime import datetime , timedelta
from django . db import models
2023-10-05 08:17:55 +00:00
2023-10-13 01:44:28 +00:00
2024-04-25 05:32:24 +00:00
class Podcast ( models . Model ) :
""" An ongoing series of episodes. """
title = models . CharField ( max_length = 50 )
slug = models . SlugField ( unique = True )
long_description = models . TextField ( blank = True )
2024-04-26 06:06:48 +00:00
icon = models . ImageField ( null = True )
2024-04-25 05:32:24 +00:00
def __str__ ( self ) :
return self . title
2023-10-05 08:17:55 +00:00
class CastTag ( models . Model ) :
""" Tagging for casts """
label = models . CharField ( max_length = 100 )
slug = models . SlugField ( )
class Meta :
2024-02-07 00:03:56 +00:00
db_table = ' cast_tags ' # legacy
2024-04-25 05:32:24 +00:00
verbose_name = ' episode tag '
verbose_name_plural = ' episode tags '
2023-10-05 08:17:55 +00:00
2023-10-13 01:44:28 +00:00
def __str__ ( self ) :
2023-10-05 08:17:55 +00:00
return self . label
2023-10-13 01:44:28 +00:00
2024-02-07 00:03:56 +00:00
class CastManager ( models . Manager ) :
def get_queryset ( self ) :
# Temporarily filter out old FaiF episodes we've imported.
return super ( ) . get_queryset ( ) . filter ( pub_date__year__gte = 2024 )
2023-10-05 08:17:55 +00:00
class Cast ( models . Model ) :
2024-04-25 05:32:24 +00:00
""" A podcast episode. """
2023-10-05 08:17:55 +00:00
title = models . CharField ( max_length = 200 )
slug = models . SlugField ( unique = True )
summary = models . TextField ( help_text = " Use raw HTML. This summary is not included at the beginning of the body when the entry is displayed. It used only for the material on the front page. " )
body = models . TextField ( help_text = " Use raw HTML. Include the full body of any show notes or other information about this episode. It will be labelled on the site as Show Notes. It is included on the detail entry, and in the description data on the cast RSS feed. " )
pub_date = models . DateTimeField ( )
2024-04-25 05:32:24 +00:00
podcast = models . ManyToManyField ( Podcast )
2023-10-05 08:17:55 +00:00
tags = models . ManyToManyField ( CastTag , blank = True )
2024-02-23 04:02:04 +00:00
ogg_path = models . CharField (
max_length = 300 , blank = True ,
help_text = " Local filename of the Ogg file, relative to webroot. File should be uploaded into the static media area for casts. " )
mp3_path = models . CharField (
max_length = 300 , blank = True ,
help_text = " Local filename of the mp3 file, relative to webroot. File should be uploaded into the static media area for casts. " )
2023-10-05 08:17:55 +00:00
ogg_length = models . IntegerField ( blank = False , help_text = " size in bytes of ogg file " )
mp3_length = models . IntegerField ( blank = False , help_text = " size in bytes of mp3 file " )
duration = models . CharField ( max_length = 8 , blank = False , help_text = " length in hh:mm:ss of mp3 file " )
date_created = models . DateTimeField ( auto_now_add = True )
date_last_modified = models . DateTimeField ( auto_now = True )
2024-02-07 00:03:56 +00:00
objects = CastManager ( )
2023-10-05 08:17:55 +00:00
class Meta :
2024-02-07 00:03:56 +00:00
db_table = ' casts_entries ' # legacy
2024-04-25 05:32:24 +00:00
verbose_name = ' episode '
verbose_name_plural = ' episodes '
2023-10-05 08:17:55 +00:00
ordering = ( ' -pub_date ' , )
get_latest_by = ' pub_date '
2023-10-13 01:44:28 +00:00
def __str__ ( self ) :
2023-10-05 08:17:55 +00:00
return self . title
2024-04-25 05:32:24 +00:00
def month_str ( self ) :
return self . pub_date . strftime ( " % b " ) . lower ( )
2023-10-05 08:17:55 +00:00
def is_recent ( self ) :
return self . pub_date > ( datetime . now ( ) - timedelta ( days = 14 ) )
# question: does datetime.now() do a syscall each time is it called?