Giter VIP home page Giter VIP logo

aldryn-sites's Introduction

aldryn-sites

image

image

Extensions to django.contrib.sites.

Features

  • Domain redirects: handles smart redirecting to a main domain from alias domains. Taking http/https into consideration.
  • Site auto-population: automatically populates the Domain name in django.contrib.sites.Site.domain based on the ALDRYN_SITES_DOMAINS setting.

Installation

  • add aldryn_sites to INSTALLED_APPS.
  • add aldryn_sites.middleware.SiteMiddleware to MIDDLEWARE_CLASSES (place it before djangosecure.middleware.SecurityMiddleware if redirects should be smart about alias domains possibly not having a valid certificate of their own. The middleware will pick up on SECURE_SSL_REDIRECT from django-secure.)

configure ALDRYN_SITES_DOMAINS:

ALDRYN_SITES_DOMAINS = {
    1: {  # matches SITE_ID
        'domain': 'www.example.com',  # main domain that all domains in redirects will redirect to.
                                      # Auto populates ``django.contrib.sites.Site.domain``
        'aliases': [                  # these domains will be accessible like the main domain (no redirect).
            'an.other.domain.com',
            r'^[a-z0-9-]+\.anysub\.com$',  # regexes are supported
        ],
        'redirects': [                # these domains will be redirected to the main domain.
            'example.com',            # add ``'*'`` to redirect all non-main domains to the main one.
            'example.ch',
            'www.example.ch',
            r'^[a-z0-9-]+\.my-redirect-domain\.com$',  # regexes are supported
            r'.*',  # matches any domain (Makes the above rules useless. It's just an example)
        ],
    }
}

When using regexes:

  • exact matches win over pattern matches
  • pattern redirect matches win over pattern alias matches

Further Settings

set ALDRYN_SITES_SET_DOMAIN_NAME to False if you don't want django.contrib.sites.Site.domain to be auto-populated (default: True).

TODOS

  • validate settings
  • test settings validators
  • log warning if there are Sites in the database that are not in the settings
  • pretty display of how redirects will work (in admin and as a simple util)
  • regex support for aliases
  • form to test redirect logic
  • pre-compile and cache regexes

aldryn-sites's People

Contributors

bplociennik avatar chive avatar czpython avatar garetjax avatar mikek avatar stefanfoulis avatar vthaian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aldryn-sites's Issues

smart auto-populating of site name

currently only the domain is updated with the domain name. By default both the domain name and the name of a site is example.com.

If domain and name are identical to begin with, it would make sense to update both with the domain name.

Failsafe when changing domains

  • Switch the domain settings in the control panel and save
  • Restore an older backup
  • Re-deploy the site on live and you may get a database error

Does not work on Django 1.7

A few tests fail because of differences in ORM behaviour in Django 1.7 and ALLOWED_HOSTS being unset. Needs further investigation.

======================================================================
ERROR: test_auto_configure_site_domain (aldryn_sites.tests.AldrynSitesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./aldryn_sites/tests.py", line 150, in test_auto_configure_site_domain
    Site.objects.all().delete()
  File "[...]/projects/aldryn/aldryn-sites/.tox/py27-dj17/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "[...]/projects/aldryn/aldryn-sites/.tox/py27-dj17/lib/python2.7/site-packages/django/db/models/query.py", line 361, in get
    num if num <= MAX_GET_RESULTS else 'more than %s' % MAX_GET_RESULTS
MultipleObjectsReturned: get() returned more than one Site -- it returned 2!

======================================================================
ERROR: test_auto_configure_site_domain_and_name_if_same (aldryn_sites.tests.AldrynSitesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./aldryn_sites/tests.py", line 162, in test_auto_configure_site_domain_and_name_if_same
    s = Site.objects.get()
  File "[...]/projects/aldryn/aldryn-sites/.tox/py27-dj17/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "[...]/projects/aldryn/aldryn-sites/.tox/py27-dj17/lib/python2.7/site-packages/django/db/models/query.py", line 361, in get
    num if num <= MAX_GET_RESULTS else 'more than %s' % MAX_GET_RESULTS
MultipleObjectsReturned: get() returned more than one Site -- it returned 2!

======================================================================
FAIL: test_auto_configure_allowed_hosts (aldryn_sites.tests.AldrynSitesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./aldryn_sites/tests.py", line 144, in test_auto_configure_allowed_hosts
    self.assertTrue(domain in settings.ALLOWED_HOSTS, '{} not in ALLOWED_HOSTS'.format(domain))
AssertionError: www.example.com not in ALLOWED_HOSTS

----------------------------------------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.