Add Course.name attribute (for clearer email generation).
authorW. Trevor King <wking@tremily.us>
Tue, 24 Apr 2012 18:33:28 +0000 (14:33 -0400)
committerW. Trevor King <wking@tremily.us>
Tue, 24 Apr 2012 18:33:28 +0000 (14:33 -0400)
pygrader/model/course.py
pygrader/storage.py
pygrader/test/course.py
test/course.conf

index f66493ae163f9ee1993ff693504f1c7bb7f727e8..652592ff0c072d232bc3da5b6c1c501616fc22bd 100644 (file)
@@ -18,7 +18,8 @@ from .. import LOG as _LOG
 
 
 class Course (object):
-    def __init__(self, assignments=None, people=None, grades=None):
+    def __init__(self, name=None, assignments=None, people=None, grades=None):
+        self.name = name
         if assignments is None:
             assignments = []
         self.assignments = sorted(assignments)
index db02f20d23b6af2b7c1f477523d9f5649d5cd9a1..7bc9a17d8bde544275b4ffacf6d2734c2c21a427 100644 (file)
@@ -39,9 +39,24 @@ _DATE_REGEXP = _re.compile('^([^T]*)(T?)([^TZ+-.]*)([.]?[0-9]*)([+-][0-9:]*|Z?)$
 
 
 def load_course(basedir):
+    """Load a course directory.
+
+    >>> from pygrader.test.course import StubCourse
+    >>> stub_course = StubCourse(load=False)
+    >>> course = load_course(basedir=stub_course.basedir)
+    >>> course.name
+    'phys101'
+    >>> course.assignments  # doctest: +ELLIPSIS
+    [<pygrader.model.assignment.Assignment object at 0x...>, ...]
+    >>> course.people  # doctest: +ELLIPSIS
+    [<pygrader.model.person.Person object at 0x...>, ...]
+    >>> course.grades
+    []
+    """
     _LOG.debug('loading course from {}'.format(basedir))
     config = _configparser.ConfigParser()
     config.read([_os_path.join(basedir, 'course.conf')])
+    name = config.get('course', 'name')
     names = {}
     for option in ['assignments', 'professors', 'assistants', 'students']:
         names[option] = [
@@ -66,7 +81,8 @@ def load_course(basedir):
                 people[person].groups = [group]
     people = people.values()
     grades = list(load_grades(basedir, assignments, people))
-    return _Course(assignments=assignments, people=people, grades=grades)
+    return _Course(
+        name=name, assignments=assignments, people=people, grades=grades)
 
 def parse_date(string):
     """Parse dates given using the W3C DTF profile of ISO 8601.
index 98da5594409437af0ca2f9c6f68533ad96ede96a..2f1379fd1cf829192605644f5e913b2defbd15f7 100644 (file)
@@ -10,6 +10,7 @@ from pygrader.storage import load_course as _load_course
 
 COURSE_CONF = """
 [course]
+name: phys101
 assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4,
   Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9,
   Assignment 1, Assignment 2, Exam 1, Exam 2
@@ -113,14 +114,15 @@ class StubCourse (object):
     course.conf
     >>> course.cleanup()
     """
-    def __init__(self):
+    def __init__(self, load=True):
         self.basedir = _tempfile.mkdtemp(prefix='pygrader-tmp-')
         try:
             self.mailbox = _os_path.join(self.basedir, 'mail')
             course_conf = _os_path.join(self.basedir, 'course.conf')
             with open(course_conf, 'w') as f:
                 f.write(COURSE_CONF)
-            self.course = _load_course(basedir=self.basedir)
+            if load:
+                self.course = _load_course(basedir=self.basedir)
         except Exception:
             self.cleanup()
 
index 744e96c10bc2013c235a5b44ba4d3d167bc2a9ed..93999ca9c33b321501e4d39d94af5276fc11c00e 100644 (file)
@@ -1,4 +1,5 @@
 [course]
+name: phys101
 assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4,
   Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9,
   Assignment 1, Assignment 2, Exam 1, Exam 2