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
3f9b1ef7
Commit
3f9b1ef7
authored
Jun 20, 2014
by
Justin Riley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add course_id arg and dry run and csv file options
Massive code clean-up as well.
parent
549b985e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
49 deletions
+53
-49
lms/djangoapps/courseware/management/commands/reset_3091_exam_attempts.py
+53
-49
No files found.
lms/djangoapps/courseware/management/commands/reset_3091_exam_attempts.py
View file @
3f9b1ef7
#!/usr/bin/python
#
# 19-Sep-13 ichuang@mit.edu
import
csv
from
courseware.module_tree_reset
import
*
from
django.core.management.base
import
BaseCommand
#-----------------------------------------------------------------------------
from
request_cache.middleware
import
RequestCache
from
xmodule.modulestore.django
import
modulestore
from
courseware.module_tree_reset
import
ProctorModuleInfo
from
django.conf
import
settings
from
xmodule.modulestore.django
import
modulestore
from
django.dispatch
import
Signal
from
request_cache.middleware
import
RequestCache
from
django.core.cache
import
get_cache
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
,
make_option
if
True
:
CACHE
=
get_cache
(
'mongo_metadata_inheritance'
)
for
store_name
in
settings
.
MODULESTORE
:
store
=
modulestore
(
store_name
)
store
.
metadata_inheritance_cache_subsystem
=
CACHE
store
.
request_cache
=
RequestCache
.
get_request_cache
()
modulestore_update_signal
=
Signal
(
providing_args
=
[
'modulestore'
,
'course_id'
,
'location'
])
store
.
modulestore_update_signal
=
modulestore_update_signal
CACHE
=
get_cache
(
'mongo_metadata_inheritance'
)
for
store_name
in
settings
.
MODULESTORE
:
store
=
modulestore
(
store_name
)
store
.
metadata_inheritance_cache_subsystem
=
CACHE
store
.
request_cache
=
RequestCache
.
get_request_cache
()
modulestore_update_signal
=
Signal
(
providing_args
=
[
'modulestore'
,
'course_id'
,
'location'
])
store
.
modulestore_update_signal
=
modulestore_update_signal
#-----------------------------------------------------------------------------
class
Command
(
BaseCommand
):
help
=
"""Reset exam attempts for 3.091 exam, Fall 2013.
Records students and problems which were reset.
Give filename as argument. Output is CSV file."""
args
=
"<course_id>"
help
=
"""Reset exam attempts for 3.091 exam, Fall 2013. Records students
\
and problems which were reset. Takes a course id and csv output filename as
\
arguments."""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--dry-run'
,
dest
=
'dry_run'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Show what would be done without actually doing '
'anything'
),
make_option
(
'--csv-output-filename'
,
dest
=
'csv_output_filename'
,
action
=
'store'
,
default
=
None
,
help
=
'Save stats to csv file'
),
)
def
handle
(
self
,
*
args
,
**
options
):
# fn = 'reset_3091exam.csv'
fn
=
args
[
0
]
pminfo
=
ProctorModuleInfo
()
students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
pminfo
.
course
.
id
)
.
order_by
(
'username'
)
# students = User.objects.filter(username='ichuang')
data
=
[]
# write out to csv file
fieldnames
=
[
'id'
,
'name'
,
'username'
,
'assignment'
,
'problem'
,
'date'
,
'earned'
,
'possible'
]
fp
=
open
(
fn
,
'w'
)
csvf
=
csv
.
DictWriter
(
fp
,
fieldnames
,
dialect
=
"excel"
,
quotechar
=
'"'
,
quoting
=
csv
.
QUOTE_ALL
)
csvf
.
writeheader
()
cnt
=
0
if
len
(
args
)
!=
1
:
raise
CommandError
(
"insufficient arguments"
)
course_id
=
args
[
0
]
dry_run
=
options
[
'dry_run'
]
csv_file
=
options
[
'csv_output_filename'
]
pminfo
=
ProctorModuleInfo
(
course_id
)
students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
pminfo
.
course
.
id
)
.
order_by
(
'username'
)
failed
=
[]
for
student
in
students
:
dat
=
pminfo
.
get_assignments_attempted_and_failed
(
student
,
do_reset
=
True
)
data
+=
dat
for
row
in
dat
:
csvf
.
writerow
(
row
)
fp
.
flush
()
cnt
+=
1
#if cnt>3:
# break
failed
+=
pminfo
.
get_assignments_attempted_and_failed
(
student
,
do_reset
=
not
dry_run
)
if
csv_file
:
self
.
write_to_csv
(
csv_file
,
failed
)
def
write_to_csv
(
self
,
file_name
,
failed_assignments
):
fieldnames
=
[
'id'
,
'name'
,
'username'
,
'assignment'
,
'problem'
,
'date'
,
'earned'
,
'possible'
]
fp
=
open
(
file_name
,
'w'
)
csvf
=
csv
.
DictWriter
(
fp
,
fieldnames
,
dialect
=
"excel"
,
quotechar
=
'"'
,
quoting
=
csv
.
QUOTE_ALL
)
csvf
.
writeheader
()
for
assignment
in
failed_assignments
:
csvf
.
writerow
(
assignment
)
fp
.
close
()
# print data
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