Skip to content

Commit 41cc8f9

Browse files
authored
Merge pull request #167 from farridav/bug/last_inline_hidden
Various fixes for inlines
2 parents 6f99079 + ecd3d60 commit 41cc8f9

File tree

6 files changed

+123
-80
lines changed

6 files changed

+123
-80
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
.tox
77
.venv
88
.env
9+
.vscode
10+
/diffs
911
/build
1012
/dist
1113
/.reports

cli.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
import argparse
44
import os
5+
import subprocess
56
from itertools import chain
67

78
import django
89
import polib
910

1011
THIS_DIR = os.path.dirname(__file__)
1112
LOCALE_DIR = os.path.join(THIS_DIR, "jazzmin", "locale")
13+
DJANGO_PATH = django.__path__[0]
1214

1315

14-
def locales(cmd_args):
16+
def locales(cmd_args: argparse.Namespace):
1517
"""
18+
19+
e.g - ./cli.py locales --prune de
20+
1621
1. cd into the jazzmin folder
1722
2. Add the desired language directory e.g mkdir -p locale/de/LC_MESSAGES
1823
3. Run django-admin makemessages
19-
4. Run ./cli.py locales --locale de to remove the django provided strings
24+
4. Run ./cli.py locales --prune de to remove the django provided strings
2025
5. Go through the strings in the locale file, any that are not genuinely new strings introduced by jazzmin, find
2126
them in the codebase, and try making them match the ones provided in either of djangos translation files
2227
@@ -26,11 +31,10 @@ def locales(cmd_args):
2631
Once you have finished, run makemessages again, until the file contains ONLY unique strings to jazzmin, there should
2732
only be a handful
2833
"""
29-
django_path = django.__path__[0]
3034
our_po = polib.pofile(os.path.join(LOCALE_DIR, cmd_args.locale, "LC_MESSAGES", "django.po"))
31-
admin_po = polib.pofile(os.path.join(django_path, "contrib", "admin", "locale", "en", "LC_MESSAGES", "django.po"))
35+
admin_po = polib.pofile(os.path.join(DJANGO_PATH, "contrib", "admin", "locale", "en", "LC_MESSAGES", "django.po"))
3236
admindocs_po = polib.pofile(
33-
os.path.join(django_path, "contrib", "admindocs", "locale", "en", "LC_MESSAGES", "django.po")
37+
os.path.join(DJANGO_PATH, "contrib", "admindocs", "locale", "en", "LC_MESSAGES", "django.po")
3438
)
3539
existing_strings = {x.msgid for x in chain(admin_po, admindocs_po)}
3640
new_po = polib.POFile()
@@ -42,12 +46,46 @@ def locales(cmd_args):
4246
new_po.save(os.path.join(LOCALE_DIR, cmd_args.locale, "LC_MESSAGES", "django.po"))
4347

4448

49+
def templates(cmd_args: argparse.Namespace):
50+
"""
51+
Generate diffs/patch files for all the templates we override, useful for seeing whats changed
52+
53+
./cli.py templates --diff
54+
55+
"""
56+
diffs = os.path.join(THIS_DIR, "diffs")
57+
templates = {
58+
os.path.join(THIS_DIR, "jazzmin", "templates", "admin"): os.path.join(
59+
DJANGO_PATH, "contrib", "admin", "templates", "admin"
60+
),
61+
os.path.join(THIS_DIR, "jazzmin", "templates", "admin_doc"): os.path.join(
62+
DJANGO_PATH, "contrib", "admindocs", "templates", "admin_doc"
63+
),
64+
}
65+
66+
for jazzmin_dir, django_dir in templates.items():
67+
for template in [os.path.join(dp, f) for dp, dn, filenames in os.walk(jazzmin_dir) for f in filenames]:
68+
original = template.replace(jazzmin_dir, django_dir)
69+
if os.path.isfile(original):
70+
result = subprocess.run(
71+
["diff", "-u", "-w", "--suppress-common-lines", original, template], stdout=subprocess.PIPE
72+
)
73+
out_file = template.replace(jazzmin_dir, diffs) + ".patch"
74+
os.makedirs(os.path.dirname(out_file), exist_ok=True)
75+
76+
with open(out_file, "wb+") as fp:
77+
fp.write(result.stdout)
78+
79+
4580
def main():
4681
parser = argparse.ArgumentParser()
4782
subparsers = parser.add_subparsers()
48-
parser_locales = subparsers.add_parser('locales', help='remove the django provided strings')
49-
parser_locales.add_argument("--locale", action="store", dest="locale", help="locale to process", default="de")
83+
parser_locales = subparsers.add_parser("locales", help="remove the django provided strings")
84+
parser_locales.add_argument("--prune", action="store", dest="locale", help="locale to prune", default="de")
5085
parser_locales.set_defaults(func=locales)
86+
parser_templates = subparsers.add_parser("templates", help="Deal with templates")
87+
parser_templates.add_argument("--diff", action="store_true", dest="template_diff", help="generate template diff")
88+
parser_templates.set_defaults(func=templates)
5189
cmd_args = parser.parse_args()
5290
cmd_args.func(cmd_args)
5391

