Fantomas42/django-blog-zinnia — Issue #134: Handle missing img src attribute in item_enclosure_url
Author: ztest
Created: 2012-03-06 16:48:07+00:00
State: open

zinnia/feeds.py:item_enclosure_url will trigger a KeyError if an img element is missing a src attribute. This seems to be possible with markup generated by older versions of TinyMCE. For example, one of the old blog entries at my company had markup like this: ``````.

It'd be great if Zinnia could handle this brokenness, especially for users migrating from old versions of WordPress. The current version of item_enclosure_url:

```python
def item_enclosure_url(self, item):
"""Returns an image for enclosure"""
if item.image:
url = item.image.url
else:
img = BeautifulSoup(item.html_content).find('img')
url = img['src'] if img else None
return urljoin(self.site_url, url) if url else None
```