Initial import

This commit is contained in:
Iacopo Spalletti 2016-06-13 22:31:45 +02:00
commit 22c0dceaf2
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
27 changed files with 797 additions and 0 deletions

2
.checkignore Normal file
View file

@ -0,0 +1,2 @@
tests/*
docs/*

9
.codeclimate.yml Normal file
View file

@ -0,0 +1,9 @@
languages:
Ruby: false
JavaScript: false
PHP: false
Python: true
exclude_paths:
- 'djangocms_multisite/migrations/*'
- 'djangocms_multisite/south_migrations/*'
- 'tests/*'

27
.coveragerc Normal file
View file

@ -0,0 +1,27 @@
[run]
branch = True
source = djangocms_multisite
[report]
omit = ../*migrations*,../*tests*,../*compat.*
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
[html]
directory = coverage_html

35
.editorconfig Normal file
View file

@ -0,0 +1,35 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
[*.md]
trim_trailing_whitespace = false
[*.rst]
max_line_length = 80
[*.py]
max_line_length = 100
[*.{scss,html}]
indent_size = 2
indent_style = space
max_line_length = 120
[*.js]
indent_size = 2
max_line_length = 120
[*.yml]
indent_size = 2
[Makefile]
indent_style = tab

49
.gitignore vendored Normal file
View file

@ -0,0 +1,49 @@
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Complexity
output/*.html
output/*/index.html
# Sphinx
docs/build
*.lokalize
lokalize*
.idea
docs/_build
*~
*.db
*.sqlite

5
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,5 @@
# This file is generated by GitLab CI
ci:
script:
- COMMAND="coverage run" tox -epep8,isort,py35-django19-cms32,py34-django18-cms31,py27-django16-cms30
- if [[ $? -eq 0 ]]; then coverage report; fi

60
.travis.yml Normal file
View file

@ -0,0 +1,60 @@
# Config file for automatic testing at travis-ci.org
language: python
sudo: false
python:
- 3.5
- 3.4
- 2.7
env:
matrix:
- TOXENV='pep8'
- TOXENV='isort'
- TOXENV='docs'
- DJANGO='django19' CMS='cms33'
- DJANGO='django19' CMS='cms32'
- DJANGO='django18' CMS='cms33'
- DJANGO='django18' CMS='cms32'
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PYVER=py27; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then export PYVER=py34; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export PYVER=py35; fi"
- "if [[ ${DJANGO}z != 'z' ]]; then export TOXENV=$PYVER-$DJANGO-$CMS; fi"
# command to run tests, e.g. python setup.py test
script: COMMAND='coverage run' tox -e$TOXENV
before_install:
- pip install -U tox>=1.8 coveralls codecov wheel pip
after_success:
- codecov
- coveralls
matrix:
exclude:
- python: 2.7
env: TOXENV='docs'
- python: 2.7
env: TOXENV='pep8'
- python: 2.7
env: TOXENV='isort'
- python: 3.4
env: TOXENV='docs'
- python: 3.4
env: TOXENV='pep8'
- python: 3.4
env: TOXENV='isort'
cache:
directories:
- $HOME/.pip-accel
- $HOME/.cache/pip

14
AUTHORS.rst Normal file
View file

@ -0,0 +1,14 @@
=======
Credits
=======
Based on code originally by Stefan Foulis
Development Lead
----------------
* Iacopo Spalletti <i.spalletti@nephila.it>
Contributors
------------

112
CONTRIBUTING.rst Normal file
View file

@ -0,0 +1,112 @@
============
Contributing
============
Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions
----------------------
Report Bugs
~~~~~~~~~~~
Report bugs at https://github.com/nephila/djangocms-multisite/issues.
If you are reporting a bug, please include:
* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting.
* Detailed steps to reproduce the bug.
Fix Bugs
~~~~~~~~
Look through the GitHub issues for bugs. Anything tagged with "bug"
is open to whoever wants to implement it.
Implement Features
~~~~~~~~~~~~~~~~~~
Look through the GitHub issues for features. Anything tagged with "feature"
is open to whoever wants to implement it.
Write Documentation
~~~~~~~~~~~~~~~~~~~
djangocms-multisite could always use more documentation, whether as part of the
official djangocms-multisite docs, in docstrings, or even on the web in blog posts,
articles, and such.
Submit Feedback
~~~~~~~~~~~~~~~
The best way to send feedback is to file an issue at https://github.com/nephila/djangocms-multisite/issues.
If you are proposing a feature:
* Explain in detail how it would work.
* Keep the scope as narrow as possible, to make it easier to implement.
* Remember that this is a volunteer-driven project, and that contributions
are welcome :)
Get Started!
------------
Ready to contribute? Here's how to set up `djangocms-multisite` for local development.
1. Fork the `djangocms-multisite` repo on GitHub.
2. Clone your fork locally::
$ git clone git@github.com:your_name_here/djangocms-multisite.git
3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
$ mkvirtualenv djangocms-multisite
$ cd djangocms-multisite/
$ python setup.py develop
4. Create a branch for local development::
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
5. When you're done making changes, check that your changes pass flake8 and the
tests, including testing other Python versions with tox::
$ flake8 djangocms_multisite tests
$ python setup.py test
$ tox
To get flake8 and tox, just pip install them into your virtualenv.
6. Commit your changes and push your branch to GitHub::
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
7. Submit a pull request through the GitHub website.
Pull Request Guidelines
-----------------------
Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check
https://travis-ci.org/nephila/djangocms-multisite/pull_requests
and make sure that the tests pass for all supported Python versions.
Tips
----
To run a subset of tests::
$ python -m unittest tests.test_djangocms_multisite

