Skip to content

Commit

Permalink
Merge pull request #52 from ecometrica/supportDjango2.0
Browse files Browse the repository at this point in the history
Support django2.0
  • Loading branch information
rebkwok committed Apr 20, 2018
2 parents 2ad523b + dda2c3f commit 866f69a
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 198 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ parts
MANIFEST
multisite/*.egg-info
.tox/
.pytest_cache/
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Release Notes
=============

1.5.0
-----
* Support Django 2.0 (PR #47 and #60)
* Remove code for Django < 1.7
* Remove obsolete PathAssistedCurrentSiteManager
* Remove obsolete template.loaders.cached
* Update README to better describe local development setup

1.4.1
-----
* Specify Django <2.0 in setup.py
Expand Down
30 changes: 25 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ Add to your settings.py TEMPLATES loaders in the OPTIONS section::
...
]

Or for Django 1.7 and earlier, add to settings.py TEMPLATES_LOADERS::
Or for Django <= 1.7, add to settings.py TEMPLATES_LOADERS::

TEMPLATE_LOADERS = (
'multisite.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

Edit settings.py MIDDLEWARE_CLASSES::
Edit settings.py MIDDLEWARE (MIDDLEWARE_CLASSES for Django < 1.10)::

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
...
'multisite.middleware.DynamicSiteMiddleware',
...
Expand Down Expand Up @@ -115,6 +115,26 @@ include wildcards.::
# will match any host ending '.example.com'


Development Environments
------------------------
Multisite returns a valid Alias when in "development mode" (defaulting to the
alias associated with the default SiteID.

Development mode is either:
- Running tests, i.e. manage.py test
- Running locally in settings.DEBUG = True, where the hostname is a
top-level name, i.e. localhost

In order to have multisite use aliases in local environments, add entries to
your local etc/hosts file to match aliases in your applications. E.g. ::

127.0.0.1 example.com
127.0.0.1 examplealias.com

And access your application at example.com:8000 or examplealias.com:8000 instead of
the usual localhost:8000.


Domain fallbacks
----------------

Expand Down Expand Up @@ -156,9 +176,9 @@ Cross-domain cookies
In order to support `cross-domain cookies`_,
for purposes like single-sign-on,
prepend the following to the top of
settings.py MIDDLEWARE_CLASSES::
settings.py MIDDLEWARE (MIDDLEWARE_CLASSES for Django < 1.10)::

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'multisite.middleware.CookieDomainMiddleware',
...
)
Expand Down
3 changes: 1 addition & 2 deletions multisite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .threadlocals import SiteDomain, SiteID

VERSION = "1.4.0"
from .__version__ import __version__
1 change: 1 addition & 0 deletions multisite/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '1.5.0'
13 changes: 2 additions & 11 deletions multisite/hosts.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from __future__ import unicode_literals
from __future__ import absolute_import

from django.utils.functional import SimpleLazyObject

from django import VERSION as django_version
from django.utils.functional import empty, SimpleLazyObject


__ALL__ = ('ALLOWED_HOSTS', 'AllowedHosts')


# In Django 1.3, LazyObject compares _wrapped against None, while in Django
# 1.4 and above, LazyObjects compares _wrapped against an instance of
# `object` stored in `empty`.
_wrapped_default = None
if django_version >= (1, 4, 0):
from django.utils.functional import empty
_wrapped_default = empty
_wrapped_default = empty


class IterableLazyObject(SimpleLazyObject):
Expand Down
20 changes: 0 additions & 20 deletions multisite/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from __future__ import unicode_literals
from __future__ import absolute_import

from warnings import warn

from django.db import models
from django.contrib.sites import managers
from django.db.models.fields import FieldDoesNotExist
Expand Down Expand Up @@ -87,21 +85,3 @@ def _get_related_model(self, model, fieldname):
return model._meta.get_field(fieldname).remote_field.model
except AttributeError:
return model._meta.get_field(fieldname).rel.to


class PathAssistedCurrentSiteManager(models.CurrentSiteManager):
"""
Deprecated: Use multisite.managers.SpanningCurrentSiteManager instead.
"""
def __init__(self, field_path):
warn(('Use multisite.managers.SpanningCurrentSiteManager instead of '
'multisite.managers.PathAssistedCurrentSiteManager'),
DeprecationWarning, stacklevel=2)
super(PathAssistedCurrentSiteManager, self).__init__()
self.__field_path = field_path

def get_queryset(self):
from django.contrib.sites.models import Site
return super(models.CurrentSiteManager, self).get_queryset().filter(
**{self.__field_path: Site.objects.get_current()}
)
2 changes: 1 addition & 1 deletion multisite/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Migration(migrations.Migration):
('domain', models.CharField(help_text='Either "domain" or "domain:port"', unique=True, max_length=100, verbose_name='domain name')),
('is_canonical', models.NullBooleanField(default=None, validators=[multisite.models.validate_true_or_none], editable=False, help_text='Does this domain name match the one in site?', verbose_name='is canonical?')),
('redirect_to_canonical', models.BooleanField(default=True, help_text='Should this domain name redirect to the one in site?', verbose_name='redirect to canonical?')),
('site', models.ForeignKey(related_name='aliases', to='sites.Site')),
('site', models.ForeignKey(related_name='aliases', to='sites.Site', on_delete=models.CASCADE)),
],
options={
'verbose_name_plural': 'aliases',
Expand Down
19 changes: 5 additions & 14 deletions multisite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from django.db import connections, models, router
from django.db.models import Q
from django.db.models.signals import pre_save, post_save
try:
from django.db.models.signals import post_migrate
except ImportError:
# Django < 1.7 compatibility
from django.db.models.signals import post_syncdb as post_migrate
from django.db.models.signals import post_migrate
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -169,7 +165,9 @@ class Alias(models.Model):
unique=True,
help_text=_('Either "domain" or "domain:port"'),
)
site = models.ForeignKey(Site, related_name='aliases')
site = models.ForeignKey(
Site, related_name='aliases', on_delete=models.CASCADE
)
is_canonical = models.NullBooleanField(
_('is canonical?'),
default=None, editable=False,
Expand Down Expand Up @@ -318,14 +316,7 @@ def site_created_hook(cls, sender, instance, raw, created,
@classmethod
def db_table_created_hook(cls, *args, **kwargs):
"""Syncs canonical Alias objects for all existing Site objects."""
if kwargs.get('created_models'):
# For post_syncdb support in Django < 1.7:
# As before, only sync_all if Alias was in
# the list of created models
if cls in kwargs['created_models']:
Alias.canonical.sync_all()
else:
Alias.canonical.sync_all()
Alias.canonical.sync_all()


# Hooks to handle Site objects being created or changed
Expand Down
49 changes: 0 additions & 49 deletions multisite/south_migrations/0001_initial.py

This file was deleted.

This file was deleted.

Empty file.
49 changes: 0 additions & 49 deletions multisite/template/loaders/cached.py

This file was deleted.

11 changes: 8 additions & 3 deletions multisite/template/loaders/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
from django.conf import settings
from django.contrib.sites.models import Site
from django.template.loaders.filesystem import Loader as FilesystemLoader
from django import VERSION as django_version


class Loader(FilesystemLoader):
def get_template_sources(self, template_name, template_dirs=None):
def get_template_sources(self, *args, **kwargs):
template_name = args[0]
domain = Site.objects.get_current().domain
default_dir = getattr(settings, 'MULTISITE_DEFAULT_TEMPLATE_DIR',
'default')
for tname in (os.path.join(domain, template_name),
os.path.join(default_dir, template_name)):
for item in super(Loader, self).get_template_sources(tname,
template_dirs):
if django_version < (2, 0, 0):
args = [tname, None]
else:
args = [tname]
for item in super(Loader, self).get_template_sources(*args, **kwargs):
yield item
22 changes: 17 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
from setuptools import find_packages, setup
import os
import sys

from setuptools import find_packages, setup

_dir_ = os.path.dirname(__file__)


if sys.version_info < (3, 4):
install_requires = ['Django>=1.7,<2.0', 'tldextract>=1.2']
else:
install_requires = ['Django>=1.7,<2.1', 'tldextract>=1.2']


def long_description():
"""Returns the value of README.rst"""
with open(os.path.join(_dir_, 'README.rst')) as f:
return f.read()

here = os.path.abspath(_dir_)
version = {}
with open(os.path.join(here, 'multisite', '__version__.py')) as f:
exec(f.read(), version)


files = ["multisite/test_templates/*"]

setup(name='django-multisite',
version='1.4.1',
version=version['__version__'],
description='Serve multiple sites from a single Django application',
long_description=long_description(),
author='Leonid S Shestera',
Expand All @@ -24,8 +37,7 @@ def long_description():
packages=find_packages(),
include_package_data=True,
package_data={'multisite': files},
install_requires=['Django>=1.7,<2.0',
'tldextract>=1.2'],
install_requires=install_requires,
setup_requires=['pytest-runner'],
tests_require=['coverage', 'mock', 'pytest', 'pytest-cov',
'pytest-django', 'pytest-pythonpath', 'tox'],
Expand All @@ -45,4 +57,4 @@ def long_description():
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities'],
)
)

0 comments on commit 866f69a

Please sign in to comment.