jazzmin/static/jazzmin/css/django.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ div.inline-related {
88
padding: 5px;
99
}
1010

11-
.inlinechangelink {
12-
content: url('../img/icon-changelink.svg');
11+
.table tr.form-row {
12+
display: table-row;
13+
}
14+
15+
.empty-form {
16+
display: none !important;
1317
}
1418

1519
.inline-related .tabular {
@@ -543,10 +547,6 @@ a.active.selector-clearall:focus, a.active.selector-clearall:hover {
543547
height: 0;
544548
}
545549

546-
.empty-form {
547-
display: none;
548-
}
549-
550550
#user_form input[type="password"] {
551551
width: 100%;
552552
}

jazzmin/templates/admin/edit_inline/stacked.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,34 @@
66
{{ inline_admin_formset.formset.non_form_errors }}
77

88
{% for inline_admin_form in inline_admin_formset %}
9-
<div class="panel inline-related{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
9+
<div class="panel inline-related{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form last-related{% endif %}"
10+
id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
1011
<div class="card card-outline {% if not inline_admin_form.original %}new-stacked card-success{% else %}card-secondary{% endif %}">
1112
<div class="card-header">
1213
<h3 class="card-title">
14+
<span class="card-tools text-sm">
1315
{% if inline_admin_form.original %}
1416
{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
15-
<span class="card-tools">
16-
<a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">
17-
{% if inline_admin_formset.has_change_permission %}
18-
<i class="fas fa-pencil-alt fa-sm float-right"></i>
19-
{% else %}
20-
<i class="fas fa-eye fa-sm float-right"></i>
21-
{% endif %}
22-
</a>
23-
</span>
17+
<a
18+
href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}"
19+
class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">
20+
{% if inline_admin_formset.has_change_permission %}
21+
<i class="fas fa-pencil-alt fa-sm"> </i>
22+
{% else %}
23+
<i class="fas fa-eye fa-sm"> </i>
24+
{% endif %}
25+
</a>
2426
{% endif %}
25-
{{ inline_admin_form.original }}
27+
{{ inline_admin_form.original }}
2628
{% else %}
27-
<span class="text-success"><i class="fas fa-plus fa-sm"></i></span> {% trans "Add new " %}{{ inline_admin_formset.opts.verbose_name|capfirst }} - #{{ forloop.counter }}
29+
<i class="fas fa-plus fa-sm text-success"> </i>
30+
{% trans "New" %} {{ inline_admin_formset.opts.verbose_name|capfirst }}
2831
{% endif %}
32+
</span>
2933
{% if inline_admin_form.show_url %}
30-
<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>
34+
<a href="{{ inline_admin_form.absolute_url }}">
35+
<i class="fas fa-eye fa-sm"> </i> {% trans "View on site" %}
36+
</a>
3137
{% endif %}
3238
</h3>
3339
{% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}
Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,65 @@
11
{% load i18n admin_urls static admin_modify %}
2-
<div class="js-inline-admin-formset inline-group" id="{{ inline_admin_formset.formset.prefix }}-group" data-inline-type="tabular" data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
2+
<div class="js-inline-admin-formset inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"
3+
data-inline-type="tabular"
4+
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
35
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
46
{{ inline_admin_formset.formset.management_form }}
57
<fieldset class="module {{ inline_admin_formset.classes }}">
68
{{ inline_admin_formset.formset.non_form_errors }}
79
<table class="table table-hover text-nowrap">
8-
<thead>
9-
<tr>
10-
<th class="original">#</th>
11-
{% for field in inline_admin_formset.fields %}
12-
{% if not field.widget.is_hidden %}
13-
<th class="column-{{ field.name }}{% if field.required %} required{% endif %}">
14-
{{ field.label|capfirst }}
15-
{% if field.help_text %}&nbsp;
16-
<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">
17-
{% endif %}
18-
</th>
19-
{% endif %}
20-
{% endfor %}
21-
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>{% trans "Delete?" %}</th>{% endif %}
22-
</tr>
23-
</thead>
10+
<thead><tr>
11+
<th class="original"></th>
12+
{% for field in inline_admin_formset.fields %}
13+
{% if not field.widget.is_hidden %}
14+
<th class="column-{{ field.name }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}
15+
{% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
16+
</th>
17+
{% endif %}
18+
{% endfor %}
19+
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>{% trans "Delete?" %}</th>{% endif %}
20+
</tr></thead>
2421

2522
<tbody>
2623
{% for inline_admin_form in inline_admin_formset %}
2724
{% if inline_admin_form.form.non_field_errors %}
28-
<tr>
29-
<td colspan="{{ inline_admin_form|cell_count }}">
30-
{{ inline_admin_form.form.non_field_errors }}
31-
</td>
32-
</tr>
25+
<tr class="row-form-errors"><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
3326
{% endif %}
34-
<tr id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}"{% if forloop.last %} class="empty-form"{% endif %}>
27+
<tr class="form-row{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}"
28+
id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
3529
<td class="original">
36-
{% if inline_admin_form.original or inline_admin_form.show_url %}<p>
30+
{% if inline_admin_form.original or inline_admin_form.show_url %}
31+
<p>
3732
{% if inline_admin_form.original %}
38-
{{ inline_admin_form.original }}
3933
{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
40-
<a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">{% if inline_admin_formset.has_change_permission %}{% trans "Change" %}{% else %}{% trans "View" %}{% endif %}</a>
34+
<a
35+
href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}"
36+
class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">
37+
{% if inline_admin_formset.has_change_permission %}
38+
<i class="fas fa-pencil-alt fa-sm"> </i>
39+
{% else %}
40+
<i class="fas fa-eye fa-sm"> </i>
41+
{% endif %}
42+
</a>
43+
{% endif %}
44+
{{ inline_admin_form.original }}
45+
46+
{% if inline_admin_form.show_url %}
47+
<a href="{{ inline_admin_form.absolute_url }}">
48+
<i class="fas fa-eye fa-sm"> </i> {% trans "View on site" %}
49+
</a>
4150
{% endif %}
4251
{% endif %}
43-
{% if inline_admin_form.show_url %}
44-
<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>
45-
{% endif %}
46-
</p>
47-
{% endif %}
48-
{% if inline_admin_form.needs_explicit_pk_field %}
49-
{{ inline_admin_form.pk_field.field }}
50-
{% endif %}
51-
{% if inline_admin_form.fk_field %}
52-
{{ inline_admin_form.fk_field.field }}
52+
</p>
53+
{% else %}
54+
<i class="fas fa-plus fa-sm text-success"> </i>
5355
{% endif %}
56+
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
57+
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
5458
{% spaceless %}
5559
{% for fieldset in inline_admin_form %}
5660
{% for line in fieldset %}
5761
{% for field in line %}
58-
{% if not field.is_readonly and field.field.is_hidden %}
59-
{{ field.field }}
60-
{% endif %}
62+
{% if not field.is_readonly and field.field.is_hidden %}{{ field.field }}{% endif %}
6163
{% endfor %}
6264
{% endfor %}
6365
{% endfor %}
@@ -67,29 +69,25 @@
6769
{% for line in fieldset %}
6870
{% for field in line %}
6971
{% if field.is_readonly or not field.field.is_hidden %}
70-
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
71-
{% if field.is_readonly %}
72-
<p>{{ field.contents }}</p>
73-
{% else %}
74-
{{ field.field.errors.as_ul }}
75-
{{ field.field }}
76-
{% endif %}
72+
<td {% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
73+
{% if field.is_readonly %}
74+
<p>{{ field.contents }}</p>
75+
{% else %}
76+
{{ field.field.errors.as_ul }}
77+
{{ field.field }}
78+
{% endif %}
7779
</td>
7880
{% endif %}
7981
{% endfor %}
8082
{% endfor %}
8183
{% endfor %}
8284
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}
83-
<td class="delete">
84-
{% if inline_admin_form.original %}
85-
{{ inline_admin_form.deletion_field.field }}
86-
{% endif %}
87-
</td>
85+
<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
8886
{% endif %}
8987
</tr>
9088
{% endfor %}
9189
</tbody>
92-
</table>
90+
</table>
9391
</fieldset>
9492
</div>
9593
</div>

tests/test_app/polls/admin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from django.utils.html import format_html
44
from django.utils.timesince import timesince
55

6-
from .models import Poll, Choice, Vote, Campaign, Cheese
6+
from .models import Campaign, Cheese, Choice, Poll, Vote
77

88

99
class ChoiceInline(admin.StackedInline):
1010
model = Choice
11-
show_change_link = True
1211
extra = 1
1312

1413

0 commit comments

Comments
 (0)