Compare commits

...
7 Commits
Author SHA1 Message Date
davide_borgonovo b8a160f746 Aggiornata versione 2022-03-15 17:59:01 +01:00
davide_borgonovo 5e3e3a1480 Revert "Converted dynamic inline CSS to external static CSS using CSS variables. #157 #93"
This reverts commit 8fe7178a13.
2022-03-15 17:56:03 +01:00
davide_borgonovo 7d649185cb Forkino per aggiungere modalità demo con un tema selezionato e per rendere il tema associabile ad un utente 2022-03-14 23:58:22 +01:00
Fabio Caccamo 3ff4f05e51 Update test-package.yml
Revert "Update test-package.yml"

This reverts commit d5cb8ff3fd09d43e3b2d333693b9fd97619a2b7f.

Update test-package.yml

Updated `create-matrix-action` version.

Update test-package.yml

Update test-package.yml

Update test-package.yml

Update test-package.yml
2022-03-10 15:50:09 +01:00
Fabio Caccamo d8cffd8c2c Updated CHANGELOG and version. 2022-03-09 10:14:57 +01:00
Mustafa M. A. U. AbuGhazy 8fe7178a13 Converted dynamic inline CSS to external static CSS using CSS variables. #157 #93 2022-03-09 10:14:57 +01:00
Fabio Caccamo d2b680e477 Update test-package.yml 2022-03-09 10:14:57 +01:00
10 changed files with 188 additions and 49 deletions
+58 -14
View File
@@ -6,12 +6,37 @@ on:
workflow_dispatch:
jobs:
build:
prepare:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create matrix
uses: fabiocaccamo/create-matrix-action@v2
id: create_matrix
with:
matrix: |
python-version {2.7}, django-version {1.8,1.9,1.10,1.11}, database {sqlite,postgres}
python-version {3.6}, django-version {1.8,1.9,1.10,1.11,2.0,2.1,2.2,3.0,3.1,3.2}, database {sqlite,postgres}
python-version {3.7}, django-version {2.0,2.1,2.2,3.0,3.1,3.2}, database {sqlite,postgres}
python-version {3.8}, django-version {2.2,3.0,3.1,3.2}, database {sqlite,postgres}
python-version {3.9}, django-version {2.2,3.0,3.1,3.2}, database {sqlite,postgres}
python-version {3.10}, django-version {3.2,4.0}, database {sqlite,postgres}
outputs:
matrix: ${{ steps.create_matrix.outputs.matrix }}
test:
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
matrix:
include: ${{fromJson(needs.prepare.outputs.matrix)}}
services:
postgres:
@@ -27,23 +52,42 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Install psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Install dependencies
- name: Upgrade pip version
run: |
pip install pip --upgrade
- name: Install django
run: |
pip install "Django ~= ${{ matrix.django-version }}"
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install tox tox-gh-actions
- name: Test with tox
run: tox
- name: Run tests
env:
DATABASE_ENGINE: ${{ matrix.database }}
run: |
coverage run --append --source=admin_interface setup.py test
coverage xml -o ./coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: false
files: ./coverage.xml
flags: unittests
verbose: true
+3
View File
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.19.0](https://github.com/fabiocaccamo/django-admin-interface/releases/tag/0.19.0) - 2022-03-08
- Converted dynamic inline CSS to external static CSS using CSS variables. #157 #93 (thanks to [@Mustafa-Abu-Ghazy](https://github.com/Mustafa-Abu-Ghazy))
## [0.18.7](https://github.com/fabiocaccamo/django-admin-interface/releases/tag/0.18.7) - 2022-02-24
- Removed public disclosures of the lib's version. #154 (thanks to [@mintyPT](https://github.com/mintyPT))
- Reformatted code with **Black**.
+7
View File
@@ -3,6 +3,7 @@
from admin_interface.compat import gettext_lazy as _
from admin_interface.models import Theme
from django.contrib.auth import models as auth_models
from django.contrib import admin
@@ -11,6 +12,7 @@ class ThemeAdmin(admin.ModelAdmin):
list_display = (
"name",
"active",
"demo",
)
list_editable = ("active",)
list_per_page = 100
@@ -24,6 +26,7 @@ class ThemeAdmin(admin.ModelAdmin):
"fields": (
"name",
"active",
"demo",
),
},
),
@@ -171,6 +174,10 @@ class ThemeAdmin(admin.ModelAdmin):
_("Recent Actions"),
{"classes": ("wide",), "fields": ("recent_actions_visible",)},
),
(
_("Users theme"),
{"classes": ("wide",), "fields": ("user",)},
),
)
save_on_top = True
+36
View File
@@ -0,0 +1,36 @@
from .models import Theme
def get_active_theme(request):
objs_manager = Theme.objects
objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)
if objs_active_count == 0:
obj = objs_manager.all().first()
if obj:
obj.set_active()
else:
obj = objs_manager.create()
elif objs_active_count == 1:
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']
# user = request.user
# break
# else:
# request = None
user = request.user
try:
obj = objs_active_qs.filter(user=user).first()
except:
obj = objs_active_ls[-1]
obj.set_active()
return {
'theme': obj,
}
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("admin_interface", "0024_remove_theme_css"),
]
operations = [
migrations.AddField(
model_name="theme",
name="demo",
field=models.BooleanField(default=False, verbose_name="demo"),
),
]
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("admin_interface", "0025_add_demo_option"),
]
operations = [
migrations.AddField(
model_name="theme",
name="user",
field=models.ForeignKey('auth.User', on_delete=models.CASCADE, null=True, blank=True, verbose_name="active for user"),
),
]
+38 -23
View File
@@ -2,16 +2,17 @@
from __future__ import unicode_literals
from admin_interface.cache import del_cached_active_theme
from admin_interface.compat import FileExtensionValidator, force_str, gettext_lazy as _
import inspect
from colorfield.fields import ColorField
from django.db import models
from django.db.models.signals import post_delete, post_save, pre_save
from six import python_2_unicode_compatible
from admin_interface.cache import del_cached_active_theme
from admin_interface.compat import FileExtensionValidator, force_str
from admin_interface.compat import gettext_lazy as _
@python_2_unicode_compatible
class Theme(models.Model):
@@ -25,22 +26,22 @@ class Theme(models.Model):
del_cached_active_theme()
Theme.get_active_theme()
@staticmethod
def post_save_handler(instance, **kwargs):
del_cached_active_theme()
if instance.active:
Theme.objects.exclude(pk=instance.pk).update(active=False)
Theme.get_active_theme()
# @staticmethod
# def post_save_handler(instance, **kwargs):
# del_cached_active_theme()
# if instance.active:
# Theme.objects.exclude(pk=instance.pk).update(active=False)
# Theme.get_active_theme()
@staticmethod
def pre_save_handler(instance, **kwargs):
if instance.pk is None:
try:
obj = Theme.objects.get(name=instance.name)
if obj:
instance.pk = obj.pk
except Theme.DoesNotExist:
pass
# @staticmethod
# def pre_save_handler(instance, **kwargs):
# if instance.pk is None:
# try:
# obj = Theme.objects.get(name=instance.name)
# if obj:
# instance.pk = obj.pk
# except Theme.DoesNotExist:
# pass
@staticmethod
def get_active_theme():
@@ -60,8 +61,19 @@ class Theme(models.Model):
obj = objs_active_ls[0]
elif objs_active_count > 1:
obj = objs_active_ls[-1]
obj.set_active()
for frame_record in inspect.stack():
if frame_record[3]=='get_response':
request = frame_record[0].f_locals['request']
user = request.user
break
else:
request = None
try:
return objs_active_qs.filter(user=user).first()
except:
obj = objs_active_ls[-1]
obj.set_active()
return obj
@@ -70,6 +82,9 @@ class Theme(models.Model):
)
active = models.BooleanField(default=True, verbose_name=_("active"))
demo = models.BooleanField(default=False, verbose_name=_("is demo"))
user = models.ForeignKey('auth.User', on_delete=models.CASCADE, null=True, blank=True, verbose_name=_("active for user"))
title = models.CharField(
max_length=50,
default=_("Django administration"),
@@ -389,5 +404,5 @@ class Theme(models.Model):
post_delete.connect(Theme.post_delete_handler, sender=Theme)
post_save.connect(Theme.post_save_handler, sender=Theme)
pre_save.connect(Theme.pre_save_handler, sender=Theme)
# post_save.connect(Theme.post_save_handler, sender=Theme)
# pre_save.connect(Theme.pre_save_handler, sender=Theme)
@@ -2,12 +2,10 @@
{% load i18n static admin_interface_tags %}
{% block title %}
{% get_admin_interface_theme as theme %}
{% if title %}{{ title }} | {% endif %}{% if theme.title %}{% trans theme.title %}{% else %}{{ site_title|default:_('Django administration') }}{% endif %}
{% endblock %}
{% block extrastyle %}
{% get_admin_interface_theme as theme %}
{% get_admin_interface_nocache as version_md5_cache %}
{% get_current_language as current_lang %}
<style type="text/css">
@@ -35,7 +33,6 @@
{% block blockbots %}
{{ block.super }}
{% get_admin_interface_theme as theme %}
{% 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">
@@ -51,7 +48,6 @@
{% endblock %}
{% block bodyclass %}
{% get_admin_interface_theme as theme %}
flat-theme admin-interface
{% if theme.name %} {{ theme.name|slugify }}-theme {% endif %}
{% if theme.foldable_apps %} foldable-apps {% endif %}
@@ -60,7 +56,6 @@ flat-theme admin-interface
{% endblock %}
{% block branding %}
{% get_admin_interface_theme as theme %}
<h1 id="site-name">
<a href="{% url 'admin:index' %}">
{% if theme.logo_visible %}
@@ -78,10 +73,9 @@ flat-theme admin-interface
{% endblock %}
{% block welcome-msg %}
{% get_admin_interface_theme as theme %}
{% if theme.language_chooser_active %}
{% get_admin_interface_languages as languages %}
{% include "admin_interface/language_chooser.html" %}
{% endif %}
{% if theme.env_visible_in_header %}<span class="environment-label {{ theme.env_name }}"></span><br>{% endif %}{{ block.super }}<br>
{% if theme.env_visible_in_header %}<span class="environment-label {{ theme.env_name }}">{{ theme.env_name }}</span><br>{% endif %}{{ block.super }}<br>
{% endblock %}
@@ -67,10 +67,10 @@ def get_admin_interface_languages(context):
@simple_tag(takes_context=True)
def get_admin_interface_theme(context):
theme = get_cached_active_theme()
if not theme:
theme = Theme.get_active_theme()
set_cached_active_theme(theme)
# theme = get_cached_active_theme()
# if not theme:
theme = Theme.get_active_theme()
# set_cached_active_theme(theme)
return theme
+1 -1
View File
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = "0.18.7"
__version__ = "0.19.2"