Commit 0aa31a05 by Chris Dodge

update models

parent 278cf650
...@@ -14,6 +14,9 @@ class Migration(SchemaMigration): ...@@ -14,6 +14,9 @@ class Migration(SchemaMigration):
('course_id', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)), ('course_id', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
('content_id', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)), ('content_id', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
('external_id', self.gf('django.db.models.fields.TextField')(null=True, db_index=True)), ('external_id', self.gf('django.db.models.fields.TextField')(null=True, db_index=True)),
('time_limit_mins', self.gf('django.db.models.fields.IntegerField')()),
('is_proctored', self.gf('django.db.models.fields.BooleanField')(default=False)),
('is_active', self.gf('django.db.models.fields.BooleanField')(default=False)),
)) ))
db.send_create_signal('edx_proctoring', ['ProctoredExam']) db.send_create_signal('edx_proctoring', ['ProctoredExam'])
...@@ -73,7 +76,10 @@ class Migration(SchemaMigration): ...@@ -73,7 +76,10 @@ class Migration(SchemaMigration):
'content_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), 'content_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), 'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'external_id': ('django.db.models.fields.TextField', [], {'null': 'True', 'db_index': 'True'}), 'external_id': ('django.db.models.fields.TextField', [], {'null': 'True', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_proctored': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'time_limit_mins': ('django.db.models.fields.IntegerField', [], {})
}, },
'edx_proctoring.proctoredexamstudentallowance': { 'edx_proctoring.proctoredexamstudentallowance': {
'Meta': {'object_name': 'ProctoredExamStudentAllowance'}, 'Meta': {'object_name': 'ProctoredExamStudentAllowance'},
......
...@@ -21,6 +21,15 @@ class ProctoredExam(models.Model): ...@@ -21,6 +21,15 @@ class ProctoredExam(models.Model):
# This will be a integration specific ID - say to SoftwareSecure. # This will be a integration specific ID - say to SoftwareSecure.
external_id = models.TextField(null=True, db_index=True) external_id = models.TextField(null=True, db_index=True)
# Time limit (in minutes) that a student can finish this exam
time_limit_mins = models.IntegerField()
# Whether this exam actually is proctored or not
is_proctored = models.BooleanField()
# This will be a integration specific ID - say to SoftwareSecure.
is_active = models.BooleanField()
class ProctoredExamStudentAttempt(models.Model): class ProctoredExamStudentAttempt(models.Model):
""" """
...@@ -92,22 +101,25 @@ class ProctoredExamStudentAllowanceHistory(TimeStampedModel): ...@@ -92,22 +101,25 @@ class ProctoredExamStudentAllowanceHistory(TimeStampedModel):
# Hook up the custom POST_UPDATE_SIGNAL signal to record updations in the ProctoredExamStudentAllowanceHistory table. # Hook up the custom POST_UPDATE_SIGNAL signal to record updations in the ProctoredExamStudentAllowanceHistory table.
@receiver(post_save, sender=ProctoredExamStudentAllowance) @receiver(post_save, sender=ProctoredExamStudentAllowance)
def archive_allowance_updations(sender, **kwargs): # pylint: disable=unused-argument def archive_allowance_updations(sender, instance, created, **kwargs): # pylint: disable=unused-argument
""" """
Archiving all changes made to the Student Allowance. Archiving all changes made to the Student Allowance.
Will only archive on update, and not on new entries created. Will only archive on update, and not on new entries created.
""" """
_make_archive_copy(kwargs['instance']) if not created:
_make_archive_copy(instance)
def _make_archive_copy(updated_obj): def _make_archive_copy(item):
""" """
Make a clone and populate in the History table Make a clone and populate in the History table
""" """
archive_object = ProctoredExamStudentAllowanceHistory() archive_object = ProctoredExamStudentAllowanceHistory(
updated_obj_dict = updated_obj.__dict__ user_id=item.user_id,
updated_obj_dict.pop('id') proctored_exam=item.proctored_exam,
archive_object.__dict__.update(updated_obj_dict) key=item.key,
value=item.value
)
archive_object.save() archive_object.save()
...@@ -28,7 +28,8 @@ class ProctoredExamModelTests(LoggedInTestCase): ...@@ -28,7 +28,8 @@ class ProctoredExamModelTests(LoggedInTestCase):
proctored_exam = ProctoredExam.objects.create( proctored_exam = ProctoredExam.objects.create(
course_id='test_course', course_id='test_course',
content_id='test_content', content_id='test_content',
external_id='123aXqe3' external_id='123aXqe3',
time_limit_mins=90
) )
ProctoredExamStudentAllowance.objects.create( ProctoredExamStudentAllowance.objects.create(
user_id=1, user_id=1,
...@@ -38,7 +39,7 @@ class ProctoredExamModelTests(LoggedInTestCase): ...@@ -38,7 +39,7 @@ class ProctoredExamModelTests(LoggedInTestCase):
) )
# No entry in the History table on creation of the Allowance entry. # No entry in the History table on creation of the Allowance entry.
proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1) proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1)
self.assertEqual(len(proctored_exam_student_history), 1) self.assertEqual(len(proctored_exam_student_history), 0)
# Update the allowance object twice # Update the allowance object twice
ProctoredExamStudentAllowance.objects.filter( ProctoredExamStudentAllowance.objects.filter(
...@@ -63,7 +64,7 @@ class ProctoredExamModelTests(LoggedInTestCase): ...@@ -63,7 +64,7 @@ class ProctoredExamModelTests(LoggedInTestCase):
# 2 new entries are created in the History table. # 2 new entries are created in the History table.
proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1) proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1)
self.assertEqual(len(proctored_exam_student_history), 3) self.assertEqual(len(proctored_exam_student_history), 2)
# also check with save() method # also check with save() method
...@@ -72,4 +73,4 @@ class ProctoredExamModelTests(LoggedInTestCase): ...@@ -72,4 +73,4 @@ class ProctoredExamModelTests(LoggedInTestCase):
allowance.save() allowance.save()
proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1) proctored_exam_student_history = ProctoredExamStudentAllowanceHistory.objects.filter(user_id=1)
self.assertEqual(len(proctored_exam_student_history), 4) self.assertEqual(len(proctored_exam_student_history), 3)
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