275
213
notes = Unicode()
280
return Store.of(self).find(ProjectGroup,
281
ProjectSet.offering_id == self.offering.id,
282
ProjectGroup.project_set_id == ProjectSet.id,
283
ProjectGroupMembership.project_group_id == ProjectGroup.id,
284
ProjectGroupMembership.user_id == self.user.id)
286
__init__ = _kwarg_init
289
return "<%s %r in %r>" % (type(self).__name__, self.user,
292
class AlreadyEnrolledError(Exception):
297
class ProjectSet(Storm):
298
__storm_table__ = "project_set"
300
id = Int(name="projectsetid", primary=True)
301
offering_id = Int(name="offeringid")
302
offering = Reference(offering_id, Offering.id)
303
max_students_per_group = Int()
305
projects = ReferenceSet(id, 'Project.project_set_id')
306
project_groups = ReferenceSet(id, 'ProjectGroup.project_set_id')
308
__init__ = _kwarg_init
311
return "<%s %d in %r>" % (type(self).__name__, self.id,
314
class Project(Storm):
315
__storm_table__ = "project"
317
id = Int(name="projectid", primary=True)
320
project_set_id = Int(name="projectsetid")
321
project_set = Reference(project_set_id, ProjectSet.id)
322
deadline = DateTime()
324
__init__ = _kwarg_init
327
return "<%s '%s' in %r>" % (type(self).__name__, self.synopsis,
328
self.project_set.offering)
330
class ProjectGroup(Storm):
331
__storm_table__ = "project_group"
333
id = Int(name="groupid", primary=True)
334
name = Unicode(name="groupnm")
335
project_set_id = Int(name="projectsetid")
336
project_set = Reference(project_set_id, ProjectSet.id)
338
created_by_id = Int(name="createdby")
339
created_by = Reference(created_by_id, User.id)
342
members = ReferenceSet(id,
343
"ProjectGroupMembership.project_group_id",
344
"ProjectGroupMembership.user_id",
347
__init__ = _kwarg_init
350
return "<%s %s in %r>" % (type(self).__name__, self.name,
351
self.project_set.offering)
353
class ProjectGroupMembership(Storm):
354
__storm_table__ = "group_member"
355
__storm_primary__ = "user_id", "project_group_id"
357
user_id = Int(name="loginid")
358
user = Reference(user_id, User.id)
359
project_group_id = Int(name="groupid")
360
project_group = Reference(project_group_id, ProjectGroup.id)
362
__init__ = _kwarg_init
365
return "<%s %r in %r>" % (type(self).__name__, self.user,
368
# WORKSHEETS AND EXERCISES #
370
class Exercise(Storm):
371
# Note: Table "problem" is called "Exercise" in the Object layer, since
372
# it's called that everywhere else.
373
__storm_table__ = "problem"
375
id = Int(primary=True, name="problemid")
376
name = Unicode(name="identifier")
379
worksheets = ReferenceSet(id,
380
'WorksheetExercise.exercise_id',
381
'WorksheetExercise.worksheet_id',
385
__init__ = _kwarg_init
388
return "<%s %s>" % (type(self).__name__, self.name)
391
def get_by_name(cls, store, name):
393
Get the Exercise from the db associated with a given store and name.
394
If the exercise is not in the database, creates it and inserts it
397
ex = store.find(cls, cls.name == unicode(name)).one()
400
ex = Exercise(name=unicode(name))
405
class Worksheet(Storm):
406
__storm_table__ = "worksheet"
408
id = Int(primary=True, name="worksheetid")
409
# XXX subject is not linked to a Subject object. This is a property of
410
# the database, and will be refactored.
412
name = Unicode(name="identifier")
416
exercises = ReferenceSet(id,
417
'WorksheetExercise.worksheet_id',
418
'WorksheetExercise.exercise_id',
420
# Use worksheet_exercises to get access to the WorksheetExercise objects
421
# binding worksheets to exercises. This is required to access the
423
worksheet_exercises = ReferenceSet(id,
424
'WorksheetExercise.worksheet_id')
426
__init__ = _kwarg_init
429
return "<%s %s>" % (type(self).__name__, self.name)
431
# XXX Refactor this - make it an instance method of Subject rather than a
432
# class method of Worksheet. Can't do that now because Subject isn't
433
# linked referentially to the Worksheet.
435
def get_by_name(cls, store, subjectname, worksheetname):
437
Get the Worksheet from the db associated with a given store, subject
438
name and worksheet name.
440
return store.find(cls, cls.subject == unicode(subjectname),
441
cls.name == unicode(worksheetname)).one()
443
def remove_all_exercises(self, store):
445
Remove all exercises from this worksheet.
446
This does not delete the exercises themselves. It just removes them
449
store.find(WorksheetExercise,
450
WorksheetExercise.worksheet == self).remove()
452
class WorksheetExercise(Storm):
453
__storm_table__ = "worksheet_problem"
454
__storm_primary__ = "worksheet_id", "exercise_id"
456
worksheet_id = Int(name="worksheetid")
457
worksheet = Reference(worksheet_id, Worksheet.id)
458
exercise_id = Int(name="problemid")
459
exercise = Reference(exercise_id, Exercise.id)
462
__init__ = _kwarg_init
465
return "<%s %s in %s>" % (type(self).__name__, self.exercise.name,
468
class ExerciseSave(Storm):
470
Represents a potential solution to an exercise that a user has submitted
471
to the server for storage.
472
A basic ExerciseSave is just the current saved text for this exercise for
473
this user (doesn't count towards their attempts).
474
ExerciseSave may be extended with additional semantics (such as
477
__storm_table__ = "problem_save"
478
__storm_primary__ = "exercise_id", "user_id", "date"
480
exercise_id = Int(name="problemid")
481
exercise = Reference(exercise_id, Exercise.id)
482
user_id = Int(name="loginid")
483
user = Reference(user_id, User.id)
487
__init__ = _kwarg_init
490
return "<%s %s by %s at %s>" % (type(self).__name__,
491
self.exercise.name, self.user.login, self.date.strftime("%c"))
493
class ExerciseAttempt(ExerciseSave):
495
An ExerciseAttempt is a special case of an ExerciseSave. Like an
496
ExerciseSave, it constitutes exercise solution data that the user has
497
submitted to the server for storage.
498
In addition, it contains additional information about the submission.
499
complete - True if this submission was successful, rendering this exercise
500
complete for this user.
501
active - True if this submission is "active" (usually true). Submissions
502
may be de-activated by privileged users for special reasons, and then
503
they won't count (either as a penalty or success), but will still be
506
__storm_table__ = "problem_attempt"
507
__storm_primary__ = "exercise_id", "user_id", "date"
509
# The "text" field is the same but has a different name in the DB table
511
text = Unicode(name="attempt")
216
__init__ = _kwarg_init
219
return "<%s %r in %r>" % (type(self).__name__, self.user,