Commit 48280006 by David Ormsbee

Merge pull request #1003 from MITx/feature/dave/close_forum

Support blackout periods for restricting student forum posts per class
parents e4c49f3a ddc4f705
......@@ -277,6 +277,21 @@ class CourseDescriptor(SequenceDescriptor):
return self.metadata.get('discussion_link', None)
@property
def forum_posts_allowed(self):
try:
blackout_periods = [(parse_time(start), parse_time(end))
for start, end
in self.metadata.get('discussion_blackouts', [])]
now = time.gmtime()
for start, end in blackout_periods:
if start <= now <= end:
return False
except:
log.exception("Error parsing discussion_blackouts for course {0}".format(self.id))
return True
@property
def hide_progress_tab(self):
"""TODO: same as above, intended to let internal CS50 hide the progress tab
until we get grade integration set up."""
......
......@@ -250,9 +250,11 @@ Values are dictionaries of the form {"metadata-key" : "metadata-value"}.
Supported fields at the course level:
* "start" -- specify the start date for the course. Format-by-example: "2012-09-05T12:00".
* "advertised_start" -- specify what you want displayed as the start date of the course in the course listing and course about pages. This can be useful if you want to let people in early before the formal start. Format-by-example: "2012-09-05T12:00".
* "enrollment_start", "enrollment_end" -- when can students enroll? (if not specified, can enroll anytime). Same format as "start".
* "end" -- specify the end date for the course. Format-by-example: "2012-11-05T12:00".
* "tabs" -- have custom tabs in the courseware. See below for details on config.
* "discussion_blackouts" -- An array of time intervals during which you want to disable a student's ability to create or edit posts in the forum. Moderators, Community TAs, and Admins are unaffected. You might use this during exam periods, but please be aware that the forum is often a very good place to catch mistakes and clarify points to students. The better long term solution would be to have better flagging/moderation mechanisms, but this is the hammer we have today. Format by example: [["2012-10-29T04:00", "2012-11-03T04:00"], ["2012-12-30T04:00", "2013-01-02T04:00"]]
* TODO: there are others
### Grading policy file contents
......
......@@ -2,6 +2,7 @@ from django.db import models
from django.contrib.auth.models import User
import logging
from courseware.courses import get_course_by_id
class Role(models.Model):
name = models.CharField(max_length=30, null=False, blank=False)
......@@ -23,6 +24,12 @@ class Role(models.Model):
self.permissions.add(Permission.objects.get_or_create(name=permission)[0])
def has_permission(self, permission):
course = get_course_by_id(self.course_id)
if self.name == "Student" and \
(permission.startswith('edit') or permission.startswith('update') or permission.startswith('create')) and \
(not course.forum_posts_allowed):
return False
return self.permissions.filter(name=permission).exists()
......
<%! from django_comment_client.permissions import has_permission %>
<%inherit file="../courseware/course_navigation.html" />
<%block name="extratabs">
% if has_permission(user, 'create_thread', course.id):
<li class="right"><a href="#" class="new-post-btn"><span class="new-post-icon"></span>New Post</a></li>
% endif
</%block>
\ No newline at end of file
......@@ -3,4 +3,6 @@
<div class="discussion-module" data-discussion-id="${discussion_id | h}">
<a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}"><span class="show-hide-discussion-icon"></span><span class="button-text">Show Discussion</span></a>
<a href="#" class="new-post-btn"><span class="new-post-icon"></span>New Post</a>
</div>
<%! from django_comment_client.permissions import has_permission %>
<script type="text/template" id="thread-template">
<article class="discussion-article" data-id="${'<%- id %>'}">
<div class="thread-content-wrapper"></div>
......@@ -7,6 +9,7 @@
<div class="post-status-closed bottom-post-status" style="display: none">
This thread is closed.
</div>
% if course is UNDEFINED or has_permission(user, 'create_comment', course.id):
<form class="discussion-reply-new" data-id="${'<%- id %>'}">
<h4>Post a response:</h4>
<ul class="discussion-errors"></ul>
......@@ -15,6 +18,7 @@
<a class="discussion-submit-post control-button" href="#">Submit</a>
</div>
</form>
% endif
</article>
</script>
......@@ -75,6 +79,7 @@
<div class="discussion-response"></div>
<ol class="comments">
<li class="new-comment response-local">
% if course is UNDEFINED or has_permission(user, 'create_sub_comment', course.id):
<form class="comment-form" data-id="${'<%- wmdId %>'}">
<ul class="discussion-errors"></ul>
<div class="comment-body" data-id="${'<%- wmdId %>'}"
......@@ -83,6 +88,7 @@
<a class="discussion-submit-comment control-button" href="#">Submit</a>
</div>
</form>
% endif
</li>
</ol>
</script>
......
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