9
HISTORY.rst Normal file
View file

@ -0,0 +1,9 @@
.. :changelog:
History
-------
0.1.0 (unreleased)
++++++++++++++++++
* First experimental release

12
LICENSE Normal file
View file

@ -0,0 +1,12 @@
Copyright (c) 2013, Iacopo Spalletti
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of djangocms-multisite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

6
MANIFEST.in Normal file
View file

@ -0,0 +1,6 @@
include AUTHORS.rst
include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.rst
recursive-include djangocms_multisite *.html *.png *.gif *js *jpg *jpeg *svg *py *css *po *mo

47
Makefile Normal file
View file

@ -0,0 +1,47 @@
.PHONY: clean-pyc clean-build docs
help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "lint - check style with flake8"
@echo "test - run tests quickly with the default Python"
@echo "testall - run tests on every Python version with tox"
@echo "coverage - check code coverage quickly with the default Python"
@echo "release - package and upload a release"
@echo "sdist - package"
clean: clean-build clean-pyc
clean-build:
python setup.py clean --all
rm -fr build/
rm -fr dist/
rm -fr *.egg-info
clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
lint:
flake8 djangocms_multisite tests
djangocms-helper djangocms_multisite pyflakes --cms
test:
djangocms-helper djangocms_multisite test --cms --nose
test-all:
tox
coverage:
coverage erase
coverage run `which djangocms-helper` djangocms_multisite test --cms --nose
coverage report -m
release: clean
python setup.py clean --all sdist bdist_wheel
twine upload dist/*
sdist: clean
python setup.py sdist
ls -l dist

101
README.rst Normal file
View file

@ -0,0 +1,101 @@
===================
djangocms-multisite
===================
.. image:: https://img.shields.io/pypi/v/djangocms-multisite.svg?style=flat-square
:target: https://pypi.python.org/pypi/djangocms-multisite
:alt: Latest PyPI version
.. image:: https://img.shields.io/pypi/dm/djangocms-multisite.svg?style=flat-square
:target: https://pypi.python.org/pypi/djangocms-multisite
:alt: Monthly downloads
.. image:: https://img.shields.io/pypi/pyversions/djangocms-multisite.svg?style=flat-square
:target: https://pypi.python.org/pypi/djangocms-multisite
:alt: Python versions
.. image:: https://img.shields.io/travis/nephila/djangocms-multisite.svg?style=flat-square
:target: https://travis-ci.org/nephila/djangocms-multisite
:alt: Latest Travis CI build status
.. image:: https://img.shields.io/coveralls/nephila/djangocms-multisite/master.svg?style=flat-square
:target: https://coveralls.io/r/nephila/djangocms-multisite?branch=master
:alt: Test coverage
.. image:: https://img.shields.io/codecov/c/github/nephila/djangocms-multisite/develop.svg?style=flat-square
:target: https://codecov.io/github/nephila/djangocms-multisite
:alt: Test coverage
.. image:: https://codeclimate.com/github/nephila/djangocms-multisite/badges/gpa.svg?style=flat-square
:target: https://codeclimate.com/github/nephila/djangocms-multisite
:alt: Code Climate
django-multisite support for django CMS
Supported Django versions:
* Django 1.6
* Django 1.7
* Django 1.8
* Django 1.9
Supported django CMS versions:
* django CMS 3.*
Usage
=====
#. Configure django-multisite as documented
#. Add ``djangocms_multisite`` to ``INSTALLED_APPS``::
INSTALLED_APPS=[
...
'djangocms_multisite',
...
]
#. Add ``djangocms_multisite.middleware.CMSMultiSiteMiddleware`` to ``MIDDLEWARE_CLASSES`` after
``django-multisite`` middleware::
MIDDLEWARE_CLASSES = [
...
'multisite.middleware.DynamicSiteMiddleware',
'djangocms_multisite.middleware.CMSMultiSiteMiddleware',
...
]
#. Configure the URL mapping as follows::
MULTISITE_CMS_URLS={
'www.example.com': 'tests.test_utils.urls1',
'www.example2.com': 'tests.test_utils.urls2',
},
MULTISITE_CMS_ALIASES={
'www.example.com': ('alias1.example.com', 'alias2.example.com',),
'www.example2.com': ('alias1.example2.com', 'alias2.example2.com',),
},
MULTISITE_CMS_FALLBACK='www.example.com'
Settings
========
MULTISITE_CMS_URLS
^^^^^^^^^^^^^^^^^^
Dictionary (or OrderedDict) containing the mapping between the domain (as configured in django
``sites``) and the corresponding urlconf.
MULTISITE_CMS_FALLBACK
^^^^^^^^^^^^^^^^^^^^^^
The default domain to load if any of the above does not match.
MULTISITE_CMS_ALIASES
^^^^^^^^^^^^^^^^^^^^^
Dictionary (or OrderedDict) containing the mapping between the domain (as configured in django
``sites``) and a list of aliases. This is optional if all the aliases are configured as
``django-multisite`` aliases

74
cms_helper.py Executable file
View file

@ -0,0 +1,74 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
from tempfile import mkdtemp
def gettext(s): return s
from multisite import SiteID
HELPER_SETTINGS = dict(
ROOT_URLCONF='tests.test_utils.urls1',
INSTALLED_APPS=[
'multisite',
'djangocms_text_ckeditor'
],
LANGUAGE_CODE='en',
LANGUAGES=(
('en', gettext('English')),
),
CMS_LANGUAGES={
1: [
{
'code': 'en',
'name': gettext('English'),
'public': True,
},
],
2: [
{
'code': 'en',
'name': gettext('English'),
'public': True,
},
],
'default': {
'hide_untranslated': False,
},
},
MIDDLEWARE_CLASSES=(
'multisite.middleware.DynamicSiteMiddleware',
'djangocms_multisite.middleware.CMSMultiSiteMiddleware',
),
MIGRATION_MODULES={},
USE_TZ=True,
TIME_ZONE='UTC',
FILE_UPLOAD_TEMP_DIR=mkdtemp(),
SITE_ID=SiteID(default=1),
MULTISITE_CMS_URLS={
'www.example.com': 'tests.test_utils.urls1',
'www.example2.com': 'tests.test_utils.urls2',
},
MULTISITE_CMS_ALIASES={
'www.example.com': ('alias1.example.com', 'alias2.example.com',),
'www.example2.com': ('alias1.example2.com', 'alias2.example2.com',),
},
MULTISITE_CMS_FALLBACK='www.example.com'
)
def run():
from djangocms_helper import runner
runner.cms('djangocms_multisite')
def setup():
import sys
from djangocms_helper import runner
runner.setup('djangocms_multisite', sys.modules[__name__], use_cms=True)
if __name__ == '__main__':
run()

View file

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '0.1.0'

View file

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.conf import settings
from django.core.urlresolvers import set_urlconf
from django.utils.cache import patch_vary_headers
from django.utils.six.moves import urllib_parse as urlparse
class CMSMultiSiteMiddleware(object):
def process_request(self, request):
try:
full_host = '{scheme}://{host}'.format(
scheme=request.scheme, host=request.META['HTTP_HOST']
)
parsed = urlparse.urlparse(full_host)
host = parsed.hostname
urlconf = None
try:
urlconf = settings.MULTISITE_CMS_URLS[host]
except KeyError:
for domain, hosts in settings.MULTISITE_CMS_ALIASES.items():
if host in hosts:
urlconf = settings.MULTISITE_CMS_URLS[domain]
break
if not urlconf:
urlconf = settings.MULTISITE_CMS_URLS[settings.MULTISITE_CMS_FALLBACK]
request.urlconf = urlconf
# sets urlconf for current thread, so that code that does not know
# about the request (e.g MyModel.get_absolute_url()) get the correct
# urlconf.
set_urlconf(urlconf)
except KeyError:
# use default urlconf (settings.ROOT_URLCONF)
set_urlconf(None)
def process_response(self, request, response):
if getattr(request, 'urlconf', None):
patch_vary_headers(response, ('Host',))
# set back to default urlconf
set_urlconf(None)
return response

View file

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

10
requirements-test.txt Normal file
View file

@ -0,0 +1,10 @@
-r requirements.txt
coverage
coveralls
mock>=1.0.1
nose>=1.3.0
django-nose>=1.2
flake8
https://github.com/nephila/djangocms-helper/archive/develop.zip
tox>=2.0
wheel

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
-e .

19
setup.cfg Normal file
View file

@ -0,0 +1,19 @@
[flake8]
exclude = *.egg-info,.git,.settings,.tox,build,dist,docs,requirements,tmp,*migrations*,*south_migrations*,tests,data
max-line-length = 99
[metadata]
license-file = LICENSE
[wheel]
universal = 1
[isort]
line_length = 99
skip = migrations, south_migrations
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = djangocms_multisite
multi_line_output = 5
not_skip = __init__.py

54
setup.py Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import djangocms_multisite
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
version = djangocms_multisite.__version__
readme = open('README.rst').read()
history = open('HISTORY.rst').read().replace('.. :changelog:', '')
setup(
name='djangocms-multisite',
version=version,
description='django-multisite supporto for django CMS',
long_description=readme + '\n\n' + history,
author='Iacopo Spalletti',
author_email='i.spalletti@nephila.it',
url='https://github.com/nephila/djangocms-multisite',
packages=[
'djangocms_multisite',
],
include_package_data=True,
install_requires=[
'django-multisite',
'django-cms',
],
license='BSD',
zip_safe=False,
keywords='djangocms-multisite, django',
test_suite='cms_helper.run',
classifiers=[
'Development Status :: 3 - Alpha',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Framework :: Django',
'Framework :: Django :: 1.6',
'Framework :: Django :: 1.7',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
)

2
tests/__init__.py Normal file
View file

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

View file

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

28
tests/test_utils/urls1.py Normal file
View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from cms.utils.conf import get_cms_setting
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.i18n import javascript_catalog
from django.views.static import serve
admin.autodiscover()
urlpatterns = [
url(r'^media/(?P<path>.*)$', serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^media/cms/(?P<path>.*)$', serve,
{'document_root': get_cms_setting('MEDIA_ROOT'), 'show_indexes': True}),
url(r'^jsi18n/(?P<packages>\S+?)/$', javascript_catalog),
]
urlpatterns += staticfiles_urlpatterns()
urlpatterns += i18n_patterns(
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)

28
tests/test_utils/urls2.py Normal file
View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from cms.utils.conf import get_cms_setting
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.i18n import javascript_catalog
from django.views.static import serve
admin.autodiscover()
urlpatterns = [
url(r'^media/(?P<path>.*)$', serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^media/cms/(?P<path>.*)$', serve,
{'document_root': get_cms_setting('MEDIA_ROOT'), 'show_indexes': True}),
url(r'^jsi18n/(?P<packages>\S+?)/$', javascript_catalog),
]
urlpatterns += staticfiles_urlpatterns()
urlpatterns += i18n_patterns(
url(r'^admin/', include(admin.site.urls)),
url(r'^subpath/', include('cms.urls')),
)

46
tox.ini Normal file
View file

@ -0,0 +1,46 @@
[tox]
envlist = pep8,isort,docs,py{35,34,27}-django{19}-{cms33,cms32},py{35,34,33,27}-django{18}-cms{33,32,31},py{34,33,27}-django{17,16}-cms{32,31,30},py{26}-django16-cms{31,30}
[testenv]
commands = {env:COMMAND:python} cms_helper.py test djangocms_multisite
deps =
django16: Django>=1.6,<1.7
django16: django-taggit<0.18
django16: django-mptt<0.8
django17: Django>=1.7,<1.8
django17: django-mptt<0.8
django18: Django>=1.8,<1.9
django18: django-mptt>=0.8
django19: Django>=1.9,<1.10
django19: django-mptt>=0.8
cms30: https://github.com/divio/django-cms/archive/release/3.0.x.zip
cms30: djangocms-text-ckeditor<2.8
cms31: https://github.com/divio/django-cms/archive/release/3.1.x.zip
cms31: djangocms-text-ckeditor<2.9
cms32: https://github.com/divio/django-cms/archive/release/3.2.x.zip
cms32: djangocms-text-ckeditor<3.0
cms33: https://github.com/divio/django-cms/archive/release/3.3.x.zip
cms33: djangocms-text-ckeditor>=3.0
https://github.com/nephila/djangocms-helper/archive/develop.zip
-r{toxinidir}/requirements-test.txt
[testenv:isort]
deps = isort
commands = isort -c -rc -df djangocms_multisite tests
skip_install = true
[testenv:pep8]
deps = flake8
commands = flake8
skip_install = true
[testenv:docs]
deps =
sphinx
sphinx-rtd-theme
-rrequirements-test.txt
changedir=docs
skip_install = true
commands=
sphinx-build -W -b html -d {envtmpdir}/doctrees . {toxinidir}/docs/_build/html