Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 18, 2024
1 parent b638277 commit 8440c97
Show file tree
Hide file tree
Showing 44 changed files with 962 additions and 698 deletions.
46 changes: 23 additions & 23 deletions setup.py
Expand Up @@ -8,46 +8,46 @@


def get_long_description():
with open('README.rst', 'r', encoding="utf-8") as file:
with open("README.rst", "r", encoding="utf-8") as file:
return file.read()


def get_install_requires(path):
requires = []

with open(path, 'r', encoding="utf-8") as file:
with open(path, "r", encoding="utf-8") as file:
for line in file:
if line.startswith('-r '):
if line.startswith("-r "):
continue
requires.append(line.strip())
return requires


setup(
name='kiwitcms-tenants',
version='2.6.1',
description='Multi-tenant support for Kiwi TCMS',
name="kiwitcms-tenants",
version="2.6.1",
description="Multi-tenant support for Kiwi TCMS",
long_description=get_long_description(),
author='Kiwi TCMS',
author_email='info@kiwitcms.org',
url='https://github.com/kiwitcms/tenants/',
license='GPLv3+',
install_requires=get_install_requires('requirements.txt'),
author="Kiwi TCMS",
author_email="info@kiwitcms.org",
url="https://github.com/kiwitcms/tenants/",
license="GPLv3+",
install_requires=get_install_requires("requirements.txt"),
include_package_data=True,
packages=find_packages(exclude=['test_project*', '*.tests']),
packages=find_packages(exclude=["test_project*", "*.tests"]),
zip_safe=False,
entry_points={"kiwitcms.plugins": ["kiwitcms_tenants = tcms_tenants"]},
classifiers=[
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.11',
"Framework :: Django",
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.11",
],
)
2 changes: 1 addition & 1 deletion tcms_settings_dir/__init__.py
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
61 changes: 40 additions & 21 deletions tcms_settings_dir/multi_tenant.py
Expand Up @@ -6,8 +6,10 @@


# start multi-tenant settings override
DATABASES['default']['ENGINE'] = 'django_tenants.postgresql_backend' # noqa: F821
DATABASE_ROUTERS = ['django_tenants.routers.TenantSyncRouter', ]
DATABASES["default"]["ENGINE"] = "django_tenants.postgresql_backend" # noqa: F821
DATABASE_ROUTERS = [
"django_tenants.routers.TenantSyncRouter",
]


# attachments storage
Expand All @@ -16,31 +18,45 @@


# this always needs to be the first app
if 'django_tenants' not in INSTALLED_APPS: # noqa: F821
INSTALLED_APPS.insert(0, 'django_tenants') # noqa: F821
if "django_tenants" not in INSTALLED_APPS: # noqa: F821
INSTALLED_APPS.insert(0, "django_tenants") # noqa: F821

for app_list in (INSTALLED_APPS, TENANT_APPS): # noqa: F821
if 'tenant_groups' not in app_list:
app_list.append('tenant_groups')
if "tenant_groups" not in app_list:
app_list.append("tenant_groups")


KIWI_TENANTS_DOMAIN = os.environ.get('KIWI_TENANTS_DOMAIN')
KIWI_TENANTS_DOMAIN = os.environ.get("KIWI_TENANTS_DOMAIN")


# TenantMainMiddleware always needs to be first
if 'django_tenants.middleware.main.TenantMainMiddleware' not in MIDDLEWARE: # noqa: F821
MIDDLEWARE.insert(0, 'django_tenants.middleware.main.TenantMainMiddleware') # noqa: F821

if 'tcms_tenants.middleware.BlockUnauthorizedUserMiddleware' not in MIDDLEWARE: # noqa: F821
MIDDLEWARE.append('tcms_tenants.middleware.BlockUnauthorizedUserMiddleware') # noqa: F821
if (
"django_tenants.middleware.main.TenantMainMiddleware" not in MIDDLEWARE
): # noqa: F821
MIDDLEWARE.insert(
0, "django_tenants.middleware.main.TenantMainMiddleware"
) # noqa: F821

if (
"tcms_tenants.middleware.BlockUnauthorizedUserMiddleware" not in MIDDLEWARE
): # noqa: F821
MIDDLEWARE.append(
"tcms_tenants.middleware.BlockUnauthorizedUserMiddleware"
) # noqa: F821

# replace ModelBackend with GroupsBackend
if 'django.contrib.auth.backends.ModelBackend' in AUTHENTICATION_BACKENDS: # noqa: F821
idx = AUTHENTICATION_BACKENDS.index('django.contrib.auth.backends.ModelBackend') # noqa: F821
AUTHENTICATION_BACKENDS[idx] = 'tenant_groups.backends.GroupsBackend' # noqa: F821
if "django.contrib.auth.backends.ModelBackend" in AUTHENTICATION_BACKENDS: # noqa: F821
idx = AUTHENTICATION_BACKENDS.index(
"django.contrib.auth.backends.ModelBackend"
) # noqa: F821
AUTHENTICATION_BACKENDS[idx] = "tenant_groups.backends.GroupsBackend" # noqa: F821

if 'tcms_tenants.backends.PubliclyReadableBackend' not in AUTHENTICATION_BACKENDS: # noqa: F821
AUTHENTICATION_BACKENDS.append('tcms_tenants.backends.PubliclyReadableBackend') # noqa: F821
if (
"tcms_tenants.backends.PubliclyReadableBackend" not in AUTHENTICATION_BACKENDS
): # noqa: F821
AUTHENTICATION_BACKENDS.append(
"tcms_tenants.backends.PubliclyReadableBackend"
) # noqa: F821


TENANT_MODEL = "tcms_tenants.Tenant"
Expand All @@ -55,7 +71,10 @@
SHARED_APPS = INSTALLED_APPS # noqa: F821

# add tennants context processor
if 'tcms_tenants.context_processors.tenant_navbar_processor' not in\
TEMPLATES[0]['OPTIONS']['context_processors']: # noqa: F821
TEMPLATES[0]['OPTIONS']['context_processors'].append( # noqa: F821
'tcms_tenants.context_processors.tenant_navbar_processor') # noqa: F821
if (
"tcms_tenants.context_processors.tenant_navbar_processor"
not in TEMPLATES[0]["OPTIONS"]["context_processors"]
): # noqa: F821
TEMPLATES[0]["OPTIONS"]["context_processors"].append( # noqa: F821
"tcms_tenants.context_processors.tenant_navbar_processor"
) # noqa: F821

0 comments on commit 8440c97

Please sign in to comment.