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
84af54b2
Commit
84af54b2
authored
Jul 28, 2015
by
Arbab Nazar
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8848 from edx/arbab/cert-whitelist-mod
modify the whitelist cert script to take list of users
parents
bee837be
21832bb9
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 @
84af54b2
...
...
@@ -12,6 +12,18 @@ from certificates.models import CertificateWhitelist
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
):
help
=
"""
...
...
@@ -57,6 +69,17 @@ class Command(BaseCommand):
if
not
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
:
course
=
CourseKey
.
from_string
(
course_id
)
...
...
@@ -69,19 +92,11 @@ class Command(BaseCommand):
if
options
[
'add'
]
or
options
[
'del'
]:
user_str
=
options
[
'add'
]
or
options
[
'del'
]
if
'@'
in
user_str
:
user
=
User
.
objects
.
get
(
email
=
user_str
)
else
:
user
=
User
.
objects
.
get
(
username
=
user_str
)
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
()
add_to_whitelist
=
True
if
options
[
'add'
]
else
False
users_list
=
user_str
.
split
(
","
)
for
username
in
users_list
:
if
username
.
strip
():
update_user_whitelist
(
username
,
add
=
add_to_whitelist
)
whitelist
=
CertificateWhitelist
.
objects
.
filter
(
course_id
=
course
)
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