V1.30 notification
This commit is contained in:
@@ -15,3 +15,4 @@ from .training_plan_day import TrainingPlanDayAdmin
|
||||
from .controlling import ControllingAdmin
|
||||
from .sport import SportAdmin
|
||||
from .app_text import AppTextAdmin
|
||||
from .notification import NotificationAdmin
|
||||
@@ -0,0 +1,35 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from ..models.notification import Notification
|
||||
|
||||
class NotificationAdmin(admin.ModelAdmin):
|
||||
list_display = ('notification_id', 'internal_name', 'message_title', 'active' )
|
||||
fields = ('internal_name', 'internal_description', 'message_title', 'message_body', 'image_url', 'get_image_preview', 'schedule_date', 'schedule_hook', 'schedule_sql', 'active' )
|
||||
list_editable = ('internal_name', 'active')
|
||||
readonly_fields = ("get_image_preview",)
|
||||
|
||||
def get_image_preview(self, obj):
|
||||
image_url = '/media/' + str(obj.image_url)
|
||||
if obj.pk:
|
||||
return format_html('<img src="{url}" title="{url}" width="30%" height="30%"/> ' \
|
||||
.format(url=image_url))
|
||||
|
||||
get_image_preview.short_description = _("Image Preview")
|
||||
|
||||
def clone_notification(self, request, queryset):
|
||||
for notif in queryset:
|
||||
notif.pk = None
|
||||
notif.internal_name = notif.internal_name + "_copy"
|
||||
notif.save()
|
||||
|
||||
clone_notification.short_description = "Clone the selected notification"
|
||||
|
||||
actions = [clone_notification]
|
||||
|
||||
|
||||
|
||||
|
||||
admin.site.register(Notification, NotificationAdmin)
|
||||
admin.autodiscover()
|
||||
@@ -12,7 +12,10 @@ class TestRouter:
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if model._meta.app_label == 'controlling':
|
||||
raise Exception("This table cannot be changed!")
|
||||
if model._meta.db_table == 'notification_history':
|
||||
return 'live'
|
||||
else:
|
||||
raise Exception("This table cannot be changed!")
|
||||
return 'default'
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
|
||||
@@ -17,4 +17,5 @@ from .split_tests import SplitTests
|
||||
from .training_plan_day import TrainingPlanDay, TrainingPlanDayTranslation
|
||||
from .controlling import Controlling
|
||||
from .sports import Sport, SportTranslation
|
||||
from .app_text import AppText, AppTextTranslation
|
||||
from .app_text import AppText, AppTextTranslation
|
||||
from .notification import Notification
|
||||
@@ -0,0 +1,22 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class Notification(models.Model):
|
||||
notification_id = models.AutoField(primary_key=True)
|
||||
message_title = models.CharField(max_length=50)
|
||||
message_body = models.TextField(max_length=100, blank=True, null=True)
|
||||
image_url = models.ImageField(upload_to='images/', help_text='The notification image')
|
||||
schedule_date = models.DateField(blank=True, null=True)
|
||||
schedule_hook = models.TextField(max_length=100, blank=True, null=True)
|
||||
schedule_sql = models.TextField(max_length=1000, blank=True, null=True)
|
||||
internal_name = models.CharField(max_length=50, blank=True, null=True)
|
||||
internal_description = models.TextField(max_length=500, blank=True, null=True)
|
||||
active = models.BooleanField(default=0)
|
||||
|
||||
class Meta:
|
||||
db_table = 'notification'
|
||||
verbose_name = _("Notification")
|
||||
verbose_name_plural = _("Notifications")
|
||||
|
||||
def __str__(self):
|
||||
return self.internal_name
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
BACKOFFICE_VERSION = "1.29.1"
|
||||
BACKOFFICE_VERSION = "1.30"
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -31,6 +31,7 @@ INSTALLED_APPS = [
|
||||
'adminsortable2',
|
||||
'inline_actions',
|
||||
'django_cron',
|
||||
'firebase-admin'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -159,5 +160,5 @@ LOGGING = {
|
||||
|
||||
|
||||
CRON_CLASSES = [
|
||||
'controlling.cron.cron.MyCronJob',
|
||||
'controlling.cron.cron.NotificationJob',
|
||||
]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
from firebase_admin import initialize_app
|
||||
|
||||
BACKOFFICE_VERSION = "1.29.1"
|
||||
BACKOFFICE_VERSION = "1.30"
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -32,6 +33,8 @@ INSTALLED_APPS = [
|
||||
'django_cron',
|
||||
]
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
@@ -143,7 +146,7 @@ LOGGING = {
|
||||
'loggers': {
|
||||
'mylogger': {
|
||||
'handlers': ['console'],
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
|
||||
'propagate': True,
|
||||
},
|
||||
},
|
||||
@@ -156,5 +159,7 @@ LOGGING = {
|
||||
|
||||
|
||||
CRON_CLASSES = [
|
||||
'controlling.cron.cron.MyCronJob',
|
||||
'controlling.cron.cron.NotificationJob',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
BACKOFFICE_VERSION = "1.29.1"
|
||||
BACKOFFICE_VERSION = "1.30"
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -31,6 +31,7 @@ INSTALLED_APPS = [
|
||||
'adminsortable2',
|
||||
'inline_actions',
|
||||
'django_cron',
|
||||
'firebase-admin',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -174,5 +175,5 @@ CACHES = {
|
||||
|
||||
|
||||
CRON_CLASSES = [
|
||||
'aitrainer_backoffice.controlling.cron.cron.MyCronJob',
|
||||
'aitrainer_backoffice.controlling.cron.cron.NotificationJob',
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path(r'^ckeditor/', include('ckeditor_uploader.urls')),
|
||||
path(r'ckeditor', include('ckeditor_uploader.urls')),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
Reference in New Issue
Block a user