misc: add a rss/atom feed cell (#6842)
This commit is contained in:
parent
2c1208c8f5
commit
be513d2166
|
@ -14,11 +14,15 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -34,6 +38,7 @@ import cmsplugin_blurp.utils
|
||||||
from .library import register_cell_class, get_cell_classes, get_cell_class
|
from .library import register_cell_class, get_cell_classes, get_cell_class
|
||||||
|
|
||||||
from combo import utils
|
from combo import utils
|
||||||
|
from combo.utils import NothingInCacheException
|
||||||
|
|
||||||
|
|
||||||
def element_is_visible(element, user=None):
|
def element_is_visible(element, user=None):
|
||||||
|
@ -469,3 +474,27 @@ class LinkCell(CellBase):
|
||||||
if self.anchor:
|
if self.anchor:
|
||||||
context['url'] += '#' + self.anchor
|
context['url'] += '#' + self.anchor
|
||||||
return super(LinkCell, self).render(context)
|
return super(LinkCell, self).render(context)
|
||||||
|
|
||||||
|
|
||||||
|
@register_cell_class
|
||||||
|
class FeedCell(CellBase):
|
||||||
|
url = models.URLField(_('URL'), blank=True)
|
||||||
|
|
||||||
|
template_name = 'combo/feed-cell.html'
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('RSS/Atom Feed')
|
||||||
|
|
||||||
|
def render(self, context):
|
||||||
|
cache_key = hashlib.md5(self.url).hexdigest()
|
||||||
|
feed_content = cache.get(cache_key)
|
||||||
|
if not context.get('ajax') and feed_content is None:
|
||||||
|
raise NothingInCacheException()
|
||||||
|
if not feed_content:
|
||||||
|
feed_response = requests.get(self.url)
|
||||||
|
if feed_response.status_code == 200:
|
||||||
|
feed_content = feed_response.content
|
||||||
|
cache.set(cache_key, feed_content, 600)
|
||||||
|
if feed_content:
|
||||||
|
context['feed'] = feedparser.parse(feed_content)
|
||||||
|
return super(FeedCell, self).render(context)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% for entry in feed.entries %}
|
||||||
|
{% if entry.link %}
|
||||||
|
<h3><a href="{{entry.link}}">{{entry.title}}</a></h3>
|
||||||
|
{% else %}
|
||||||
|
<h3>{{entry.title}}</h3>
|
||||||
|
{% endif %}
|
||||||
|
{% if entry.description %}<p>{{entry.description}}</p>{% endif %}
|
||||||
|
{% endfor %}
|
|
@ -12,6 +12,7 @@ Depends: ${misc:Depends}, ${python:Depends},
|
||||||
python-django (>= 1.7),
|
python-django (>= 1.7),
|
||||||
python-gadjo,
|
python-gadjo,
|
||||||
python-requests,
|
python-requests,
|
||||||
|
python-feedparser,
|
||||||
python-django-cmsplugin-blurp
|
python-django-cmsplugin-blurp
|
||||||
Recommends: python-django-mellon
|
Recommends: python-django-mellon
|
||||||
Description: Portal Management System (Python module)
|
Description: Portal Management System (Python module)
|
||||||
|
|
|
@ -4,3 +4,4 @@ django-ckeditor
|
||||||
django-cmsplugin-blurp
|
django-cmsplugin-blurp
|
||||||
django-jsonfield
|
django-jsonfield
|
||||||
requests
|
requests
|
||||||
|
feedparser
|
||||||
|
|
Loading…
Reference in New Issue