Commit 426b44e9 by Matjaz Gregoric Committed by GitHub

Merge pull request #136 from open-craft/mtyaka/extended-course-key-2

Use django Q objects instead of raw SQL query
parents c1db1116 e502a556
......@@ -11,7 +11,7 @@ dependencies:
- "pip install -r requirements.txt"
- "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/base.txt"
- "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/test.txt"
- "pip uninstall -y xblock-problem-builder && python setup.py sdist && pip install dist/xblock-problem-builder-2.6.4.tar.gz"
- "pip uninstall -y xblock-problem-builder && python setup.py sdist && pip install dist/xblock-problem-builder-2.6.5.tar.gz"
- "pip install -r test_requirements.txt"
- "mkdir var"
test:
......
......@@ -25,6 +25,7 @@ from lazy import lazy
from django.core.exceptions import ValidationError
from django.db import IntegrityError
from django.db.models import Q
from django.utils.crypto import get_random_string
from .models import Answer
......@@ -70,16 +71,11 @@ class AnswerMixin(XBlockWithPreviewMixin, XBlockWithTranslationServiceMixin):
@staticmethod
def _fetch_model_object(name, student_id, course_id):
sql_query = '''SELECT * FROM problem_builder_answer
WHERE name = %s
AND student_id = %s
AND (course_key = %s
OR course_id = %s)'''
params = [name, student_id, course_id, course_id]
try:
answer = Answer.objects.raw(sql_query, params)[0]
except IndexError:
raise Answer.DoesNotExist()
answer = Answer.objects.get(
Q(name=name),
Q(student_id=student_id),
Q(course_key=course_id) | Q(course_id=course_id)
)
if not answer.course_key:
answer.course_key = answer.course_id
return answer
......
......@@ -71,7 +71,7 @@ BLOCKS = [
setup(
name='xblock-problem-builder',
version='2.6.4',
version='2.6.5',
description='XBlock - Problem Builder',
packages=['problem_builder', 'problem_builder.v1'],
install_requires=[
......
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