Skip to content

Commit

Permalink
Lint + Apply Black (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmaanT committed Nov 23, 2019
1 parent 43a2770 commit 1be0f19
Show file tree
Hide file tree
Showing 44 changed files with 717 additions and 538 deletions.
129 changes: 60 additions & 69 deletions Platform/settings/base.py
Expand Up @@ -22,108 +22,100 @@
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', 'o7ql0!vuk0%rgrh9p2bihq#pege$qqlm@zo#8&t==%&za33m*2')
SECRET_KEY = os.environ.get("SECRET_KEY", "o7ql0!vuk0%rgrh9p2bihq#pege$qqlm@zo#8&t==%&za33m*2")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_api_key',
'oauth2_provider',
'corsheaders',
'shortener.apps.ShortenerConfig',
'org.apps.OrgConfig',
'accounts.apps.AccountsConfig',
'services.apps.ServicesConfig',
'application'
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
"rest_framework_api_key",
"oauth2_provider",
"corsheaders",
"shortener.apps.ShortenerConfig",
"org.apps.OrgConfig",
"accounts.apps.AccountsConfig",
"services.apps.ServicesConfig",
"application",
]


MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'oauth2_provider.middleware.OAuth2TokenMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"oauth2_provider.middleware.OAuth2TokenMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'Platform.urls'
ROOT_URLCONF = "Platform.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['Platform/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["Platform/templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
},
}
]

WSGI_APPLICATION = 'Platform.wsgi.application'
WSGI_APPLICATION = "Platform.wsgi.application"


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
'default': dj_database_url.config(default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'))
"default": dj_database_url.config(default="sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3"))
}

# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]

# Authentication Backends

AUTHENTICATION_BACKENDS = (
'oauth2_provider.backends.OAuth2Backend',
'django.contrib.auth.backends.ModelBackend',
'accounts.backends.ShibbolethRemoteUserBackend',
"oauth2_provider.backends.OAuth2Backend",
"django.contrib.auth.backends.ModelBackend",
"accounts.backends.ShibbolethRemoteUserBackend",
)


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'America/New_York'
TIME_ZONE = "America/New_York"

USE_I18N = True

Expand All @@ -135,8 +127,8 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")

# CORS Settings

Expand All @@ -145,19 +137,18 @@
# OAuth2 Settings

OAUTH2_PROVIDER = {
'SCOPES': {
'read': 'Read scope',
'write': 'Write scope',
'introspection': 'Introspect token scope',
"SCOPES": {
"read": "Read scope",
"write": "Write scope",
"introspection": "Introspect token scope",
},
'ALLOWED_REDIRECT_URI_SCHEMES': ['http', 'https'],

"ALLOWED_REDIRECT_URI_SCHEMES": ["http", "https"],
}

# Custom User Model

AUTH_USER_MODEL = 'accounts.User'
AUTH_USER_MODEL = "accounts.User"

EMAIL_WEB_SERVICE_URL = os.environ.get('EMAIL_WEB_SERVICE_URL', 'http://127.0.0.1')
EMAIL_WEB_SERVICE_USERNAME = os.environ.get('EMAIL_WEB_SERVICE_USERNAME', '')
EMAIL_WEB_SERVICE_PASSWORD = os.environ.get('EMAIL_WEB_SERVICE_PASSWORD', '')
EMAIL_WEB_SERVICE_URL = os.environ.get("EMAIL_WEB_SERVICE_URL", "http://127.0.0.1")
EMAIL_WEB_SERVICE_USERNAME = os.environ.get("EMAIL_WEB_SERVICE_USERNAME", "")
EMAIL_WEB_SERVICE_PASSWORD = os.environ.get("EMAIL_WEB_SERVICE_PASSWORD", "")
6 changes: 3 additions & 3 deletions Platform/settings/ci.py
@@ -1,6 +1,6 @@
from Platform.settings.base import *
from Platform.settings.base import * # noqa


TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
TEST_RUNNER = "xmlrunner.extra.djangotestrunner.XMLTestRunner"
TEST_OUTPUT_VERBOSE = 2
TEST_OUTPUT_DIR = 'test-results'
TEST_OUTPUT_DIR = "test-results"
2 changes: 1 addition & 1 deletion Platform/settings/development.py
@@ -1 +1 @@
from Platform.settings.base import *
from Platform.settings.base import * # noqa
34 changes: 17 additions & 17 deletions Platform/settings/production.py
@@ -1,37 +1,37 @@
import os

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from Platform.settings.base import *
from Platform.settings.base import * # noqa
from Platform.settings.base import DATABASES


DEBUG = False

# Fix MySQL Emoji support
DATABASES['default']['OPTIONS'] = {'charset': 'utf8mb4'}
DATABASES["default"]["OPTIONS"] = {"charset": "utf8mb4"}

# Honour the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# Allow production host headers
ALLOWED_HOSTS = ['platform.pennlabs.org', 'platform.apps.pennlabs.org']
ALLOWED_HOSTS = ["platform.pennlabs.org", "platform.apps.pennlabs.org"]

SENTRY_URL = os.environ.get('SENTRY_URL', '')
SENTRY_URL = os.environ.get("SENTRY_URL", "")

sentry_sdk.init(
dsn=SENTRY_URL,
integrations=[DjangoIntegration()]
)
sentry_sdk.init(dsn=SENTRY_URL, integrations=[DjangoIntegration()])

# CORS settings
CORS_ORIGIN_ALLOW_ALL = False

CORS_ORIGIN_WHITELIST = (
'auth.pennlabs.org',
'pennbasics.com',
'penncfa.com',
'pennclubs.com',
'penncoursealert.com',
'penncourseplan.com',
'penncoursereview.com',
'pennlabs.org',
"auth.pennlabs.org",
"pennbasics.com",
"penncfa.com",
"pennclubs.com",
"penncoursealert.com",
"penncourseplan.com",
"penncoursereview.com",
"pennlabs.org",
)
27 changes: 14 additions & 13 deletions Platform/urls.py
Expand Up @@ -4,19 +4,20 @@
from rest_framework.schemas import get_schema_view


admin.site.site_header = 'Platform Admin'
admin.site.site_header = "Platform Admin"

urlpatterns = [
path('', include('application.urls')),
path('accounts/', include('accounts.urls')),
path('org/', include('org.urls')),
path('services/', include('services.urls')),
path('admin/', admin.site.urls),
path('openapi/', get_schema_view(
title='Platform Documentation'
), name='openapi-schema'),
path('documentation/', TemplateView.as_view(
template_name='redoc.html',
extra_context={'schema_url': 'openapi-schema'}
), name='documentation'),
path("", include("application.urls")),
path("accounts/", include("accounts.urls")),
path("org/", include("org.urls")),
path("services/", include("services.urls")),
path("admin/", admin.site.urls),
path("openapi/", get_schema_view(title="Platform Documentation"), name="openapi-schema"),
path(
"documentation/",
TemplateView.as_view(
template_name="redoc.html", extra_context={"schema_url": "openapi-schema"}
),
name="documentation",
),
]
2 changes: 1 addition & 1 deletion Platform/wsgi.py
Expand Up @@ -12,6 +12,6 @@
from django.core.wsgi import get_wsgi_application


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Platform.settings.production')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Platform.settings.production")

application = get_wsgi_application()
44 changes: 28 additions & 16 deletions accounts/admin.py
Expand Up @@ -4,10 +4,10 @@


class StudentAdmin(admin.ModelAdmin):
readonly_fields = ('user',)
search_fields = ('user__username', 'user__first_name', 'user__last_name')
list_display = ('username', 'first_name', 'last_name')
list_filter = ('school', 'major')
readonly_fields = ("user",)
search_fields = ("user__username", "user__first_name", "user__last_name")
list_display = ("username", "first_name", "last_name")
list_filter = ("school", "major")

def username(self, obj):
return obj.user.username
Expand All @@ -20,19 +20,31 @@ def last_name(self, obj):


class UserAdmin(admin.ModelAdmin):
readonly_fields = ('username', 'pennid', 'last_login', 'date_joined')
search_fields = ('username', 'first_name', 'last_name')
list_display = ('username', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser', 'is_active', 'affiliation')
readonly_fields = ("username", "pennid", "last_login", "date_joined")
search_fields = ("username", "first_name", "last_name")
list_display = ("username", "first_name", "last_name", "is_staff")
list_filter = ("is_staff", "is_superuser", "is_active", "affiliation")
fieldsets = (
(None, {
'fields': ('username', 'pennid', 'first_name', 'last_name', 'email', 'is_superuser', 'is_staff',
'is_active', 'affiliation', 'product_permission', 'last_login', 'date_joined')
}),
('Advanced', {
'classes': ('collapse',),
'fields': ('groups', 'user_permissions')
})
(
None,
{
"fields": (
"username",
"pennid",
"first_name",
"last_name",
"email",
"is_superuser",
"is_staff",
"is_active",
"affiliation",
"product_permission",
"last_login",
"date_joined",
)
},
),
("Advanced", {"classes": ("collapse",), "fields": ("groups", "user_permissions")}),
)


Expand Down
2 changes: 1 addition & 1 deletion accounts/apps.py
Expand Up @@ -2,4 +2,4 @@


class AccountsConfig(AppConfig):
name = 'accounts'
name = "accounts"
2 changes: 1 addition & 1 deletion accounts/auth.py
Expand Up @@ -5,7 +5,7 @@

class LabsMixin(ProtectedResourceMixin):
def dispatch(self, request, *args, **kwargs):
if hasattr(request.user, 'student') and hasattr(request.user.student, 'member'):
if hasattr(request.user, "student") and hasattr(request.user.student, "member"):
return super().dispatch(request, *args, **kwargs)
return HttpResponseForbidden()

Expand Down

0 comments on commit 1be0f19

Please sign in to comment.