Skip to content

Commit

Permalink
formatted files
Browse files Browse the repository at this point in the history
  • Loading branch information
hemant10yadav committed Jan 3, 2025
1 parent 7fef39a commit 028b870
Show file tree
Hide file tree
Showing 53 changed files with 842 additions and 660 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CI

on:
pull_request:
branches: [ 'main' ]
branches: ['main']

push:
branches: [ 'main' ]
branches: ['main']

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ repos:
ci:
autoupdate_schedule: weekly
skip: []
submodules: false
submodules: false
12 changes: 6 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from oauth2_provider.models import Application
from rest_framework.test import APIClient

from users.factories import UserFactory, FCMDeviceFactory
from messaging.factories import ServerFactory
from users.factories import FCMDeviceFactory, UserFactory


@pytest.fixture
def user(db):
Expand All @@ -27,7 +27,7 @@ def auth_device(user, api_client):
"""
Create the Basic Authentication credentials for the test user.
"""
credentials = f"{user.username}:testpass".encode("utf-8")
credentials = f"{user.username}:testpass".encode()
base64_credentials = base64.b64encode(credentials).decode("utf-8")
cred = f"Basic {base64_credentials}"
api_client.credentials(HTTP_AUTHORIZATION=cred)
Expand All @@ -50,7 +50,7 @@ def oauth_app(user):

@pytest.fixture
def authed_client(api_client, oauth_app):
auth = f'{oauth_app.client_id}:{oauth_app.raw_client_secret}'.encode('utf-8')
credentials = base64.b64encode(auth).decode('utf-8')
api_client.defaults['HTTP_AUTHORIZATION'] = 'Basic ' + credentials
auth = f"{oauth_app.client_id}:{oauth_app.raw_client_secret}".encode()
credentials = base64.b64encode(auth).decode("utf-8")
api_client.defaults["HTTP_AUTHORIZATION"] = "Basic " + credentials
return api_client
2 changes: 1 addition & 1 deletion connectid/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'connectid.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "connectid.settings")

application = get_asgi_application()
21 changes: 9 additions & 12 deletions connectid/localsettings.example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-yofpqrszrdtv0ftihjd09cuim2al9^n9j^b85%-y0v*^_lj18d'
SECRET_KEY = "django-insecure-yofpqrszrdtv0ftihjd09cuim2al9^n9j^b85%-y0v*^_lj18d"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -8,20 +8,17 @@
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'connect',
'USER': 'connect',
'PASSWORD': 'connect',
'HOST': 'localhost',
'PORT': '5433'
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "connect",
"USER": "connect",
"PASSWORD": "connect",
"HOST": "localhost",
"PORT": "5433",
}
}

ALLOWED_HOSTS = [
'127.0.0.1',
'localhost'
]
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]

