Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
983eab0a
Commit
983eab0a
authored
Aug 11, 2016
by
Saleem Latif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Management Command for adding Site and SiteThemes
parent
d5863143
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
192 additions
and
1 deletions
+192
-1
docs/theming.rst
+44
-0
ecommerce/theming/management/commands/create_or_update_site_theme.py
+68
-0
ecommerce/theming/management/commands/tests/__init__.py
+0
-0
ecommerce/theming/management/commands/tests/test_create_or_update_site_theme.py
+79
-0
ecommerce/theming/management/commands/tests/test_update_assets.py
+1
-1
No files found.
docs/theming.rst
View file @
983eab0a
...
...
@@ -130,6 +130,50 @@ Disabling a Theme
-----------------
Theme can be disabled by removing its corresponding ``Site Theme`` entry using django admin.
---------------------------------------
Creating or Updating Site and SiteTheme
---------------------------------------
If you have already setup ``COMPREHENSIVE_THEME_DIRS`` then you can use management command for adding
``Site`` and ``SiteTheme`` directly from the terminal.
.. code-block:: Bash
python manage.py create_or_update_site_theme --site-domain=localhost:8002 --site-name=localhost:8002 --site-theme=my-theme
``create_or_update_site_theme`` accepts the following optional arguments
:--settings: settings file to use, ``default: ecommerce.settings.devstack``
.. code-block:: Bash
python manage.py create_or_update_site_theme --settings=ecommerce.settings.production
:--site-id: id of the site that you want to update
.. code-block:: Bash
# update domain of the site with id 1 and add a new theme ``my-theme`` for this site
python manage.py create_or_update_site_theme --site-id=1 --site-domain=my-theme.localhost:8002 --site-name=my-theme.localhost:8002 --site-theme=my-theme
:--site-domain: domain of the site to be created,
.. code-block:: Bash
python manage.py create_or_update_site_theme --site-domain=localhost:8002 --site-theme=my-theme
:--site-name: Name of the site to be created, ``default: ''``
.. code-block:: Bash
python manage.py create_or_update_site_theme --site-domain=localhost:8002 --site-name=localhost:8002 --site-theme=my-theme
:--site-theme: theme dir for the new theme,
.. code-block:: Bash
python manage.py create_or_update_site_theme --site-domain=localhost:8002 --site-name=localhost:8002 --site-theme=my-theme
--------------------
Compiling Theme Sass
--------------------
...
...
ecommerce/theming/management/commands/create_or_update_site_theme.py
0 → 100644
View file @
983eab0a
"""
Creates or updates a Site and Site Theme.
"""
from
__future__
import
unicode_literals
import
logging
from
django.contrib.sites.models
import
Site
from
django.core.management
import
BaseCommand
from
ecommerce.theming.models
import
SiteTheme
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
'Create or update Site and SiteTheme'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--site-id'
,
action
=
'store'
,
dest
=
'site_id'
,
type
=
int
,
help
=
'ID of the Site to update.'
)
parser
.
add_argument
(
'--site-domain'
,
action
=
'store'
,
dest
=
'site_domain'
,
type
=
str
,
required
=
True
,
help
=
'Domain of the Site to create or update.'
)
parser
.
add_argument
(
'--site-name'
,
action
=
'store'
,
dest
=
'site_name'
,
type
=
str
,
default
=
''
,
help
=
'Name of the Site to create or update.'
)
parser
.
add_argument
(
'--site-theme'
,
action
=
'store'
,
dest
=
'site_theme'
,
type
=
str
,
required
=
True
,
help
=
'Name of the theme to apply to the site.'
)
def
handle
(
self
,
*
args
,
**
options
):
site_id
=
options
.
get
(
'site_id'
)
site_domain
=
options
.
get
(
'site_domain'
)
site_name
=
options
.
get
(
'site_name'
)
site_theme
=
options
.
get
(
'site_theme'
)
try
:
site
=
Site
.
objects
.
get
(
id
=
site_id
)
except
Site
.
DoesNotExist
:
site
,
site_created
=
Site
.
objects
.
get_or_create
(
domain
=
site_domain
)
if
site_created
:
logger
.
info
(
'Site created with domain
%
s'
,
site_domain
)
site
.
domain
=
site_domain
if
site_name
:
site
.
name
=
site_name
site
.
save
()
_
,
created
=
SiteTheme
.
objects
.
update_or_create
(
site
=
site
,
defaults
=
{
'theme_dir_name'
:
site_theme
,
}
)
logger
.
info
(
'Site Theme
%
s with theme "
%
s"'
,
"created"
if
created
else
"updated"
,
site_theme
)
ecommerce/theming/management/commands/tests/__init__.py
0 → 100644
View file @
983eab0a
ecommerce/theming/management/commands/tests/test_create_or_update_site_theme.py
0 → 100644
View file @
983eab0a
"""
Tests for management command for creating or updating site themes.
"""
from
django.test
import
TestCase
from
django.core.management
import
call_command
,
CommandError
from
django.contrib.sites.models
import
Site
from
ecommerce.theming.models
import
SiteTheme
class
TestCreateUpdateSiteTheme
(
TestCase
):
"""
Test django management command for creating or updating site themes.
"""
def
test_errors_for_invalid_arguments
(
self
):
"""
Test Error in case of invalid arguments.
"""
# make sure error is raised if no argument is given
with
self
.
assertRaises
(
CommandError
):
call_command
(
"create_or_update_site_theme"
)
# make sure error is raised if --site-theme is not given
with
self
.
assertRaises
(
CommandError
):
call_command
(
"create_or_update_site_theme"
,
site_domain
=
"test.localhost"
)
def
test_create_site_theme
(
self
):
"""
Test that site theme is created properly.
"""
call_command
(
"create_or_update_site_theme"
,
"--site-domain=test.localhost"
,
"--site-name=Site Name"
,
'--site-theme=test'
,
)
# Verify updated site name
site
=
Site
.
objects
.
get
(
domain
=
"test.localhost"
)
site_theme
=
SiteTheme
.
objects
.
get
(
site
=
site
)
self
.
assertEqual
(
site
.
name
,
"Site Name"
)
self
.
assertEqual
(
site_theme
.
theme_dir_name
,
"test"
)
def
test_update_site
(
self
):
"""
Test that site is updated properly if site-id belongs to an existing site.
"""
# Create a site to update
site
=
Site
.
objects
.
create
(
domain
=
"test.localhost"
,
name
=
"Test Site"
)
call_command
(
"create_or_update_site_theme"
,
"--site-id={}"
.
format
(
site
.
id
),
"--site-name=updated name"
,
"--site-domain=test.localhost"
,
'--site-theme=test'
,
)
# Verify updated site name
site
=
Site
.
objects
.
get
(
id
=
site
.
id
)
self
.
assertEqual
(
site
.
name
,
"updated name"
)
def
test_update_site_theme
(
self
):
"""
Test that site theme is updated properly when site and site theme already exist.
"""
# Create a site and site theme to update
site
=
Site
.
objects
.
create
(
domain
=
"test.localhost"
,
name
=
"Test Site"
)
site_theme
=
SiteTheme
.
objects
.
create
(
site
=
site
,
theme_dir_name
=
"site_theme_1"
)
call_command
(
"create_or_update_site_theme"
,
"--site-domain=test.localhost"
,
'--site-theme=site_theme_2'
,
)
# Verify updated site name
site_theme
=
SiteTheme
.
objects
.
get
(
id
=
site_theme
.
id
)
self
.
assertEqual
(
site_theme
.
theme_dir_name
,
"site_theme_2"
)
ecommerce/theming/
tests/test_command
s.py
→
ecommerce/theming/
management/commands/tests/test_update_asset
s.py
View file @
983eab0a
...
...
@@ -16,7 +16,7 @@ from ecommerce.theming.management.commands.update_assets import (
class
TestUpdateAssets
(
TestCase
):
"""
Test
comprehensive theming helper function
s.
Test
management command for updating/compiling themed asset
s.
"""
def
setUp
(
self
):
super
(
TestUpdateAssets
,
self
)
.
setUp
()
...
...
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