14 |
14 |
# You should have received a copy of the GNU Affero General Public License
|
15 |
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
|
17 |
import feedparser
|
17 |
18 |
import json
|
|
19 |
import requests
|
18 |
20 |
|
19 |
21 |
from django.conf import settings
|
20 |
22 |
from django.contrib.auth.models import Group
|
21 |
23 |
from django.contrib.contenttypes.models import ContentType
|
|
24 |
from django.core.cache import cache
|
22 |
25 |
from django.core.exceptions import ObjectDoesNotExist
|
23 |
26 |
from django.core import serializers
|
24 |
27 |
from django.db import models
|
... | ... | |
34 |
37 |
from .library import register_cell_class, get_cell_classes, get_cell_class
|
35 |
38 |
|
36 |
39 |
from combo import utils
|
|
40 |
from combo.utils import NothingInCacheException
|
37 |
41 |
|
38 |
42 |
|
39 |
43 |
def element_is_visible(element, user=None):
|
... | ... | |
469 |
473 |
if self.anchor:
|
470 |
474 |
context['url'] += '#' + self.anchor
|
471 |
475 |
return super(LinkCell, self).render(context)
|
|
476 |
|
|
477 |
|
|
478 |
@register_cell_class
|
|
479 |
class FeedCell(CellBase):
|
|
480 |
url = models.URLField(_('URL'), blank=True)
|
|
481 |
|
|
482 |
template_name = 'combo/feed-cell.html'
|
|
483 |
|
|
484 |
class Meta:
|
|
485 |
verbose_name = _('RSS/Atom Feed')
|
|
486 |
|
|
487 |
def render(self, context):
|
|
488 |
cache_key = self.url
|
|
489 |
feed_content = cache.get(cache_key)
|
|
490 |
if not context.get('ajax') and feed_content is None:
|
|
491 |
raise NothingInCacheException()
|
|
492 |
feed_response = requests.get(self.url)
|
|
493 |
if feed_response.status_code == 200:
|
|
494 |
feed_content = feed_response.content
|
|
495 |
cache.set(cache_key, feed_content, 600)
|
|
496 |
context['feed'] = feedparser.parse(feed_content)
|
|
497 |
return super(FeedCell, self).render(context)
|