Changeset - 49e3c43299e8
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 3 months ago 2024-02-23 04:06:59
ben@sturm.com.au
poddjango: Further lint fixes
2 files changed with 20 insertions and 8 deletions:
0 comments (0 inline, 0 general)
conservancy/podjango/feeds.py
Show inline comments
...
 
@@ -20,28 +20,31 @@
 
from datetime import datetime
 

	
 
from django.contrib.sites.shortcuts import get_current_site
 
from django.contrib.syndication.views import Feed, add_domain
 
from django.shortcuts import render
 
from django.utils.feedgenerator import Rss201rev2Feed
 

	
 
from .models import Cast
 

	
 
# FIXME: Settings here should not be hard-coded for given casts, but
 
# should instead have settings from the main screen.
 

	
 

	
 
class CastFeedBase(Feed):
 
    def copyright_holder(self): return "Bradley M. Kuhn, Karen M. Sandler"
 
    def copyright_holder(self):
 
        return "Bradley M. Kuhn, Karen M. Sandler"
 

	
 
    def license_no_html(self): return "Licensed under a Creative Commons Attribution-Share Alike 3.0 USA License."
 
    def license_no_html(self):
 
        return "Licensed under a Creative Commons Attribution-Share Alike 3.0 USA License."
 

	
 
    def item_copyright(self, item):
 
        year = 2008
 
        for attr in ('pub_date', 'date_created', 'date_last_modified'):
 
            if hasattr(item, attr):
 
                if hasattr(getattr(item, attr), 'year'):
 
                    year = getattr(getattr(item, attr), 'year')
 
                    break
 
        return 'Copyright (C) %d, %s.  %s' % (year, self.copyright_holder(), self.license_no_html())
 

	
 
    def item_extra_kwargs(self, item):
 
        year = 2008
...
 
@@ -123,48 +126,51 @@ def podcast_helper_add_root_elements(self, handler):
 
    handler.addQuickElement("itunes:email", self.feed['author_email'])
 
    handler.addQuickElement("itunes:name", self.feed['author_name'])
 
    handler.endElement("itunes:owner")
 

	
 
    handler.addQuickElement("itunes:summary", self.feed['description'])
 
    handler.addQuickElement("itunes:subtitle", self.feed['iTunesSubtitle'])
 

	
 
    handler.addQuickElement("itunes:author", self.feed['iTunesAuthor'])
 
    handler.addQuickElement('atom:link', '', {'rel': "self", 'href': self.feed['feed_url'],
 
                                              'type': "application/rss+xml"})
 

	
 
    years = {}
 
    for ii in self.items: years[ii['year']] = 1
 
    for ii in self.items:
 
        years[ii['year']] = 1
 

	
 
    copyrightString = ""
 
    ll = years.keys()
 
    sorted(ll)
 
    for yy in ll: copyrightString += "%d, " % yy 
 
    for yy in ll:
 
        copyrightString += "%d, " % yy
 
    copyrightString += "%s.  %s" % (self.feed['copyrightHolder'], self.feed['copyrightLicense'])
 

	
 
    handler.addQuickElement('copyright', copyrightString)
 
    handler.addQuickElement('media:copyright', "Copyright (C) " + copyrightString)
 

	
 

	
 
def podcast_helper_add_item_elements(self, handler, item):
 
    handler.addQuickElement("itunes:explicit", self.feed['iTunesExplicit'])
 
    handler.addQuickElement("itunes:block", self.feed['iTunesBlock'])
 
    handler.addQuickElement("itunes:keywords", self.feed['keywords'])
 
#    handler.addQuickElement('dc:creator', self.feed['dcCreator'])
 
    handler.addQuickElement("itunes:author", item['author_name'])
 
    handler.addQuickElement("itunes:duration", item['duration'])
 
    if 'enclosure' in item:
 
        handler.addQuickElement('media:content', '', {'url': item['enclosure'].url,
 
                                                      'fileSize': item['enclosure'].length,
 
                                                      'type': item['enclosure'].mime_type})
 

	
 

	
 
# http://www.feedforall.com/itune-tutorial-tags.htm
 
# http://www.feedforall.com/mediarss.htm
 
class iTunesFeedType(Rss201rev2Feed):
 
    def root_attributes(self):
 
        attrs = super().root_attributes()
 
        attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
 
        attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
 
        attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
 
#        attrs['xmlns:dc'] = "http://purl.org/dc/elements/1.1/"
 
        return attrs
 

	
 
    def add_root_elements(self, handler):
...
 
@@ -226,35 +232,41 @@ class CastFeed(CastFeedBase):
 

	
 
    def item_extra_kwargs(self, item):
 
        return for_podcast_item_extra_kwargs(self, item)
 

	
 
# FIXME:
 
# GUEST NAME GOES HERE!!!
 
#<itunes:author>
 
#     If applicable, at the item level, this tag can contain information
 
#     about the person(s) featured on a specific episode.
 

	
 

	
 
class Mp3CastFeed(CastFeed):
 
    def item_enclosure_mime_type(self): return "audio/mpeg"
 
    def item_enclosure_mime_type(self):
 
        return "audio/mpeg"
 

	
 
    def item_enclosure_url(self, item):
 
        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_mime_type(self):
 
        return "audio/ogg"
 

	
 
    def item_enclosure_url(self, item):
 
        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,
 
}
 

	
 
# make each feed know its canonical url
 
for k, v in feed_dict.items():
 
    v.get_absolute_url = '/feeds/%s/' % k
conservancy/podjango/urls.py
Show inline comments
...
 
@@ -48,26 +48,26 @@ urlpatterns = [
 
    url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', DateDetailView.as_view(**info_dict), name='detail'),
 
    url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', DayArchiveView.as_view(**info_dict), name='day-archive'),
 
    url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', MonthArchiveView.as_view(**info_dict), name='month-archive'),
 
    url(r'^(?P<year>\d{4})/$', YearArchiveView.as_view(**info_dict), name='year-archive'),
 
    url(r'^all/$', custom_index, dict(info_dict, paginate_by=20), name='cast'),
 
    url(r'^query/$', query, name='query'),
 
    url(r'^feeds/ogg/$', OggCastFeed(), name='feed-ogg'),
 
    url(r'^feeds/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')
 
    from django.conf.urls.static import static
 
    urlpatterns += static('/', document_root='podjango/static')
 

	
 

	
 
def all_tags_by_use_amount():
 
    """Returns all tags with an added 'cnt' attribute (how many times used)
 

	
 
    Also sorts the tags so most-used tags appear first.
 
    """
 

	
 
    # tally use amount
 
    retval = []
 
    current = None
 
    for obj in CastTag.objects.filter(cast__pub_date__lte=datetime.now(),
0 comments (0 inline, 0 general)