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
3808ff85
Commit
3808ff85
authored
Aug 28, 2012
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added django command to generate random serial numbers.
parent
9cf8c02d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
1 deletions
+65
-1
lms/djangoapps/licenses/management/commands/generate_serial_numbers.py
+65
-0
lms/djangoapps/licenses/management/commands/import_serial_numbers.py
+0
-1
No files found.
lms/djangoapps/licenses/management/commands/generate_serial_numbers.py
0 → 100644
View file @
3808ff85
import
os.path
from
uuid
import
uuid4
from
optparse
import
make_option
from
django.utils.html
import
escape
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.django
import
modulestore
from
licenses.models
import
CourseSoftware
,
UserLicense
class
Command
(
BaseCommand
):
help
=
"""Generate random serial numbers for software used in a course.
Usage: generate_serial_numbers <course_id> <software_name> <count>
<count> is the number of numbers to generate.
Example:
import_serial_numbers MITx/6.002x/2012_Fall matlab 100
"""
args
=
"course_id software_id count"
def
handle
(
self
,
*
args
,
**
options
):
"""
"""
course_id
,
software_name
,
count
=
self
.
_parse_arguments
(
args
)
software
,
_
=
CourseSoftware
.
objects
.
get_or_create
(
course_id
=
course_id
,
name
=
software_name
)
self
.
_generate_serials
(
software
,
count
)
def
_parse_arguments
(
self
,
args
):
if
len
(
args
)
!=
3
:
raise
CommandError
(
"Incorrect number of arguments"
)
course_id
=
args
[
0
]
courses
=
modulestore
()
.
get_courses
()
known_course_ids
=
set
(
c
.
id
for
c
in
courses
)
if
course_id
not
in
known_course_ids
:
raise
CommandError
(
"Unknown course_id"
)
software_name
=
escape
(
args
[
1
]
.
lower
())
try
:
count
=
int
(
args
[
2
])
except
ValueError
:
raise
CommandError
(
"Invalid <count> argument."
)
return
course_id
,
software_name
,
count
def
_generate_serials
(
self
,
software
,
count
):
print
"Generating {0} serials"
.
format
(
count
)
# add serial numbers them to the database
for
_
in
xrange
(
count
):
serial
=
str
(
uuid4
())
license
=
UserLicense
(
software
=
software
,
serial
=
serial
)
license
.
save
()
print
"{0} new serial numbers generated."
.
format
(
count
)
lms/djangoapps/licenses/management/commands/import_serial_numbers.py
View file @
3808ff85
import
os.path
from
optparse
import
make_option
from
django.utils.html
import
escape
...
...
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