Commit 2bfe0cb9 by Matthew Mongeau

Add parsed rss entries to home page with caching

parent b4eb9ffd
......@@ -5,6 +5,7 @@ import random
import string
import sys
import uuid
import feedparser
from django.conf import settings
from django.contrib.auth import logout, authenticate, login
......@@ -19,6 +20,8 @@ from django.http import HttpResponse, Http404
from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string
from django.core.urlresolvers import reverse
from BeautifulSoup import BeautifulSoup
from django.core.cache import cache
from django_future.csrf import ensure_csrf_cookie
from student.models import Registration, UserProfile, PendingNameChange, PendingEmailChange, CourseEnrollment
......@@ -44,11 +47,23 @@ def csrf_token(context):
def index(request):
''' Redirects to main page -- info page if user authenticated, or marketing if not
'''
entries = None
if settings.RSS_URL:
feed = cache.get("students_index_rss_feed")
if feed == None:
feed = feedparser.parse(settings.RSS_URL)
cache.set("students_index_rss_feed", feed, settings.RSS_TIMEOUT)
entries = feed['entries'][0:3]
for entry in entries:
soup = BeautifulSoup(entry.description)
if soup.img:
entry.image = soup.img['src']
if settings.COURSEWARE_ENABLED and request.user.is_authenticated():
return redirect(reverse('dashboard'))
else:
# TODO: Clean up how 'error' is done.
return render_to_response('index.html', {'courses': modulestore().get_courses()})
return render_to_response('index.html', {'courses': modulestore().get_courses(), 'entries': entries})
@login_required
......
......@@ -104,6 +104,8 @@ LIB_URL = '/static/js/'
# Dev machines shouldn't need the book
# BOOK_URL = '/static/book/'
BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # For AWS deploys
RSS_URL = 'https://github.com/blog.atom'
RSS_TIMEOUT = 600
# Configuration option for when we want to grab server error pages
STATIC_GRAB = False
......
<%! from django.core.urlresolvers import reverse %>
<%! from time import strftime %>
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
......@@ -91,35 +92,19 @@
</header>
<section class="news">
<section class="blog-posts">
<article>
<a href="#" class="post-graphics">
<img src="${static.url('images/mongolia_post.jpeg')}" />
</a>
<div class="post-name">
<a href="">Opening Doors For Exceptional Students: 6.002x in Mongolia.</a>
<p class="post-date">7/12/2012</p>
</div>
</article>
<article>
<a href="#" class="post-graphics">
<img src="${static.url('images/courses/space1.jpg')}" />
</a>
<div class="post-name">
<a href="">Online Classes Cut Costs, But Do They Dilute Brands?</a>
<p class="post-date">7/12/2012</p>
</div>
</article>
<article>
<a href="#" class="post-graphics">
<img src="${static.url('images/courses/space1.jpg')}" />
</a>
<div class="post-name">
<a href="">Online Classes Cut Costs, But Do They Dilute Brands?</a>
<p class="post-date">7/12/2012</p>
</div>
</article>
%for entry in entries:
<article>
%if hasattr(entry, 'image'):
<a href="${entry.link}" class="post-graphics">
<img src="${entry.image}" />
</a>
%endif
<div class="post-name">
<a href="${entry.link}">${entry.title}</a>
<p class="post-date">${strftime("%m/%d/%y", entry.published_parsed)}</p>
</div>
</article>
%endfor
</section>
</section>
</section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment