Skip to content

Commit

Permalink
Merge pull request #21 from lukpueh/upgrade-django-18
Browse files Browse the repository at this point in the history
Upgrade to at least Django 1.8 Fix - #6
  • Loading branch information
aaaaalbert authored Feb 1, 2017
2 parents 7c5fc06 + 4e4b6ab commit 2840e00
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 94 deletions.
43 changes: 24 additions & 19 deletions html/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,49 @@
Custom Installer Builder.
"""

from django.conf.urls import patterns, url
from django.conf.urls import url

import custominstallerbuilder.common.constants as constants
import custominstallerbuilder.html.views as views


urlpatterns = patterns('custominstallerbuilder.html.views',
urlpatterns = [

# Builder interface.

# These patterns match the string between ^ and $ against the end portion of
# the URL.
# Example: http://example.com/custominstallerbuilder/
# or http://example.com/custominstallerbuilder/ajax/build/
url(r'^$', 'builder_page', name='builder'),
url(r'^fastlane/$', 'fastlane_page', name='fastlane_page'),
url(r'^ajax/build/$', 'build_installers', name='ajax-build'),
url(r'^ajax/save/$', 'save_state', name='ajax-save'),
url(r'^ajax/restore/$', 'restore_state', name='ajax-restore'),
url(r'^ajax/reset/$', 'reset_state', name='ajax-reset'),
url(r'^ajax/add-user/$', 'add_user', name='ajax-add-user'),
url(r'^$', views.builder_page, name='builder'),
url(r'^fastlane/$', views.fastlane_page, name='fastlane_page'),
url(r'^ajax/build/$', views.build_installers, name='ajax-build'),
url(r'^ajax/save/$', views.save_state, name='ajax-save'),
url(r'^ajax/restore/$', views.restore_state, name='ajax-restore'),
url(r'^ajax/reset/$', views.reset_state, name='ajax-reset'),
url(r'^ajax/add-user/$', views.add_user, name='ajax-add-user'),


# Download pages.

# This pattern matches against the end portion of a URL with a valid build
# ID (as specified by custominstallerbuilder.common.constants.BUILD_ID_REGEX)
# followed by a slash.
# Example: http://example.com/custominstallerbuilder/28d0ccc35d16fc9114f47f251968b3354183544c/
url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/$', 'download_installers_page', name='download-installers-page'),
url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/$',
views.download_installers_page, name='download-installers-page'),

# This pattern extends the one above by appending 'keys/' to the URL.
url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/keys/$', 'download_keys_page', name='download-keys-page'),

url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/keys/$',
views.download_keys_page, name='download-keys-page'),

# This pattern extends the one above by further matching against a build ID
# and two lowercase alphabetic strings, each followed by a slash.
# Example: http://example.com/custominstallerbuilder/28d0ccc35d16fc9114f47f251968b3354183544c/foo/bar/
url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/installers/(?P<platform>[a-z]+)/$',
'download_installer', name='download-installer'),
url(r'^(?P<build_id>' + constants.BUILD_ID_REGEX + ')/keys/(?P<key_type>[a-z]+)/$',
'download_keys', name='download-keys'),
)
url(r'^(?P<build_id>' +
constants.BUILD_ID_REGEX + ')/installers/(?P<platform>[a-z]+)/$',
views.download_installer, name='download-installer'),
url(r'^(?P<build_id>' +
constants.BUILD_ID_REGEX + ')/keys/(?P<key_type>[a-z]+)/$',
views.download_keys, name='download-keys'),
]
83 changes: 40 additions & 43 deletions html/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
import json

from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import Http404, HttpResponse, HttpResponseRedirect, \
FileResponse
from django.shortcuts import render

import custominstallerbuilder.common.constants as constants
import custominstallerbuilder.common.packager as packager
Expand Down Expand Up @@ -91,10 +90,10 @@ def wrapper(request, *args, **kwargs):
######################

def TextResponse(message=''):
return HttpResponse(message, mimetype='text/plain')
return HttpResponse(message, content_type='text/plain')

def ErrorResponse(message=''):
return HttpResponse(message, status=500, mimetype='text/plain')
return HttpResponse(message, status=500, content_type='text/plain')



Expand Down Expand Up @@ -137,8 +136,8 @@ def build_installers(request):
try:
manager = BuildManager(vessel_list=build_data['vessels'], user_data=user_data)
build_results = manager.prepare()
except validations.ValidationError, e:
return ErrorResponse(e.message)
except validations.ValidationError as e:
return ErrorResponse(e)
except:
log_exception(request)
return ErrorResponse('Unknown error occured while trying to build the installers.')
Expand Down Expand Up @@ -177,9 +176,9 @@ def save_state(request):
"""
if 'build_string' not in request.POST:
return ErrorResponse('Unable to save configuration.')

request.session['build_string'] = request.POST['build_string']

return TextResponse()


Expand Down Expand Up @@ -271,8 +270,8 @@ def ErrorResponse(message=''):
if public_key is not None:
validations.validate_public_key(public_key)

except validations.ValidationError, e:
return ErrorResponse(e.message)
except validations.ValidationError as e:
return ErrorResponse(e)
except:
log_exception(request)
return ErrorResponse('Unknown error occured while trying to add user.')
Expand Down Expand Up @@ -352,7 +351,9 @@ def download_keys(request, build_id, key_type):
# Generally, it is undesirable to serve files directly through django, but
# the key bundles should be very small and still download quickly.
bundle_filename = key_filenames[key_type]
response = HttpResponse(FileWrapper(file(bundle_filename)), content_type='application/zip')
# FileResponse is a subclass of StreamingHttpResponse optimized
# for binary files requires Django >1.8
response = FileResponse(open(bundle_filename), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=' + os.path.split(bundle_filename)[1]
response['Content-Length'] = os.path.getsize(bundle_filename)

Expand Down Expand Up @@ -387,12 +388,10 @@ def builder_page(request):
<Returns>
A Django response.
"""
return render_to_response('builder.html',
{
'step': 'build',
},
context_instance=RequestContext(request),
)
return render(request, 'builder.html',
{
'step': 'build',
})



Expand Down Expand Up @@ -433,15 +432,13 @@ def download_keys_page(request, build_id):
has_private_keys = True
break

return render_to_response('download_keys.html',
{
'build_id': build_id,
'has_private_keys': has_private_keys,
'keys_downloaded': keys_downloaded,
'step': 'keys',
},
context_instance=RequestContext(request)
)
return render(request, 'download_keys.html',
{
'build_id': build_id,
'has_private_keys': has_private_keys,
'keys_downloaded': keys_downloaded,
'step': 'keys',
})



Expand All @@ -465,7 +462,7 @@ def download_installers_page(request, build_id):
"""

manager = BuildManager(build_id=build_id)

# Invalid build IDs should results in an error.
if not os.path.isdir(manager.get_build_directory()):
raise Http404
Expand All @@ -492,16 +489,14 @@ def download_installers_page(request, build_id):
if 'fast_lane_build' in request.session['build_results'][build_id]:
step = False

return render_to_response('download_installers.html',
{
'build_id': build_id,
'installers': installer_links,
'share_url': share_url,
'step': step,
'user_built': user_built,
},
context_instance=RequestContext(request)
)
return render(request, 'download_installers.html',
{
'build_id': build_id,
'installers': installer_links,
'share_url': share_url,
'step': step,
'user_built': user_built,
})



Expand Down Expand Up @@ -603,13 +598,13 @@ def fastlane_page(request):
args=[build_id]))


return render_to_response('download_installers.html', {
return render(request, 'download_installers.html', {
'fast_lane': True,
'build_id': build_id,
'installers': installer_links,
'share_url': share_url,
'keys_downloaded': keys_downloaded,
}, context_instance=RequestContext(request))
})



Expand All @@ -632,5 +627,7 @@ def error_page(request):

# Automatically choose the email address of the first administrator given
# in the settings file.
return render_to_response('error.html', {'email': settings.ADMINS[0][1]},
context_instance=RequestContext(request))
return render(request, 'error.html',
{
'email': settings.ADMINS[0][1]
})
5 changes: 4 additions & 1 deletion local/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

