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
d0a8027a
Commit
d0a8027a
authored
Aug 27, 2012
by
Tom Giannattasio
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/rocha/wiki-cheatsheet
parents
7b3098ed
7e2e90cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
26 deletions
+144
-26
common/lib/xmodule/xmodule/modulestore/xml.py
+66
-24
lms/djangoapps/lms_migration/management/commands/manage_course_groups.py
+76
-0
lms/envs/dev.py
+2
-2
No files found.
common/lib/xmodule/xmodule/modulestore/xml.py
View file @
d0a8027a
import
hashlib
import
json
import
logging
import
os
...
...
@@ -43,14 +44,76 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
xmlstore: the XMLModuleStore to store the loaded modules in
"""
self
.
unnamed
_modules
=
0
self
.
used_
slugs
=
set
()
self
.
unnamed
=
defaultdict
(
int
)
# category -> num of new url_names for that category
self
.
used_
names
=
defaultdict
(
set
)
# category -> set of used url_names
self
.
org
,
self
.
course
,
self
.
url_name
=
course_id
.
split
(
'/'
)
def
process_xml
(
xml
):
"""Takes an xml string, and returns a XModuleDescriptor created from
that xml.
"""
def
make_name_unique
(
xml_data
):
"""
Make sure that the url_name of xml_data is unique. If a previously loaded
unnamed descriptor stole this element's url_name, create a new one.
Removes 'slug' attribute if present, and adds or overwrites the 'url_name' attribute.
"""
# VS[compat]. Take this out once course conversion is done (perhaps leave the uniqueness check)
attr
=
xml_data
.
attrib
tag
=
xml_data
.
tag
id
=
lambda
x
:
x
# Things to try to get a name, in order (key, cleaning function, remove key after reading?)
lookups
=
[(
'url_name'
,
id
,
False
),
(
'slug'
,
id
,
True
),
(
'name'
,
Location
.
clean
,
False
),
(
'display_name'
,
Location
.
clean
,
False
)]
url_name
=
None
for
key
,
clean
,
remove
in
lookups
:
if
key
in
attr
:
url_name
=
clean
(
attr
[
key
])
if
remove
:
del
attr
[
key
]
break
def
fallback_name
():
"""Return the fallback name for this module. This is a function instead of a variable
because we want it to be lazy."""
# use the hash of the content--the first 12 bytes should be plenty.
return
tag
+
"_"
+
hashlib
.
sha1
(
xml
)
.
hexdigest
()[:
12
]
# Fallback if there was nothing we could use:
if
url_name
is
None
or
url_name
==
""
:
url_name
=
fallback_name
()
# Don't log a warning--we don't need this in the log. Do
# put it in the error tracker--content folks need to see it.
need_uniq_names
=
(
'problem'
,
'sequence'
,
'video'
,
'course'
,
'chapter'
)
if
tag
in
need_uniq_names
:
error_tracker
(
"ERROR: no name of any kind specified for {tag}. Student "
"state won't work right. Problem xml: '{xml}...'"
.
format
(
tag
=
tag
,
xml
=
xml
[:
100
]))
else
:
# TODO (vshnayder): We may want to enable this once course repos are cleaned up.
# (or we may want to give up on the requirement for non-state-relevant issues...)
#error_tracker("WARNING: no name specified for module. xml='{0}...'".format(xml[:100]))
pass
# Make sure everything is unique
if
url_name
in
self
.
used_names
[
tag
]:
msg
=
(
"Non-unique url_name in xml. This may break content. url_name={0}. Content={1}"
.
format
(
url_name
,
xml
[:
100
]))
error_tracker
(
"ERROR: "
+
msg
)
log
.
warning
(
msg
)
# Just set name to fallback_name--if there are multiple things with the same fallback name,
# they are actually identical, so it's fragile, but not immediately broken.
url_name
=
fallback_name
()
self
.
used_names
[
tag
]
.
add
(
url_name
)
xml_data
.
set
(
'url_name'
,
url_name
)
try
:
# VS[compat]
# TODO (cpennington): Remove this once all fall 2012 courses
...
...
@@ -62,32 +125,11 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
err
=
str
(
err
),
xml
=
xml
))
raise
# VS[compat]. Take this out once course conversion is done
if
xml_data
.
get
(
'slug'
)
is
None
and
xml_data
.
get
(
'url_name'
)
is
None
:
if
xml_data
.
get
(
'name'
):
slug
=
Location
.
clean
(
xml_data
.
get
(
'name'
))
elif
xml_data
.
get
(
'display_name'
):
slug
=
Location
.
clean
(
xml_data
.
get
(
'display_name'
))
else
:
self
.
unnamed_modules
+=
1
slug
=
'{tag}_{count}'
.
format
(
tag
=
xml_data
.
tag
,
count
=
self
.
unnamed_modules
)
while
slug
in
self
.
used_slugs
:
self
.
unnamed_modules
+=
1
slug
=
'{slug}_{count}'
.
format
(
slug
=
slug
,
count
=
self
.
unnamed_modules
)
self
.
used_slugs
.
add
(
slug
)
# log.debug('-> slug=%s' % slug)
xml_data
.
set
(
'url_name'
,
slug
)
make_name_unique
(
xml_data
)
descriptor
=
XModuleDescriptor
.
load_from_xml
(
etree
.
tostring
(
xml_data
),
self
,
self
.
org
,
self
.
course
,
xmlstore
.
default_class
)
#log.debug('==> importing descriptor location %s' %
# repr(descriptor.location))
descriptor
.
metadata
[
'data_dir'
]
=
course_dir
xmlstore
.
modules
[
course_id
][
descriptor
.
location
]
=
descriptor
...
...
lms/djangoapps/lms_migration/management/commands/manage_course_groups.py
0 → 100644
View file @
d0a8027a
#!/usr/bin/python
#
# File: manage_course_groups
#
# interactively list and edit membership in course staff and instructor groups
import
os
,
sys
,
string
,
re
import
datetime
from
getpass
import
getpass
import
json
import
readline
from
django.core.management.base
import
BaseCommand
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
Group
#-----------------------------------------------------------------------------
# get all staff groups
class
Command
(
BaseCommand
):
help
=
"Manage course group membership, interactively."
def
handle
(
self
,
*
args
,
**
options
):
gset
=
Group
.
objects
.
all
()
print
"Groups:"
for
cnt
,
g
in
zip
(
range
(
len
(
gset
)),
gset
):
print
"
%
d.
%
s"
%
(
cnt
,
g
)
gnum
=
int
(
raw_input
(
'Choose group to manage (enter #): '
))
group
=
gset
[
gnum
]
#-----------------------------------------------------------------------------
# users in group
uall
=
User
.
objects
.
all
()
if
uall
.
count
()
<
50
:
print
"----"
print
"List of All Users:
%
s"
%
[
str
(
x
.
username
)
for
x
in
uall
]
print
"----"
else
:
print
"----"
print
"There are
%
d users, which is too many to list"
%
uall
.
count
()
print
"----"
while
True
:
print
"Users in the group:"
uset
=
group
.
user_set
.
all
()
for
cnt
,
u
in
zip
(
range
(
len
(
uset
)),
uset
):
print
"
%
d.
%
s"
%
(
cnt
,
u
)
action
=
raw_input
(
'Choose user to delete (enter #) or enter usernames (comma delim) to add: '
)
m
=
re
.
match
(
'^[0-9]+$'
,
action
)
if
m
:
unum
=
int
(
action
)
u
=
uset
[
unum
]
print
"Deleting user
%
s"
%
u
u
.
groups
.
remove
(
group
)
else
:
for
uname
in
action
.
split
(
','
):
try
:
user
=
User
.
objects
.
get
(
username
=
action
)
except
Exception
as
err
:
print
"Error
%
s"
%
err
continue
print
"adding
%
s to group
%
s"
%
(
user
,
group
)
user
.
groups
.
add
(
group
)
lms/envs/dev.py
View file @
d0a8027a
...
...
@@ -15,7 +15,7 @@ TEMPLATE_DEBUG = True
MITX_FEATURES
[
'DISABLE_START_DATES'
]
=
True
MITX_FEATURES
[
'ENABLE_SQL_TRACKING_LOGS'
]
=
True
MITX_FEATURES
[
'SUBDOMAIN_COURSE_LISTINGS'
]
=
True
MITX_FEATURES
[
'SUBDOMAIN_COURSE_LISTINGS'
]
=
False
# Enable to test subdomains--otherwise, want all courses to show up
MITX_FEATURES
[
'SUBDOMAIN_BRANDING'
]
=
True
WIKI_ENABLED
=
True
...
...
@@ -107,7 +107,7 @@ LMS_MIGRATION_ALLOWED_IPS = ['127.0.0.1']
MITX_FEATURES
[
'AUTH_USE_OPENID'
]
=
True
MITX_FEATURES
[
'BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'
]
=
True
INSTALLED_APPS
+=
(
'external_auth'
,)
INSTALLED_APPS
+=
(
'external_auth'
,)
INSTALLED_APPS
+=
(
'django_openid_auth'
,)
OPENID_CREATE_USERS
=
False
...
...
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