Skip to content

Commit

Permalink
Update and include more apps to yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeacom committed Jul 9, 2018
1 parent e5298bf commit 8aa3523
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 572 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
repos:
- repo: git://github.com/pre-commit/mirrors-isort
sha: 'v4.3.3'
hooks:
- id: isort
args:
- --recursive
- --settings-path
- ./setup.cfg
- .
- repo: local
hooks:
- id: eslint
Expand All @@ -29,4 +20,13 @@ repos:
language: python
entry: yapf
files: \.py$
args: [-r, -e, "app/**/migrations/", app/dataviz/, app/app/, app/enssubdomain/]
args: ["-i", "-r", "-e", "app/**/migrations/", "-p", "app/app/", "app/avatar/", "app/credits/", "app/dataviz/", "app/enssubdomain/", "app/ethos/", "app/github/"]
- repo: git://github.com/pre-commit/mirrors-isort
sha: 'v4.3.4'
hooks:
- id: isort
args:
- --recursive
- --settings-path
- ./setup.cfg
- .
2 changes: 1 addition & 1 deletion .stickler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ files:
- 'docs'
- 'node_modules/*'
- 'requirements'
- '**/migrations/*.py'
- 'app/**/migrations/*.py'
fixers:
enable: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fix-stylelint: ## Run stylelint --fix against the project directory. Requires no
@npm run stylelint:fix

fix-yapf: ## Run yapf against any included or newly introduced Python code.
@docker-compose exec web yapf -i -r -e "app/**/migrations/*.py" -p app/dataviz/ app/app/ app/enssubdomain/ app/avatar/
@docker-compose exec web yapf -i -r -e "app/**/migrations/*.py" -p app/app/ app/avatar/ app/credits/ app/dataviz/ app/enssubdomain/ app/ethos/ app/github/

fix: fix-eslint fix-stylelint fix-isort fix-yapf ## Attempt to run all fixes against the project directory.

Expand Down
170 changes: 43 additions & 127 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,60 +53,22 @@

# Application definition
INSTALLED_APPS = [
'corsheaders',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'storages',
'social_django',
'cookielaw',
'django.contrib.humanize',
'django.contrib.sitemaps',
'django.contrib.sites',
'django_extensions',
'easy_thumbnails',
'app',
'avatar',
'retail',
'rest_framework',
'bootstrap3',
'marketing',
'economy',
'dashboard',
'enssubdomain',
'faucet',
'tdi',
'gas',
'github',
'legacy',
'chartit',
'email_obfuscator',
'linkshortener',
'credits',
'gitcoinbot',
'external_bounties',
'dataviz',
'ethos',
'corsheaders', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.messages', 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles',
'storages', 'social_django', 'cookielaw', 'django.contrib.humanize', 'django.contrib.sitemaps',
'django.contrib.sites', 'django_extensions', 'easy_thumbnails', 'app', 'avatar', 'retail', 'rest_framework',
'bootstrap3', 'marketing', 'economy', 'dashboard', 'enssubdomain', 'faucet', 'tdi', 'gas', 'github', 'legacy',
'chartit', 'email_obfuscator', 'linkshortener', 'credits', 'gitcoinbot', 'external_bounties', 'dataviz', 'ethos',
'impersonate',
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'ratelimit.middleware.RatelimitMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'ratelimit.middleware.RatelimitMiddleware', 'social_django.middleware.SocialAuthExceptionMiddleware',
'impersonate.middleware.ImpersonateMiddleware',
]

Expand All @@ -119,28 +81,19 @@
'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'retail/templates/',
'external_bounties/templates/',
'dataviz/templates',
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['retail/templates/', 'external_bounties/templates/', 'dataviz/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',
'app.context.insert_settings', 'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
'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',
'app.context.insert_settings',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
}, ]

SITE_ID = env.int('SITE_ID', default=1)
WSGI_APPLICATION = env('WSGI_APPLICATION', default='app.wsgi.application')
Expand All @@ -151,20 +104,15 @@

# Password validation
# https://docs.djangoproject.com/en/1.11/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',
},
]
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',
}, ]

REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
Expand Down Expand Up @@ -323,22 +271,13 @@
SOCIAL_AUTH_GITHUB_SECRET = GITHUB_CLIENT_SECRET
SOCIAL_AUTH_POSTGRES_JSONFIELD = True
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'first_name', 'last_name', 'email']
SOCIAL_AUTH_GITHUB_SCOPE = [
'read:public_repo',
'read:user',
'user:email',
]
SOCIAL_AUTH_GITHUB_SCOPE = ['read:public_repo', 'read:user', 'user:email', ]

SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',
'app.pipeline.save_profile',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.social_auth.social_details', 'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed', 'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username', 'social_core.pipeline.user.create_user', 'app.pipeline.save_profile',
'social_core.pipeline.social_auth.associate_user', 'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)

Expand Down Expand Up @@ -391,10 +330,7 @@
env('GA_AUTH_PROVIDER_X509_CERT_URL', default='https://www.googleapis.com/oauth2/v1/certs'),
'client_x509_cert_url': env('GA_CLIENT_X509_CERT_URL', default='')
}
HOTJAR_CONFIG = {
'hjid': env.int('HOTJAR_ID', default=0),
'hjsv': env.int('HOTJAR_SV', default=0),
}
HOTJAR_CONFIG = {'hjid': env.int('HOTJAR_ID', default=0), 'hjsv': env.int('HOTJAR_SV', default=0), }

