Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
630f482c
Commit
630f482c
authored
Nov 03, 2017
by
Hasnain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WL-1295 | Added management command to create the sites and their partners.
parent
c2cbe4a6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
course_discovery/apps/core/management/commands/create_partners_and_sites.py
+89
-0
No files found.
course_discovery/apps/core/management/commands/create_partners_and_sites.py
0 → 100644
View file @
630f482c
""" Creates sites and partners """
import
logging
from
django.contrib.sites.models
import
Site
from
django.core.management
import
BaseCommand
from
course_discovery.apps.core.models
import
Partner
logger
=
logging
.
getLogger
(
__name__
)
SITES
=
{
"mitxpro"
:
{
"partner_code"
:
"mitxpro"
,
"site"
:
"mitxpro"
},
"hms"
:
{
"partner_code"
:
"hms"
,
"site"
:
"hms"
},
"wharton"
:
{
"partner_code"
:
"wharton"
,
"site"
:
"wharton"
},
"harvardx"
:
{
"partner_code"
:
"harvardx"
,
"site"
:
"harvardx"
},
}
class
Command
(
BaseCommand
):
help
=
'Create new sites and associated Partners.'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--dns-name'
,
action
=
'store'
,
type
=
str
,
dest
=
'dns_name'
,
required
=
True
,
help
=
'DNS name of sandbox.'
,
)
def
handle
(
self
,
*
args
,
**
options
):
""" Creates or updates a Partner record. """
dns_name
=
options
[
'dns_name'
]
for
_
,
site_data
in
SITES
.
items
():
site
=
site_data
[
'site'
]
logger
.
info
(
"dns_name: {dns_name}"
.
format
(
dns_name
=
dns_name
))
site_obj
,
created
=
Site
.
objects
.
get_or_create
(
domain
=
"{domain}-{dns_name}.sandbox.edx.org"
.
format
(
domain
=
site
,
dns_name
=
dns_name
),
defaults
=
{
"name"
:
site
}
)
studio_url
=
"https://studio-{dns_name}.sandbox.edx.org"
.
format
(
dns_name
=
dns_name
)
oidc_url_root
=
"https://{site}-{dns_name}.sandbox.edx.org/oauth2"
.
format
(
site
=
site
,
dns_name
=
dns_name
)
oidc_key
=
"{dns_name}-discovery-key"
.
format
(
dns_name
=
dns_name
)
oidc_secret
=
"{dns_name}-discovery-secret"
.
format
(
dns_name
=
dns_name
)
courses_api_url
=
"https://{site}-{dns_name}.sandbox.edx.org/api/courses/v1/"
.
format
(
site
=
site
,
dns_name
=
dns_name
)
ecommerce_api_url
=
"https://ecommerce-{site}-{dns_name}.sandbox.edx.org/"
.
format
(
site
=
site
,
dns_name
=
dns_name
)
organizations_api_url
=
"https://{site}-{dns_name}.sandbox.edx.org/api/organizations/v0/"
.
format
(
site
=
site
,
dns_name
=
dns_name
)
__
,
created
=
Partner
.
objects
.
update_or_create
(
short_code
=
site_data
[
'partner_code'
],
defaults
=
{
'site'
:
site_obj
,
'name'
:
site_data
[
'partner_code'
],
'oidc_key'
:
oidc_key
,
'studio_url'
:
studio_url
,
'oidc_secret'
:
oidc_secret
,
'oidc_url_root'
:
oidc_url_root
,
'courses_api_url'
:
courses_api_url
,
'ecommerce_api_url'
:
ecommerce_api_url
,
'organizations_api_url'
:
organizations_api_url
}
)
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