Commit 2bfe0cb9 by Matthew Mongeau

Add parsed rss entries to home page with caching

parent b4eb9ffd
...@@ -5,6 +5,7 @@ import random ...@@ -5,6 +5,7 @@ import random
import string import string
import sys import sys
import uuid import uuid
import feedparser
from django.conf import settings from django.conf import settings
from django.contrib.auth import logout, authenticate, login from django.contrib.auth import logout, authenticate, login
...@@ -19,6 +20,8 @@ from django.http import HttpResponse, Http404 ...@@ -19,6 +20,8 @@ from django.http import HttpResponse, Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
from django.core.urlresolvers import reverse 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 django_future.csrf import ensure_csrf_cookie
from student.models import Registration, UserProfile, PendingNameChange, PendingEmailChange, CourseEnrollment from student.models import Registration, UserProfile, PendingNameChange, PendingEmailChange, CourseEnrollment
...@@ -44,11 +47,23 @@ def csrf_token(context): ...@@ -44,11 +47,23 @@ def csrf_token(context):
def index(request): def index(request):
''' Redirects to main page -- info page if user authenticated, or marketing if not ''' 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(): if settings.COURSEWARE_ENABLED and request.user.is_authenticated():
return redirect(reverse('dashboard')) return redirect(reverse('dashboard'))
else: else:
# TODO: Clean up how 'error' is done. # 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 @login_required
......
...@@ -104,6 +104,8 @@ LIB_URL = '/static/js/' ...@@ -104,6 +104,8 @@ LIB_URL = '/static/js/'
# Dev machines shouldn't need the book # Dev machines shouldn't need the book
# BOOK_URL = '/static/book/' # BOOK_URL = '/static/book/'
BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # For AWS deploys 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 # Configuration option for when we want to grab server error pages
STATIC_GRAB = False STATIC_GRAB = False
......
<%! from django.core.urlresolvers import reverse %> <%! from django.core.urlresolvers import reverse %>
<%! from time import strftime %>
<%inherit file="main.html" /> <%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
...@@ -91,35 +92,19 @@ ...@@ -91,35 +92,19 @@
</header> </header>
<section class="news"> <section class="news">
<section class="blog-posts"> <section class="blog-posts">
<article> %for entry in entries:
<a href="#" class="post-graphics"> <article>
<img src="${static.url('images/mongolia_post.jpeg')}" /> %if hasattr(entry, 'image'):
</a> <a href="${entry.link}" class="post-graphics">
<div class="post-name"> <img src="${entry.image}" />
<a href="">Opening Doors For Exceptional Students: 6.002x in Mongolia.</a> </a>
<p class="post-date">7/12/2012</p> %endif
</div> <div class="post-name">
</article> <a href="${entry.link}">${entry.title}</a>
<p class="post-date">${strftime("%m/%d/%y", entry.published_parsed)}</p>
<article> </div>
<a href="#" class="post-graphics"> </article>
<img src="${static.url('images/courses/space1.jpg')}" /> %endfor
</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>
</section> </section>
</section> </section>
</section> </section>
......
...@@ -15,6 +15,7 @@ django_debug_toolbar ...@@ -15,6 +15,7 @@ django_debug_toolbar
django-staticfiles>=1.2.1 django-staticfiles>=1.2.1
fs fs
beautifulsoup beautifulsoup
feedparser
requests requests
sympy sympy
newrelic newrelic
......
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