Commit 24ef6f76 by Carlos Andrés Rocha

Add backend for displaying news on the student dashboard

[#39472239]
parent c01c17d1
......@@ -69,20 +69,6 @@ def index(request, extra_context={}, user=None):
extra_context is used to allow immediate display of certain modal windows, eg signup,
as used by external_auth.
'''
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
feed_data = render_to_string("feed.rss", None)
cache.set("students_index_rss_feed_data", feed_data, settings.RSS_TIMEOUT)
feed = feedparser.parse(feed_data)
entries = feed['entries'][0:3]
for entry in entries:
soup = BeautifulSoup(entry.description)
entry.image = soup.img['src'] if soup.img else None
entry.summary = soup.getText()
# The course selection work is done in courseware.courses.
domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN') # normally False
......@@ -90,7 +76,11 @@ def index(request, extra_context={}, user=None):
domain = request.META.get('HTTP_HOST')
universities = get_courses_by_university(None,
domain=domain)
context = {'universities': universities, 'entries': entries}
# Get the 3 most recent news
top_news = _get_news(top=3)
context = {'universities': universities, 'news': top_news}
context.update(extra_context)
return render_to_response('index.html', context)
......@@ -230,12 +220,16 @@ def dashboard(request):
cert_statuses = { course.id: cert_info(request.user, course) for course in courses}
# Get the 3 most recent news
top_news = _get_news(top=3)
context = {'courses': courses,
'message': message,
'staff_access': staff_access,
'errored_courses': errored_courses,
'show_courseware_links_for' : show_courseware_links_for,
'cert_statuses': cert_statuses,
'news': top_news,
}
return render_to_response('dashboard.html', context)
......@@ -883,3 +877,24 @@ def test_center_login(request):
return redirect('/courses/MITx/6.002x/2012_Fall/courseware/Final_Exam/Final_Exam_Fall_2012/')
else:
return HttpResponseForbidden()
def _get_news(top=None):
"Return the n top news items on settings.RSS_URL"
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
feed_data = render_to_string("feed.rss", None)
cache.set("students_index_rss_feed_data", feed_data, settings.RSS_TIMEOUT)
feed = feedparser.parse(feed_data)
entries = feed['entries'][0:top] # all entries if top is None
for entry in entries:
soup = BeautifulSoup(entry.description)
entry.image = soup.img['src'] if soup.img else None
entry.summary = soup.getText()
return entries
......@@ -150,6 +150,7 @@
</ul>
</section>
%if news:
<article class="news-carousel">
<header>
<h4>edX News</h4>
......@@ -162,38 +163,25 @@
</nav>
</header>
<div class="pages">
% for entry in news:
<section class="page">
%if entry.image:
<div class="news-image">
<a href="#"><img src="/static/content-berkeley-cs169x/images/course_image.jpg" /></a>
<a href="${entry.link}"><img src="${entry.image}" /></a>
</div>
<h5><a href="#">BerkeleyX to offer Computer Graphics course</a></h5>
%endif
<h5><a href="${entry.link}">${entry.title}</a></h5>
<div class="excerpt">
<p>BerkeleyX will be offering CS184.1x: Foundations of Computer Graphics starting on November 5, 2012.</p>
<p><a href="#">Learn More ›</a></p>
</div>
</section>
<section class="page">
<div class="news-image">
<a href="#"><img src="/static/content-mit-6002x/images/course_image.jpg" /></a>
</div>
<h5><a href="#">MIT has a new class</a></h5>
<div class="excerpt">
<p>BerkeleyX will be offering CS184.1x: Foundations of Computer Graphics starting on November 5, 2012.</p>
<p><a href="#">Learn More ›</a></p>
</div>
</section>
<section class="page">
<div class="news-image">
<a href="#"><img src="/static/6.00x/images/course_image.jpg" /></a>
</div>
<h5><a href="#">Look at this class, too!</a></h5>
<div class="excerpt">
<p>BerkeleyX will be offering CS184.1x: Foundations of Computer Graphics starting on November 5, 2012.</p>
<p><a href="#">Learn More ›</a></p>
%if entry.summary:
<p>${entry.summary}</p>
%endif
<p><a href="${entry.link}">Learn More ›</a></p>
</div>
</section>
%endfor
</div>
</article>
%endif
</section>
<section class="my-courses">
......@@ -268,7 +256,7 @@
<p class="message-copy">You did not complete the necessary requirements for
completion of this course.</p>
% endif
% if cert_status['show_disabled_download_button'] or cert_status['show_download_url'] or cert_status['show_survey_button']:
<ul class="actions">
% if cert_status['show_disabled_download_button']:
......@@ -280,7 +268,7 @@
title="This link will open/download a PDF document">
Download Your PDF Certificate</a></li>
% endif
% if cert_status['show_survey_button']:
<li class="action"><a class="cta" href="${cert_status['survey_url']}">
Complete our course feedback survey</a></li>
......
......@@ -111,7 +111,7 @@
</header>
<section class="news">
<section class="blog-posts">
%for entry in entries:
%for entry in news:
<article>
%if entry.image:
<a href="${entry.link}" class="post-graphics" target="_blank"><img src="${entry.image}" /></a>
......
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