Skip to content

Commit

Permalink
Merge pull request #88 from trepmag/develop
Browse files Browse the repository at this point in the history
Add AdminSite.each_context() variables to templates context + "normalize" action display name across interface
  • Loading branch information
saxix committed Feb 28, 2016
2 parents deda833 + 770558d commit 504caf3
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 20 deletions.
12 changes: 10 additions & 2 deletions src/adminactions/byrows_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,24 @@ def __init__(self, *args, **kwargs):
ctx = {
'adminform': adminform,
'actionform': actionform,
'title': u"By rows update %s" % smart_text(modeladmin.opts.verbose_name_plural),
'action_short_description': byrows_update.short_description,
'title': u"%s (%s)" % (
byrows_update.short_description.capitalize(),
smart_text(modeladmin.opts.verbose_name_plural),
),
'formset': formset,
'opts': modeladmin.model._meta,
'app_label': modeladmin.model._meta.app_label,
}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())

return render_to_response(tpl, RequestContext(request, ctx))


byrows_update.short_description = "By rows update"
byrows_update.short_description = _("By rows update")


def byrows_update_get_fields(modeladmin):
Expand Down
40 changes: 35 additions & 5 deletions src/adminactions/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import chain
from six.moves import zip

import django
from django import forms
from django.conf import settings
from django.contrib import messages
Expand Down Expand Up @@ -36,7 +37,7 @@ def get_action(request):
return request.POST.getlist('action')[action_index]


def base_export(modeladmin, request, queryset, title, impl, name, template, form_class, ):
def base_export(modeladmin, request, queryset, title, impl, name, action_short_description, template, form_class, ):
"""
export a queryset to csv file
"""
Expand Down Expand Up @@ -109,6 +110,7 @@ def base_export(modeladmin, request, queryset, title, impl, name, template, form
# tpl = 'adminactions/export_csv.html'
ctx = {'adminform': adminForm,
'change': True,
'action_short_description': action_short_description,
'title': title,
'is_popup': False,
'save_as': False,
Expand All @@ -119,14 +121,22 @@ def base_export(modeladmin, request, queryset, title, impl, name, template, form
'opts': queryset.model._meta,
'app_label': queryset.model._meta.app_label,
'media': mark_safe(media)}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())
return render_to_response(template, RequestContext(request, ctx))


def export_as_csv(modeladmin, request, queryset):
return base_export(modeladmin, request, queryset,
impl=_export_as_csv,
name='export_as_csv',
title=_('Export as CSV'),
action_short_description=export_as_csv.short_description,
title=u"%s (%s)" % (
export_as_csv.short_description.capitalize(),
modeladmin.opts.verbose_name_plural,
),
template='adminactions/export_csv.html',
form_class=CSVOptions)

Expand All @@ -138,7 +148,11 @@ def export_as_xls(modeladmin, request, queryset):
return base_export(modeladmin, request, queryset,
impl=_export_as_xls,
name='export_as_xls',
title=_('Export as XLS'),
action_short_description=export_as_xls.short_description,
title=u"%s (%s)" % (
export_as_xls.short_description.capitalize(),
modeladmin.opts.verbose_name_plural,
),
template='adminactions/export_xls.html',
form_class=XLSOptions)

Expand Down Expand Up @@ -287,7 +301,11 @@ def export_as_fixture(modeladmin, request, queryset):
tpl = 'adminactions/export_fixture.html'
ctx = {'adminform': adminForm,
'change': True,
'title': _('Export as Fixture'),
'action_short_description': export_as_fixture.short_description,
'title': "%s (%s)" % (
export_as_fixture.short_description.capitalize(),
modeladmin.opts.verbose_name_plural,
),
'is_popup': False,
'save_as': False,
'has_delete_permission': False,
Expand All @@ -297,6 +315,10 @@ def export_as_fixture(modeladmin, request, queryset):
'opts': queryset.model._meta,
'app_label': queryset.model._meta.app_label,
'media': mark_safe(media)}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())
return render_to_response(tpl, RequestContext(request, ctx))


Expand Down Expand Up @@ -374,7 +396,11 @@ def export_delete_tree(modeladmin, request, queryset):
tpl = 'adminactions/export_fixture.html'
ctx = {'adminform': adminForm,
'change': True,
'title': _('Export Delete Tree'),
'action_short_description': export_delete_tree.short_description,
'title': u"%s (%s)" % (
export_delete_tree.short_description.capitalize(),
modeladmin.opts.verbose_name_plural,
),
'is_popup': False,
'save_as': False,
'has_delete_permission': False,
Expand All @@ -384,6 +410,10 @@ def export_delete_tree(modeladmin, request, queryset):
'opts': queryset.model._meta,
'app_label': queryset.model._meta.app_label,
'media': mark_safe(media)}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())
return render_to_response(tpl, RequestContext(request, ctx))


