Projet

Général

Profil

0001-misc-add-a-rss-atom-feed-cell-6842.patch

Frédéric Péters, 24 août 2015 14:32

Télécharger (3,09 ko)

Voir les différences:

Subject: [PATCH] misc: add a rss/atom feed cell (#6842)

 combo/data/models.py | 26 ++++++++++++++++++++++++++
 debian/control       |  1 +
 requirements.txt     |  1 +
 setup.py             |  1 +
 4 files changed, 29 insertions(+)
combo/data/models.py
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, 3600)
496
            context['feed'] = feedparser.parse(feed_content)
497
        return super(FeedCell, self).render(context)
debian/control
12 12
    python-django (>= 1.7),
13 13
    python-gadjo,
14 14
    python-requests,
15
    python-feedparser,
15 16
    python-django-cmsplugin-blurp
16 17
Recommends: python-django-mellon
17 18
Description: Portal Management System (Python module)
requirements.txt
4 4
django-cmsplugin-blurp
5 5
django-jsonfield
6 6
requests
7
feedparser
setup.py
106 106
        'django-ckeditor',
107 107
        'gadjo',
108 108
        'django-cmsplugin-blurp',
109
        'feedparser'
109 110
        'django-jsonfield',
110 111
        ],
111 112
    zip_safe=False,
112
-