diff --git a/completion/models.py b/completion/models.py index 777d469..7cdfe05 100644 --- a/completion/models.py +++ b/completion/models.py @@ -14,12 +14,17 @@ from model_utils.models import TimeStampedModel +from eventtracking import tracker + from . import waffle log = logging.getLogger(__name__) User = auth.get_user_model() +BLOCK_COMPLETION_CHANGED_EVENT_TYPE = 'edx.completion.block_completion.changed' + + def validate_percent(value): """ Verify that the passed value is between 0.0 and 1.0. @@ -126,6 +131,31 @@ def submit_completion(self, user, block_key, completion): "BlockCompletion.objects.submit_completion should not be \ called when the feature is disabled." ) + """ + id = BigAutoField(primary_key=True) # pylint: disable=invalid-name + user = models.ForeignKey(User, on_delete=models.CASCADE) + context_key = LearningContextKeyField(max_length=255, db_column="course_key") + + # note: this usage key may not have the run filled in for + # old mongo courses. Use the full_block_key property + # instead when you want to use/compare the usage_key. + block_key = UsageKeyField(max_length=255) + block_type = models.CharField(max_length=64) + completion = models.FloatField(validators=[validate_percent]) + """ + tracker.emit( + str(BLOCK_COMPLETION_CHANGED_EVENT_TYPE), + { + 'user_id': user.id, + 'course_id': str(block_key.course_key), + 'context_key': str(context_key), + 'block_key': str(block_key), + 'block_type': block_type, + 'completion': completion, + 'is_new': is_new, + } + ) + return obj, is_new @transaction.atomic()