From 80639ff31b3bc6780659f526d518526cf63fcaec Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 24 Apr 2012 16:48:56 -0400 Subject: [PATCH] Add Assignment.submittable attribute to configure student submission. 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 | 3 ++- pygrader/storage.py | 51 +++++++++++++++++++++++++++++++++--- pygrader/test/course.py | 2 ++ test/course.conf | 2 ++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/pygrader/model/assignment.py b/pygrader/model/assignment.py index 4b3a6fb..7a8e990 100644 --- a/pygrader/model/assignment.py +++ b/pygrader/model/assignment.py @@ -15,11 +15,12 @@ # pygrader. If not, see . 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) diff --git a/pygrader/storage.py b/pygrader/storage.py index 2b1e185..28ffd9c 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -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`` diff --git a/pygrader/test/course.py b/pygrader/test/course.py index 1c6e780..1d8e3a9 100644 --- a/pygrader/test/course.py +++ b/pygrader/test/course.py @@ -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 diff --git a/test/course.conf b/test/course.conf index 375de45..7fd41e3 100644 --- a/test/course.conf +++ b/test/course.conf @@ -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 -- 2.26.2