Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
abidibo committed Feb 21, 2024
2 parents 005d6e9 + 202a166 commit e484adb
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 10 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ Other features:

> In order for this feature to work, the user browser must support html template tags.
Baton lets you include templates directly inside the change form page, in any position you desire. It's as simple as specifying the template path, the field name used as anchor and the position of the template:
Baton lets you include templates directly inside the change form page near a field, in any position you desire. It's as simple as specifying the template path, the field name used as anchor and the position of the template:

```python
@admin.register(News)
Expand Down Expand Up @@ -769,6 +769,17 @@ And, of course, you can access the `{{ original }}` object variable inside your

It works seamlessly with the tab facility, if you include content related to a field inside one tab, then the content will be placed in the same tab.

Baton lets also include templates in the object tools top bar in the change form page, keep in mind that suche templates are injected inside an `ul` tag. The template can be inserted on the left or the right:

```python
@admin.register(News)
class NewsAdmin(admin.ModelAdmin):
#...
baton_form_object_tools_include = ('news/object_tools_include.html', 'left', )
```

![Baton form object tools includes](docs/images/baton_form_object_tools_include.png)

## <a name="collapsable-stackedinline"></a>Collapsable stacked inlines entries

![Screenshot](docs/images/collapsable_stackedinline.png)
Expand Down
2 changes: 1 addition & 1 deletion baton/static/baton/app/dist/baton.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions baton/static/baton/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion baton/static/baton/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baton",
"version": "3.0.2",
"version": "3.1.0",
"description": "Django Baton App",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion baton/static/baton/app/src/core/ChangeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const ChangeForm = {
bottom: 'append',
right: 'after',
}
$('template').each(function(_, template) {
$('template:not(#template-object-tools)').each(function(_, template) {
const field = $(template).attr('id').replace('template-', '')
const position = positionMap[$(template).attr('data-position')]
if (position !== undefined) {
Expand All @@ -200,6 +200,12 @@ const ChangeForm = {
console.error('Baton: wrong form include position detected')
}
})

$('template#template-object-tools').each(function(_, template) {
const position = $(template).attr('data-position') === 'right' ? 'append' : 'prepend'
const el = $('ul.object-tools')
el[position]($(template).html())
})
},
fixSubmitRow: function() {
$('#content-main form').addClass('baton-fixed-submit-row')
Expand Down
7 changes: 7 additions & 0 deletions baton/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
</div>
</template>
{% endfor %}

{% if adminform.model_admin.baton_form_object_tools_include %}
<template id="template-object-tools" data-position="{{ adminform.model_admin.baton_form_object_tools_include.1 }}">
{% include adminform.model_admin.baton_form_object_tools_include.0 %}
</template>
{% endif %}

{% endblock %}
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
# built documents.
#
# The short X.Y version.
version = u'3.0.2'
release = u'3.0.2'
version = u'3.1.0'
release = u'3.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 10 additions & 0 deletions docs/form_includes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ You can specify the following positions:
And, of course, you can access the `{{ original }}` object variable inside your template.

It works seamlessly with the tab facility, if you include content related to a field inside one tab, then the content will be placed in the same tab.

Baton lets also include templates in the object tools top bar in the change form page, keep in mind that suche templates are injected inside an ``ul`` tag. The template can be inserted on the left or the right::

@admin.register(News)
class NewsAdmin(admin.ModelAdmin):
#...
baton_form_object_tools_include = ('news/object_tools_include.html', 'left', )


.. image:: images/baton_form_object_tools_include.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='django-baton',
version='3.0.2',
version='3.1.0',
packages=['baton', 'baton.autodiscover', 'baton.templatetags'],
include_package_data=True,
license='MIT License',
Expand Down
Binary file modified testapp/app/db.sqlite3
Binary file not shown.
4 changes: 3 additions & 1 deletion testapp/app/news/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class NewsAdmin(ImportExportModelAdmin):
('news/admin_title_include.html', 'title', 'right', ),
]

baton_form_object_tools_include = ('news/object_tools_include.html', 'left', )

baton_cl_includes = [
('news/admin_cl_top_include.html', 'top', ),
]
Expand All @@ -154,7 +156,7 @@ def baton_cl_rows_attributes(self, request, cl):
'class': 'table-info',
# 'selector': '#result_list tr input[name=_selected_action][value=%d]' % news.id,
}
data[news.id] = {
data[1] = {
'class': 'table-success',
'selector': '.span-category-id-%d' % 1,
'getParent': 'td',
Expand Down
3 changes: 3 additions & 0 deletions testapp/app/news/templates/news/object_tools_include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li>
<a href="#" class="btn btn-primary btn-sm">Custom action</a>
</li>

0 comments on commit e484adb

Please sign in to comment.