Fix formatting errors after doing app wide instead of only the heldesk

folder
This commit is contained in:
Christopher Broderick 2025-04-01 11:09:34 +01:00
parent 0952ac9743
commit 75bd375c6b
14 changed files with 308 additions and 281 deletions

View File

@ -14,7 +14,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_crkn1+fnzu5$vns_-d+^ayiq%z4k*s!!ag0!mfy36(y!vrazd' SECRET_KEY = "_crkn1+fnzu5$vns_-d+^ayiq%z4k*s!!ag0!mfy36(y!vrazd"
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
@ -34,60 +34,64 @@ ALLOWED_HOSTS = []
# remember when setting up your own development / production server! # remember when setting up your own development / production server!
# Default teams mode to enabled unless overridden by an environment variable set to "false" # Default teams mode to enabled unless overridden by an environment variable set to "false"
HELPDESK_TEAMS_MODE_ENABLED=os.getenv("HELPDESK_TEAMS_MODE_ENABLED", "true").lower() == "true" HELPDESK_TEAMS_MODE_ENABLED = (
os.getenv("HELPDESK_TEAMS_MODE_ENABLED", "true").lower() == "true"
)
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'django.contrib.sites', "django.contrib.sites",
'django.contrib.humanize', "django.contrib.humanize",
'bootstrap4form', "bootstrap4form",
'helpdesk', # This is us! "helpdesk", # This is us!
'rest_framework', # required for the API "rest_framework", # required for the API
] ]
if HELPDESK_TEAMS_MODE_ENABLED: if HELPDESK_TEAMS_MODE_ENABLED:
INSTALLED_APPS.extend([ INSTALLED_APPS.extend(
'account', # Required by pinax-teams [
'pinax.invitations', # required by pinax-teams "account", # Required by pinax-teams
'pinax.teams', # team support "pinax.invitations", # required by pinax-teams
'reversion', # required by pinax-teams "pinax.teams", # team support
]) "reversion", # required by pinax-teams
]
)
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
ROOT_URLCONF = 'demodesk.config.urls' ROOT_URLCONF = "demodesk.config.urls"
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [], "DIRS": [],
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'debug': True, "debug": True,
'context_processors': [ "context_processors": [
'django.template.context_processors.debug', "django.template.context_processors.debug",
'django.template.context_processors.request', "django.template.context_processors.request",
'django.contrib.auth.context_processors.auth', "django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages', "django.contrib.messages.context_processors.messages",
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'demodesk.config.wsgi.application' WSGI_APPLICATION = "demodesk.config.wsgi.application"
# django-helpdesk configuration settings # django-helpdesk configuration settings
@ -97,13 +101,13 @@ WSGI_APPLICATION = 'demodesk.config.wsgi.application'
# Some common settings are below. # Some common settings are below.
HELPDESK_DEFAULT_SETTINGS = { HELPDESK_DEFAULT_SETTINGS = {
'use_email_as_submitter': True, "use_email_as_submitter": True,
'email_on_ticket_assign': True, "email_on_ticket_assign": True,
'email_on_ticket_change': True, "email_on_ticket_change": True,
'login_view_ticketlist': True, "login_view_ticketlist": True,
'email_on_ticket_apichange': True, "email_on_ticket_apichange": True,
'preset_replies': True, "preset_replies": True,
'tickets_per_page': 25 "tickets_per_page": 25,
} }
# Should the public web portal be enabled? # Should the public web portal be enabled?
@ -122,8 +126,8 @@ HELPDESK_SHOW_CHANGE_PASSWORD = True
# Instead of showing the public web portal first, # Instead of showing the public web portal first,
# we can instead redirect users straight to the login page. # we can instead redirect users straight to the login page.
HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False
LOGIN_URL = 'helpdesk:login' LOGIN_URL = "helpdesk:login"
LOGIN_REDIRECT_URL = 'helpdesk:home' LOGIN_REDIRECT_URL = "helpdesk:home"
# You can also redirect to a specific page after logging out (instead of logout page) # You can also redirect to a specific page after logging out (instead of logout page)
# LOGOUT_REDIRECT_URL = 'helpdesk:home' # LOGOUT_REDIRECT_URL = 'helpdesk:home'
@ -133,9 +137,9 @@ LOGIN_REDIRECT_URL = 'helpdesk:home'
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.sqlite3', "ENGINE": "django.db.backends.sqlite3",
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
} }
} }
@ -167,16 +171,16 @@ SESSION_COOKIE_AGE = 86400 # = 1 day
AUTH_PASSWORD_VALIDATORS = [ 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",
}, },
] ]
@ -185,9 +189,9 @@ AUTH_PASSWORD_VALIDATORS = [
# This demo uses the console backend, which simply prints emails to the console # This demo uses the console backend, which simply prints emails to the console
# rather than actually sending them out. # rather than actually sending them out.
DEFAULT_FROM_EMAIL = 'helpdesk@example.com' DEFAULT_FROM_EMAIL = "helpdesk@example.com"
SERVER_EMAIL = 'helpdesk@example.com' SERVER_EMAIL = "helpdesk@example.com"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# If you want to test sending real emails, uncomment and modify the following: # If you want to test sending real emails, uncomment and modify the following:
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
@ -201,9 +205,9 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# The most complete translations are: es-MX, ru, zh-Hans # The most complete translations are: es-MX, ru, zh-Hans
# Contribute to our translations via Transifex if you can! # Contribute to our translations via Transifex if you can!
# See CONTRIBUTING.rst for more info. # See CONTRIBUTING.rst for more info.
LANGUAGE_CODE = 'en-US' LANGUAGE_CODE = "en-US"
TIME_ZONE = 'UTC' TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
@ -215,27 +219,27 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ # https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = "/static/"
# static root needs to be defined in order to use collectstatic # static root needs to be defined in order to use collectstatic
STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_ROOT = os.path.join(BASE_DIR, "static")
# MEDIA_ROOT is where media uploads are stored. # MEDIA_ROOT is where media uploads are stored.
# We set this to a directory to host file attachments created # We set this to a directory to host file attachments created
# with tickets. # with tickets.
MEDIA_URL = '/media/' MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Fixtures # Fixtures
# https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-FIXTURE_DIRS # https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-FIXTURE_DIRS
# - This is only necessary to make the demo project work, not needed for # - This is only necessary to make the demo project work, not needed for
# your own projects unless you make your own fixtures # your own projects unless you make your own fixtures
FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures')] FIXTURE_DIRS = [os.path.join(BASE_DIR, "fixtures")]
# for Django 3.2+, set default for autofields: # for Django 3.2+, set default for autofields:
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
try: try:
from .local_settings import * from .local_settings import * # noqa
except ImportError: except ImportError:
pass pass

View File

@ -13,6 +13,7 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
@ -26,7 +27,7 @@ from django.urls import include, path
# https://docs.djangoproject.com/en/1.10/howto/static-files/ # https://docs.djangoproject.com/en/1.10/howto/static-files/
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path("admin/", admin.site.urls),
path('', include('helpdesk.urls', namespace='helpdesk')), path("", include("helpdesk.urls", namespace="helpdesk")),
path('api/auth/', include('rest_framework.urls', namespace='rest_framework')) path("api/auth/", include("rest_framework.urls", namespace="rest_framework")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -7,7 +7,6 @@ For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
""" """
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
import os import os

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Python packaging.""" """Python packaging."""
import os import os
from setuptools import setup from setuptools import setup
@ -8,42 +9,42 @@ here = os.path.abspath(os.path.dirname(__file__))
project_root = os.path.dirname(here) project_root = os.path.dirname(here)
NAME = 'django-helpdesk-demodesk' NAME = "django-helpdesk-demodesk"
DESCRIPTION = 'A demo Django project using django-helpdesk' DESCRIPTION = "A demo Django project using django-helpdesk"
README = open(os.path.join(here, 'README.rst')).read() README = open(os.path.join(here, "README.rst")).read()
VERSION = '0.5.0' VERSION = "0.5.0"
# VERSION = open(os.path.join(project_root, 'VERSION')).read().strip() # VERSION = open(os.path.join(project_root, 'VERSION')).read().strip()
AUTHOR = 'django-helpdesk team' AUTHOR = "django-helpdesk team"
URL = 'https://github.com/django-helpdesk/django-helpdesk' URL = "https://github.com/django-helpdesk/django-helpdesk"
CLASSIFIERS = ['Development Status :: 4 - Beta', CLASSIFIERS = [
'License :: OSI Approved :: BSD License', "Development Status :: 4 - Beta",
'Programming Language :: Python :: 3.8', "License :: OSI Approved :: BSD License",
'Programming Language :: Python :: 3.9', "Programming Language :: Python :: 3.8",
'Programming Language :: Python :: 3.10', "Programming Language :: Python :: 3.9",
'Framework :: Django :: 3.2', "Programming Language :: Python :: 3.10",
'Framework :: Django :: 4.0'] "Framework :: Django :: 3.2",
KEYWORDS = [] "Framework :: Django :: 4.0",
PACKAGES = ['demodesk']
REQUIREMENTS = [
'django-helpdesk'
] ]
ENTRY_POINTS = { KEYWORDS = []
'console_scripts': ['demodesk = demodesk.manage:main'] PACKAGES = ["demodesk"]
} REQUIREMENTS = ["django-helpdesk"]
ENTRY_POINTS = {"console_scripts": ["demodesk = demodesk.manage:main"]}
if __name__ == '__main__': # Don't run setup() when we import this module. if __name__ == "__main__": # Don't run setup() when we import this module.
setup(name=NAME, setup(
name=NAME,
version=VERSION, version=VERSION,
description=DESCRIPTION, description=DESCRIPTION,
long_description=README, long_description=README,
classifiers=CLASSIFIERS, classifiers=CLASSIFIERS,
keywords=' '.join(KEYWORDS), keywords=" ".join(KEYWORDS),
author=AUTHOR, author=AUTHOR,
url=URL, url=URL,
license='BSD', license="BSD",
packages=PACKAGES, packages=PACKAGES,
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
install_requires=REQUIREMENTS, install_requires=REQUIREMENTS,
entry_points=ENTRY_POINTS) entry_points=ENTRY_POINTS,
)

View File

@ -442,7 +442,8 @@ def process_queue(q, logger):
q.email_box_port = mail_defaults[email_box_type][encryption]["port"] q.email_box_port = mail_defaults[email_box_type][encryption]["port"]
server = mail_defaults[email_box_type][encryption]["init"]( server = mail_defaults[email_box_type][encryption]["init"](
q.email_box_host or helpdesk_settings.QUEUE_EMAIL_BOX_HOST, int(q.email_box_port) q.email_box_host or helpdesk_settings.QUEUE_EMAIL_BOX_HOST,
int(q.email_box_port),
) )
logger.info("Attempting %s server login" % email_box_type.upper()) logger.info("Attempting %s server login" % email_box_type.upper())
mail_defaults[email_box_type]["sync"](q, logger, server) mail_defaults[email_box_type]["sync"](q, logger, server)

View File

@ -41,16 +41,16 @@ def get_search_filter_args(search):
if not subsearch: if not subsearch:
continue continue
my_filter |= ( my_filter |= (
Q(id__icontains=subsearch) | Q(id__icontains=subsearch)
Q(title__icontains=subsearch) | | Q(title__icontains=subsearch)
Q(description__icontains=subsearch) | | Q(description__icontains=subsearch)
Q(priority__icontains=subsearch) | | Q(priority__icontains=subsearch)
Q(resolution__icontains=subsearch) | | Q(resolution__icontains=subsearch)
Q(submitter_email__icontains=subsearch) | | Q(submitter_email__icontains=subsearch)
Q(assigned_to__email__icontains=subsearch) | | Q(assigned_to__email__icontains=subsearch)
Q(ticketcustomfieldvalue__value__icontains=subsearch) | | Q(ticketcustomfieldvalue__value__icontains=subsearch)
Q(created__icontains=subsearch) | | Q(created__icontains=subsearch)
Q(due_date__icontains=subsearch) | Q(due_date__icontains=subsearch)
) )
return my_filter return my_filter

View File

@ -49,11 +49,15 @@ HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = getattr(
) )
HELPDESK_PUBLIC_VIEW_PROTECTOR = getattr( HELPDESK_PUBLIC_VIEW_PROTECTOR = getattr(
settings, "HELPDESK_PUBLIC_VIEW_PROTECTOR", lambda _: None settings,
"HELPDESK_PUBLIC_VIEW_PROTECTOR",
lambda _: None, # noqa
) )
HELPDESK_STAFF_VIEW_PROTECTOR = getattr( HELPDESK_STAFF_VIEW_PROTECTOR = getattr(
settings, "HELPDESK_STAFF_VIEW_PROTECTOR", lambda _: None settings,
"HELPDESK_STAFF_VIEW_PROTECTOR",
lambda _: None, # noqa
) )
# Enable ticket and Email attachments # Enable ticket and Email attachments
@ -390,7 +394,7 @@ if HELPDESK_TEAMS_MODE_ENABLED:
else: else:
HELPDESK_TEAMS_MODEL = settings.AUTH_USER_MODEL HELPDESK_TEAMS_MODEL = settings.AUTH_USER_MODEL
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = [] HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = []
HELPDESK_KBITEM_TEAM_GETTER = lambda _: None HELPDESK_KBITEM_TEAM_GETTER = lambda _: None # noqa
# show knowledgebase links? # show knowledgebase links?
# If Teams mode is enabled then it has to be on # If Teams mode is enabled then it has to be on

View File

@ -512,8 +512,7 @@ class GetEmailCommonTests(TestCase):
ticket = helpdesk.email.extract_email_metadata( ticket = helpdesk.email.extract_email_metadata(
message.as_string(), self.queue_public, self.logger message.as_string(), self.queue_public, self.logger
) )
self.assertIsNone(ticket, f"Ticket was created when it should not be: {ticket}" self.assertIsNone(ticket, f"Ticket was created when it should not be: {ticket}")
)
class EmailTaskTests(TestCase): class EmailTaskTests(TestCase):

View File

@ -25,42 +25,43 @@ class QuickDjangoTest:
Based on a script published by Lukasz Dziedzia at: Based on a script published by Lukasz Dziedzia at:
http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
""" """
DIRNAME = os.path.dirname(__file__) DIRNAME = os.path.dirname(__file__)
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.humanize', "django.contrib.humanize",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.sites', "django.contrib.sites",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'bootstrap4form', "bootstrap4form",
# The following commented apps are optional, # The following commented apps are optional,
# related to teams functionalities # related to teams functionalities
# 'account', # 'account',
# 'pinax.invitations', # 'pinax.invitations',
# 'pinax.teams', # 'pinax.teams',
'rest_framework', "rest_framework",
'helpdesk', "helpdesk",
# 'reversion', # 'reversion',
) )
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'context_processors': ( "context_processors": (
# Defaults: # Defaults:
"django.contrib.auth.context_processors.auth", "django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug", "django.template.context_processors.debug",
@ -82,37 +83,39 @@ class QuickDjangoTest:
self._tests() self._tests()
def _tests(self): def _tests(self):
settings.configure( settings.configure(
DEBUG=True, DEBUG=True,
TIME_ZONE='UTC', TIME_ZONE="UTC",
DATABASES={ DATABASES={
'default': { "default": {
'ENGINE': 'django.db.backends.sqlite3', "ENGINE": "django.db.backends.sqlite3",
'NAME': os.path.join(self.DIRNAME, 'database.db'), "NAME": os.path.join(self.DIRNAME, "database.db"),
'USER': '', "USER": "",
'PASSWORD': '', "PASSWORD": "",
'HOST': '', "HOST": "",
'PORT': '', "PORT": "",
} }
}, },
INSTALLED_APPS=self.INSTALLED_APPS, INSTALLED_APPS=self.INSTALLED_APPS,
MIDDLEWARE=self.MIDDLEWARE, MIDDLEWARE=self.MIDDLEWARE,
ROOT_URLCONF='helpdesk.tests.urls', ROOT_URLCONF="helpdesk.tests.urls",
STATIC_URL='/static/', STATIC_URL="/static/",
LOGIN_URL='/login/', LOGIN_URL="/login/",
TEMPLATES=self.TEMPLATES, TEMPLATES=self.TEMPLATES,
SITE_ID=1, SITE_ID=1,
SECRET_KEY='wowdonotusethisfakesecuritykeyyouneedarealsecure1', SECRET_KEY="wowdonotusethisfakesecuritykeyyouneedarealsecure1",
# The following settings disable teams # The following settings disable teams
HELPDESK_TEAMS_MODEL='auth.User', HELPDESK_TEAMS_MODEL="auth.User",
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES=[], HELPDESK_TEAMS_MIGRATION_DEPENDENCIES=[],
HELPDESK_KBITEM_TEAM_GETTER=lambda _: None, HELPDESK_KBITEM_TEAM_GETTER=lambda _: None,
# Set IMAP Server Debug Verbosity # Set IMAP Server Debug Verbosity
HELPDESK_IMAP_DEBUG_LEVEL=int(os.environ.get("HELPDESK_IMAP_DEBUG_LEVEL", "0")), HELPDESK_IMAP_DEBUG_LEVEL=int(
os.environ.get("HELPDESK_IMAP_DEBUG_LEVEL", "0")
),
) )
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=self.kwargs["verbosity"]) test_runner = DiscoverRunner(verbosity=self.kwargs["verbosity"])
django.setup() django.setup()
@ -121,7 +124,7 @@ class QuickDjangoTest:
sys.exit(failures) sys.exit(failures)
if __name__ == '__main__': if __name__ == "__main__":
""" """
What do when the user hits this file from the shell. What do when the user hits this file from the shell.
@ -130,13 +133,10 @@ if __name__ == '__main__':
$ python quicktest.py test1 test2 $ python quicktest.py test1 test2
""" """
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(usage="[args]", description="Run Django tests.")
usage="[args]", parser.add_argument("tests", nargs="*", type=str)
description="Run Django tests."
)
parser.add_argument('tests', nargs="*", type=str)
parser.add_argument("--verbosity", "-v", nargs="?", type=int, default=1) parser.add_argument("--verbosity", "-v", nargs="?", type=int, default=1)
args = parser.parse_args() args = parser.parse_args()
if not args.tests: if not args.tests:
args.tests = ['helpdesk'] args.tests = ["helpdesk"]
QuickDjangoTest(*args.tests, verbosity=args.verbosity) QuickDjangoTest(*args.tests, verbosity=args.verbosity)

View File

@ -1,4 +1,5 @@
"""django-helpdesk setup""" """django-helpdesk setup"""
from distutils.util import convert_path from distutils.util import convert_path
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
import os import os
@ -6,7 +7,7 @@ from setuptools import find_packages, setup
import sys import sys
version = '1.4.0' version = "1.4.0"
# Provided as an attribute, so you can append to these instead # Provided as an attribute, so you can append to these instead
@ -77,8 +78,7 @@ def find_package_data(
bad_name = True bad_name = True
if show_ignored: if show_ignored:
print( print(
"Directory %s ignored by pattern %s" % ( "Directory %s ignored by pattern %s" % (fn, pattern),
fn, pattern),
file=sys.stderr, file=sys.stderr,
) )
@ -92,8 +92,7 @@ def find_package_data(
new_package = package + "." + name new_package = package + "." + name
stack.append((fn, "", new_package, False)) stack.append((fn, "", new_package, False))
else: else:
stack.append((fn, prefix + name + "/", stack.append((fn, prefix + name + "/", package, only_in_packages))
package, only_in_packages))
elif package or not only_in_packages: elif package or not only_in_packages:
# is a file # is a file
bad_name = False bad_name = False
@ -102,8 +101,7 @@ def find_package_data(
bad_name = True bad_name = True
if show_ignored: if show_ignored:
print( print(
"File %s ignored by pattern %s" % ( "File %s ignored by pattern %s" % (fn, pattern),
fn, pattern),
file=sys.stderr, file=sys.stderr,
) )
break break

View File

@ -1,2 +1 @@
local_urlpatterns = [ local_urlpatterns = []
]

View File

@ -8,8 +8,8 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/ https://docs.djangoproject.com/en/1.11/ref/settings/
""" """
import os import os
from django.core.exceptions import ImproperlyConfigured
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@ -21,70 +21,72 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Read SECRET_KEY from DJANGO_HELPDESK_SECRET_KEY env var # Read SECRET_KEY from DJANGO_HELPDESK_SECRET_KEY env var
try: try:
SECRET_KEY = os.environ['DJANGO_HELPDESK_SECRET_KEY'] SECRET_KEY = os.environ["DJANGO_HELPDESK_SECRET_KEY"]
except KeyError: except KeyError:
raise Exception("DJANGO_HELPDESK_SECRET_KEY environment variable is not set") raise Exception("DJANGO_HELPDESK_SECRET_KEY environment variable is not set")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False DEBUG = False
ALLOWED_HOSTS = os.environ.get("DJANGO_HELPDESK_ALLOWED_HOSTS", "*, localhost, 0.0.0.0").split(",") ALLOWED_HOSTS = os.environ.get(
"DJANGO_HELPDESK_ALLOWED_HOSTS", "*, localhost, 0.0.0.0"
).split(",")
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'django.contrib.sites', "django.contrib.sites",
'django.contrib.humanize', "django.contrib.humanize",
'bootstrap4form', "bootstrap4form",
'account', # Required by pinax-teams "account", # Required by pinax-teams
'pinax.invitations', # required by pinax-teams "pinax.invitations", # required by pinax-teams
'pinax.teams', # team support "pinax.teams", # team support
'reversion', # required by pinax-teams "reversion", # required by pinax-teams
'helpdesk', # This is us! "helpdesk", # This is us!
'rest_framework', # required for the API "rest_framework", # required for the API
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware",
] ]
ROOT_URLCONF = 'standalone.config.urls' ROOT_URLCONF = "standalone.config.urls"
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [], "DIRS": [],
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'debug': True, "debug": True,
'context_processors': [ "context_processors": [
'django.template.context_processors.debug', "django.template.context_processors.debug",
'django.template.context_processors.request', "django.template.context_processors.request",
'django.contrib.auth.context_processors.auth', "django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages', "django.contrib.messages.context_processors.messages",
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'standalone.config.wsgi.application' WSGI_APPLICATION = "standalone.config.wsgi.application"
# django-helpdesk configuration settings # django-helpdesk configuration settings
@ -94,43 +96,57 @@ WSGI_APPLICATION = 'standalone.config.wsgi.application'
# Some common settings are below. # Some common settings are below.
HELPDESK_DEFAULT_SETTINGS = { HELPDESK_DEFAULT_SETTINGS = {
'use_email_as_submitter': os.environ.get('HELPDESK_USE_EMAIL_AS_SUBMITTER', 'True') == 'True', "use_email_as_submitter": os.environ.get("HELPDESK_USE_EMAIL_AS_SUBMITTER", "True")
'email_on_ticket_assign': os.environ.get('HELPDESK_EMAIL_ON_TICKET_ASSIGN', 'True') == 'True', == "True",
'email_on_ticket_change': os.environ.get('HELPDESK_EMAIL_ON_TICKET_CHANGE', 'True') == 'True', "email_on_ticket_assign": os.environ.get("HELPDESK_EMAIL_ON_TICKET_ASSIGN", "True")
'login_view_ticketlist': os.environ.get('HELPDESK_LOGIN_VIEW_TICKETLIST', 'True') == 'True', == "True",
'preset_replies': os.environ.get('HELPDESK_PRESET_REPLIES', 'True') == 'True', "email_on_ticket_change": os.environ.get("HELPDESK_EMAIL_ON_TICKET_CHANGE", "True")
'tickets_per_page': os.environ.get('HELPDESK_TICKETS_PER_PAGE', '25'), == "True",
"login_view_ticketlist": os.environ.get("HELPDESK_LOGIN_VIEW_TICKETLIST", "True")
== "True",
"preset_replies": os.environ.get("HELPDESK_PRESET_REPLIES", "True") == "True",
"tickets_per_page": os.environ.get("HELPDESK_TICKETS_PER_PAGE", "25"),
} }
# Should the public web portal be enabled? # Should the public web portal be enabled?
HELPDESK_PUBLIC_ENABLED = os.environ.get('HELPDESK_PUBLIC_ENABLED', 'True') == 'True' HELPDESK_PUBLIC_ENABLED = os.environ.get("HELPDESK_PUBLIC_ENABLED", "True") == "True"
HELPDESK_VIEW_A_TICKET_PUBLIC = os.environ.get('HELPDESK_VIEW_A_TICKET_PUBLIC', 'True') == 'True' HELPDESK_VIEW_A_TICKET_PUBLIC = (
HELPDESK_SUBMIT_A_TICKET_PUBLIC = os.environ.get('HELPDESK_SUBMIT_A_TICKET_PUBLIC', 'True') == 'True' os.environ.get("HELPDESK_VIEW_A_TICKET_PUBLIC", "True") == "True"
)
HELPDESK_SUBMIT_A_TICKET_PUBLIC = (
os.environ.get("HELPDESK_SUBMIT_A_TICKET_PUBLIC", "True") == "True"
)
# Should the Knowledgebase be enabled? # Should the Knowledgebase be enabled?
HELPDESK_KB_ENABLED = os.environ.get('HELPDESK_KB_ENABLED', 'True') == 'True' HELPDESK_KB_ENABLED = os.environ.get("HELPDESK_KB_ENABLED", "True") == "True"
HELPDESK_TICKETS_TIMELINE_ENABLED = os.environ.get('HELPDESK_TICKETS_TIMELINE_ENABLED', 'True') == 'True' HELPDESK_TICKETS_TIMELINE_ENABLED = (
os.environ.get("HELPDESK_TICKETS_TIMELINE_ENABLED", "True") == "True"
)
# Allow users to change their passwords # Allow users to change their passwords
HELPDESK_SHOW_CHANGE_PASSWORD = os.environ.get('HELPDESK_SHOW_CHANGE_PASSWORD', 'True') == 'True' HELPDESK_SHOW_CHANGE_PASSWORD = (
os.environ.get("HELPDESK_SHOW_CHANGE_PASSWORD", "True") == "True"
)
# Instead of showing the public web portal first, # Instead of showing the public web portal first,
# we can instead redirect users straight to the login page. # we can instead redirect users straight to the login page.
HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = os.environ.get('HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT', 'False') == 'True' HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = (
LOGIN_URL = 'helpdesk:login' os.environ.get("HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT", "False") == "True"
LOGIN_REDIRECT_URL = 'helpdesk:home' )
LOGIN_URL = "helpdesk:login"
LOGIN_REDIRECT_URL = "helpdesk:home"
DATABASES = { DATABASES = {
# Setup postgress db with postgres as host and db name and read password from env var # Setup postgress db with postgres as host and db name and read password from env var
'default': { "default": {
'ENGINE': 'django.db.backends.postgresql', "ENGINE": "django.db.backends.postgresql",
'NAME': os.environ.get('POSTGRES_DB', 'postgres'), "NAME": os.environ.get("POSTGRES_DB", "postgres"),
'USER': os.environ.get('POSTGRES_USER', 'postgres'), "USER": os.environ.get("POSTGRES_USER", "postgres"),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'), "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "postgres"),
'HOST': os.environ.get('POSTGRES_HOST', 'postgres'), "HOST": os.environ.get("POSTGRES_HOST", "postgres"),
'PORT': os.environ.get('POSTGRES_PORT', '5432'), "PORT": os.environ.get("POSTGRES_PORT", "5432"),
} }
} }
@ -154,16 +170,16 @@ SESSION_COOKIE_AGE = 86400 # = 1 day
AUTH_PASSWORD_VALIDATORS = [ 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",
}, },
] ]
@ -172,21 +188,21 @@ AUTH_PASSWORD_VALIDATORS = [
# This demo uses the console backend, which simply prints emails to the console # This demo uses the console backend, which simply prints emails to the console
# rather than actually sending them out. # rather than actually sending them out.
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'example@example.com') DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL", "example@example.com")
SERVER_EMAIL = os.environ.get('SERVER_EMAIL', 'example@example.com') SERVER_EMAIL = os.environ.get("SERVER_EMAIL", "example@example.com")
if os.environ.get('EMAIL_HOST', None): if os.environ.get("EMAIL_HOST", None):
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
try: try:
EMAIL_HOST = os.environ['EMAIL_HOST'] EMAIL_HOST = os.environ["EMAIL_HOST"]
except KeyError: except KeyError:
raise ImproperlyConfigured('Please set the EMAIL_HOST environment variable.') raise ImproperlyConfigured("Please set the EMAIL_HOST environment variable.")
try: try:
EMAIL_PORT = os.environ['EMAIL_PORT'] EMAIL_PORT = os.environ["EMAIL_PORT"]
except KeyError: except KeyError:
raise ImproperlyConfigured('Please set the EMAIL_PORT environment variable.') raise ImproperlyConfigured("Please set the EMAIL_PORT environment variable.")
else: else:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ # https://docs.djangoproject.com/en/1.11/topics/i18n/
@ -195,9 +211,9 @@ else:
# The most complete translations are: es-MX, ru, zh-Hans # The most complete translations are: es-MX, ru, zh-Hans
# Contribute to our translations via Transifex if you can! # Contribute to our translations via Transifex if you can!
# See CONTRIBUTING.rst for more info. # See CONTRIBUTING.rst for more info.
LANGUAGE_CODE = 'en-US' LANGUAGE_CODE = "en-US"
TIME_ZONE = 'UTC' TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
@ -213,32 +229,34 @@ def normpath(*args):
PROJECT_ROOT = normpath(__file__, "..", "..") PROJECT_ROOT = normpath(__file__, "..", "..")
STATIC_ROOT = os.environ.get("DJANGO_HELPDESK_STATIC_ROOT", normpath(PROJECT_ROOT, "static")) STATIC_ROOT = os.environ.get(
"DJANGO_HELPDESK_STATIC_ROOT", normpath(PROJECT_ROOT, "static")
)
STATIC_URL = os.environ.get("DJANGO_HELPDESK_STATIC_URL", "/static/") STATIC_URL = os.environ.get("DJANGO_HELPDESK_STATIC_URL", "/static/")
# MEDIA_ROOT is where media uploads are stored. # MEDIA_ROOT is where media uploads are stored.
# We set this to a directory to host file attachments created # We set this to a directory to host file attachments created
# with tickets. # with tickets.
MEDIA_URL = '/media/' MEDIA_URL = "/media/"
MEDIA_ROOT = '/data/media' MEDIA_ROOT = "/data/media"
# for Django 3.2+, set default for autofields: # for Django 3.2+, set default for autofields:
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
LOGGING = { LOGGING = {
'version': 1, "version": 1,
'disable_existing_loggers': False, "disable_existing_loggers": False,
'handlers': { "handlers": {
'console': { "console": {
'class': 'logging.StreamHandler', "class": "logging.StreamHandler",
}, },
}, },
'loggers': { "loggers": {
'django': { "django": {
'handlers': ['console'], "handlers": ["console"],
'level': 'ERROR', # Change to 'DEBUG' if you want to print all debug messages as well "level": "ERROR", # Change to 'DEBUG' if you want to print all debug messages as well
'propagate': True, "propagate": True,
}, },
}, },
} }

View File

@ -5,8 +5,12 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = (
path('admin/', admin.site.urls), [
path('', include('helpdesk.urls', namespace='helpdesk')), path("admin/", admin.site.urls),
path('api/auth/', include('rest_framework.urls', namespace='rest_framework')) path("", include("helpdesk.urls", namespace="helpdesk")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + local_urlpatterns path("api/auth/", include("rest_framework.urls", namespace="rest_framework")),
]
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ local_urlpatterns
)

View File

@ -7,7 +7,6 @@ For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
""" """
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
import os import os