Commit bc342f58 authored by guglielmo's avatar guglielmo

some tenants settings adjusted;

dynamic configuration with constance;
slack notification integrated
parent 6cf697f8
......@@ -7,10 +7,10 @@ root: ./
# socket_name: foo
# Ensure used daemons are used before start
pre: pg_ctl -D /usr/local/var/postgres start
pre: if [ $(pg_ctl -D /usr/local/var/postgres status | grep 'no server running' | wc -l) == 1 ]; then pg_ctl -D /usr/local/var/postgres start; fi
# Runs after everything. Use it to attach to tmux with custom options etc.
post: pg_ctl -D /usr/local/var/postgres stop
post: if [ $(tmux ls| wc -l) == 0 ]; then pg_ctl -D /usr/local/var/postgres stop; else echo there are $(tmux ls | wc -l) tmux sessions running, could not stop postgres; fi
windows:
- shell_plus:
......
......@@ -130,9 +130,14 @@ TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(str(PROJECT_PATH), "templates")],
"APP_DIRS": True,
"APP_DIRS": False,
"OPTIONS": {
"debug": DEBUG,
"loaders": [
"django_tenants.template.loaders.filesystem.Loader", # Must be first
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"context_processors": [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
......@@ -149,6 +154,10 @@ TEMPLATES = [
}
]
MULTITENANT_TEMPLATE_DIRS = [
os.path.join(str(PROJECT_PATH), "tenants", "%s", "templates"),
]
# MIDDLEWARE CONFIGURATION
# -----------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
......@@ -184,9 +193,9 @@ SHARED_APPS = (
# 'django.contrib.admindocs',
# Django helper
"django_extensions",
"django_slack",
# Customers or tenants
"project.tenants",
# Live settings
)
# Apps specific for this project go here.
......@@ -203,8 +212,10 @@ TENANT_APPS = (
# admin enhancers apps
"django_object_actions",
"django_admin_row_actions",
"django_slack",
# The app
"project.webapp",
# Live settings
"constance",
"constance.backends.database",
)
......@@ -306,9 +317,15 @@ TENANT_DOMAIN_MODEL = "tenants.Domain"
# CONSTANCE (LIVE SETTINGS) CONFIGURATION
# -------------------
CONSTANCE_CONFIG = {
'THE_ANSWER': (42, 'Answer to the Ultimate Question of Life, '
'The Universe, and Everything'),
'USE_SLACK': (False, "Enable notifications to slack channel. If False, then email is used", bool),
'SLACK_TOKEN': ("", "The token for slack integration, as read from slack"),
'SLACK_CHANNEL': ("", "The channel used for automatic notifications"),
'SLACK_USERNAME': ("", "The username sending automatic notifications"),
'SLACK_FAIL_SILENTLY': (True, "Whether to allow slack to silently fail", bool),
'SLACK_ICON_URL': ("", "The URL of an icon for this channel"),
'SLACK_ENDPOINT_URL': ("", "The slack app endpoint url. for example: https://hooks.slack.com/services/<TXXXX>/<GIBBERISH>")
}
CONSTANCE_IGNORE_ADMIN_VERSION_CHECK = True
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
# END CONSTANCE (LIVE SETTINGS) CONFIGURATION
......
......@@ -16,7 +16,11 @@ class DomainInline(admin.TabularInline):
@admin.register(Instance)
class InstanceAdmin(TenantAdminMixin, admin.ModelAdmin):
inlines = [DomainInline, ]
list_display = ('name', 'on_trial')
list_display = ('name', '_domains', 'on_trial')
def _domains(self, obj):
return list(obj.domains.values_list('domain', flat=True))
_domains.short_description = 'Domains'
def has_module_permission(self, request):
"""
......
{% extends django_slack %}
{% block text %}
Notifica task: Una prova
{% endblock %}
{% block endpoint_url %}{{ config.SLACK_ENDPOINT_URL }}{% endblock %}
{% block channel %}{{ config.SLACK_CHANNEL }}{% endblock %}
{% block username %}{{ config.SLACK_USERNAME }}{% endblock %}
{% block token %}{{ config.SLACK_TOKEN }}{% endblock %}
......@@ -56,9 +56,8 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
if obj.verification_status == 2:
msg = obj.verification_error
return "{0} - {1}".format(status, msg)
return mark_safe(f"{status} - {msg}")
_status_and_message.allow_tags = True
_status_and_message.short_description = 'Status'
# list actions on many objects (checkbox)
......
from django.core.management.base import BaseCommand
from django_slack import slack_message
from constance import config
from django.conf import settings
class Command(BaseCommand):
help = 'Test slack message'
def handle(self, *args, **options):
settings.DEGUG = False
slack_message('slack/test.slack', context={'config': config}, backend="django_slack.backends.UrllibBackend")
print(f"Message sent to channel {config.SLACK_CHANNEL} by {config.SLACK_USERNAME}")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment