diff --git a/app/forms.py b/app/forms.py index 8e581ca9..00524669 100644 --- a/app/forms.py +++ b/app/forms.py @@ -6,6 +6,7 @@ from django.contrib.auth.forms import AuthenticationForm from django.utils.translation import ugettext_lazy as _ + class BootstrapAuthenticationForm(AuthenticationForm): """Authentication form which uses boostrap CSS.""" username = forms.CharField(max_length=254, @@ -15,4 +16,4 @@ class BootstrapAuthenticationForm(AuthenticationForm): password = forms.CharField(label=_("Password"), widget=forms.PasswordInput({ 'class': 'form-control', - 'placeholder':'Password'})) + 'placeholder': 'Password'})) diff --git a/app/tests.py b/app/tests.py index 5d2c892a..fb40294e 100644 --- a/app/tests.py +++ b/app/tests.py @@ -8,6 +8,7 @@ # TODO: Configure your database in settings.py and sync before running tests. + class ViewTest(TestCase): """Tests for the application views.""" diff --git a/app/views.py b/app/views.py index 97f215e4..6875790b 100644 --- a/app/views.py +++ b/app/views.py @@ -7,43 +7,46 @@ from django.template import RequestContext from datetime import datetime + def home(request): """Renders the home page.""" assert isinstance(request, HttpRequest) return render( request, 'app/index.html', - context_instance = RequestContext(request, - { - 'title':'Home Page', - 'year':datetime.now().year, - }) + context_instance=RequestContext(request, + { + 'title': 'Home Page', + 'year': datetime.now().year, + }) ) + def contact(request): """Renders the contact page.""" assert isinstance(request, HttpRequest) return render( request, 'app/contact.html', - context_instance = RequestContext(request, - { - 'title':'Contact', - 'message':'Your contact page.', - 'year':datetime.now().year, - }) + context_instance=RequestContext(request, + { + 'title': 'Contact', + 'message': 'Your contact page.', + 'year': datetime.now().year, + }) ) + def about(request): """Renders the about page.""" assert isinstance(request, HttpRequest) return render( request, 'app/about.html', - context_instance = RequestContext(request, - { - 'title':'About', - 'message':'Your application description page.', - 'year':datetime.now().year, - }) + context_instance=RequestContext(request, + { + 'title': 'About', + 'message': 'Your application description page.', + 'year': datetime.now().year, + }) ) diff --git a/django_get_started/settings.py b/django_get_started/settings.py index 5130dbfe..38325679 100644 --- a/django_get_started/settings.py +++ b/django_get_started/settings.py @@ -86,7 +86,7 @@ STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', + # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. @@ -96,7 +96,7 @@ TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', + # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( diff --git a/django_get_started/urls.py b/django_get_started/urls.py index 0410f903..48fe1a09 100644 --- a/django_get_started/urls.py +++ b/django_get_started/urls.py @@ -12,32 +12,32 @@ # admin.autodiscover() urlpatterns = patterns('', - # Examples: - url(r'^$', 'app.views.home', name='home'), - url(r'^contact$', 'app.views.contact', name='contact'), - url(r'^about', 'app.views.about', name='about'), - url(r'^login/$', - 'django.contrib.auth.views.login', - { - 'template_name': 'app/login.html', - 'authentication_form': BootstrapAuthenticationForm, - 'extra_context': - { - 'title':'Log in', - 'year':datetime.now().year, - } - }, - name='login'), - url(r'^logout$', - 'django.contrib.auth.views.logout', - { - 'next_page': '/', - }, - name='logout'), + # Examples: + url(r'^$', 'app.views.home', name='home'), + url(r'^contact$', 'app.views.contact', name='contact'), + url(r'^about', 'app.views.about', name='about'), + url(r'^login/$', + 'django.contrib.auth.views.login', + { + 'template_name': 'app/login.html', + 'authentication_form': BootstrapAuthenticationForm, + 'extra_context': + { + 'title': 'Log in', + 'year': datetime.now().year, + } + }, + name='login'), + url(r'^logout$', + 'django.contrib.auth.views.logout', + { + 'next_page': '/', + }, + name='logout'), - # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), + # Uncomment the admin/doc line below to enable admin documentation: + # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - # Uncomment the next line to enable the admin: - # url(r'^admin/', include(admin.site.urls)), -) + # Uncomment the next line to enable the admin: + # url(r'^admin/', include(admin.site.urls)), + ) diff --git a/django_get_started/wsgi.py b/django_get_started/wsgi.py index 75987321..02ed3942 100644 --- a/django_get_started/wsgi.py +++ b/django_get_started/wsgi.py @@ -13,6 +13,7 @@ framework. """ +from django.core.wsgi import get_wsgi_application import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_get_started.settings") @@ -20,7 +21,6 @@ # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. -from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Apply WSGI middleware here. diff --git a/ptvs_virtualenv_proxy.py b/ptvs_virtualenv_proxy.py index 8e8737a6..97de10af 100644 --- a/ptvs_virtualenv_proxy.py +++ b/ptvs_virtualenv_proxy.py @@ -1,16 +1,16 @@ - # ############################################################################ - # - # Copyright (c) Microsoft Corporation. - # - # This source code is subject to terms and conditions of the Apache License, Version 2.0. A - # copy of the license can be found in the License.html file at the root of this distribution. If - # you cannot locate the Apache License, Version 2.0, please send an email to - # vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - # by the terms of the Apache License, Version 2.0. - # - # You must not remove this notice, or any other, from this software. - # - # ########################################################################### +# ############################################################################ +# +# Copyright (c) Microsoft Corporation. +# +# This source code is subject to terms and conditions of the Apache License, Version 2.0. A +# copy of the license can be found in the License.html file at the root of this distribution. If +# you cannot locate the Apache License, Version 2.0, please send an email to +# vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound +# by the terms of the Apache License, Version 2.0. +# +# You must not remove this notice, or any other, from this software. +# +# ########################################################################### import datetime import os @@ -31,6 +31,7 @@ def execfile(path, global_dict): def to_str(value): return value.encode(sys.getfilesystemencoding()) + def log(txt): """Logs fatal errors to a log file if WSGI_LOG env var is defined""" log_file = os.environ.get('WSGI_LOG') @@ -41,6 +42,7 @@ def log(txt): finally: f.close() + ptvsd_secret = os.getenv('WSGI_PTVSD_SECRET') if ptvsd_secret: log('Enabling ptvsd ...\n') @@ -49,18 +51,19 @@ def log(txt): try: ptvsd.enable_attach(ptvsd_secret) log('ptvsd enabled.\n') - except: + except: log('ptvsd.enable_attach failed\n') except ImportError: - log('error importing ptvsd.\n'); + log('error importing ptvsd.\n') + def get_wsgi_handler(handler_name): if not handler_name: raise Exception('WSGI_ALT_VIRTUALENV_HANDLER env var must be set') - + if not isinstance(handler_name, str): handler_name = to_str(handler_name) - + module_name, _, callable_name = handler_name.rpartition('.') should_call = callable_name.endswith('()') callable_name = callable_name[:-2] if should_call else callable_name @@ -80,20 +83,24 @@ def get_wsgi_handler(handler_name): except ImportError: module_name, _, callable_name = module_name.rpartition('.') should_call = callable_name.endswith('()') - callable_name = callable_name[:-2] if should_call else callable_name + callable_name = callable_name[:- + 2] if should_call else callable_name name_list.insert(0, (callable_name, should_call)) handler = None last_tb = ': ' + traceback.format_exc() - + if handler is None: - raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb)) - + raise ValueError('"%s" could not be imported%s' % + (handler_name, last_tb)) + return handler + activate_this = os.getenv('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS') if not activate_this: raise Exception('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS is not set') + def get_virtualenv_handler(): log('Activating virtualenv with %s\n' % activate_this) execfile(activate_this, dict(__file__=activate_this)) @@ -103,14 +110,15 @@ def get_virtualenv_handler(): log('Got handler: %r\n' % handler) return handler + def get_venv_handler(): log('Activating venv with executable at %s\n' % activate_this) import site sys.executable = activate_this old_sys_path, sys.path = sys.path, [] - + site.main() - + sys.path.insert(0, '') for item in old_sys_path: if item not in sys.path: