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
21832bb9
Commit
21832bb9
authored
Jul 09, 2015
by
arbabnazar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify the whitelist cert script to take list of users
parent
cd60dd56
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
13 deletions
+28
-13
lms/djangoapps/certificates/management/commands/cert_whitelist.py
+28
-13
No files found.
lms/djangoapps/certificates/management/commands/cert_whitelist.py
View file @
21832bb9
...
@@ -12,6 +12,18 @@ from certificates.models import CertificateWhitelist
...
@@ -12,6 +12,18 @@ from certificates.models import CertificateWhitelist
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
def
get_user_from_identifier
(
identifier
):
"""
This function takes the string identifier and fetch relevant user object from database
"""
identifier
=
identifier
.
strip
()
if
'@'
in
identifier
:
user
=
User
.
objects
.
get
(
email
=
identifier
)
else
:
user
=
User
.
objects
.
get
(
username
=
identifier
)
return
user
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
"""
help
=
"""
...
@@ -57,6 +69,17 @@ class Command(BaseCommand):
...
@@ -57,6 +69,17 @@ class Command(BaseCommand):
if
not
course_id
:
if
not
course_id
:
raise
CommandError
(
"You must specify a course-id"
)
raise
CommandError
(
"You must specify a course-id"
)
def
update_user_whitelist
(
username
,
add
=
True
):
"""
Update the status of whitelist user(s)
"""
user
=
get_user_from_identifier
(
username
)
cert_whitelist
,
_created
=
CertificateWhitelist
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course
)
cert_whitelist
.
whitelist
=
add
cert_whitelist
.
save
()
# try to parse the serialized course key into a CourseKey
# try to parse the serialized course key into a CourseKey
try
:
try
:
course
=
CourseKey
.
from_string
(
course_id
)
course
=
CourseKey
.
from_string
(
course_id
)
...
@@ -69,19 +92,11 @@ class Command(BaseCommand):
...
@@ -69,19 +92,11 @@ class Command(BaseCommand):
if
options
[
'add'
]
or
options
[
'del'
]:
if
options
[
'add'
]
or
options
[
'del'
]:
user_str
=
options
[
'add'
]
or
options
[
'del'
]
user_str
=
options
[
'add'
]
or
options
[
'del'
]
if
'@'
in
user_str
:
add_to_whitelist
=
True
if
options
[
'add'
]
else
False
user
=
User
.
objects
.
get
(
email
=
user_str
)
users_list
=
user_str
.
split
(
","
)
else
:
for
username
in
users_list
:
user
=
User
.
objects
.
get
(
username
=
user_str
)
if
username
.
strip
():
update_user_whitelist
(
username
,
add
=
add_to_whitelist
)
cert_whitelist
,
_created
=
\
CertificateWhitelist
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course
)
if
options
[
'add'
]:
cert_whitelist
.
whitelist
=
True
elif
options
[
'del'
]:
cert_whitelist
.
whitelist
=
False
cert_whitelist
.
save
()
whitelist
=
CertificateWhitelist
.
objects
.
filter
(
course_id
=
course
)
whitelist
=
CertificateWhitelist
.
objects
.
filter
(
course_id
=
course
)
wl_users
=
'
\n
'
.
join
(
wl_users
=
'
\n
'
.
join
(
...
...
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