Skip to content
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/ruff-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ruff-check
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: ruff check --output-format=github
Comment on lines +5 to +18
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ dependencies = [
"django-mathfilters>=1.0.0",
"django-humanize>=0.1.2",
]

[tool.ruff.lint.per-file-ignores]
"*/migrations/*.py" = ["RUF012"]
Empty file removed slack_bot/slack.py
Empty file.
4 changes: 1 addition & 3 deletions twisted/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ HACKATIME_CLIENT_SECRET =
HACKATIME_REDIRECT_URI = https://localhost:8000/auth/hackatime_callback

SLACK_TOKEN = xoxb-***
SLACK_SIGNING_SECRET =
SLACK_APP_TOKEN = xapp-***
SLACK_MODE = https
SLACK_LOG_CHANNEL = C***

ALLOWED_HOSTS = 127.0.0.1, localhost
CSRF_TRUSTED_ORIGINS = http://127.0.0.1:8000, http://localhost:8000
Expand Down
1 change: 0 additions & 1 deletion twisted/common/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.contrib import admin

# Register your models here.
2 changes: 1 addition & 1 deletion twisted/common/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class CommonConfig(AppConfig):
name = 'common'
name = "common"
1 change: 0 additions & 1 deletion twisted/common/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.db import models

# Create your models here.
1 change: 0 additions & 1 deletion twisted/common/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# Create your tests here.
8 changes: 1 addition & 7 deletions twisted/common/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import os
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.utils.translation import gettext_lazy as _
import requests
import json

5 changes: 3 additions & 2 deletions twisted/manage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +19,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion twisted/mysite/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', 'mysite.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_asgi_application()
4 changes: 3 additions & 1 deletion twisted/mysite/middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import zoneinfo

from django.utils import timezone


class TimezoneMiddleware:
def __init__(self, get_response):
self.get_response = get_response
Expand All @@ -13,7 +15,7 @@ def __call__(self, request):
timezone.activate(zoneinfo.ZoneInfo(tzname))
else:
timezone.deactivate()
except Exception as e:
except (zoneinfo.ZoneInfoNotFoundError, ValueError):
timezone.deactivate()

return self.get_response(request)
139 changes: 74 additions & 65 deletions twisted/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""
from dotenv import load_dotenv

import os
from pathlib import Path

if not os.environ.get('ALLOWED_HOSTS'):
from dotenv import load_dotenv

if not os.environ.get("ALLOWED_HOSTS"):
load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand All @@ -24,14 +26,14 @@
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
SECRET_KEY = os.environ["SECRET_KEY"]

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', 'false').lower() in ['true', 'on', '1']
DEBUG_REVIEW = os.environ.get('DEBUG_REVIEW', str(DEBUG)).lower() in ['true', 'on', '1']
DEBUG = os.environ.get("DEBUG", "false").lower() in ["true", "on", "1"]
DEBUG_REVIEW = os.environ.get("DEBUG_REVIEW", str(DEBUG)).lower() in ["true", "on", "1"]

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# Behind the TLS-terminating proxy above, cookies should never travel over plain
# HTTP once we're not in local dev.
Expand All @@ -42,56 +44,58 @@
SECURE_HSTS_INCLUDE_SUBDOMAINS = not DEBUG
SECURE_HSTS_PRELOAD = not DEBUG

X_FRAME_OPTIONS = 'SAMEORIGIN'
X_FRAME_OPTIONS = "SAMEORIGIN"

allowed_hosts_raw = os.getenv("ALLOWED_HOSTS", "127.0.0.1,localhost")
ALLOWED_HOSTS = [host.strip() for host in allowed_hosts_raw.split(",") if host.strip()]


csrf_origins_raw = os.getenv("CSRF_TRUSTED_ORIGINS", "http://127.0.0.1:8000,http://localhost:8000")
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in csrf_origins_raw.split(",") if origin.strip()]
csrf_origins_raw = os.getenv(
"CSRF_TRUSTED_ORIGINS", "http://127.0.0.1:8000,http://localhost:8000"
)
CSRF_TRUSTED_ORIGINS = [
origin.strip() for origin in csrf_origins_raw.split(",") if origin.strip()
]

# Application definition
TAILWIND_APP_NAME = 'tailwindcsstheme'
TAILWIND_APP_NAME = "tailwindcsstheme"

INSTALLED_APPS = [
# 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',

"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.humanize",
# Your apps
'common',
'twisted_site',

"common",
"twisted_site",
# 3rd party apps
'django_cotton',
'django_cotton_ui',
'tailwind',
"django_cotton",
"django_cotton_ui",
"tailwind",
TAILWIND_APP_NAME,
'django_htmx',
'django_extensions',
'mathfilters',
'django_humanize'
"django_htmx",
"django_extensions",
"mathfilters",
"django_humanize",
]

if DEBUG:
# Add django_browser_reload only in DEBUG mode
INSTALLED_APPS += ["django_browser_reload"]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
'mysite.middleware.TimezoneMiddleware',
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"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",
"mysite.middleware.TimezoneMiddleware",
"django_htmx.middleware.HtmxMiddleware",
]

Expand All @@ -101,24 +105,24 @@
"django_browser_reload.middleware.BrowserReloadMiddleware",
]

ROOT_URLCONF = 'mysite.urls'
ROOT_URLCONF = "mysite.urls"

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

WSGI_APPLICATION = 'mysite.wsgi.application'
WSGI_APPLICATION = "mysite.wsgi.application"


# Database
Expand All @@ -141,26 +145,26 @@

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


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

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

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True
USE_L10N = True
Expand All @@ -171,8 +175,8 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "static"
CSRF_COOKIE_HTTPONLY = False
NPM_BIN_PATH = os.environ.get("NPM_BIN_PATH", "npm")

Expand All @@ -182,23 +186,28 @@

# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False, # Keeps Gunicorn's loggers active
'handlers': {
'console': {
'class': 'logging.StreamHandler',
"version": 1,
"disable_existing_loggers": False, # Keeps Gunicorn's loggers active
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
"root": {
"handlers": ["console"],
"level": "INFO",
},
}

# Ari (Review)
# https://ari.hackclub.com/docs/webhooks
ARI_INGEST_ENDPOINT = os.environ.get('ARI_INGEST_ENDPOINT')
ARI_SIGNING_SECRET = os.environ.get('ARI_SIGNING_SECRET')
ARI_INGEST_ENDPOINT = os.environ.get("ARI_INGEST_ENDPOINT")
ARI_SIGNING_SECRET = os.environ.get("ARI_SIGNING_SECRET")
# Separate from ARI_SIGNING_SECRET: signs deliveries Ari sends to us (Settings -> Webhooks),
# not requests we send to Ari.
ARI_WEBHOOK_SECRET = os.environ.get('ARI_WEBHOOK_SECRET')
ARI_WEBHOOK_SECRET = os.environ.get('ARI_WEBHOOK_SECRET')


# Slack
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')
SLACK_LOG_CHANNEL = os.environ.get('SLACK_LOG_CHANNEL')
2 changes: 1 addition & 1 deletion twisted/mysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path

urlpatterns = [
path("", include("twisted_site.urls")),
Expand Down
2 changes: 1 addition & 1 deletion twisted/mysite/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion twisted/tailwindcsstheme/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class TailwindcssthemeConfig(AppConfig):
name = 'tailwindcsstheme'
name = "tailwindcsstheme"
1 change: 0 additions & 1 deletion twisted/twisted_site/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.contrib import admin

# Register your models here.
2 changes: 1 addition & 1 deletion twisted/twisted_site/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class TwistedSiteConfig(AppConfig):
name = 'twisted_site'
name = "twisted_site"
Loading
Loading