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 11:07:34 +00:00
from django . urls import reverse
2023-10-05 08:17:55 +00:00
2023-10-13 01:44:28 +00:00
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
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
def get_absolute_url ( self ) :
2023-10-05 11:07:34 +00:00
return reverse ( ' podjango:cast ' ) + " ?tag= %s " % self . slug
2023-10-05 08:17:55 +00:00
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 ) :
""" Cast """
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 ( )
tags = models . ManyToManyField ( CastTag , blank = True )
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. " )
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
2023-10-05 08:17:55 +00:00
verbose_name_plural = ' casts '
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
def get_absolute_url ( self ) :
2023-10-05 11:07:34 +00:00
return reverse (
' podjango:detail ' ,
kwargs = {
' year ' : self . pub_date . year ,
' month ' : self . pub_date . strftime ( " % b " ) . lower ( ) ,
' day ' : self . pub_date . day ,
' slug ' : self . slug ,
}
)
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?