momo: render feed cells as external links (#8804)
This commit is contained in:
parent
bebbee9069
commit
c7e74f8cdd
|
@ -30,7 +30,7 @@ from django.views.generic import TemplateView, UpdateView
|
|||
|
||||
import ckeditor
|
||||
|
||||
from combo.data.models import CellBase, LinkCell, Page
|
||||
from combo.data.models import CellBase, LinkCell, FeedCell, Page
|
||||
from .models import MomoIconCell, MomoOptions
|
||||
|
||||
|
||||
|
@ -48,7 +48,8 @@ def get_page_dict(request, page, manifest):
|
|||
|
||||
link_cells = [x for x in cells if isinstance(x, LinkCell)]
|
||||
icon_cells = [x for x in cells if isinstance(x, MomoIconCell)]
|
||||
cells = [x for x in cells if not isinstance(x, LinkCell)]
|
||||
feed_cells = [x for x in cells if isinstance(x, FeedCell)]
|
||||
cells = [x for x in cells if not (isinstance(x, LinkCell) or isinstance(x, FeedCell))]
|
||||
|
||||
if cells:
|
||||
context = RequestContext(request, {
|
||||
|
@ -86,16 +87,34 @@ def get_page_dict(request, page, manifest):
|
|||
if page_dict.get('external') and icon_cells[0].embed_page:
|
||||
page_dict['external'] = False
|
||||
|
||||
|
||||
if hasattr(page, '_children') and page._children:
|
||||
children = page._children
|
||||
else:
|
||||
children = page.get_children()
|
||||
|
||||
if children:
|
||||
page_dict['pages'] = []
|
||||
for child in children:
|
||||
page_dict['pages'].append(get_page_dict(request, child, manifest))
|
||||
|
||||
if feed_cells:
|
||||
if not 'pages' in page_dict:
|
||||
page_dict['pages'] = []
|
||||
# turn feed entries in external pages
|
||||
for feed_cell in feed_cells:
|
||||
feed_context = feed_cell.get_cell_extra_context()
|
||||
if feed_context.get('feed'):
|
||||
for entry in feed_context.get('feed').entries:
|
||||
feed_entry_page = {
|
||||
'title': entry.title,
|
||||
'id': 'feed-entry-%s-%s' % (feed_cell.id, entry.id),
|
||||
'url': entry.link,
|
||||
'external': True,
|
||||
}
|
||||
if entry.description:
|
||||
feed_entry_page['description'] = entry.description
|
||||
page_dict['pages'].append(feed_entry_page)
|
||||
|
||||
return page_dict
|
||||
|
||||
|
||||
|
|
|
@ -526,11 +526,10 @@ class FeedCell(CellBase):
|
|||
def is_visible(self, user=None):
|
||||
return bool(self.url) and super(FeedCell, self).is_visible(user=user)
|
||||
|
||||
def render(self, context):
|
||||
def get_cell_extra_context(self):
|
||||
context = super(FeedCell, self).get_cell_extra_context()
|
||||
cache_key = hashlib.md5(self.url).hexdigest()
|
||||
feed_content = cache.get(cache_key)
|
||||
if not context.get('synchronous') and feed_content is None:
|
||||
raise NothingInCacheException()
|
||||
if not feed_content:
|
||||
feed_response = requests.get(self.url)
|
||||
if feed_response.status_code == 200:
|
||||
|
@ -538,4 +537,11 @@ class FeedCell(CellBase):
|
|||
cache.set(cache_key, feed_content, 600)
|
||||
if feed_content:
|
||||
context['feed'] = feedparser.parse(feed_content)
|
||||
return context
|
||||
|
||||
def render(self, context):
|
||||
cache_key = hashlib.md5(self.url).hexdigest()
|
||||
feed_content = cache.get(cache_key)
|
||||
if not context.get('synchronous') and feed_content is None:
|
||||
raise NothingInCacheException()
|
||||
return super(FeedCell, self).render(context)
|
||||
|
|
Loading…
Reference in New Issue