Skip to content

Commit

Permalink
feat: Add Django 2.2 Compatability (#96)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: dropped support for Python 2 and Django < 2.2

* Remove unneeded import

* Fix url

* Move jQuery UI out to base admin template (fixes broken inlines)

* Pass correct args to inlines

* Style fix for M2M widget

* Rename admin CSS class "field-box" to "fieldBox".

(This addresses a change made in Django 2.1 to fix
Django bug #29248.)

* Style fixes for selector element

* Update tested python versions

* More fixes for selector CSS

* Use "select[multiple]" in CSS selectors.

(This addresses a change made in Django 2.1 to fix
Django bug #29041.)

* Revert "More fixes for selector CSS"

This reverts commit 1a24ef7

* Fix for selector widgets

* Fix for "Add another", see #98

Co-authored-by: zriv <[email protected]>
  • Loading branch information
Pete Dermott and zriv authored Aug 12, 2020
1 parent 035e210 commit 7755ffd
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
3 changes: 1 addition & 2 deletions grappelli_safe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from __future__ import unicode_literals
VERSION = '2.0'
VERSION = '2.0'
4 changes: 2 additions & 2 deletions grappelli_safe/static/grappelli/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ form .aligned input + label + .help {
td .help {
margin-bottom: 3px; padding: 0;
}
fieldset .field-box {
fieldset .fieldBox {
float: left;
margin-right: 45px;
white-space: nowrap;
Expand Down Expand Up @@ -214,7 +214,7 @@ select {
padding: 4px 3px 4px 0;
height: 25px;
}
select[multiple=multiple] {
select[multiple] {
padding-left: 1px;
height: 160px;
}
Expand Down
2 changes: 1 addition & 1 deletion grappelli_safe/static/grappelli/css/rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ form ul.inline li {
padding-left: 7px;
}

fieldset .field-box {
fieldset .fieldBox {
float: right;
margin-left: 20px;
}
Expand Down
33 changes: 16 additions & 17 deletions grappelli_safe/static/grappelli/css/widgets.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
------------------------------------------------------------------------------------------------------ */

.selector {
align-items: center;
display: flex;
position: relative; float: left; overflow: hidden;
width: 700px;
}

.selector-available, .selector-chosen {
float: left;
width: 338px;
border: 1px solid #ccc;
-moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
background: #ddd;
width: 49%;
}
.stacked .selector-available, .stacked .selector-chosen {
width: 698px;
}

.selector h2, .inline-group .selector h2,
.selector h2, .inline-group .selector h2,
.inline-related fieldset .selector-available h2, .inline-related fieldset .selector-chosen h2 {
padding: 7px 5px 6px 7px;
font-size: 12px; line-height: 13px; font-weight: bold;
border: none;
border-bottom: 1px solid #d0d0d0;
background: transparent;
}

.selector .selector-filter {
padding: 3px 5px 2px 2px;
border-top: 1px solid #e4e4e4;
Expand All @@ -55,26 +52,28 @@
.selector .selector-filter img {
display: none;
}

.selector select[multiple=multiple] {
.selector select {
min-height: 300px;
width: 100%;
}
.selector select[multiple] {
margin: 0; padding-left: 3px;
width: 338px; height: 200px;
width: 100%;
border-top: 1px solid #d0d0d0;
border-bottom: 1px solid #d0d0d0;
border-left: none;
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
}
.selector.stacked select[multiple=multiple] {
.selector.stacked select[multiple] {
width: 698px;
}
.selector-chosen select[multiple=multiple] {
.selector-chosen select[multiple] {
height: 232px;
}
.selector h2 + select {
position: relative; top: -1px;
border-top: none;
}

.selector ul.selector-chooser {
float: left;
margin: 110px 2px 0; padding: 0;
Expand Down Expand Up @@ -158,15 +157,15 @@ input.vDateField + span, input.vTimeField + span {
vertical-align: middle;
color: #ccc; font-size: 11px; line-height: 11px;
}
input.vDateField + span a:first-child,
input.vDateField + span a:first-child,
input.vTimeField + span a:first-child {
position: relative; top: 1px;
}

.form-row label + p.datetime {
margin: 0;
}
.change-list form table input.vDateField + span,
.change-list form table input.vDateField + span,
.change-list form table input.vTimeField + span {
vertical-align: baseline;
}
Expand Down Expand Up @@ -260,7 +259,7 @@ a[id^="clocklink"]:hover, a[id^="clocklink"]:active {
color: #444;
}

.calendar td a:hover, .calendar td a:active,
.calendar td a:hover, .calendar td a:active,
.timelist a:hover, .timelist a:active {
color: #fff;
background: #309bbf;
Expand Down Expand Up @@ -290,7 +289,7 @@ a.calendarnav-next {
-moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px;
background-image: url('../img/icons/icon-calendarnav_next.png');
}
a.calendarnav-previous:hover, a.calendarnav-previous:active,
a.calendarnav-previous:hover, a.calendarnav-previous:active,
a.calendarnav-next:hover, a.calendarnav-next:active {
background-color: #309bbf;
}
Expand Down
1 change: 1 addition & 0 deletions grappelli_safe/static/grappelli/js/admin/Inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jQuery(function($) {
}
if ($(this).attr('href')) {
$(this).attr('href', $(this).attr('href').replace(/-\d+-/g, "-" + parseInt(items - 1) + "-"));
$(this).attr('href', $(this).attr('href').replace(/__prefix__/g, "" + parseInt(items - 1) ));
}
});
/// remove calendars and clocks, re-init
Expand Down
2 changes: 2 additions & 0 deletions grappelli_safe/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<!-- JAVASCRIPTS / EXTRAHEAD -->
{% block javascripts %}
<script type="text/javascript" src="{% static "mezzanine/js/"|add:settings.JQUERY_FILENAME %}"></script>
<script type="text/javascript" src="{% static "mezzanine/js/"|add:settings.JQUERY_UI_FILENAME %}"></script>

<script type="text/javascript">
// Ensures jQuery does not pollute the global namespace
$.noConflict();
Expand Down
15 changes: 14 additions & 1 deletion grappelli_safe/templates/admin/edit_inline/stacked.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ <h3><b>Sortable Helper</b></h3>

(function($) {
var prefix = "{{ inline_admin_formset.formset.prefix|escapejs }}";
$("#{{ inline_admin_formset.formset.prefix|escapejs }}-group .inline-related").stackedFormset({
var selector = "#" + prefix + "-group .inline-related"
$(selector).stackedFormset(selector, {
prefix: prefix,
addText: "{% filter escapejs %}{% blocktrans with inline_admin_formset.opts.verbose_name|capfirst as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}{% endfilter %}",
deleteText: "{% filter escapejs %}{% trans 'Delete Item' %}{% endfilter %}",
Expand All @@ -68,6 +69,18 @@ <h3><b>Sortable Helper</b></h3>
.addClass("deletelink")
.attr("title", $deleteLink.text())
.text("");
// Execute the StackedInlineAdded callback
if ($.isFunction(window.__onStackedInlineAdded)) {
window.__onStackedInlineAdded($row, targetPrefix);
}
}
});
$(document).on("formset:removed", function(event, $row, targetPrefix) {
if (targetPrefix === prefix) {
// Execute the StackedInlineRemoved callback
if ($.isFunction(window.__onStackedInlineRemoved)) {
window.__onStackedInlineRemoved($row, targetPrefix);
}
}
});
})(django.jQuery);
Expand Down
15 changes: 14 additions & 1 deletion grappelli_safe/templates/admin/edit_inline/tabular.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ <h3><b>&nbsp;</b></h3>

(function($) {
var prefix = "{{ inline_admin_formset.formset.prefix|escapejs }}";
$("#{{ inline_admin_formset.formset.prefix|escapejs }}-group .inline-related").stackedFormset({
var selector = "#" + prefix + "-group .inline-related"
$(selector).stackedFormset(selector, {
prefix: prefix,
addText: "{% filter escapejs %}{% blocktrans with inline_admin_formset.opts.verbose_name|capfirst as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}{% endfilter %}",
deleteText: "{% filter escapejs %}{% trans 'Delete Item' %}{% endfilter %}"
Expand All @@ -96,6 +97,18 @@ <h3><b>&nbsp;</b></h3>
.addClass("deletelink")
.attr("title", $deleteLink.text())
.text("");
// Execute the TabularInlineAdded callback
if ($.isFunction(window.__onTabularInlineAdded)) {
window.__onTabularInlineAdded($row, targetPrefix);
}
}
});
$(document).on("formset:removed", function(event, $row, targetPrefix) {
if (targetPrefix === prefix) {
// Execute the StackedInlineRemoved callback
if ($.isFunction(window.__onTabularInlineRemoved)) {
window.__onTabularInlineRemoved($row, targetPrefix);
}
}
});
})(django.jQuery);
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
zip_safe=False,
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.8",
],
)

0 comments on commit 7755ffd

Please sign in to comment.