KindOfGuy
KindOfGuy

Reputation: 3211

Django syndication function error

I'm trying to create a custom Django RSS feed using django syndication (actually using django wagtail feeds). I have an error which I think I've identified as stemming from a NoneType object which is returned by the get_object() function inside syndication/views.py.

`AttributeError at /feed/basic/Chups/ 'NoneType' object has no attribute 'startswith'

Exception Location: /Users/technical/.virtualenvs/wagtest4-plnzODoN/lib/python3.6/site-packages/django/contrib/syndication/views.py in add_domain, line 19`

That function is called as part of class Feed() and looks like this:

def get_object(self, request, *args, **kwargs):
    return None

That function is called at line 36 but fails because get_object() returns a None object.

My customisation of django wagtail feeds extends Feed in the following way:

from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import (
    SyndicationFeed, rfc3339_date, Rss201rev2Feed
)
from .models import RSSFeedsSettings, RSSFeed

class BasicFeed(Feed):

    # FEED TYPE
    feed_type = Rss201rev2Feed

    def get_object(self, request, category):
        return category

try:
    feed_app_settings = RSSFeedsSettings.objects.get(feed_category_name="Flex")
    print(feed_app_settings)
    feed_app_label = feed_app_settings.feed_app_label
    feed_model_name = feed_app_settings.feed_model_name
    feed_category_name = feed_app_settings.feed_category_name
    use_feed_image = feed_app_settings.feed_image_in_content
except:  # pragma: no cover
    feed_app_settings = None

try:
    feed_model = apps.get_model(app_label=feed_app_label,
                                model_name=feed_model_name)
except:  # pragma: no cover
    feed_model = None

# The RSS information that gets shown at the top of the feed.
if feed_app_settings is not None:
    title = feed_app_settings.feed_title
    link = feed_app_settings.feed_link
    description = feed_app_settings.feed_description

    author_email = feed_app_settings.feed_author_email
    author_link = feed_app_settings.feed_author_link

    item_description_field = feed_app_settings.feed_item_description_field
    item_content_field = feed_app_settings.feed_item_content_field

def items(self, obj):
    url_category = obj
    categories = ContentType(app_label="blog", model="blogcategory")
    category_id = categories.get_object_for_this_type(name=url_category).id
    return feed_model.objects.filter(categories=category_id).order_by('-date').live()

def item_pubdate(self, item):
    return datetime.combine(item.date, time())

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

def item_author_name(self, item):
    pass

urls.py includes this and requests seem to be reaching the function fine.

url(r'^feed/basic/(?P<category>[0-9a-zA-Z]+)/$', BasicFeed(), name='basic_feed'),

Can anyone tell me why that might be? I'm missing something about the expected functioning of this. Thanks!

Upvotes: 0

Views: 206

Answers (0)

Related Questions