# Unless you are actively debugging, these should be set to False.
DEBUG = True
TEMPLATE_DEBUG = DEBUG

# During testing, you may want to use Django's built-in static file server.
SERVE_STATIC = False
Expand All @@ -45,3 +44,7 @@

# The locations of the customized installers created by this program.
CUSTOM_INSTALLER_URL = PROJECT_URL + 'static/installers/'

# If you set DEBUG to False, you also need to properly set the ALLOWED_HOSTS
# setting, eg.:
# ALLOWED_HOSTS = ["example.com"]
34 changes: 23 additions & 11 deletions settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,39 @@

ROOT_URLCONF = 'custominstallerbuilder.urls'

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.media',
'django.core.context_processors.request',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Adds 'debug' and 'sql_queries' to template context
#'django.template.context_processors.debug',
# Adds 'LANGUAGES' and 'LANGUAGE_CODE' to template context
# 'django.template.context_processors.i18n',
'django.template.context_processors.media',
# Adds 'STATIC_URL' to template context
# 'django.template.context_processors.static',
# Adds 'TIME_ZONE' to template context
# 'django.template.context_processors.tz',
# Adds 'request' to template context
# 'django.template.context_processors.request',
# Adds 'messages' and 'DEFAULT_MESSAGE_LEVELS' to context
#'django.contrib.messages.context_processors.messages',
],
},
},
]

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

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',

'custominstallerbuilder.common.logging.AutoLogger',
)

INSTALLED_APPS = (
'django.contrib.sessions',

'custominstallerbuilder.common',
'custominstallerbuilder.html',
'custominstallerbuilder.xmlrpc',
Expand Down Expand Up @@ -103,7 +116,6 @@

# Unless you are actively debugging, these should be set to False.
DEBUG = False
TEMPLATE_DEBUG = DEBUG

SECRET_KEY = '***** This should be changed to a random string *****'

Expand Down
19 changes: 10 additions & 9 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
initiates a static file server if local settings call for it.
"""

from django.conf.urls import include, patterns, url
from django.conf.urls import include, url
from django.conf import settings

from django.views.static import serve

# Display errors gracefully.
handler500 = 'custominstallerbuilder.html.views.error_page'

urlpatterns = patterns('',
urlpatterns = [
# XML-RPC URL patterns. Matches all URLs which start with 'xmlrpc' followed
# by a slash.
# Example: http://example.com/custominstallerbuilder/xmlrpc/[...]
Expand All @@ -32,18 +32,19 @@
# Example: http://example.com/custominstallerbuilder/
# or http://example.com/custominstallerbuilder/ajax/build/
url(r'', include('custominstallerbuilder.html.urls')),
)
]

# Use the 'SERVE_STATIC' and 'STATIC_BASE' custom settings to determine if
# Django should serve static files itself. This is useful for debugging.
if getattr(settings, 'SERVE_STATIC', False):

# Matches URLs which start with the contents of STATIC_BASE as specified in
# settings.py, followed by a slash then any string. That string is
# interpreted as a path for a file to lookup.
# Example: http://example.com/custominstallerbuilder/static/[...]
regex = r'^%s/(?P<path>.*)$' % settings.STATIC_BASE.rstrip('/')

urlpatterns += patterns('',
url(regex, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': settings.DEBUG}),
)

urlpatterns += [
url(regex, serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': settings.DEBUG}),
]
10 changes: 6 additions & 4 deletions xmlrpc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
Custom Installer Builder.
"""

from django.conf.urls import patterns, url
from django.conf.urls import url
import custominstallerbuilder.xmlrpc.views as views



# Note: All URLs that have been delegated to these patterns have already
# matched the '^xmlrpc/' prefix. These patterns test against the rest of the
# URL string.

urlpatterns = patterns('',
urlpatterns = [
# Matches the empty string.
# Example: http://example.com/custominstallerbuilder/xmlrpc/
url(r'^$', 'custominstallerbuilder.xmlrpc.views.xmlrpc_handler', name='xmlrpc-handler'),
)
url(r'^$', views.xmlrpc_handler, name='xmlrpc-handler'),
]
Loading

0 comments on commit 2840e00

Please sign in to comment.