Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8185c7edf6 | ||
|
|
51862ad3ed | ||
|
|
0eed8c8679 | ||
|
|
d74fcd4001 | ||
|
|
97e1a2b315 | ||
|
|
45266906a3 | ||
|
|
5496f996be | ||
|
|
d85690fb9c | ||
|
|
c44621dae1 | ||
|
|
5f2e2982b1 | ||
|
|
1b0d20f494 | ||
|
|
7e85ebac9b | ||
|
|
95fb2df285 | ||
|
|
363bc310a1 | ||
|
|
2ee03fc2de |
@@ -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",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
import django
|
||||||
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib import admin, messages
|
||||||
|
from django.contrib.auth import get_permission_codename
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.core.files.storage import default_storage
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.template.response import TemplateResponse
|
||||||
|
from django.urls import path, reverse
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from .. import models
|
||||||
|
from .forms import ImportForm
|
||||||
|
|
||||||
|
|
||||||
|
class ImportMixin(admin.ModelAdmin):
|
||||||
|
"""
|
||||||
|
Import mixin.
|
||||||
|
|
||||||
|
This is intended to be mixed with django.contrib.admin.ModelAdmin
|
||||||
|
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#modeladmin-objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
#: template for change_list view
|
||||||
|
change_list_template = 'admin/import_export/change_list_import.html'
|
||||||
|
#: template for import view
|
||||||
|
import_template_name = 'admin/import_export/import.html'
|
||||||
|
|
||||||
|
def get_model_info(self):
|
||||||
|
app_label = self.model._meta.app_label
|
||||||
|
return (self.model._meta.app_label, self.model._meta.model_name)
|
||||||
|
|
||||||
|
def has_import_permission(self, request):
|
||||||
|
"""
|
||||||
|
Returns whether a request has import permission.
|
||||||
|
"""
|
||||||
|
IMPORT_PERMISSION_CODE = getattr(settings, 'IMPORT_EXPORT_IMPORT_PERMISSION_CODE', None)
|
||||||
|
if IMPORT_PERMISSION_CODE is None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
opts = self.opts
|
||||||
|
codename = get_permission_codename(IMPORT_PERMISSION_CODE, opts)
|
||||||
|
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
info = self.get_model_info()
|
||||||
|
my_urls = [
|
||||||
|
path('import/',
|
||||||
|
self.admin_site.admin_view(self.import_action),
|
||||||
|
name='%s_%s_import' % info),
|
||||||
|
]
|
||||||
|
return my_urls + urls
|
||||||
|
|
||||||
|
def get_import_context_data(self, **kwargs):
|
||||||
|
return self.get_context_data(**kwargs)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def get_form_kwargs(self, form, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Prepare/returns kwargs for the import form.
|
||||||
|
|
||||||
|
To distinguish between import and confirm import forms,
|
||||||
|
the following approach may be used:
|
||||||
|
|
||||||
|
if isinstance(form, ImportForm):
|
||||||
|
# your code here for the import form kwargs
|
||||||
|
# e.g. update.kwargs({...})
|
||||||
|
elif isinstance(form, ConfirmImportForm):
|
||||||
|
# your code here for the confirm import form kwargs
|
||||||
|
# e.g. update.kwargs({...})
|
||||||
|
...
|
||||||
|
"""
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def import_action(self, request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Perform a dry_run of the import to make sure the import will not
|
||||||
|
result in errors. If there where no error, save the user
|
||||||
|
uploaded file to a local temp file that will be used by
|
||||||
|
'process_import' for the actual import.
|
||||||
|
"""
|
||||||
|
if not self.has_import_permission(request):
|
||||||
|
raise PermissionDenied
|
||||||
|
|
||||||
|
context = self.get_import_context_data()
|
||||||
|
|
||||||
|
form_type = ImportForm
|
||||||
|
form_kwargs = self.get_form_kwargs(form_type, *args, **kwargs)
|
||||||
|
form = form_type(request.POST or None,
|
||||||
|
request.FILES or None,
|
||||||
|
**form_kwargs)
|
||||||
|
|
||||||
|
if request.POST and form.is_valid():
|
||||||
|
import_file_tema = form.cleaned_data['tema']
|
||||||
|
if zipfile.is_zipfile(import_file_tema):
|
||||||
|
with zipfile.ZipFile(import_file_tema, 'r') as zip_ref:
|
||||||
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
|
zip_ref.extractall(tempdir)
|
||||||
|
lst = os.listdir(tempdir)
|
||||||
|
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)]
|
||||||
|
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())
|
||||||
|
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.')
|
||||||
|
skip_result = True
|
||||||
|
if not skip_result:
|
||||||
|
try:
|
||||||
|
new_theme = models.Theme(
|
||||||
|
**result[0]['fields']
|
||||||
|
)
|
||||||
|
new_theme.save()
|
||||||
|
|
||||||
|
messages.success(request, _('Import finished'))
|
||||||
|
except:
|
||||||
|
messages.error(request, 'Struttura del file .json errata.')
|
||||||
|
else:
|
||||||
|
messages.error(request, 'È richiesto un file .zip')
|
||||||
|
|
||||||
|
url = reverse('admin:%s_%s_changelist' % self.get_model_info(),
|
||||||
|
current_app=self.admin_site.name)
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
else:
|
||||||
|
context.update(self.admin_site.each_context(request))
|
||||||
|
|
||||||
|
context['title'] = _("Import")
|
||||||
|
context['form'] = form
|
||||||
|
context['opts'] = self.model._meta
|
||||||
|
|
||||||
|
request.current_app = self.admin_site.name
|
||||||
|
return TemplateResponse(request, [self.import_template_name],
|
||||||
|
context)
|
||||||
|
|
||||||
|
def changelist_view(self, request, extra_context=None):
|
||||||
|
if extra_context is None:
|
||||||
|
extra_context = {}
|
||||||
|
extra_context['has_import_permission'] = self.has_import_permission(request)
|
||||||
|
return super().changelist_view(request, extra_context)
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import os.path
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
from django.contrib.admin.helpers import ActionForm
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class ImportForm(forms.Form):
|
||||||
|
tema = forms.FileField(
|
||||||
|
label='Zip'
|
||||||
|
)
|
||||||
Binary file not shown.
@@ -0,0 +1,139 @@
|
|||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
#
|
||||||
|
# Christian Galeffi <chri@gallochri.com>, 2015.
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2020-06-04 09:27+0200\n"
|
||||||
|
"PO-Revision-Date: 2015-08-30 20:32+0100\n"
|
||||||
|
"Last-Translator: Christian Galeffi <chri@gallochri.com>\n"
|
||||||
|
"Language-Team: Italian <kde-i18n-it@kde.org>\n"
|
||||||
|
"Language: it\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Generator: Poedit 1.5.4\n"
|
||||||
|
|
||||||
|
#: admin.py:194
|
||||||
|
#, python-format
|
||||||
|
msgid "%s through import_export"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: admin.py:200
|
||||||
|
msgid "Import finished, with {} new and {} updated {}."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: admin.py:298
|
||||||
|
#, python-format
|
||||||
|
msgid "<h1>Imported file has a wrong encoding: %s</h1>"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: admin.py:300
|
||||||
|
#, python-format
|
||||||
|
msgid "<h1>%s encountered while trying to read file: %s</h1>"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: admin.py:331 templates/admin/import_export/change_list_import_item.html:5
|
||||||
|
#: templates/admin/import_export/import.html:10
|
||||||
|
msgid "Import"
|
||||||
|
msgstr "Importare"
|
||||||
|
|
||||||
|
#: admin.py:496 templates/admin/import_export/change_list_export_item.html:5
|
||||||
|
#: templates/admin/import_export/export.html:7
|
||||||
|
msgid "Export"
|
||||||
|
msgstr "Esportare"
|
||||||
|
|
||||||
|
#: admin.py:554
|
||||||
|
msgid "You must select an export format."
|
||||||
|
msgstr "Devi selezionare un formato di esportazione."
|
||||||
|
|
||||||
|
#: admin.py:567
|
||||||
|
#, python-format
|
||||||
|
msgid "Export selected %(verbose_name_plural)s"
|
||||||
|
msgstr "Esporta selezionati %(verbose_name_plural)s"
|
||||||
|
|
||||||
|
#: forms.py:10
|
||||||
|
msgid "File to import"
|
||||||
|
msgstr "File da importare"
|
||||||
|
|
||||||
|
#: forms.py:13 forms.py:41 forms.py:66
|
||||||
|
msgid "Format"
|
||||||
|
msgstr "Formato"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/base.html:11
|
||||||
|
msgid "Home"
|
||||||
|
msgstr "Home"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/export.html:31
|
||||||
|
#: templates/admin/import_export/import.html:52
|
||||||
|
msgid "Submit"
|
||||||
|
msgstr "Inviare"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:20
|
||||||
|
msgid ""
|
||||||
|
"Below is a preview of data to be imported. If you are satisfied with the "
|
||||||
|
"results, click 'Confirm import'"
|
||||||
|
msgstr ""
|
||||||
|
"Questa è un'anteprima dei dati che saranno importati. Se il risultato è "
|
||||||
|
"soddisfacente, premi 'Conferma importazione'"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:23
|
||||||
|
msgid "Confirm import"
|
||||||
|
msgstr "Conferma importazione"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:31
|
||||||
|
msgid "This importer will import the following fields: "
|
||||||
|
msgstr "Verranno importati i seguenti campi:"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:61
|
||||||
|
#: templates/admin/import_export/import.html:90
|
||||||
|
msgid "Errors"
|
||||||
|
msgstr "Errori"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:72
|
||||||
|
msgid "Line number"
|
||||||
|
msgstr "Numero linea"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:82
|
||||||
|
msgid "Some rows failed to validate"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:84
|
||||||
|
msgid ""
|
||||||
|
"Please correct these errors in your data where possible, then reupload it "
|
||||||
|
"using the form above."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:89
|
||||||
|
msgid "Row"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:116
|
||||||
|
msgid "Non field specific"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:137
|
||||||
|
msgid "Preview"
|
||||||
|
msgstr "Anteprima"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:152
|
||||||
|
msgid "New"
|
||||||
|
msgstr "Nuovo"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:154
|
||||||
|
msgid "Skipped"
|
||||||
|
msgstr "Salta"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:156
|
||||||
|
msgid "Delete"
|
||||||
|
msgstr "Cancella"
|
||||||
|
|
||||||
|
#: templates/admin/import_export/import.html:158
|
||||||
|
msgid "Update"
|
||||||
|
msgstr "Aggiorna"
|
||||||
|
|
||||||
|
#~ msgid "Import finished"
|
||||||
|
#~ msgstr "Importazione terminata"
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
.import-preview .errors {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-count {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #e40000;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: white;
|
||||||
|
font-size: 0.9em;
|
||||||
|
position: relative;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-top: -2px;
|
||||||
|
padding: 0.2em 0.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-container {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
background-color: #ffc1c1;
|
||||||
|
padding: 14px 15px 10px;
|
||||||
|
top: 25px;
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
width: 200px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.import-preview tr.skip {
|
||||||
|
background-color: #d2d2d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.import-preview tr.new {
|
||||||
|
background-color: #bdd8b2;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.import-preview tr.delete {
|
||||||
|
background-color: #f9bebf;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.import-preview tr.update {
|
||||||
|
background-color: #fdfdcf;
|
||||||
|
}
|
||||||
|
|
||||||
|
.import-preview td:hover .validation-error-count {
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
.import-preview td:hover .validation-error-container {
|
||||||
|
opacity: 1;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-list {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-list li {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-list > li > ul {
|
||||||
|
margin: 8px 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-list > li > ul > li {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 10px;
|
||||||
|
line-height: 1.28em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-error-field-label {
|
||||||
|
display: block;
|
||||||
|
border-bottom: 1px solid #e40000;
|
||||||
|
color: #e40000;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{% extends "admin/base_site.html" %}
|
||||||
|
{% load i18n admin_modify %}
|
||||||
|
{% load admin_urls %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %}
|
||||||
|
{% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
|
||||||
|
{% if not is_popup %}
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
<div class="breadcrumbs">
|
||||||
|
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
|
||||||
|
› <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
|
||||||
|
› <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
|
||||||
|
› {% block breadcrumbs_last %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% endif %}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
|
||||||
|
{# Original template renders object-tools only when has_add_permission is True. #}
|
||||||
|
{# This hack allows sub templates to add to object-tools #}
|
||||||
|
{% block object-tools %}
|
||||||
|
<ul class="object-tools">
|
||||||
|
{% block object-tools-items %}
|
||||||
|
{% if has_add_permission %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{% extends "admin/import_export/change_list.html" %}
|
||||||
|
|
||||||
|
{% block object-tools-items %}
|
||||||
|
{% include "admin/import_export/change_list_import_item.html" %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
{% extends "admin/import_export/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load admin_urls %}
|
||||||
|
{% load import_export_tags %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "import_export/import.css" %}" />{% endblock %}
|
||||||
|
|
||||||
|
{% block breadcrumbs_last %}
|
||||||
|
{% trans "Import" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% if confirm_form %}
|
||||||
|
<form action="{% url opts|admin_urlname:"process_import" %}" method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ confirm_form.as_p }}
|
||||||
|
<p>
|
||||||
|
{% trans "Below is a preview of data to be imported. If you are satisfied with the results, click 'Confirm import'" %}
|
||||||
|
</p>
|
||||||
|
<div class="submit-row">
|
||||||
|
<input type="submit" class="default" name="confirm" value="{% trans "Confirm import" %}">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{% trans "This importer will import the following fields: " %}
|
||||||
|
<code>{{ fields|join:", " }}</code>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<fieldset class="module aligned">
|
||||||
|
{% for field in form %}
|
||||||
|
<div class="form-row">
|
||||||
|
{{ field.errors }}
|
||||||
|
|
||||||
|
{{ field.label_tag }}
|
||||||
|
|
||||||
|
{{ field }}
|
||||||
|
|
||||||
|
{% if field.field.help_text %}
|
||||||
|
<p class="help">{{ field.field.help_text|safe }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="submit-row">
|
||||||
|
<input type="submit" class="default" value="{% trans "Submit" %}">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if result %}
|
||||||
|
|
||||||
|
{% if result.has_errors %}
|
||||||
|
|
||||||
|
<h2>{% trans "Errors" %}</h2>
|
||||||
|
<ul>
|
||||||
|
{% for error in result.base_errors %}
|
||||||
|
<li>
|
||||||
|
{{ error.error }}
|
||||||
|
<div class="traceback">{{ error.traceback|linebreaks }}</div>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% for line, errors in result.row_errors %}
|
||||||
|
{% for error in errors %}
|
||||||
|
<li>
|
||||||
|
{% trans "Line number" %}: {{ line }} - {{ error.error }}
|
||||||
|
<div><code>{{ error.row.values|join:", " }}</code></div>
|
||||||
|
<div class="traceback">{{ error.traceback|linebreaks }}</div>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% elif result.has_validation_errors %}
|
||||||
|
|
||||||
|
<h2>{% trans "Some rows failed to validate" %}</h2>
|
||||||
|
|
||||||
|
<p>{% trans "Please correct these errors in your data where possible, then reupload it using the form above." %}</p>
|
||||||
|
|
||||||
|
<table class="import-preview">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Row" %}</th>
|
||||||
|
<th>{% trans "Errors" %}</th>
|
||||||
|
{% for field in result.diff_headers %}
|
||||||
|
<th>{{ field }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for row in result.invalid_rows %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ row.number }} </td>
|
||||||
|
<td class="errors">
|
||||||
|
<span class="validation-error-count">{{ row.error_count }}</span>
|
||||||
|
<div class="validation-error-container">
|
||||||
|
<ul class="validation-error-list">
|
||||||
|
{% for field_name, error_list in row.field_specific_errors.items %}
|
||||||
|
<li>
|
||||||
|
<span class="validation-error-field-label">{{ field_name }}</span>
|
||||||
|
<ul>
|
||||||
|
{% for error in error_list %}
|
||||||
|
<li>{{ error }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% if row.non_field_specific_errors %}
|
||||||
|
<li>
|
||||||
|
<span class="validation-error-field-label">{% trans "Non field specific" %}</span>
|
||||||
|
<ul>
|
||||||
|
{% for error in row.non_field_specific_errors %}
|
||||||
|
<li>{{ error }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
{% for field in row.values %}
|
||||||
|
<td>{{ field }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
<h2>{% trans "Preview" %}</h2>
|
||||||
|
|
||||||
|
<table class="import-preview">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
{% for field in result.diff_headers %}
|
||||||
|
<th>{{ field }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for row in result.valid_rows %}
|
||||||
|
<tr class="{{ row.import_type }}">
|
||||||
|
<td class="import-type">
|
||||||
|
{% if row.import_type == 'new' %}
|
||||||
|
{% trans "New" %}
|
||||||
|
{% elif row.import_type == 'skip' %}
|
||||||
|
{% trans "Skipped" %}
|
||||||
|
{% elif row.import_type == 'delete' %}
|
||||||
|
{% trans "Delete" %}
|
||||||
|
{% elif row.import_type == 'update' %}
|
||||||
|
{% trans "Update" %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
{% for field in row.diff %}
|
||||||
|
<td>{{ field }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -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),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
# Generated by Django 4.0.3 on 2022-10-25 13:59
|
# Generated by Django 4.0.3 on 2022-10-25 13:59
|
||||||
|
|
||||||
from django.db import migrations
|
from django.conf import settings
|
||||||
from django.db import transaction, connection
|
import django.db.models.deletion
|
||||||
|
from django.db import connection, migrations, models, transaction
|
||||||
|
|
||||||
|
|
||||||
def forward(apps, schema_editor):
|
def forward(apps, schema_editor):
|
||||||
Theme = apps.get_model("admin_interface", "Theme")
|
Theme = apps.get_model("admin_interface", "Theme")
|
||||||
|
|||||||
@@ -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
|
@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,3 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__version__ = "0.19.4"
|
__version__ = "0.19.8"
|
||||||
|
|||||||
Reference in New Issue
Block a user