From 4b281bd8218bf555c45b520e834da23774c2adec Mon Sep 17 00:00:00 2001 From: panjing <599194993@qq.com> Date: Mon, 30 Nov 2020 11:55:46 +0800 Subject: [PATCH 1/6] fix #314 bug --- simpleui/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleui/__init__.py b/simpleui/__init__.py index f33fea0b..e9f7c26c 100644 --- a/simpleui/__init__.py +++ b/simpleui/__init__.py @@ -2,4 +2,4 @@ def get_version(): - return '2020.9.26' + return '2020.12.01' From 8a02da4b9ddffb8cf0668bc8d047020fc5427e86 Mon Sep 17 00:00:00 2001 From: panjing <599194993@qq.com> Date: Mon, 30 Nov 2020 13:28:57 +0800 Subject: [PATCH 2/6] Optimize UI controls --- simpleui/templates/admin/actions.html | 22 +++++++++---------- .../templates/admin/includes/js-part.html | 4 +++- simpleui/templates/admin/search_form.html | 9 ++++---- simpleui/templates/admin/submit_line.html | 12 +++++----- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/simpleui/templates/admin/actions.html b/simpleui/templates/admin/actions.html index 71be2c1b..dc7635eb 100644 --- a/simpleui/templates/admin/actions.html +++ b/simpleui/templates/admin/actions.html @@ -7,7 +7,7 @@ {% if has_add_permission %} {% url cl.opts|admin_urlname:'add' as add_url %} - + {% trans 'Add' %} {% endif %} @@ -16,13 +16,13 @@ {% if field.0 %} {% if field.0 == 'delete_selected' %} - {% trans 'Delete' %} {% else %} {% if field.0 == 'export_admin_action' %} - + - {{ field.1 }} + {{ field.1 }} {% else %} - {{ field.1 }} @@ -44,11 +44,11 @@ {% if cl.formset and cl.result_count %} - {% trans 'Save' %} {% endif %} - + @@ -69,14 +69,14 @@ {% endif %} {% endblock %} - + {% if cl.search_fields or cl.has_filters %} - {% endif %} - - diff --git a/simpleui/templates/admin/includes/js-part.html b/simpleui/templates/admin/includes/js-part.html index efcf8211..7561bf5b 100644 --- a/simpleui/templates/admin/includes/js-part.html +++ b/simpleui/templates/admin/includes/js-part.html @@ -1,6 +1,8 @@ {% load static simpletags %} {% if "SIMPLEUI_STATIC_OFFLINE"|get_config %} - + + +{# #} {% else %} diff --git a/simpleui/templates/admin/search_form.html b/simpleui/templates/admin/search_form.html index 69cd4875..6b7f4f9e 100644 --- a/simpleui/templates/admin/search_form.html +++ b/simpleui/templates/admin/search_form.html @@ -21,7 +21,7 @@ {% if cl.search_fields %} - - + {% for option in spec.lookup_choices %} {% endfor %} @@ -59,7 +60,7 @@ {% else %} - {% if spec|get_date_type == 'time' %} {% for option in spec.lookup_choices %} @@ -91,7 +92,7 @@ {% endfor %} {% endif %} - {% trans 'Search' %} + {% trans 'Search' %} {% if show_result_count %} diff --git a/simpleui/templates/admin/submit_line.html b/simpleui/templates/admin/submit_line.html index f24469ae..10bd19c0 100644 --- a/simpleui/templates/admin/submit_line.html +++ b/simpleui/templates/admin/submit_line.html @@ -1,31 +1,31 @@ {% load i18n admin_urls simpletags%}
{% if '_popup' not in request.GET %} - {% endif %} {% if show_delete_link %} {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %} - {% trans "Delete" %} {% endif %} {% if show_save_as_new %} - {% trans 'Save as new' %} {% endif %} {% if show_save_and_add_another %} - {% endif %} {% if show_save_and_continue %} - {% endif %} {% if show_save %} - + {% endif %}
From 443a3201e40088bbb7735a32948542ba4ecc200a Mon Sep 17 00:00:00 2001 From: panjing <599194993@qq.com> Date: Mon, 30 Nov 2020 17:02:16 +0800 Subject: [PATCH 3/6] Add custom pop-up dialog box --- simpleui/__init__.py | 2 +- simpleui/admin.py | 27 ++++ simpleui/templates/admin/actions.html | 201 +++++++++++++++++++++++++- simpleui/templatetags/simpletags.py | 12 +- 4 files changed, 233 insertions(+), 9 deletions(-) create mode 100644 simpleui/admin.py diff --git a/simpleui/__init__.py b/simpleui/__init__.py index e9f7c26c..ff11571d 100644 --- a/simpleui/__init__.py +++ b/simpleui/__init__.py @@ -2,4 +2,4 @@ def get_version(): - return '2020.12.01' + return '2021.1.0' diff --git a/simpleui/admin.py b/simpleui/admin.py new file mode 100644 index 00000000..c9787264 --- /dev/null +++ b/simpleui/admin.py @@ -0,0 +1,27 @@ +from django.contrib import admin +from django.urls import path + + +class AjaxAdmin(admin.ModelAdmin): + + def callback(self, request): + post = request.POST + action = post.get('_action') + selected = post.get('_selected') + + # call admin + if hasattr(self, action): + func, action, description = self.get_action(action) + # 这里的queryset 会有数据过滤,只包含选中的数据 + queryset = self.get_queryset(request) + if selected and selected.split(','): + queryset = queryset.filter(pk__in=selected.split(',')) + + return func(self, request, queryset) + + def get_urls(self): + info = self.model._meta.app_label, self.model._meta.model_name + + return super().get_urls() + [ + path('ajax', self.callback, name='%s_%s_ajax' % info) + ] diff --git a/simpleui/templates/admin/actions.html b/simpleui/templates/admin/actions.html index dc7635eb..7652dc34 100644 --- a/simpleui/templates/admin/actions.html +++ b/simpleui/templates/admin/actions.html @@ -7,7 +7,8 @@ {% if has_add_permission %} {% url cl.opts|admin_urlname:'add' as add_url %} - + {% trans 'Add' %} {% endif %} @@ -32,7 +33,13 @@
{{ field.1 }} {% else %} - {{ field.1 }} + + {{ field.1 }} @@ -60,7 +67,8 @@ {{ selection_note_all }} {% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %} + title="{% trans "Click here to select the objects across all pages" %}">{% blocktrans with cl.result_count as total_count %} + Select all {{ total_count }} {{ module_name }}{% endblocktrans %} {% trans "Clear selection" %} @@ -82,9 +90,177 @@
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+