Add Assignment.submittable attribute to configure student submission.
authorW. Trevor King <wking@tremily.us>
Tue, 24 Apr 2012 20:48:56 +0000 (16:48 -0400)
committerW. Trevor King <wking@tremily.us>
Tue, 24 Apr 2012 20:48:56 +0000 (16:48 -0400)
If `Assignment.submittable` is `True`, mailpipe will accept student
submissions for that assignment.  However, there may also be
assignments where you don't want to accept direct submissions
(e.g. attendance and written, in-class exams).  For these assignments,
you should leave the `submittable` option at its default `False`
value.

Note that `mailpipe` doesn't use this value yet (implementation coming
soon).

pygrader/model/assignment.py
pygrader/storage.py
pygrader/test/course.py
test/course.conf

index 4b3a6fb83b93080899c1a72a2c45d46d989b1335..7a8e990ccca82d8cb78453f12dd8b690a1e199cc 100644 (file)
 # pygrader.  If not, see <http://www.gnu.org/licenses/>.
 
 class Assignment (object):
-    def __init__(self, name, points=1, weight=0, due=0):
+    def __init__(self, name, points=1, weight=0, due=0, submittable=True):
         self.name = name
         self.points = points
         self.weight = weight
         self.due = due
+        self.submittable = submittable
 
     def __str__(self):
         return '<{} {}>'.format(type(self).__name__, self.name)
index 2b1e185083821131fab99e4c811ed00b56de3a08..28ffd9cb942a7f491b5baeeb29f704fa81aa2582 100644 (file)
@@ -174,6 +174,46 @@ def parse_date(string):
         ret -= offset
     return ret
 
+def parse_boolean(value):
+    """Convert a boolean string into ``True`` or ``False``.
+
+    Supports the same values as ``RawConfigParser``
+
+    >>> parse_boolean('YES')
+    True
+    >>> parse_boolean('Yes')
+    True
+    >>> parse_boolean('tRuE')
+    True
+    >>> parse_boolean('False')
+    False
+    >>> parse_boolean('FALSE')
+    False
+    >>> parse_boolean('no')
+    False
+    >>> parse_boolean('none')
+    Traceback (most recent call last):
+      ...
+    ValueError: Not a boolean: none
+    >>> parse_boolean('')  # doctest: +NORMALIZE_WHITESPACE
+    Traceback (most recent call last):
+      ...
+    ValueError: Not a boolean:
+
+    It passes through boolean inputs without modification (so you
+    don't have to use strings for default values):
+
+    >>> parse_boolean({}.get('my-option', True))
+    True
+    >>> parse_boolean({}.get('my-option', False))
+    False
+    """
+    if value in [True, False]:
+        return value
+    # Using an underscored method is hackish, but it should be fairly stable.
+    p = _configparser.RawConfigParser()
+    return p._convert_to_boolean(value)
+
 def load_assignment(name, data):
     r"""Load an assignment from a ``dict``
 
@@ -183,9 +223,11 @@ def load_assignment(name, data):
     ...     data={'points': '1',
     ...           'weight': '0.1/2',
     ...           'due': '2011-10-04T00:00-04:00',
+    ...           'submittable': 'yes',
     ...           })
-    >>> print('{0.name} (points: {0.points}, weight: {0.weight}, due: {0.due})'.format(a))
-    Attendance 1 (points: 1, weight: 0.05, due: 1317700800)
+    >>> print(('{0.name} (points: {0.points}, weight: {0.weight}, '
+    ...        'due: {0.due}, submittable: {0.submittable})').format(a))
+    Attendance 1 (points: 1, weight: 0.05, due: 1317700800, submittable: True)
     >>> print(formatdate(a.due, localtime=True))
     Tue, 04 Oct 2011 00:00:00 -0400
     """
@@ -197,7 +239,10 @@ def load_assignment(name, data):
         assert len(wterms) == 2, wterms
         weight = float(wterms[0])/float(wterms[1])
     due = parse_date(data['due'])
-    return _Assignment(name=name, points=points, weight=weight, due=due)
+    submittable = parse_boolean(data.get('submittable', False))
+    return _Assignment(
+        name=name, points=points, weight=weight, due=due,
+        submittable=submittable)
 
 def load_person(name, data={}):
     r"""Load a person from a ``dict``
index 1c6e7800c05bc86697afa8387e842ddafb699ef7..1d8e3a9b4b0430930e7828ab39191382cbc4e4e7 100644 (file)
@@ -68,11 +68,13 @@ due: 2011-10-15
 points: 10
 weight: 0.4/2
 due: 2011-10-10
+submittable: yes
 
 [Assignment 2]
 points: 1
 weight: 0.4/2
 due: 2011-10-17
+submittable: yes
 
 [Exam 1]
 points: 10
index 375de456e29104cd975d2702c16b3db6de276cfa..7fd41e3a4ce5fc044073141f2111aab5e680e01c 100644 (file)
@@ -57,11 +57,13 @@ due: 2011-10-15
 points: 10
 weight: 0.4/2
 due: 2011-10-10
+submittable: yes
 
 [Assignment 2]
 points: 1
 weight: 0.4/2
 due: 2011-10-17
+submittable: yes
 
 [Exam 1]
 points: 10