Skip to content

Commit

Permalink
Merge pull request #25 from edx/ri/EDUCATOR-3030-donot-submit-complet…
Browse files Browse the repository at this point in the history
…ion-grader-response

EDUCATOR-3030 don't submit completion for grader's response while updating problem score.
  • Loading branch information
Rabia23 authored Aug 29, 2018
2 parents cf259f7 + 383ca8a commit 685b4fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from __future__ import unicode_literals


__version__ = '0.1.8'
__version__ = '0.1.9'

default_app_config = 'completion.apps.CompletionAppConfig' # pylint: disable=invalid-name
13 changes: 7 additions & 6 deletions completion/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def scorable_block_completion(sender, **kwargs): # pylint: disable=unused-argum
completion = 0.0
else:
completion = 1.0
BlockCompletion.objects.submit_completion(
user=user,
course_key=course_key,
block_key=block_key,
completion=completion,
)
if not kwargs.get('grader_response'):
BlockCompletion.objects.submit_completion(
user=user,
course_key=course_key,
block_key=block_key,
completion=completion,
)
37 changes: 12 additions & 25 deletions completion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models, IntegrityError, transaction
from django.db import models, transaction
from django.utils.translation import ugettext as _

from model_utils.models import TimeStampedModel
Expand Down Expand Up @@ -91,37 +91,24 @@ def submit_completion(self, user, course_key, block_key, completion):
raise ValueError(
"block_key must be an instance of `opaque_keys.edx.keys.UsageKey`. Got {}".format(type(block_key))
)

if waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
is_new = False
kwargs = {
"user": user,
"course_key": course_key,
"block_type": block_type,
"block_key": block_key
}
try:
obj, is_new = self.get_or_create( # pylint: disable=unpacking-non-sequence
defaults={'completion': completion},
**kwargs
)
except IntegrityError:
# log information for duplicate entry and get the record as above command failed.
log.exception(
'block_completion: IntegrityError for student %s - '
'course_id %s - block_type %s - block_key %s',
user, course_key, block_type, block_key
)
obj = self.get(**kwargs)

obj, is_new = self.get_or_create( # pylint: disable=unpacking-non-sequence
user=user,
course_key=course_key,
block_type=block_type,
block_key=block_key,
defaults={'completion': completion},
)
if not is_new and obj.completion != completion:
obj.completion = completion
obj.full_clean()
obj.save()
else:
# If the feature is not enabled, this method should not be called. Error out with a RuntimeError.
# If the feature is not enabled, this method should not be called.
# Error out with a RuntimeError.
raise RuntimeError(
"BlockCompletion.objects.submit_completion should not be called when the feature is disabled."
"BlockCompletion.objects.submit_completion should not be \
called when the feature is disabled."
)
return obj, is_new

Expand Down

0 comments on commit 685b4fd

Please sign in to comment.