# Rollbar - https://rollbar.com/docs/notifier/pyrollbar/#django
ROLLBAR_CLIENT_TOKEN = env('ROLLBAR_CLIENT_TOKEN', default='') # post_client_item
Expand All @@ -411,28 +347,10 @@
'capture_ip': 'anonymize',
'capture_username': True,
'scrub_fields': [
'pw',
'passwd',
'password',
'secret',
'confirm_password',
'confirmPassword',
'password_confirmation',
'passwordConfirmation',
'access_token',
'accessToken',
'auth',
'authentication',
'github_access_token',
'github_client_secret',
'secret_key',
'twitter_access_token',
'twitter_access_secret',
'twitter_consumer_secret',
'mixpanel_token',
'slack_verification_token',
'redirect_state',
'slack_token',
'pw', 'passwd', 'password', 'secret', 'confirm_password', 'confirmPassword', 'password_confirmation',
'passwordConfirmation', 'access_token', 'accessToken', 'auth', 'authentication', 'github_access_token',
'github_client_secret', 'secret_key', 'twitter_access_token', 'twitter_access_secret',
'twitter_consumer_secret', 'mixpanel_token', 'slack_verification_token', 'redirect_state', 'slack_token',
'priv_key',
],
}
Expand All @@ -448,9 +366,7 @@
rollbar.init(**ROLLBAR)

# List of github usernames to not count as comments on an issue
IGNORE_COMMENTS_FROM = [
'gitcoinbot',
]
IGNORE_COMMENTS_FROM = ['gitcoinbot', ]

# optional: only needed if you run the activity-report management command
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID', default='')
Expand Down
26 changes: 3 additions & 23 deletions app/app/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,9 @@ class StaticViewSitemap(sitemaps.Sitemap):

def items(self):
return [
'dashboard',
'new_funding',
'fulfill_bounty',
'process_funding',
'funding_details',
'tip',
'terms',
'privacy',
'cookie',
'prirp',
'apitos',
'about',
'index',
'help',
'whitepaper',
'whitepaper_access',
'_leaderboard',
'ios',
'faucet',
'mission',
'slack',
'universe_index',
'results',
'dashboard', 'new_funding', 'fulfill_bounty', 'process_funding', 'funding_details', 'tip', 'terms',
'privacy', 'cookie', 'prirp', 'apitos', 'about', 'index', 'help', 'whitepaper', 'whitepaper_access',
'_leaderboard', 'ios', 'faucet', 'mission', 'slack', 'universe_index', 'results',
]

def location(self, item):
Expand Down
6 changes: 1 addition & 5 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ def sync_profile(handle, user=None, hide_profile=True):
rollbar.report_message('Failed to fetch github username', 'warning', extra_data=data)
return None

defaults = {
'last_sync_date': timezone.now(),
'data': data,
'hide_profile': hide_profile,
}
defaults = {'last_sync_date': timezone.now(), 'data': data, 'hide_profile': hide_profile, }

if user and isinstance(user, User):
defaults['user'] = user
Expand Down
4 changes: 1 addition & 3 deletions app/avatar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class AvatarAdmin(GeneralAdmin):
ordering = ['-id']
fields = ['config', 'use_github_avatar', 'svg_asset', 'png_asset', 'created_on', 'modified_on']
readonly_fields = ['svg_asset', 'png_asset', 'created_on', 'modified_on']
inlines = [
ProfileInline,
]
inlines = [ProfileInline, ]

def svg_asset(self, instance):
"""Define the avatar SVG tag to be displayed in the admin."""
Expand Down
5 changes: 1 addition & 4 deletions app/avatar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@
from .views import avatar, save_avatar

app_name = 'avatar'
urlpatterns = [
re_path(r'^view', avatar, name='view_avatar'),
re_path(r'^save', save_avatar, name='save_avatar'),
]
urlpatterns = [re_path(r'^view', avatar, name='view_avatar'), re_path(r'^save', save_avatar, name='save_avatar'), ]
8 changes: 2 additions & 6 deletions app/avatar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def build_avatar_svg(svg_path='avatar.svg', line_color='#781623', icon_size=None

# Build the list of avatar components
components = [
icon_width,
icon_height,
icon_width, icon_height,
Line([(0, icon_height / 2), (icon_width, icon_height / 2)],
width=f'{icon_height}px',
color=payload.get('background_color')),
Expand Down Expand Up @@ -270,10 +269,7 @@ def handle_avatar_payload(request):
for k, v in body.items():
if v and k in valid_component_keys:
component_type, svg_asset = v.lstrip('v2/images/avatar/').split('/')
avatar_dict[k] = {
'component_type': component_type,
'svg_asset': svg_asset,
}
avatar_dict[k] = {'component_type': component_type, 'svg_asset': svg_asset, }
elif v and k in valid_color_keys:
avatar_dict[k] = v
return avatar_dict
Expand Down
Loading

0 comments on commit 8aa3523

Please sign in to comment.