Skip to content

Commit

Permalink
Replace django-subdomain with django-hosts
Browse files Browse the repository at this point in the history
django-subdomains has been unmaintained for a long time, while
django-hosts is still actively maintained and is basically a drop-in
replacement.
  • Loading branch information
stianjensen authored and lionleaf committed Oct 18, 2018
1 parent 3637eea commit 5af5bd4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 20 deletions.
7 changes: 7 additions & 0 deletions dwitter/hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django_hosts import patterns, host

host_patterns = patterns(
'',
host(r'www', 'dwitter.urls', name='www'),
host(r'dweet', 'dwitter.dweet.urls', name='dweet'),
)
24 changes: 15 additions & 9 deletions dwitter/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_URL = 'https://dwitter.net/'

PARENT_HOST = 'dwitter.net'

REGISTRATION_OPEN = True # If True, users can register
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_AUTO_LOGIN = True # If True, the user will be automatically logged in.
Expand All @@ -26,7 +28,10 @@
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
'dweet.localhost',
'localhost',
]


# Application definition
Expand All @@ -46,12 +51,12 @@
'dwitter.user',
'dwitter.feed',
'dwitter.dweet',
'subdomains',
'anymail',
'compressor',
'dbbackup',
'debug_toolbar',
'corsheaders',
'django_hosts',
]

DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
Expand All @@ -74,9 +79,9 @@
# )

MIDDLEWARE = [
'django_hosts.middleware.HostsRequestMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'subdomains.middleware.SubdomainURLRoutingMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand All @@ -85,15 +90,13 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django_hosts.middleware.HostsResponseMiddleware',
]

ROOT_URLCONF = 'dwitter.urls'

# A dictionary of urlconf module paths, keyed by their subdomain.
SUBDOMAIN_URLCONFS = {
'dwitter': 'dwitter.urls',
'dweet': 'dwitter.dweet.urls',
}
ROOT_HOSTCONF = 'dwitter.hosts'
DEFAULT_HOST = 'www'

TEMPLATES = [
{
Expand All @@ -107,6 +110,9 @@
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'builtins': [
'django_hosts.templatetags.hosts_override',
],
},
},
]
Expand Down Expand Up @@ -174,7 +180,7 @@


def show_debug_toolbar_when_debug_true_but_not_for_the_dweet_subdomain(request):
if request.subdomain == 'dweet':
if request.host.name == 'dweet':
return False
# Import here so that we get the settings from local.py as well
from django.conf import settings
Expand Down
1 change: 0 additions & 1 deletion dwitter/templates/feed.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends 'base.html' %}
{% load subdomainurls %}

{% block meta_description %}
Dwitter is a social network for building and sharing visual javascript demos limited to 140 characters. See the impressive creations crammed into so few characters, and play around with your own code!
Expand Down
3 changes: 1 addition & 2 deletions dwitter/templates/feed/embed.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% load subdomainurls %}
{% load staticfiles %}
{% load compress %}

<html>
<head>
<title>
<title>
{% if dweet.deleted %}
Embedded - deleted dweet | Dwitter
{% else %}
Expand Down
1 change: 0 additions & 1 deletion dwitter/templates/feed/permalink.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends 'base.html' %}
{% load subdomainurls %}

{% block head %}
{% load staticfiles %}
Expand Down
1 change: 0 additions & 1 deletion dwitter/templates/snippets/deleted_dweet_card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load subdomainurls %}
<div class=dweet-wrapper>
<div class=dweet >
<div class=author-remix-wrapper>
Expand Down
3 changes: 1 addition & 2 deletions dwitter/templates/snippets/dweet_card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load subdomainurls %}
{% load to_gravatar_url %}
{% load insert_magic_links %}
{% load insert_code_blocks %}
Expand All @@ -7,7 +6,7 @@
<div class=canvas-iframe-container-wrapper>
<div class=canvas-iframe-container >
<iframe class="dweetiframe"
src="{% url 'fullscreen_dweet' subdomain='dweet' dweet_id=dweet.id %}"
src="{% url 'fullscreen_dweet' dweet_id=dweet.id host 'dweet' %}"
sandbox="allow-same-origin allow-scripts" id="{{ dweet.id }}"></iframe>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions dwitter/templates/snippets/new_dweet_card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load subdomainurls %}
<div class="dweet submit-box">
<div
class=canvas-iframe-container-wrapper
Expand All @@ -7,7 +6,7 @@
class=canvas-iframe-container
id="iframe-container-submit">
<iframe class="dweetiframe" id=preview-iframe
src="{% url 'blank_dweet' subdomain='dweet' %}"
src="{% url 'blank_dweet' host 'dweet' %}"
sandbox="allow-scripts allow-same-origin"></iframe>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion dwitter/tests/dweet/test_dweet_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def assertResponse(self, response, **kwargs):

class DweetTestCase(TransactionTestCase):
def setUp(self):
self.client = Client(HTTP_HOST='dweet.example.com')
self.client = Client(HTTP_HOST='dweet.localhost:8000')
self.user = User.objects.create(username="user", password="")
self.dweet = Dweet.objects.create(id=1,
code="dweet code",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
boto==2.42
django-anymail==4.3
django-compressor==2.2
django-cors-headers==2.4.0
django-dbbackup==3.0.2
django-debug-toolbar==1.9.1
django-filter==1.1
django-hosts==3.0
django-registration-redux==1.8
django-storages-redux==1.3.2
django-subdomains==2.1.0rc0
django==1.11.15
djangorestframework==3.7.1
flake8==2.6.2
Expand Down

0 comments on commit 5af5bd4

Please sign in to comment.