Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Run PEP8 on content #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,4 +16,4 @@ class BootstrapAuthenticationForm(AuthenticationForm):
password = forms.CharField(label=_("Password"),
widget=forms.PasswordInput({
'class': 'form-control',
'placeholder':'Password'}))
'placeholder': 'Password'}))
1 change: 1 addition & 0 deletions app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# TODO: Configure your database in settings.py and sync before running tests.


class ViewTest(TestCase):
"""Tests for the application views."""

Expand Down
37 changes: 20 additions & 17 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
)
4 changes: 2 additions & 2 deletions django_get_started/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = (
Expand Down
54 changes: 27 additions & 27 deletions django_get_started/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
2 changes: 1 addition & 1 deletion django_get_started/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
framework.

"""
from django.core.wsgi import get_wsgi_application
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_get_started.settings")

# 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.
Expand Down
54 changes: 31 additions & 23 deletions ptvs_virtualenv_proxy.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -41,6 +42,7 @@ def log(txt):
finally:
f.close()


ptvsd_secret = os.getenv('WSGI_PTVSD_SECRET')
if ptvsd_secret:
log('Enabling ptvsd ...\n')
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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:
Expand Down