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
ed88708d
Commit
ed88708d
authored
Aug 21, 2012
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed models and commands for importing serial numbers.
parent
24d5c916
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
32 deletions
+25
-32
lms/djangoapps/licenses/management/commands/import_serial_numbers.py
+18
-26
lms/djangoapps/licenses/models.py
+7
-6
No files found.
lms/djangoapps/licenses/management/commands/import_serials.py
→
lms/djangoapps/licenses/management/commands/import_serial
_number
s.py
View file @
ed88708d
...
...
@@ -7,20 +7,18 @@ from django.core.management.base import BaseCommand, CommandError
from
xmodule.modulestore.django
import
modulestore
from
licenses.models
import
Software
,
StudentLicense
from
licenses.models
import
CourseSoftware
,
UserLicense
class
Command
(
BaseCommand
):
help
=
"""Imports serial numbers for software used in a course.
Usage: import_serial
s course_id software_id serial_file
Usage: import_serial
_numbers <course_id> <software_name> <filename>
serial_file is a text file that list one available serial number per line.
Example:
import_serials.py
MITx/6.002x/2012_Fall matlab /tmp/matlab-serials.txt
django-admin.py import_serial_numbers
MITx/6.002x/2012_Fall matlab /tmp/matlab-serials.txt
"""
args
=
"course_id software_id serial_file"
def
handle
(
self
,
*
args
,
**
options
):
...
...
@@ -28,8 +26,8 @@ class Command(BaseCommand):
"""
course_id
,
software_name
,
filename
=
self
.
_parse_arguments
(
args
)
software
=
self
.
_find_software
(
course_id
,
software_name
)
software
,
_
=
CourseSoftware
.
objects
.
get_or_create
(
course_id
=
course_id
,
name
=
software_name
)
self
.
_import_serials
(
software
,
filename
)
def
_parse_arguments
(
self
,
args
):
...
...
@@ -51,27 +49,21 @@ class Command(BaseCommand):
return
course_id
,
software_name
,
filename
def
_find_software
(
self
,
course_id
,
software_name
):
try
:
software
=
Software
.
objects
.
get
(
course_id
=
course_id
,
name
=
software_name
)
except
Software
.
DoesNotExist
:
software
=
Software
(
name
=
software_name
,
course_id
=
course_id
)
software
.
save
()
return
software
def
_import_serials
(
self
,
software
,
filename
):
print
"Importing serial numbers for {0} {1}"
.
format
(
software
.
name
,
software
.
course_id
)
print
"Importing serial numbers for {0}."
.
format
(
software
)
serials
=
set
(
unicode
(
l
.
strip
())
for
l
in
open
(
filename
))
known_serials
=
set
(
l
.
serial
for
l
in
StudentLicense
.
objects
.
filter
(
software
=
software
))
# remove serial numbers we already have
licenses
=
UserLicense
.
objects
.
filter
(
software
=
software
)
known_serials
=
set
(
l
.
serial
for
l
in
licenses
)
if
known_serials
:
serials
=
serials
.
difference
(
known_serials
)
count
=
0
serials
=
list
(
l
.
strip
()
for
l
in
open
(
filename
))
for
s
in
serials
:
if
s
not
in
known_serials
:
license
=
StudentLicense
(
software
=
software
,
serial
=
s
)
license
.
save
()
count
+=
1
# add serial numbers them to the database
for
serial
in
serials
:
license
=
UserLicense
(
software
=
software
,
serial
=
serial
)
license
.
save
()
print
"{0} new serial numbers imported."
.
format
(
count
)
print
"{0} new serial numbers imported."
.
format
(
len
(
serials
)
)
lms/djangoapps/licenses/models.py
View file @
ed88708d
"""
"""
from
django.db
import
models
from
student.models
import
User
class
Software
(
models
.
Model
):
class
Course
Software
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
full_name
=
models
.
CharField
(
max_length
=
255
)
url
=
models
.
CharField
(
max_length
=
255
)
course_id
=
models
.
CharField
(
max_length
=
255
)
def
__unicode__
(
self
):
return
u'{0} for {1}'
.
format
(
self
.
name
,
self
.
course_id
)
class
StudentLicense
(
models
.
Model
):
software
=
models
.
ForeignKey
(
Software
,
db_index
=
True
)
class
UserLicense
(
models
.
Model
):
software
=
models
.
ForeignKey
(
CourseSoftware
,
db_index
=
True
)
user
=
models
.
ForeignKey
(
User
,
null
=
True
)
serial
=
models
.
CharField
(
max_length
=
255
)
user
=
models
.
ForeignKey
(
User
,
null
=
True
,
blank
=
True
)
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