Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8185c7edf6 | |||
| 51862ad3ed | |||
| 0eed8c8679 | |||
| d74fcd4001 | |||
| 97e1a2b315 | |||
| 45266906a3 | |||
| 5496f996be | |||
| d85690fb9c | |||
| c44621dae1 | |||
| 5f2e2982b1 | |||
| 1b0d20f494 | |||
| 7e85ebac9b | |||
| 95fb2df285 |
@@ -6,6 +6,8 @@ from django.contrib.auth import models as auth_models
|
||||
from admin_interface.compat import gettext_lazy as _
|
||||
from admin_interface.models import Theme, UserTheme
|
||||
|
||||
from .import_tema.admin import ImportMixin
|
||||
|
||||
|
||||
class UserInline(admin.TabularInline):
|
||||
model = UserTheme
|
||||
@@ -13,13 +15,14 @@ class UserInline(admin.TabularInline):
|
||||
autocomplete_fields = ('user', )
|
||||
|
||||
|
||||
class ThemeAdmin(admin.ModelAdmin):
|
||||
class ThemeAdmin(ImportMixin, admin.ModelAdmin):
|
||||
inlines = [UserInline, ]
|
||||
|
||||
list_display = (
|
||||
"name",
|
||||
"active",
|
||||
"demo",
|
||||
"default",
|
||||
)
|
||||
list_editable = ("active",)
|
||||
list_per_page = 100
|
||||
@@ -34,6 +37,7 @@ class ThemeAdmin(admin.ModelAdmin):
|
||||
"name",
|
||||
"active",
|
||||
"demo",
|
||||
"default",
|
||||
),
|
||||
},
|
||||
),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from .models import Theme
|
||||
from .models import Theme, UserTheme
|
||||
|
||||
def get_active_theme(request):
|
||||
objs_manager = Theme.objects
|
||||
user_theme_manager = UserTheme.objects
|
||||
objs_active_qs = objs_manager.filter(active=True)
|
||||
objs_active_ls = list(objs_active_qs)
|
||||
objs_active_count = len(objs_active_ls)
|
||||
@@ -17,6 +18,7 @@ def get_active_theme(request):
|
||||
obj = objs_active_ls[0]
|
||||
|
||||
elif objs_active_count > 1:
|
||||
|
||||
# for frame_record in inspect.stack():
|
||||
# if frame_record[3]=='get_response':
|
||||
# request = frame_record[0].f_locals['request']
|
||||
@@ -26,10 +28,15 @@ def get_active_theme(request):
|
||||
# request = None
|
||||
user = request.user
|
||||
try:
|
||||
obj = objs_active_qs.filter(user=user).first()
|
||||
obj = user_theme_manager.filter(user=user, theme__active=True).first().theme
|
||||
except:
|
||||
obj = objs_active_ls[-1]
|
||||
obj.set_active()
|
||||
objs_default_qs = objs_active_qs.filter(default=True)
|
||||
if len(objs_default_qs) == 0:
|
||||
obj = objs_active_qs.first()
|
||||
if obj:
|
||||
obj.set_default()
|
||||
else:
|
||||
obj = objs_default_qs.first()
|
||||
|
||||
return {
|
||||
'theme': obj,
|
||||
|
||||
@@ -109,14 +109,18 @@ class ImportMixin(admin.ModelAdmin):
|
||||
allowed_extensions=[".gif", ".jpg", ".jpeg", ".png", ".svg"]
|
||||
try:
|
||||
tema_json = [s for s in os.listdir(f'{tempdir}/{lst[0]}') if '.json' in s][0]
|
||||
logo = [s for s in os.listdir(f'{tempdir}/{lst[0]}/logo') if any(ele in s for ele in allowed_extensions)][0]
|
||||
favicon = [s for s in os.listdir(f'{tempdir}/{lst[0]}/favicon') if any(ele in s for ele in allowed_extensions)][0]
|
||||
logo = [s for s in os.listdir(f'{tempdir}/{lst[0]}/logo') if any(ele in s for ele in allowed_extensions)]
|
||||
logo = logo[0] if logo else None
|
||||
favicon = [s for s in os.listdir(f'{tempdir}/{lst[0]}/favicon') if any(ele in s for ele in allowed_extensions)]
|
||||
favicon = favicon[0] if favicon else None
|
||||
with open(f'{tempdir}/{lst[0]}/{tema_json}', 'r') as temporary_file:
|
||||
result = json.loads(temporary_file.read())
|
||||
with open(f'{tempdir}/{lst[0]}/logo/{logo}', 'rb') as temporary_file:
|
||||
default_storage.save(f"admin-interface/logo/{temporary_file.name.split('/')[-1]}", temporary_file)
|
||||
with open(f'{tempdir}/{lst[0]}/favicon/{favicon}', 'rb') as temporary_file:
|
||||
default_storage.save(f"admin-interface/favicon/{temporary_file.name.split('/')[-1]}", temporary_file)
|
||||
if logo:
|
||||
with open(f'{tempdir}/{lst[0]}/logo/{logo}', 'rb') as temporary_file:
|
||||
default_storage.save(f"admin-interface/logo/{temporary_file.name.split('/')[-1]}", temporary_file)
|
||||
if favicon:
|
||||
with open(f'{tempdir}/{lst[0]}/favicon/{favicon}', 'rb') as temporary_file:
|
||||
default_storage.save(f"admin-interface/favicon/{temporary_file.name.split('/')[-1]}", temporary_file)
|
||||
skip_result = False
|
||||
except FileNotFoundError as e:
|
||||
messages.error(request, 'Struttura del file .zip errata.')
|
||||
|
||||
@@ -45,5 +45,5 @@ class Migration(migrations.Migration):
|
||||
verbose_name="link selected color",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(default_link_selected),
|
||||
migrations.RunPython(default_link_selected,migrations.RunPython.noop),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.0.3 on 2023-01-30 14:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('admin_interface', '0029_auto_20221025_1559'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='theme',
|
||||
name='default',
|
||||
field=models.BooleanField(default=False, verbose_name='default'),
|
||||
),
|
||||
]
|
||||
@@ -57,6 +57,7 @@ class Theme(models.Model):
|
||||
@staticmethod
|
||||
def get_active_theme():
|
||||
objs_manager = Theme.objects
|
||||
user_theme_manager = UserTheme.objects
|
||||
objs_active_qs = objs_manager.filter(active=True)
|
||||
objs_active_ls = list(objs_active_qs)
|
||||
objs_active_count = len(objs_active_ls)
|
||||
@@ -81,10 +82,15 @@ class Theme(models.Model):
|
||||
request = None
|
||||
|
||||
try:
|
||||
return objs_active_qs.filter(user=user).first()
|
||||
return user_theme_manager.filter(user=user, theme__active=True).first().theme
|
||||
except:
|
||||
obj = objs_active_ls[-1]
|
||||
obj.set_active()
|
||||
objs_default_qs = objs_active_qs.filter(default=True)
|
||||
if len(objs_default_qs) == 0:
|
||||
obj = objs_active_qs.first()
|
||||
if obj:
|
||||
obj.set_default()
|
||||
else:
|
||||
obj = objs_default_qs.first()
|
||||
|
||||
return obj
|
||||
|
||||
@@ -94,6 +100,9 @@ class Theme(models.Model):
|
||||
active = models.BooleanField(default=True, verbose_name=_("active"))
|
||||
|
||||
demo = models.BooleanField(default=False, verbose_name=_("is demo"))
|
||||
|
||||
default = models.BooleanField(default=False, verbose_name="default")
|
||||
|
||||
users = models.ManyToManyField('auth.User', through=UserTheme)
|
||||
|
||||
title = models.CharField(
|
||||
@@ -408,6 +417,15 @@ class Theme(models.Model):
|
||||
self.active = True
|
||||
self.save()
|
||||
|
||||
def set_default(self):
|
||||
self.default = True
|
||||
self.save()
|
||||
|
||||
def save(self):
|
||||
if self.default:
|
||||
Theme.objects.update(default=False)
|
||||
super().save()
|
||||
|
||||
class Meta:
|
||||
app_label = "admin_interface"
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
}
|
||||
windowRef = {
|
||||
name: widgetName,
|
||||
location: windowRef.location,
|
||||
close: function() {
|
||||
openerRef.dismissRelatedObjectModal();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block extrastyle %}
|
||||
{% get_admin_interface_nocache as version_md5_cache %}
|
||||
{% get_current_language as current_lang %}
|
||||
<style type="text/css">
|
||||
{% include "admin_interface/css/admin-interface.css" %}
|
||||
@@ -33,11 +32,10 @@
|
||||
|
||||
{% block blockbots %}
|
||||
{{ block.super }}
|
||||
{% get_admin_interface_nocache as version_md5_cache %}
|
||||
{# https://github.com/elky/django-flat-responsive#important-note #}
|
||||
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive.css' %}?nocache={{ version_md5_cache }}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive_rtl.css' %}?nocache={{ version_md5_cache }}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive.css' %}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive_rtl.css' %}">
|
||||
{% include "admin_interface/favicon.html" %}
|
||||
{% include "admin_interface/foldable-apps.html" %}
|
||||
{% include "admin_interface/related-modal.html" %}
|
||||
|
||||
@@ -164,12 +164,15 @@
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
.admin-interface #header #user-tools a {
|
||||
.admin-interface #header #user-tools a,
|
||||
.admin-interface #header #user-tools button {
|
||||
color:{{ theme.css_header_link_color }};
|
||||
}
|
||||
|
||||
.admin-interface #header #user-tools a:hover,
|
||||
.admin-interface #header #user-tools a:active {
|
||||
.admin-interface #header #user-tools a:active,
|
||||
.admin-interface #header #user-tools button:active,
|
||||
.admin-interface #header #user-tools button:hover {
|
||||
color:{{ theme.css_header_link_hover_color }};
|
||||
border-bottom-color:rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{% if theme.favicon %}
|
||||
<link rel="icon" href="{{ theme.favicon.url }}">
|
||||
{% if theme.env_visible_in_favicon %}
|
||||
<script type="text/javascript" src="{% static 'admin_interface/favico/favico-0.3.10-patched.min.js' %}?nocache={{ version_md5_cache }}"></script>
|
||||
<script type="text/javascript" src="{% static 'admin_interface/favico/favico-0.3.10-patched.min.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
var favicon = new Favico({
|
||||
type: 'circle',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% load static %}
|
||||
|
||||
{% if theme.foldable_apps %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/foldable-apps/foldable-apps.css' %}?nocache={{ version_md5_cache }}">
|
||||
<script type="text/javascript" src="{% static 'admin_interface/foldable-apps/foldable-apps.js' %}?nocache={{ version_md5_cache }}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/foldable-apps/foldable-apps.css' %}">
|
||||
<script type="text/javascript" src="{% static 'admin_interface/foldable-apps/foldable-apps.js' %}"></script>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% load static %}
|
||||
|
||||
{% if theme.related_modal_active %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/magnific-popup/magnific-popup.css' %}?nocache={{ version_md5_cache }}">
|
||||
<script type="text/javascript" src="{% static 'admin_interface/magnific-popup/jquery.magnific-popup.js' %}?nocache={{ version_md5_cache }}"></script>
|
||||
<script type="text/javascript" src="{% static 'admin_interface/related-modal/related-modal.js' %}?nocache={{ version_md5_cache }}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/magnific-popup/magnific-popup.css' %}">
|
||||
<script type="text/javascript" src="{% static 'admin_interface/magnific-popup/jquery.magnific-popup.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'admin_interface/related-modal/related-modal.js' %}"></script>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__version__ = "0.19.4"
|
||||
__version__ = "0.19.8"
|
||||
|
||||
Reference in New Issue
Block a user