Expand Down
13 changes: 11 additions & 2 deletions src/adminactions/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json

import django
from django.views.decorators.csrf import csrf_exempt
from six.moves import zip

Expand Down Expand Up @@ -147,13 +148,21 @@ def graph_queryset(modeladmin, request, queryset): # noqa
ctx = {'adminform': adminForm,
'action': 'graph_queryset',
'opts': modeladmin.model._meta,
'title': u"Graph %s" % smart_text(modeladmin.opts.verbose_name_plural),
'action_short_description': graph_queryset.short_description,
'title': u"%s (%s)" % (
graph_queryset.short_description.capitalize(),
smart_text(modeladmin.opts.verbose_name_plural),
),
'app_label': queryset.model._meta.app_label,
'media': media,
'extra': extra,
'as_json': json.dumps(table),
'graph_type': graph_type}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())
return render_to_response('adminactions/charts.html', RequestContext(request, ctx))


graph_queryset.short_description = "Graph selected records"
graph_queryset.short_description = _("Graph selected records")
13 changes: 11 additions & 2 deletions src/adminactions/mass_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# else:
from collections import OrderedDict as SortedDict, defaultdict

import django
from django import forms
from django.contrib import messages
from django.contrib.admin import helpers
Expand Down Expand Up @@ -345,7 +346,11 @@ def _doit():
tpl = 'adminactions/mass_update.html'
ctx = {'adminform': adminForm,
'form': form,
'title': u"Mass update %s" % smart_text(modeladmin.opts.verbose_name_plural),
'action_short_description': mass_update.short_description,
'title': u"%s (%s)" % (
mass_update.short_description.capitalize(),
smart_text(modeladmin.opts.verbose_name_plural),
),
'grouped': grouped,
'fieldvalues': json.dumps(grouped, default=dthandler),
'change': True,
Expand All @@ -361,8 +366,12 @@ def _doit():
# 'select_across': request.POST.get('select_across')=='1',
'media': mark_safe(media),
'selection': queryset}
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())

return render_to_response(tpl, RequestContext(request, ctx))


mass_update.short_description = "Mass update"
mass_update.short_description = _("Mass update")
11 changes: 10 additions & 1 deletion src/adminactions/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from datetime import datetime

import django
from django import forms
from django.contrib import messages
from django.contrib.admin import helpers
Expand Down Expand Up @@ -179,9 +180,17 @@ def raw_widget(field, **kwargs):
ctx.update({'adminform': adminForm,
'formset': formset,
'media': mark_safe(media),
'title': u"Merge %s" % smart_text(modeladmin.opts.verbose_name_plural),
'action_short_description': merge.short_description,
'title': u"%s (%s)" % (
merge.short_description.capitalize(),
smart_text(modeladmin.opts.verbose_name_plural),
),
'master': master,
'other': other})
if django.VERSION[:2] > (1, 7):
ctx.update(modeladmin.admin_site.each_context(request))
else:
ctx.update(modeladmin.admin_site.each_context())
return render_to_response(tpl, RequestContext(request, ctx))


Expand Down
4 changes: 2 additions & 2 deletions src/adminactions/templates/adminactions/byrows_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href=".">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
By row update
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}

Expand All @@ -41,7 +41,7 @@
<thead>
<tr>
{% for field in form.visible_fields %}
<th>{{ field.label|capfirst }}</th>
<th><label class="{% if field.field.required %}required{% endif %}">{{ field.label|capfirst }}</label></th>
{% endfor %}
</tr>
</thead>
Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/templates/adminactions/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href=".">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
Graph
{{ action_short_description|capfirst }}
</div>
{% endif %}
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/templates/adminactions/export_csv.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<a href="{% url 'admin:index' %}{{ app_label}}">{{ app_label|capfirst }}</a> &rsaquo;
{% if has_change_permission %}<a
href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% trans "CSV Export Options" %}
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href=".">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
Fixture Export Options
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/templates/adminactions/export_xls.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a href="{% url 'admin:index' %}{{ app_label}}">{{ app_label|capfirst }}</a> &rsaquo;
{% if has_change_permission %}<a
href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% trans "XLS Export Options" %}
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/templates/adminactions/mass_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href=".">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
Mass Update
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/templates/adminactions/merge.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href=".">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% trans "Merge records" %}
{{ action_short_description|capfirst }}
</div>
{% endif %}{% endblock %}
{% block content %}
Expand Down

0 comments on commit 504caf3

Please sign in to comment.