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
0ed80426
Commit
0ed80426
authored
Nov 06, 2017
by
Troy Sankey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
django_comment_client management command cleanup for Django 1.11
parent
61793775
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
87 additions
and
76 deletions
+87
-76
lms/djangoapps/django_comment_client/management/commands/assign_role.py
+18
-17
lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py
+12
-11
lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
+7
-9
lms/djangoapps/django_comment_client/management/commands/get_discussion_link.py
+6
-6
lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
+15
-7
lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
+9
-9
lms/djangoapps/django_comment_client/management/commands/show_permissions.py
+19
-16
lms/djangoapps/django_comment_client/management/commands/sync_user_info.py
+1
-1
No files found.
lms/djangoapps/django_comment_client/management/commands/assign_role.py
View file @
0ed80426
from
optparse
import
make_op
tion
from
__future__
import
print_func
tion
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
django_comment_common.models
import
Role
from
django_comment_common.models
import
Role
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
option_list
=
BaseCommand
.
option_list
+
(
help
=
'Assign a discussion forum role to a user.'
make_option
(
'--remove'
,
action
=
'store_true'
,
def
add_arguments
(
self
,
parser
):
dest
=
'remove'
,
parser
.
add_argument
(
'name_or_email'
,
default
=
False
,
help
=
'username or email address of the user to assign a role'
)
help
=
'Remove the role instead of adding it'
),
parser
.
add_argument
(
'role'
,
)
help
=
'the role to which the user will be assigned'
)
parser
.
add_argument
(
'course_id'
,
args
=
'<user|email> <role> <course_id>'
help
=
'the edx course_id'
)
help
=
'Assign a discussion forum role to a user '
parser
.
add_argument
(
'--remove'
,
action
=
'store_true'
,
help
=
'remove the role instead of adding/assigning it'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
3
:
name_or_email
=
options
[
'name_or_email'
]
raise
CommandError
(
'Usage is assign_role {0}'
.
format
(
self
.
args
))
role
=
options
[
'role'
]
course_id
=
options
[
'course_id'
]
name_or_email
,
role
,
course_id
=
args
role
=
Role
.
objects
.
get
(
name
=
role
,
course_id
=
course_id
)
role
=
Role
.
objects
.
get
(
name
=
role
,
course_id
=
course_id
)
...
@@ -36,4 +37,4 @@ class Command(BaseCommand):
...
@@ -36,4 +37,4 @@ class Command(BaseCommand):
else
:
else
:
user
.
roles
.
add
(
role
)
user
.
roles
.
add
(
role
)
print
'Success!'
print
(
'Success!'
)
lms/djangoapps/django_comment_client/management/commands/assign_roles_for_course.py
View file @
0ed80426
...
@@ -4,26 +4,27 @@ This must be run only after seed_permissions_roles.py!
...
@@ -4,26 +4,27 @@ This must be run only after seed_permissions_roles.py!
Creates default roles for all users in the provided course. Just runs through
Creates default roles for all users in the provided course. Just runs through
Enrollments.
Enrollments.
"""
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
__future__
import
print_function
from
django.core.management.base
import
BaseCommand
from
django_comment_common.models
import
assign_default_role_on_enrollment
from
django_comment_common.models
import
assign_default_role_on_enrollment
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
'course_id'
help
=
'Add roles for all users in a course.'
help
=
'Add roles for all users in a course'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'course_id'
,
help
=
'the edx course_id'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
==
0
:
course_id
=
options
[
'course_id'
]
raise
CommandError
(
"Please provide a course id"
)
if
len
(
args
)
>
1
:
raise
CommandError
(
"Too many arguments"
)
course_id
=
args
[
0
]
print
"Updated roles for "
,
print
(
'Updated roles for '
,
end
=
' '
)
for
i
,
enrollment
in
enumerate
(
CourseEnrollment
.
objects
.
filter
(
course_id
=
course_id
,
is_active
=
1
),
start
=
1
):
for
i
,
enrollment
in
enumerate
(
CourseEnrollment
.
objects
.
filter
(
course_id
=
course_id
,
is_active
=
1
),
start
=
1
):
assign_default_role_on_enrollment
(
None
,
enrollment
)
assign_default_role_on_enrollment
(
None
,
enrollment
)
if
i
%
1000
==
0
:
if
i
%
1000
==
0
:
print
"{0}..."
.
format
(
i
),
print
(
'{0}...'
.
format
(
i
),
end
=
' '
)
print
print
()
lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
View file @
0ed80426
...
@@ -4,23 +4,21 @@ This must be run only after seed_permissions_roles.py!
...
@@ -4,23 +4,21 @@ This must be run only after seed_permissions_roles.py!
Creates default roles for all users currently in the database. Just runs through
Creates default roles for all users currently in the database. Just runs through
Enrollments.
Enrollments.
"""
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
__future__
import
print_function
from
django.core.management.base
import
BaseCommand
from
django_comment_common.models
import
assign_default_role_on_enrollment
from
django_comment_common.models
import
assign_default_role_on_enrollment
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
'course_id'
help
=
'Seed default permisssions and roles.'
help
=
'Seed default permisssions and roles'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
0
:
print
(
"Updated roles for "
,
end
=
' '
)
raise
CommandError
(
"This Command takes no arguments"
)
print
"Updated roles for "
,
for
i
,
enrollment
in
enumerate
(
CourseEnrollment
.
objects
.
filter
(
is_active
=
1
),
start
=
1
):
for
i
,
enrollment
in
enumerate
(
CourseEnrollment
.
objects
.
filter
(
is_active
=
1
),
start
=
1
):
assign_default_role_on_enrollment
(
None
,
enrollment
)
assign_default_role_on_enrollment
(
None
,
enrollment
)
if
i
%
1000
==
0
:
if
i
%
1000
==
0
:
print
"{0}..."
.
format
(
i
),
print
(
'{0}...'
.
format
(
i
),
end
=
' '
)
print
print
()
lms/djangoapps/django_comment_client/management/commands/get_discussion_link.py
View file @
0ed80426
...
@@ -5,14 +5,14 @@ from courseware.courses import get_course
...
@@ -5,14 +5,14 @@ from courseware.courses import get_course
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
"<course_id>"
help
=
"Write a discussion link for a given course on standard output."
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'course_id'
,
help
=
'course for which to write a discussion link'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
not
args
:
course_id
=
options
[
'course_id'
]
raise
CommandError
(
"Course id not specified"
)
if
len
(
args
)
>
1
:
raise
CommandError
(
"Only one course id may be specifiied"
)
course_id
=
args
[
0
]
course_key
=
CourseKey
.
from_string
(
course_id
)
course_key
=
CourseKey
.
from_string
(
course_id
)
...
...
lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
View file @
0ed80426
"""
"""
Reload forum (comment client) users from existing users.
Reload forum (comment client) users from existing users.
"""
"""
from
__future__
import
print_function
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
...
@@ -8,21 +10,27 @@ import lms.lib.comment_client as cc
...
@@ -8,21 +10,27 @@ import lms.lib.comment_client as cc
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
'Reload forum (comment client) users from existing users'
help
=
'Reload forum (comment client) users from existing users.'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'usernames'
,
nargs
=
'*'
,
metavar
=
'username'
,
help
=
'zero or more usernames (zero implies all users)'
)
def
adduser
(
self
,
user
):
def
adduser
(
self
,
user
):
print
user
print
(
user
)
try
:
try
:
cc_user
=
cc
.
User
.
from_django_user
(
user
)
cc_user
=
cc
.
User
.
from_django_user
(
user
)
cc_user
.
save
()
cc_user
.
save
()
except
Exception
as
err
:
except
Exception
as
err
:
print
"update user info to discussion failed for user with id:
%
s, error=
%
s"
%
(
user
,
str
(
err
))
print
(
'update user info to discussion failed for user with id: {}, error={}'
.
format
(
user
,
str
(
err
)
))
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
0
:
if
len
(
options
[
'usernames'
])
>=
1
:
use
t
=
[
User
.
objects
.
get
(
username
=
x
)
for
x
in
args
]
use
r_list
=
User
.
objects
.
filter
(
username__in
=
options
[
'usernames'
])
else
:
else
:
uset
=
User
.
objects
.
all
()
use
r_lis
t
=
User
.
objects
.
all
()
for
user
in
uset
:
for
user
in
use
r_lis
t
:
self
.
adduser
(
user
)
self
.
adduser
(
user
)
lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
View file @
0ed80426
"""
"""
Management command to seed default permissions and roles.
Management command to seed default permissions and roles.
"""
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys.edx.keys
import
CourseKey
from
django_comment_common.utils
import
seed_permissions_roles
from
django_comment_common.utils
import
seed_permissions_roles
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
'course_id'
help
=
'Seed default permisssions and roles.'
help
=
'Seed default permisssions and roles'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'course_id'
,
help
=
'the edx course_id'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
==
0
:
course_id
=
options
[
'course_id'
]
raise
CommandError
(
"Please provide a course id"
)
if
len
(
args
)
>
1
:
raise
CommandError
(
"Too many arguments"
)
course_id
=
CourseKey
.
from_string
(
args
[
0
])
seed_permissions_roles
(
course_id
)
course_key
=
CourseKey
.
from_string
(
course_id
)
seed_permissions_roles
(
course_key
)
lms/djangoapps/django_comment_client/management/commands/show_permissions.py
View file @
0ed80426
from
__future__
import
print_function
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
'user'
help
=
"Show a user's roles and permissions."
help
=
"Show a user's roles and permissions"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'email_or_username'
,
help
=
'the email or username of the user'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
print
args
email_or_username
=
options
[
'email_or_username'
]
if
len
(
args
)
!=
1
:
raise
CommandError
(
"The number of arguments does not match. "
)
try
:
try
:
if
'@'
in
args
[
0
]
:
if
'@'
in
email_or_username
:
user
=
User
.
objects
.
get
(
email
=
args
[
0
]
)
user
=
User
.
objects
.
get
(
email
=
email_or_username
)
else
:
else
:
user
=
User
.
objects
.
get
(
username
=
args
[
0
]
)
user
=
User
.
objects
.
get
(
username
=
email_or_username
)
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
print
"User
%
s does not exist. "
%
args
[
0
]
print
(
'User {} does not exist. '
.
format
(
email_or_username
))
print
"Available users: "
print
(
'Available users: '
)
print
User
.
objects
.
all
(
)
print
(
User
.
objects
.
all
()
)
return
return
roles
=
user
.
roles
.
all
()
roles
=
user
.
roles
.
all
()
print
"
%
s has
%
d roles:"
%
(
user
,
len
(
roles
))
print
(
'{} has
%
d roles:'
.
format
(
user
,
len
(
roles
)
))
for
role
in
roles
:
for
role
in
roles
:
print
"
\t
%
s"
%
role
print
(
'
\t
{}'
.
format
(
role
))
for
role
in
roles
:
for
role
in
roles
:
print
"
%
s has permissions: "
%
role
print
(
'{} has permissions: '
.
format
(
role
))
print
role
.
permissions
.
all
(
)
print
(
role
.
permissions
.
all
()
)
lms/djangoapps/django_comment_client/management/commands/sync_user_info.py
View file @
0ed80426
...
@@ -13,7 +13,7 @@ class Command(BaseCommand):
...
@@ -13,7 +13,7 @@ class Command(BaseCommand):
"""
"""
Management command for adding all users to the discussion service.
Management command for adding all users to the discussion service.
"""
"""
help
=
'Sync all user ids, usernames, and emails to the discussion service'
help
=
'Sync all user ids, usernames, and emails to the discussion service
.
'
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
for
user
in
User
.
objects
.
all
()
.
iterator
():
for
user
in
User
.
objects
.
all
()
.
iterator
():
...
...
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