Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
0b0af599
Commit
0b0af599
authored
Dec 07, 2016
by
Matjaz Gregoric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use django Q objects instead of raw SQL.
parent
c1db1116
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
10 deletions
+6
-10
problem_builder/answer.py
+6
-10
No files found.
problem_builder/answer.py
View file @
0b0af599
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment