diff --git a/DjangoPlugin/setup.py b/DjangoPlugin/setup.py
index c47cc5d..7df9411 100644
--- a/DjangoPlugin/setup.py
+++ b/DjangoPlugin/setup.py
@@ -1,11 +1,9 @@
from setuptools import setup
setup(
- name='Django Plugin',
- version='1.1',
- packages=['tracdjangoplugin'],
+ name="Django Plugin",
+ version="1.1",
+ packages=["tracdjangoplugin"],
include_package_data=True,
- entry_points = {
- 'trac.plugins': ['tracdjangoplugin = tracdjangoplugin']
- }
+ entry_points={"trac.plugins": ["tracdjangoplugin = tracdjangoplugin"]},
)
diff --git a/DjangoPlugin/tracdjangoplugin/__init__.py b/DjangoPlugin/tracdjangoplugin/__init__.py
index 166149e..1b09208 100644
--- a/DjangoPlugin/tracdjangoplugin/__init__.py
+++ b/DjangoPlugin/tracdjangoplugin/__init__.py
@@ -12,20 +12,22 @@ class CustomWikiModule(WikiModule):
"""
def get_active_navigation_item(self, req):
- pagename = req.args.get('page')
- if pagename == 'Reports':
- return 'custom_reports'
- return 'wiki'
+ pagename = req.args.get("page")
+ if pagename == "Reports":
+ return "custom_reports"
+ return "wiki"
class CustomNewTicket(Component):
"""Hide certain options for the new ticket page"""
+
implements(IRequestFilter, IRequestHandler)
- hidden_fields = frozenset(['stage', 'needs_tests', 'needs_docs',
- 'needs_better_patch'])
+ hidden_fields = frozenset(
+ ["stage", "needs_tests", "needs_docs", "needs_better_patch"]
+ )
def match_request(self, req):
- return req.path_info == '/simpleticket'
+ return req.path_info == "/simpleticket"
def process_request(self, req):
req.redirect(req.href.newticket())
@@ -36,26 +38,32 @@ def pre_process_request(self, req, handler):
def post_process_request(self, req, template, data, content_type):
if data is None:
data = {}
- if req.path_info == '/newticket' and not data.get('preview_mode', False):
- simple_interface = 'TICKET_BATCH_MODIFY' not in req.perm
- if simple_interface and 'fields' in data:
- data['fields'] = [f for f in data['fields']
- if f['name'] not in self.hidden_fields]
- data['simple_interface'] = simple_interface
- template = 'custom_ticket.html'
+ if req.path_info == "/newticket" and not data.get("preview_mode", False):
+ simple_interface = "TICKET_BATCH_MODIFY" not in req.perm
+ if simple_interface and "fields" in data:
+ data["fields"] = [
+ f for f in data["fields"] if f["name"] not in self.hidden_fields
+ ]
+ data["simple_interface"] = simple_interface
+ template = "custom_ticket.html"
return template, data, content_type
class CustomNavigationBar(Component):
"""Implements some more items for the navigation bar."""
+
implements(INavigationContributor)
def get_active_navigation_item(self, req):
- return ''
+ return ""
def get_navigation_items(self, req):
return [
- ('mainnav', 'custom_reports', Markup('Reports' % req.href.wiki('Reports'))),
+ (
+ "mainnav",
+ "custom_reports",
+ Markup('Reports' % req.href.wiki("Reports")),
+ ),
]
@@ -68,14 +76,13 @@ def get_navigation_items(self, req):
from genshi.builder import tag
class GitHubBrowserWithSVNChangesets(GitHubBrowser):
-
- def _format_changeset_link(self, formatter, ns, chgset, label,
- fullmatch=None):
+ def _format_changeset_link(self, formatter, ns, chgset, label, fullmatch=None):
# Dead-simple version for SVN changesets
if chgset.isnumeric():
- href = formatter.href.changeset(chgset, None, '/')
+ href = formatter.href.changeset(chgset, None, "/")
return tag.a(label, class_="changeset", href=href)
# Fallback to the default implemntation
- return (super(GitHubBrowserWithSVNChangesets,self)
- ._format_changeset_link(formatter, ns, chgset, label, fullmatch))
+ return super(GitHubBrowserWithSVNChangesets, self)._format_changeset_link(
+ formatter, ns, chgset, label, fullmatch
+ )
diff --git a/DjangoPlugin/tracdjangoplugin/djangoauth.py b/DjangoPlugin/tracdjangoplugin/djangoauth.py
index 79c449b..2af7f91 100644
--- a/DjangoPlugin/tracdjangoplugin/djangoauth.py
+++ b/DjangoPlugin/tracdjangoplugin/djangoauth.py
@@ -38,25 +38,26 @@
class DjangoAuth:
-
- login_url = getattr(settings, 'BASIC_AUTH_LOGIN_URL', '/login')
- message = getattr(settings, 'BASIC_AUTH_MESSAGE', "Authorization required.")
- message_type = getattr(settings, 'BASIC_AUTH_MESSAGE_TYPE', 'text/plain')
- realm = getattr(settings, 'BASIC_AUTH_REALM', "Authenticate")
+ login_url = getattr(settings, "BASIC_AUTH_LOGIN_URL", "/login")
+ message = getattr(settings, "BASIC_AUTH_MESSAGE", "Authorization required.")
+ message_type = getattr(settings, "BASIC_AUTH_MESSAGE_TYPE", "text/plain")
+ realm = getattr(settings, "BASIC_AUTH_REALM", "Authenticate")
def __init__(self, application):
self.application = application
def __call__(self, environ, start_response):
-
try:
if get_path_info(environ) == self.login_url:
username = self.process_authorization(environ)
if username is None:
- start_response('401 Unauthorized', [
- ('Content-Type', self.message_type),
- ('WWW-Authenticate', 'Basic realm="%s"' % self.realm),
- ])
+ start_response(
+ "401 Unauthorized",
+ [
+ ("Content-Type", self.message_type),
+ ("WWW-Authenticate", 'Basic realm="%s"' % self.realm),
+ ],
+ )
return [self.message]
finally:
close_old_connections()
@@ -66,24 +67,24 @@ def __call__(self, environ, start_response):
@staticmethod
def process_authorization(environ):
# Don't override authentication information set by another component.
- remote_user = environ.get('REMOTE_USER')
+ remote_user = environ.get("REMOTE_USER")
if remote_user is not None:
return
- authorization = environ.get('HTTP_AUTHORIZATION')
+ authorization = environ.get("HTTP_AUTHORIZATION")
if authorization is None:
return
- if six.PY3: # because fuck you PEP 3333.
- authorization = authorization.encode('iso-8859-1').decode('utf-8')
+ if six.PY3: # because fuck you PEP 3333.
+ authorization = authorization.encode("iso-8859-1").decode("utf-8")
- method, _, credentials = authorization.partition(' ')
- if not method.lower() == 'basic':
+ method, _, credentials = authorization.partition(" ")
+ if not method.lower() == "basic":
return
try:
credentials = b64decode(credentials.strip())
- username, _, password = credentials.partition(':')
+ username, _, password = credentials.partition(":")
except Exception:
return
@@ -92,9 +93,9 @@ def process_authorization(environ):
remote_user = username
- if six.PY3: # because fuck you PEP 3333.
- remote_user = remote_user.encode('utf-8').decode('iso-8859-1')
+ if six.PY3: # because fuck you PEP 3333.
+ remote_user = remote_user.encode("utf-8").decode("iso-8859-1")
- environ['REMOTE_USER'] = remote_user
+ environ["REMOTE_USER"] = remote_user
return username
diff --git a/DjangoPlugin/tracdjangoplugin/settings.py b/DjangoPlugin/tracdjangoplugin/settings.py
index 4d6dbb5..436d815 100644
--- a/DjangoPlugin/tracdjangoplugin/settings.py
+++ b/DjangoPlugin/tracdjangoplugin/settings.py
@@ -1,28 +1,28 @@
import json
import os
-with open(os.environ.get('SECRETS_FILE')) as handle:
+with open(os.environ.get("SECRETS_FILE")) as handle:
SECRETS = json.load(handle)
DEBUG = False
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'djangoproject',
- 'USER': 'djangoproject',
- 'HOST': SECRETS.get('db_host', ''),
- 'PORT': SECRETS.get('db_port', 5432),
- 'PASSWORD': SECRETS.get('db_password', ''),
+ "default": {
+ "ENGINE": "django.db.backends.postgresql_psycopg2",
+ "NAME": "djangoproject",
+ "USER": "djangoproject",
+ "HOST": SECRETS.get("db_host", ""),
+ "PORT": SECRETS.get("db_port", 5432),
+ "PASSWORD": SECRETS.get("db_password", ""),
},
}
INSTALLED_APPS = [
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
+ "django.contrib.auth",
+ "django.contrib.contenttypes",
]
-SECRET_KEY = str(SECRETS['secret_key'])
+SECRET_KEY = str(SECRETS["secret_key"])
BASIC_AUTH_REALM = "Django's Trac"
diff --git a/DjangoPlugin/tracdjangoplugin/wsgi.py b/DjangoPlugin/tracdjangoplugin/wsgi.py
index 265ed1b..afcfc68 100644
--- a/DjangoPlugin/tracdjangoplugin/wsgi.py
+++ b/DjangoPlugin/tracdjangoplugin/wsgi.py
@@ -1,14 +1,17 @@
import os
import trac.web.main
+
application = trac.web.main.dispatch_request
# Massive hack to make Trac fast, otherwise every git call tries to close ulimit -n (1e6) fds
# Python 3 would perform better here, but we are still on 2.7 for Trac, so leak fds for now.
from tracopt.versioncontrol.git import PyGIT
+
PyGIT.close_fds = False
from .djangoauth import DjangoAuth
+
application = DjangoAuth(application)
trac_dsn = os.getenv("SENTRY_DSN")
@@ -16,9 +19,9 @@
if trac_dsn:
import sentry_sdk
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
+
sentry_sdk.init(
dsn=trac_dsn,
-
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production,