Changeset - 9381e607cd90
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 7 months ago 2023-10-13 01:41:20
ben@sturm.com.au
Automatically generate feed enclosure URL prefix
2 files changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
www/podjango/feeds.py
Show inline comments
...
 
@@ -14,13 +14,14 @@
 
#
 
# 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 django.contrib.syndication.views import Feed
 
from django.contrib.sites.shortcuts import get_current_site
 
from django.contrib.syndication.views import add_domain, Feed
 
from django.utils.feedgenerator import Rss201rev2Feed 
 
#from podjango.apps.staff.models import Person
 
from podjango.apps.cast.models import Cast
 

	
 
from django.shortcuts import render
 
from django.conf import settings
...
 
@@ -178,14 +179,25 @@ class CastFeed(CastFeedBase):
 
    description = "A bi-weekly discussion of legal, policy, and other issues in the open source and software freedom community (including occasional interviews) from Brooklyn, New York, USA.  Presented by Karen Sandler and Bradley M. Kuhn."
 
    author_email = "podcast@faif.us"
 
    author_link = "http://www.faif.us/"
 
    author_name = "Free as in Freedom"
 
    title_template = "feeds/podcast_title.html"
 
    description_template = "feeds/podcast_description.html"
 

	
 
    def get_feed(self, obj, request):
 
        # Enclosure (media) URLs don't automatically get the protocol and
 
        # domain, but these are required for the podcast to work
 
        # properly. added. This provides current_site and is_secure to the feed
 
        # so that we have it in context for use in `item_enclosure_url`.
 
        self.current_site = get_current_site(request)
 
        self.is_secure = request.is_secure()
 
        return super().get_feed(obj, request)
 

	
 
    def items(self):
 
        return Cast.objects.filter(pub_date__lte=datetime.now()).order_by('-pub_date')
 

	
 
    def item_pubdate(self, item):
 
        return item.pub_date
 

	
 
    def item_link(self, item):
 
        return item.get_absolute_url()
 

	
...
 
@@ -218,20 +230,20 @@ class CastFeed(CastFeedBase):
 
#     about the person(s) featured on a specific episode.
 

	
 

	
 
class Mp3CastFeed(CastFeed):
 
    def item_enclosure_mime_type(self): return "audio/mpeg"
 
    def item_enclosure_url(self, item):
 
        return item.mp3_path
 
        return add_domain(self.current_site.domain, item.mp3_path, self.is_secure)
 
    def item_enclosure_length(self, item):
 
        return item.mp3_length
 

	
 
class OggCastFeed(CastFeed):
 
    def item_enclosure_mime_type(self): return "audio/ogg"
 
    def item_enclosure_url(self, item):
 
        return item.ogg_path
 
        return add_domain(self.current_site.domain, item.ogg_path, self.is_secure)
 
    def item_enclosure_length(self, item):
 
        return item.ogg_length
 

	
 
feed_dict = {
 
    'cast-ogg': OggCastFeed,
 
    'cast-mp3': Mp3CastFeed,
www/podjango/urls.py
Show inline comments
...
 
@@ -30,14 +30,14 @@ from podjango import frontpage
 
admin.autodiscover()
 

	
 
app_name = 'podjango'
 
urlpatterns = [
 
    url(r'^$', frontpage.view),
 
    url(r'^cast/', include('podjango.apps.cast.urls')),
 
    url(r'^feeds/cast-ogg/$', Mp3CastFeed(), name='feed-ogg'),
 
    url(r'^feeds/cast-mp3/$', OggCastFeed(), name='feed-mp3'),
 
    url(r'^feeds/cast-ogg/$', OggCastFeed(), name='feed-ogg'),
 
    url(r'^feeds/cast-mp3/$', Mp3CastFeed(), name='feed-mp3'),
 
    url(r'^feeds/$', view, name='feeds'),
 
]
 

	
 
if settings.DEBUG:
 
  from django.conf.urls.static import static
 
  urlpatterns += static('/', document_root='podjango/static')
0 comments (0 inline, 0 general)