diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index ef46408fde..2115088f6b 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -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 diff --git a/lms/envs/common.py b/lms/envs/common.py index ed84d9efb8..e9755c01bf 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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 diff --git a/lms/templates/index.html b/lms/templates/index.html index dd2d9690b3..77a07a11dc 100644 --- a/lms/templates/index.html +++ b/lms/templates/index.html @@ -1,4 +1,5 @@ <%! 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 @@
- - - - - + %for entry in entries: +
+ %if hasattr(entry, 'image'): + + + + %endif +
+ ${entry.title} + +
+
+ %endfor
diff --git a/requirements.txt b/requirements.txt index 27202f0380..6e03cd4307 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ django_debug_toolbar django-staticfiles>=1.2.1 fs beautifulsoup +feedparser requests sympy newrelic