Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
355d4be7
Commit
355d4be7
authored
Nov 20, 2014
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it so that CSV-cert generation passes back file-like objs instead of strings.
parent
12a599b0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
9 deletions
+30
-9
lms/djangoapps/certificates/queue.py
+11
-3
lms/djangoapps/instructor/views/api.py
+12
-2
lms/djangoapps/instructor_task/models.py
+7
-4
No files found.
lms/djangoapps/certificates/queue.py
View file @
355d4be7
...
...
@@ -125,7 +125,7 @@ class XQueueCertInterface(object):
raise
NotImplementedError
def
add_cert
(
self
,
student
,
course_id
,
course
=
None
,
forced_grade
=
None
,
template_file
=
None
,
title
=
'None'
):
def
add_cert
(
self
,
student
,
course_id
,
course
=
None
,
forced_grade
=
None
,
template_file
=
None
,
title
=
'None'
,
forced_percentage_grade
=
None
):
"""
Request a new certificate for a student.
...
...
@@ -135,7 +135,9 @@ class XQueueCertInterface(object):
forced_grade - a string indicating a grade parameter to pass with
the certificate request. If this is given, grading
will be skipped.
forced_percentage_grade - Value between 0 and 1 that is the overall
percentage grade that the student got for
this course.
Will change the certificate status to 'generating'.
Certificate must be in the 'unavailable', 'error',
...
...
@@ -179,7 +181,13 @@ class XQueueCertInterface(object):
course_name
=
course
.
display_name
or
course_id
.
to_deprecated_string
()
is_whitelisted
=
self
.
whitelist
.
filter
(
user
=
student
,
course_id
=
course_id
,
whitelist
=
True
)
.
exists
()
grade
=
grades
.
grade
(
student
,
self
.
request
,
course
)
if
forced_percentage_grade
is
None
:
grade
=
grades
.
grade
(
student
,
self
.
request
,
course
)
else
:
grade
=
dict
(
percent
=
forced_percentage_grade
,
grade
=
grades
.
grade_for_percentage
(
course
.
grade_cutoffs
,
forced_percentage_grade
)
)
enrollment_mode
,
__
=
CourseEnrollment
.
enrollment_mode_for_user
(
student
,
course_id
)
mode_is_verified
=
(
enrollment_mode
==
GeneratedCertificate
.
MODES
.
verified
)
user_is_verified
=
SoftwareSecurePhotoVerification
.
user_is_verified
(
student
)
...
...
lms/djangoapps/instructor/views/api.py
View file @
355d4be7
...
...
@@ -86,6 +86,8 @@ from opaque_keys.edx.keys import CourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys
import
InvalidKeyError
from
student.models
import
UserProfile
,
Registration
from
certificates.queue
import
XQueueCertInterface
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -1599,8 +1601,16 @@ def calculate_grades_csv(request, course_id):
def
_generate_certificates_from_grades_csv_task
(
course_id
,
filename
):
"""Assume this will be run async later."""
report_store
=
ReportStore
.
from_config
()
grades_csv
=
report_store
.
get_as_string
(
CourseKey
.
from_string
(
course_id
),
filename
)
print
grades_csv
course_key
=
CourseKey
.
from_string
(
course_id
)
grades_csv
=
report_store
.
get
(
course_key
,
filename
)
course
=
get_course_by_id
(
course_key
,
depth
=
2
)
csv_reader
=
csv
.
DictReader
(
grades_csv
)
xq
=
XQueueCertInterface
()
for
row
in
csv_reader
:
student
=
User
.
objects
.
get
(
username
=
row
[
'username'
])
percentage_grade
=
float
(
row
[
'grade'
])
xq
.
add_cert
(
student
,
course_key
,
course
=
course
,
forced_percentage_grade
=
percentage_grade
)
@ensure_csrf_cookie
...
...
lms/djangoapps/instructor_task/models.py
View file @
355d4be7
...
...
@@ -274,9 +274,12 @@ class S3ReportStore(ReportStore):
return
key
def
get
_as_string
(
self
,
course_id
,
filename
):
def
get
(
self
,
course_id
,
filename
):
key
=
self
.
key_for
(
course_id
,
filename
)
return
key
.
get_contents_as_string
()
buff
=
StringIO
()
key
.
get_contents_to_file
(
buff
)
buff
.
seek
(
0
)
return
GzipFile
(
fileobj
=
buff
)
def
store
(
self
,
course_id
,
filename
,
buff
):
"""
...
...
@@ -377,10 +380,10 @@ class LocalFSReportStore(ReportStore):
"""Return the full path to a given file for a given course."""
return
os
.
path
.
join
(
self
.
root_path
,
urllib
.
quote
(
course_id
.
to_deprecated_string
(),
safe
=
''
),
filename
)
def
get
_as_string
(
self
,
course_id
,
filename
):
def
get
(
self
,
course_id
,
filename
):
full_path
=
self
.
path_to
(
course_id
,
filename
)
with
open
(
full_path
,
"rb"
)
as
report_file
:
return
report_file
.
read
(
)
return
StringIO
(
report_file
.
read
()
)
def
store
(
self
,
course_id
,
filename
,
buff
):
"""
...
...
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