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
ee7a8494
Commit
ee7a8494
authored
Nov 19, 2012
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish basic implementation of forum admin on instructor dash
parent
8b1b6300
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
39 deletions
+73
-39
lms/djangoapps/django_comment_client/models.py
+1
-1
lms/djangoapps/instructor/views.py
+64
-30
lms/templates/courseware/instructor_dashboard.html
+8
-8
No files found.
lms/djangoapps/django_comment_client/models.py
View file @
ee7a8494
...
...
@@ -15,7 +15,7 @@ class Role(models.Model):
def
inherit_permissions
(
self
,
role
):
# TODO the name of this method is a little bit confusing,
# since it's one-off and doesn't handle inheritance later
if
role
.
course_id
and
role
.
course_id
!=
self
.
course_id
:
logging
.
warning
(
"
%
s cannot inher
e
t permissions from
%
s due to course_id inconsistency"
%
logging
.
warning
(
"
%
s cannot inher
i
t permissions from
%
s due to course_id inconsistency"
%
(
self
,
role
))
for
per
in
role
.
permissions
.
all
():
self
.
add_permission
(
per
)
...
...
lms/djangoapps/instructor/views.py
View file @
ee7a8494
...
...
@@ -43,6 +43,11 @@ log = logging.getLogger("mitx.courseware")
template_imports
=
{
'urllib'
:
urllib
}
FORUM_ROLE_ADMINISTRATOR
=
'Administrator'
FORUM_ROLE_MODERATOR
=
'Moderator'
FORUM_ROLE_COMMUNITY_TA
=
'Community TA'
FORUM_ROLE_ADD
=
'add'
FORUM_ROLE_REMOVE
=
'remove'
@ensure_csrf_cookie
@cache_control
(
no_cache
=
True
,
no_store
=
True
,
must_revalidate
=
True
)
...
...
@@ -208,9 +213,8 @@ def instructor_dashboard(request, course_id):
#----------------------------------------
# forum administration
elif
action
==
'List course forum administrators'
:
rolename
=
'Administrator'
rolename
=
FORUM_ROLE_ADMINISTRATOR
datatable
=
{}
msg
+=
_list_course_forum_members
(
course_id
,
rolename
,
datatable
)
track
.
views
.
server_track
(
request
,
'list-
%
s'
%
rolename
,
{},
page
=
'idashboard'
)
...
...
@@ -218,50 +222,50 @@ def instructor_dashboard(request, course_id):
elif
action
==
'Remove forum admin'
:
uname
=
request
.
POST
[
'forumadmin'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Administrator'
,
'remove'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'remove'
,
uname
,
'Administrator'
,
course_id
),
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_ADMINISTRATOR
,
FORUM_ROLE_REMOVE
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_REMOVE
,
uname
,
FORUM_ROLE_ADMINISTRATOR
,
course_id
),
{},
page
=
'idashboard'
)
elif
action
==
'Add forum admin'
:
uname
=
request
.
POST
[
'forumadmin'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Administrator'
,
'add'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'add'
,
uname
,
'Administrator'
,
course_id
),
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_ADMINISTRATOR
,
FORUM_ROLE_ADD
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_ADD
,
uname
,
FORUM_ROLE_ADMINISTRATOR
,
course_id
),
{},
page
=
'idashboard'
)
elif
action
==
'List course forum moderators'
:
rolename
=
'Moderator'
rolename
=
FORUM_ROLE_MODERATOR
datatable
=
{}
msg
+=
_list_course_forum_members
(
course_id
,
rolename
,
datatable
)
track
.
views
.
server_track
(
request
,
'list-
%
s'
%
rolename
,
{},
page
=
'idashboard'
)
elif
action
==
'Remove forum moderator'
:
uname
=
request
.
POST
[
'forummoderator'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Moderator'
,
'remove'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'remove'
,
uname
,
'Moderator'
,
course_id
),
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_MODERATOR
,
FORUM_ROLE_REMOVE
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_REMOVE
,
uname
,
FORUM_ROLE_MODERATOR
,
course_id
),
{},
page
=
'idashboard'
)
elif
action
==
'Add forum moderator'
:
uname
=
request
.
POST
[
'forummoderator'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Moderator'
,
'add'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'add'
,
uname
,
'Moderator'
,
course_id
),
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_MODERATOR
,
FORUM_ROLE_ADD
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_ADD
,
uname
,
FORUM_ROLE_MODERATOR
,
course_id
),
{},
page
=
'idashboard'
)
elif
action
==
'List course forum community TAs'
:
rolename
=
'Community TA'
rolename
=
FORUM_ROLE_COMMUNITY_TA
datatable
=
{}
msg
+=
_list_course_forum_members
(
course_id
,
rolename
,
datatable
)
track
.
views
.
server_track
(
request
,
'list-
%
s'
%
rolename
,
{},
page
=
'idashboard'
)
elif
action
==
'Remove forum community TA'
:
uname
=
request
.
POST
[
'forum
communityta
'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Community TA'
,
'remove'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'remove'
,
uname
,
'Community TA'
,
course_id
),
uname
=
request
.
POST
[
'forum
moderator
'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_COMMUNITY_TA
,
FORUM_ROLE_REMOVE
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_REMOVE
,
uname
,
FORUM_ROLE_COMMUNITY_TA
,
course_id
),
{},
page
=
'idashboard'
)
elif
action
==
'Add forum community TA'
:
uname
=
request
.
POST
[
'forum
communityta
'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
'Community TA'
,
'add'
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
'add'
,
uname
,
'Community TA'
,
course_id
),
uname
=
request
.
POST
[
'forum
moderator
'
]
msg
+=
_update_forum_role_membership
(
uname
,
course_id
,
FORUM_ROLE_COMMUNITY_TA
,
FORUM_ROLE_ADD
)
track
.
views
.
server_track
(
request
,
'
%
s
%
s as
%
s for
%
s'
%
(
FORUM_ROLE_ADD
,
uname
,
FORUM_ROLE_COMMUNITY_TA
,
course_id
),
{},
page
=
'idashboard'
)
#----------------------------------------
...
...
@@ -296,39 +300,69 @@ def instructor_dashboard(request, course_id):
return
render_to_response
(
'courseware/instructor_dashboard.html'
,
context
)
def
_list_course_forum_members
(
course_id
,
rolename
,
datatable
):
''' TODO
'''
Fills in datatable with forum membership information, for a given role,
so that it will be displayed on instructor dashboard.
course_ID = course's ID string
rolename = one of "Administrator", "Moderator", "Community TA"
Returns message status string to append to displayed message, if role is unknown.
'''
# make sure datatable is set up properly for display first, before checking for errors
datatable
[
'header'
]
=
[
'Username'
,
'Full name'
,
'Roles'
]
datatable
[
'title'
]
=
'List of Forum
%
ss in course
%
s'
%
(
rolename
,
course_id
)
datatable
[
'data'
]
=
[];
try
:
role
=
Role
.
objects
.
get
(
name
=
rolename
,
course_id
=
course_id
)
uset
=
role
.
users
.
all
()
except
Role
.
DoesNotExist
:
return
'<font color="red">Error: unknown rolename "
%
s"</font>'
%
rolename
uset
=
role
.
users
.
all
()
.
order_by
(
'username'
)
msg
=
'Role =
%
s'
%
rolename
log
.
debug
(
'role=
%
s'
%
rolename
)
datatable
[
'header'
]
=
[
'Username'
,
'Full name'
,
'Roles'
]
datatable
[
'data'
]
=
[[
x
.
username
,
x
.
profile
.
name
,
', '
.
join
([
r
.
name
for
r
in
x
.
roles
.
all
()])]
for
x
in
uset
]
datatable
[
'title'
]
=
'List of Forum
%
s in course
%
s'
%
(
rolename
,
course_id
)
datatable
[
'data'
]
=
[[
x
.
username
,
x
.
profile
.
name
,
', '
.
join
([
r
.
name
for
r
in
x
.
roles
.
filter
(
course_id
=
course_id
)
.
order_by
(
'name'
)])]
for
x
in
uset
]
return
msg
def
_update_forum_role_membership
(
uname
,
course_id
,
rolename
,
add_or_remove
):
'''
Supports adding a user to a course's forum role
uname = username string for user
course_ID = course's ID string
rolename = one of "Administrator", "Moderator", "Community TA"
add_or_remove = one of "add" or "remove"
returns message status to append to displayed message
Returns message status string to append to displayed message, Status is returned if user
or role is unknown, or if entry already exists when adding, or if entry doesn't exist when removing.
'''
msg
=
''
# check that username and rolename are valid:
try
:
user
=
User
.
objects
.
get
(
username
=
uname
)
except
User
.
DoesNotExist
:
return
'<font color="red">Error: unknown username "
%
s"</font>'
%
uname
if
user
is
not
None
:
try
:
role
=
Role
.
objects
.
get
(
name
=
rolename
,
course_id
=
course_id
)
except
Role
.
DoesNotExist
:
return
'<font color="red">Error: unknown rolename "
%
s"</font>'
%
rolename
# check whether role already has the specified user:
alreadyexists
=
role
.
users
.
filter
(
username
=
uname
)
.
exists
()
msg
=
''
log
.
debug
(
'rolename=
%
s'
%
rolename
)
if
(
add_or_remove
==
'remove'
):
if
(
add_or_remove
==
FORUM_ROLE_REMOVE
):
if
(
not
alreadyexists
):
msg
=
'<font color="red">Error: user
%
s does not have rolename "
%
s", cannot remove</font>'
%
(
uname
,
rolename
)
else
:
user
.
roles
.
remove
(
role
)
msg
+=
'<font color="green">Removed
%
s from
%
s forum role =
%
s</font>'
%
(
user
,
course_id
,
rolename
)
msg
=
'<font color="green">Removed
%
s from
%
s forum role =
%
s</font>'
%
(
user
,
course_id
,
rolename
)
else
:
if
(
alreadyexists
):
msg
=
'<font color="red">Error: user
%
s already has rolename "
%
s", cannot add</font>'
%
(
uname
,
rolename
)
else
:
user
.
roles
.
add
(
role
)
msg
+=
'<font color="green">Added
%
s to
%
s forum role =
%
s</font>'
%
(
user
,
course_id
,
rolename
)
msg
=
'<font color="green">Added
%
s to
%
s forum role =
%
s</font>'
%
(
user
,
course_id
,
rolename
)
return
msg
...
...
lms/templates/courseware/instructor_dashboard.html
View file @
ee7a8494
...
...
@@ -56,8 +56,8 @@ function goto( mode)
%if settings.MITX_FEATURES.get('ENABLE_PSYCHOMETRICS'):
<a
href=
"#"
onclick=
"goto('Psychometrics');"
class=
"${modeflag.get('Psychometrics')}"
>
Psychometrics
</a>
|
%endif
<a
href=
"#"
onclick=
"goto('Admin');"
class=
"${modeflag.get('Admin')}"
>
Admin
</a>
]
<a
href=
"#"
onclick=
"goto('Forum Admin');"
class=
"${modeflag.get('Admin')}"
>
Forum Admin
</a>
]
<a
href=
"#"
onclick=
"goto('Admin');"
class=
"${modeflag.get('Admin')}"
>
Admin
</a>
|
<a
href=
"#"
onclick=
"goto('Forum Admin');"
class=
"${modeflag.get('
Forum
Admin')}"
>
Forum Admin
</a>
]
</h2>
<div
style=
"text-align:right"
id=
"djangopid"
>
${djangopid}
</div>
...
...
@@ -150,16 +150,16 @@ function goto( mode)
%if instructor_access or forum_admin_access:
<p>
<input
type=
"submit"
name=
"action"
value=
"List course forum moderators"
>
<p>
<input
type=
"text"
name=
"forummoderator"
>
<input
type=
"submit"
name=
"action"
value=
"Remove forum moderator"
>
<input
type=
"submit"
name=
"action"
value=
"Add forum moderator"
>
<hr
width=
"40%"
style=
"align:left"
>
<p>
<input
type=
"submit"
name=
"action"
value=
"List course forum community TAs"
>
<p>
<input
type=
"text"
name=
"forumcommunityta"
>
<input
type=
"submit"
name=
"action"
value=
"Remove forum community TA"
>
<input
type=
"text"
name=
"forummoderator"
>
<input
type=
"submit"
name=
"action"
value=
"Remove forum moderator"
>
<input
type=
"submit"
name=
"action"
value=
"Add forum moderator"
>
<input
type=
"submit"
name=
"action"
value=
"Remove forum community TA"
>
<input
type=
"submit"
name=
"action"
value=
"Add forum community TA"
>
<hr
width=
"40%"
style=
"align:left"
>
%else:
<p>
User requires forum administrator privileges to perform administration tasks. See instructor.
</p>
%endif
%endif
...
...
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