TWILIO_ACCOUNT_SID = None
TWILIO_AUTH_TOKEN = None
Expand Down
191 changes: 93 additions & 98 deletions connectid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"""
import logging
import os
import sentry_sdk

from pathlib import Path

import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.redis import RedisIntegration


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -32,60 +31,60 @@
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'phonenumber_field',
'users.apps.UsersConfig',
'messaging',
'oauth2_provider',
'payments',
'rest_framework',
'axes',
'fcm_django',
'django.contrib.sites',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"phonenumber_field",
"users.apps.UsersConfig",
"messaging",
"oauth2_provider",
"payments",
"rest_framework",
"axes",
"fcm_django",
"django.contrib.sites",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'axes.middleware.AxesMiddleware',
'utils.middleware.CurrentVersionMiddleware'
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"axes.middleware.AxesMiddleware",
"utils.middleware.CurrentVersionMiddleware",
]

AUTHENTICATION_BACKENDS = [
# AxesStandaloneBackend should be the first backend in the AUTHENTICATION_BACKENDS list.
'axes.backends.AxesStandaloneBackend',
'django.contrib.auth.backends.ModelBackend',
"axes.backends.AxesStandaloneBackend",
"django.contrib.auth.backends.ModelBackend",
]

ROOT_URLCONF = 'connectid.urls'
ROOT_URLCONF = "connectid.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "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_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 = 'connectid.wsgi.application'
WSGI_APPLICATION = "connectid.wsgi.application"


TRUSTED_COMMCAREHQ_HOSTS = [
Expand All @@ -99,19 +98,17 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'users.validators.EntropyPasswordValidator',
'OPTIONS': {
'min_strength': 2
}
"NAME": "users.validators.EntropyPasswordValidator",
"OPTIONS": {"min_strength": 2},
},
]

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

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

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -120,89 +117,86 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

AUTH_USER_MODEL = 'users.ConnectUser'
AUTH_USER_MODEL = "users.ConnectUser"

LOG_DIR = BASE_DIR
DJANGO_LOG_FILE = LOG_DIR / 'django.log'
DJANGO_LOG_FILE = LOG_DIR / "django.log"
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'django.server': {
'()': 'django.utils.log.ServerFormatter',
'format': '[{server_time}] {message}',
'style': '{',
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[{server_time}] {message}",
"style": "{",
}
},
'handlers': {
'file' : {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': DJANGO_LOG_FILE,
'maxBytes': 10 * 1024 * 1024, # 10 MB
'backupCount': 20 # Backup 200 MB of logs
"handlers": {
"file": {
"level": "INFO",
"class": "logging.handlers.RotatingFileHandler",
"filename": DJANGO_LOG_FILE,
"maxBytes": 10 * 1024 * 1024, # 10 MB
"backupCount": 20, # Backup 200 MB of logs
},
'console': {
'class': 'logging.StreamHandler',
"console": {
"class": "logging.StreamHandler",
},
'django.server': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'django.server',
"django.server": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "django.server",
},
},
'loggers': {
'django': {
'handlers': ['file', 'console'],
'level': 'INFO',
'propagate': True,
"loggers": {
"django": {
"handlers": ["file", "console"],
"level": "INFO",
"propagate": True,
},
'django.server': {
'handlers': ['django.server'],
'level': 'INFO',
'propagate': False,
"django.server": {
"handlers": ["django.server"],
"level": "INFO",
"propagate": False,
},
},
}


REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.BasicAuthentication",
"oauth2_provider.contrib.rest_framework.OAuth2Authentication",
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.AnonRateThrottle",
"rest_framework.throttling.UserRateThrottle",
],
'DEFAULT_THROTTLE_RATES': {
'anon': '100/day',
'user': '1000/day'
},
"DEFAULT_THROTTLE_RATES": {"anon": "100/day", "user": "1000/day"},
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.AcceptHeaderVersioning",
"DEFAULT_VERSION": "1.0",
"ALLOWED_VERSIONS": ["1.0"]
"ALLOWED_VERSIONS": ["1.0"],
}


AXES_COOLOFF_TIME = 6
AXES_IPWARE_META_PRECEDENCE_ORDER = [
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR',
"HTTP_X_FORWARDED_FOR",
"REMOTE_ADDR",
]

LOGIN_URL = '/admin/login/'
LOGIN_URL = "/admin/login/"

OAUTH2_PROVIDER = {
"OIDC_ENABLED": True,
Expand All @@ -225,7 +219,7 @@
"DELETE_INACTIVE_DEVICES": False,
}

OAUTH2_PROVIDER_APPLICATION_MODEL = 'oauth2_provider.Application'
OAUTH2_PROVIDER_APPLICATION_MODEL = "oauth2_provider.Application"

SITE_ID = 1

Expand All @@ -236,11 +230,12 @@
SENTRY_TRACES_SAMPLE_RATE = 0.0


from .localsettings import *
from .localsettings import * # noqa: F403, F401, E402

# Firebase
if FCM_CREDENTIALS:
from firebase_admin import credentials, initialize_app

creds = credentials.Certificate(FCM_CREDENTIALS)
default_app = initialize_app(credential=creds)

Expand Down
Loading

0 comments on commit 028b870

Please sign in to comment.