Merge lp:~gesha/linaro-license-protection/add-multiple-sites-support into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Superseded
Proposed branch: lp:~gesha/linaro-license-protection/add-multiple-sites-support
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 261 lines (+212/-0)
8 files modified
license_protected_downloads/wsgi_releases.py (+42/-0)
license_protected_downloads/wsgi_snapshots.py (+42/-0)
middleware.py (+19/-0)
releases_urls.py (+36/-0)
settings.py (+6/-0)
settings_releases.py (+16/-0)
settings_snapshots.py (+15/-0)
snapshots_urls.py (+36/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/add-multiple-sites-support
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+117659@code.launchpad.net

This proposal has been superseded by a proposal from 2012-08-06.

Description of the change

This branch adds support of multi-sites per single Django application. It is now configured to serve releases.linaro.org and snapshots.linaro.org. Both sites use the same database for licenses. License acceptance is site-dependent: for example if you have accepted the license on snapshots you will need to accept the same license on releases if asked.

To post a comment you must log in.
96. By Georgy Redkozubov

Moved templates addition to own branch

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks fine.

Since we have multiple settings and wsgi files it would be possible to use a separate database for each site and remove the site_id requirement. The databases build themselves up as they go, so unless the OpenID code stores data in them, we can just delete the existing database at a later date and start fresh.

Currently the set up uses sqlite3, which is fine for development but not for deployment, but I assume you and the sys-admins know that and will use a more traditional database when live!

review: Approve
97. By Georgy Redkozubov

Removed not used SITE_ID. Can be added later if there will be a real need.

98. By Georgy Redkozubov

Added deployment steps to README.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'license_protected_downloads/wsgi_releases.py'
--- license_protected_downloads/wsgi_releases.py 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/wsgi_releases.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,42 @@
1"""
2WSGI config for license_protected_downloads project.
3
4This module contains the WSGI application used by Django's development server
5and any production WSGI deployments. It should expose a module-level variable
6named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7this application via the ``WSGI_APPLICATION`` setting.
8
9Usually you will have the standard Django WSGI application here, but it also
10might make sense to replace the whole Django WSGI application with a custom one
11that later delegates to the Django one. For example, you could introduce WSGI
12middleware here, or combine a Django application with an application of another
13framework.
14
15"""
16import os
17import sys
18sys.path.append("/usr/lib/python2.7/dist-packages")
19sys.path.append("/usr/lib/pymodules/python2.7")
20sys.path.append("/usr/lib/python2.7")
21
22# NOTE: Set actual path to directory containing linaro-license-protection app
23sys.path.append("/srv/releases.linaro.org")
24sys.path.append("/srv/releases.linaro.org/linaro-license-protection")
25
26os.environ.setdefault(
27 "DJANGO_SETTINGS_MODULE",
28 "linaro-license-protection.settings_releases"
29)
30
31# This application object is used by any WSGI server configured to use this
32# file. This includes Django's development server, if the WSGI_APPLICATION
33# setting points here.
34#from django.core.wsgi import get_wsgi_application
35#application = get_wsgi_application()
36
37import django.core.handlers.wsgi
38application = django.core.handlers.wsgi.WSGIHandler()
39
40# Apply WSGI middleware here.
41# from helloworld.wsgi import HelloWorldApplication
42# application = HelloWorldApplication(application)
043
=== added file 'license_protected_downloads/wsgi_snapshots.py'
--- license_protected_downloads/wsgi_snapshots.py 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/wsgi_snapshots.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,42 @@
1"""
2WSGI config for license_protected_downloads project.
3
4This module contains the WSGI application used by Django's development server
5and any production WSGI deployments. It should expose a module-level variable
6named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7this application via the ``WSGI_APPLICATION`` setting.
8
9Usually you will have the standard Django WSGI application here, but it also
10might make sense to replace the whole Django WSGI application with a custom one
11that later delegates to the Django one. For example, you could introduce WSGI
12middleware here, or combine a Django application with an application of another
13framework.
14
15"""
16import os
17import sys
18sys.path.append("/usr/lib/python2.7/dist-packages")
19sys.path.append("/usr/lib/pymodules/python2.7")
20sys.path.append("/usr/lib/python2.7")
21
22# NOTE: Set actual path to directory containing linaro-license-protection app
23sys.path.append("/srv/snapshots.linaro.org")
24sys.path.append("/srv/snapshots.linaro.org/linaro-license-protection")
25
26os.environ.setdefault(
27 "DJANGO_SETTINGS_MODULE",
28 "linaro-license-protection.settings_snapshots"
29)
30
31# This application object is used by any WSGI server configured to use this
32# file. This includes Django's development server, if the WSGI_APPLICATION
33# setting points here.
34#from django.core.wsgi import get_wsgi_application
35#application = get_wsgi_application()
36
37import django.core.handlers.wsgi
38application = django.core.handlers.wsgi.WSGIHandler()
39
40# Apply WSGI middleware here.
41# from helloworld.wsgi import HelloWorldApplication
42# application = HelloWorldApplication(application)
043
=== added file 'middleware.py'
--- middleware.py 1970-01-01 00:00:00 +0000
+++ middleware.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,19 @@
1from django.conf import settings
2from django.utils.cache import patch_vary_headers
3
4
5class MultiHostMiddleware:
6
7 def process_request(self, request):
8 try:
9 host = request.META["HTTP_HOST"]
10 if host[-3:] == ":80":
11 host = host[:-3] # ignore default port number, if present
12 request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
13 except KeyError:
14 pass # use default urlconf (settings.ROOT_URLCONF)
15
16 def process_response(self, request, response):
17 if getattr(request, "urlconf", None):
18 patch_vary_headers(response, ('Host',))
19 return response
020
=== added file 'releases_urls.py'
--- releases_urls.py 1970-01-01 00:00:00 +0000
+++ releases_urls.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,36 @@
1from django.conf.urls.defaults import patterns, include, url
2
3# Uncomment the next two lines to enable the admin:
4from django.contrib import admin
5admin.autodiscover()
6
7
8urlpatterns = patterns('',
9 # Uncomment the admin/doc line below to enable admin documentation:
10 url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
11
12 # Uncomment the next line to enable the admin:
13 url(r'^admin/', include(admin.site.urls)),
14
15 url(r'^openid/', include('django_openid_auth.urls')),
16 url(r'^logout/$', 'django.contrib.auth.views.logout'),
17
18 # The license page...
19 url(r'^license$',
20 'license_protected_downloads.views.show_license',
21 name='show_license'),
22
23 # Exceptions redirected to root...
24 url(r'^license',
25 'license_protected_downloads.views.redirect_to_root',
26 name='redirect_to_root'),
27
28 # Accept the license
29 url(r'^accept-license',
30 'license_protected_downloads.views.accept_license',
31 name='accept_license'),
32
33 # Catch-all. We always return a file (or try to) if it exists.
34 # This handler does that.
35 url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
36)
037
=== modified file 'settings.py'
--- settings.py 2012-07-11 13:08:55 +0000
+++ settings.py 2012-08-06 11:55:23 +0000
@@ -86,6 +86,7 @@
86)86)
8787
88MIDDLEWARE_CLASSES = (88MIDDLEWARE_CLASSES = (
89 'middleware.MultiHostMiddleware',
89 'django.middleware.common.CommonMiddleware',90 'django.middleware.common.CommonMiddleware',
90 'django.contrib.sessions.middleware.SessionMiddleware',91 'django.contrib.sessions.middleware.SessionMiddleware',
91 'django.middleware.csrf.CsrfViewMiddleware',92 'django.middleware.csrf.CsrfViewMiddleware',
@@ -154,3 +155,8 @@
154 'django.contrib.messages.context_processors.messages',155 'django.contrib.messages.context_processors.messages',
155 'django.contrib.auth.context_processors.auth',156 'django.contrib.auth.context_processors.auth',
156)157)
158
159HOST_MIDDLEWARE_URLCONF_MAP = {
160 "releases.linaro.org": ROOT_DIR + ".releases_urls",
161 "snapshots.linaro.org": ROOT_DIR + ".snapshots_urls",
162}
157163
=== added file 'settings_releases.py'
--- settings_releases.py 1970-01-01 00:00:00 +0000
+++ settings_releases.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,16 @@
1from settings import *
2
3
4DATABASES = {
5 'default': {
6 'ENGINE': 'django.db.backends.sqlite3',
7 'NAME': '/srv/releases.linaro.org/db/licenses.db',
8 'USER': '',
9 'PASSWORD': '',
10 'HOST': '',
11 'PORT': '',
12 }
13}
14
15TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_releases" ),)
16SERVED_PATHS = ['/srv/releases.linaro.org/www']
017
=== added file 'settings_snapshots.py'
--- settings_snapshots.py 1970-01-01 00:00:00 +0000
+++ settings_snapshots.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,15 @@
1from settings import *
2
3DATABASES = {
4 'default': {
5 'ENGINE': 'django.db.backends.sqlite3',
6 'NAME': '/srv/snapshots.linaro.org/db/licenses.db',
7 'USER': '',
8 'PASSWORD': '',
9 'HOST': '',
10 'PORT': '',
11 }
12}
13
14TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_snapshots" ),)
15SERVED_PATHS = ['/srv/snapshots.linaro.org/www']
016
=== added file 'snapshots_urls.py'
--- snapshots_urls.py 1970-01-01 00:00:00 +0000
+++ snapshots_urls.py 2012-08-06 11:55:23 +0000
@@ -0,0 +1,36 @@
1from django.conf.urls.defaults import patterns, include, url
2
3# Uncomment the next two lines to enable the admin:
4from django.contrib import admin
5admin.autodiscover()
6
7
8urlpatterns = patterns('',
9 # Uncomment the admin/doc line below to enable admin documentation:
10 url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
11
12 # Uncomment the next line to enable the admin:
13 url(r'^admin/', include(admin.site.urls)),
14
15 url(r'^openid/', include('django_openid_auth.urls')),
16 url(r'^logout/$', 'django.contrib.auth.views.logout'),
17
18 # The license page...
19 url(r'^license$',
20 'license_protected_downloads.views.show_license',
21 name='show_license'),
22
23 # Exceptions redirected to root...
24 url(r'^license',
25 'license_protected_downloads.views.redirect_to_root',
26 name='redirect_to_root'),
27
28 # Accept the license
29 url(r'^accept-license',
30 'license_protected_downloads.views.accept_license',
31 name='accept_license'),
32
33 # Catch-all. We always return a file (or try to) if it exists.
34 # This handler does that.
35 url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
36)

Subscribers

People subscribed via source and target branches