Compare commits

...

13 Commits

13 changed files with 81 additions and 28 deletions
+5 -1
View File
@@ -6,6 +6,8 @@ from django.contrib.auth import models as auth_models
from admin_interface.compat import gettext_lazy as _ from admin_interface.compat import gettext_lazy as _
from admin_interface.models import Theme, UserTheme from admin_interface.models import Theme, UserTheme
from .import_tema.admin import ImportMixin
class UserInline(admin.TabularInline): class UserInline(admin.TabularInline):
model = UserTheme model = UserTheme
@@ -13,13 +15,14 @@ class UserInline(admin.TabularInline):
autocomplete_fields = ('user', ) autocomplete_fields = ('user', )
class ThemeAdmin(admin.ModelAdmin): class ThemeAdmin(ImportMixin, admin.ModelAdmin):
inlines = [UserInline, ] inlines = [UserInline, ]
list_display = ( list_display = (
"name", "name",
"active", "active",
"demo", "demo",
"default",
) )
list_editable = ("active",) list_editable = ("active",)
list_per_page = 100 list_per_page = 100
@@ -34,6 +37,7 @@ class ThemeAdmin(admin.ModelAdmin):
"name", "name",
"active", "active",
"demo", "demo",
"default",
), ),
}, },
), ),
+11 -4
View File
@@ -1,7 +1,8 @@
from .models import Theme from .models import Theme, UserTheme
def get_active_theme(request): def get_active_theme(request):
objs_manager = Theme.objects objs_manager = Theme.objects
user_theme_manager = UserTheme.objects
objs_active_qs = objs_manager.filter(active=True) objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs) objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls) objs_active_count = len(objs_active_ls)
@@ -17,6 +18,7 @@ def get_active_theme(request):
obj = objs_active_ls[0] obj = objs_active_ls[0]
elif objs_active_count > 1: elif objs_active_count > 1:
# for frame_record in inspect.stack(): # for frame_record in inspect.stack():
# if frame_record[3]=='get_response': # if frame_record[3]=='get_response':
# request = frame_record[0].f_locals['request'] # request = frame_record[0].f_locals['request']
@@ -26,10 +28,15 @@ def get_active_theme(request):
# request = None # request = None
user = request.user user = request.user
try: try:
obj = objs_active_qs.filter(user=user).first() obj = user_theme_manager.filter(user=user, theme__active=True).first().theme
except: except:
obj = objs_active_ls[-1] objs_default_qs = objs_active_qs.filter(default=True)
obj.set_active() if len(objs_default_qs) == 0:
obj = objs_active_qs.first()
if obj:
obj.set_default()
else:
obj = objs_default_qs.first()
return { return {
'theme': obj, 'theme': obj,
+10 -6
View File
@@ -109,14 +109,18 @@ class ImportMixin(admin.ModelAdmin):
allowed_extensions=[".gif", ".jpg", ".jpeg", ".png", ".svg"] allowed_extensions=[".gif", ".jpg", ".jpeg", ".png", ".svg"]
try: try:
tema_json = [s for s in os.listdir(f'{tempdir}/{lst[0]}') if '.json' in s][0] 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] logo = [s for s in os.listdir(f'{tempdir}/{lst[0]}/logo') if any(ele in s for ele in allowed_extensions)]
favicon = [s for s in os.listdir(f'{tempdir}/{lst[0]}/favicon') if any(ele in s for ele in allowed_extensions)][0] 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: with open(f'{tempdir}/{lst[0]}/{tema_json}', 'r') as temporary_file:
result = json.loads(temporary_file.read()) result = json.loads(temporary_file.read())
with open(f'{tempdir}/{lst[0]}/logo/{logo}', 'rb') as temporary_file: if logo:
default_storage.save(f"admin-interface/logo/{temporary_file.name.split('/')[-1]}", temporary_file) with open(f'{tempdir}/{lst[0]}/logo/{logo}', 'rb') as temporary_file:
with open(f'{tempdir}/{lst[0]}/favicon/{favicon}', 'rb') as temporary_file: default_storage.save(f"admin-interface/logo/{temporary_file.name.split('/')[-1]}", temporary_file)
default_storage.save(f"admin-interface/favicon/{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 skip_result = False
except FileNotFoundError as e: except FileNotFoundError as e:
messages.error(request, 'Struttura del file .zip errata.') messages.error(request, 'Struttura del file .zip errata.')
@@ -45,5 +45,5 @@ class Migration(migrations.Migration):
verbose_name="link selected color", 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'),
),
]
+21 -3
View File
@@ -57,6 +57,7 @@ class Theme(models.Model):
@staticmethod @staticmethod
def get_active_theme(): def get_active_theme():
objs_manager = Theme.objects objs_manager = Theme.objects
user_theme_manager = UserTheme.objects
objs_active_qs = objs_manager.filter(active=True) objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs) objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls) objs_active_count = len(objs_active_ls)
@@ -81,10 +82,15 @@ class Theme(models.Model):
request = None request = None
try: try:
return objs_active_qs.filter(user=user).first() return user_theme_manager.filter(user=user, theme__active=True).first().theme
except: except:
obj = objs_active_ls[-1] objs_default_qs = objs_active_qs.filter(default=True)
obj.set_active() if len(objs_default_qs) == 0:
obj = objs_active_qs.first()
if obj:
obj.set_default()
else:
obj = objs_default_qs.first()
return obj return obj
@@ -94,6 +100,9 @@ class Theme(models.Model):
active = models.BooleanField(default=True, verbose_name=_("active")) active = models.BooleanField(default=True, verbose_name=_("active"))
demo = models.BooleanField(default=False, verbose_name=_("is demo")) demo = models.BooleanField(default=False, verbose_name=_("is demo"))
default = models.BooleanField(default=False, verbose_name="default")
users = models.ManyToManyField('auth.User', through=UserTheme) users = models.ManyToManyField('auth.User', through=UserTheme)
title = models.CharField( title = models.CharField(
@@ -408,6 +417,15 @@ class Theme(models.Model):
self.active = True self.active = True
self.save() 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: class Meta:
app_label = "admin_interface" app_label = "admin_interface"
@@ -16,6 +16,7 @@
} }
windowRef = { windowRef = {
name: widgetName, name: widgetName,
location: windowRef.location,
close: function() { close: function() {
openerRef.dismissRelatedObjectModal(); openerRef.dismissRelatedObjectModal();
} }
@@ -6,7 +6,6 @@
{% endblock %} {% endblock %}
{% block extrastyle %} {% block extrastyle %}
{% get_admin_interface_nocache as version_md5_cache %}
{% get_current_language as current_lang %} {% get_current_language as current_lang %}
<style type="text/css"> <style type="text/css">
{% include "admin_interface/css/admin-interface.css" %} {% include "admin_interface/css/admin-interface.css" %}
@@ -33,11 +32,10 @@
{% block blockbots %} {% block blockbots %}
{{ block.super }} {{ block.super }}
{% get_admin_interface_nocache as version_md5_cache %}
{# https://github.com/elky/django-flat-responsive#important-note #} {# 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"> <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.css' %}">
<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_rtl.css' %}">
{% include "admin_interface/favicon.html" %} {% include "admin_interface/favicon.html" %}
{% include "admin_interface/foldable-apps.html" %} {% include "admin_interface/foldable-apps.html" %}
{% include "admin_interface/related-modal.html" %} {% include "admin_interface/related-modal.html" %}
@@ -164,12 +164,15 @@
{% endif %} {% 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 }}; color:{{ theme.css_header_link_color }};
} }
.admin-interface #header #user-tools a:hover, .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 }}; color:{{ theme.css_header_link_hover_color }};
border-bottom-color:rgba(255, 255, 255, 0.5); border-bottom-color:rgba(255, 255, 255, 0.5);
} }
@@ -3,7 +3,7 @@
{% if theme.favicon %} {% if theme.favicon %}
<link rel="icon" href="{{ theme.favicon.url }}"> <link rel="icon" href="{{ theme.favicon.url }}">
{% if theme.env_visible_in_favicon %} {% 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"> <script type="text/javascript">
var favicon = new Favico({ var favicon = new Favico({
type: 'circle', type: 'circle',
@@ -1,6 +1,6 @@
{% load static %} {% load static %}
{% if theme.foldable_apps %} {% if theme.foldable_apps %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/foldable-apps/foldable-apps.css' %}?nocache={{ version_md5_cache }}"> <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' %}?nocache={{ version_md5_cache }}"></script> <script type="text/javascript" src="{% static 'admin_interface/foldable-apps/foldable-apps.js' %}"></script>
{% endif %} {% endif %}
@@ -1,7 +1,7 @@
{% load static %} {% load static %}
{% if theme.related_modal_active %} {% if theme.related_modal_active %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/magnific-popup/magnific-popup.css' %}?nocache={{ version_md5_cache }}"> <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' %}?nocache={{ version_md5_cache }}"></script> <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' %}?nocache={{ version_md5_cache }}"></script> <script type="text/javascript" src="{% static 'admin_interface/related-modal/related-modal.js' %}"></script>
{% endif %} {% endif %}
+1 -1
View File
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = "0.19.4" __version__ = "0.19.8"