-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/1.1: (62 commits) bump 1.1 fixes #79 update readme add french translation Display required columns in byrows_update formset. Normalize action display name across interface. Fix AdminSite.each_context() calls for django < 1.8. Add AdminSite.each_context() to templates context. Compilemessages failed for Spanish translations change packaging to properly use installed code in tox update README fixes tests update tests update tests tests refactoring byrows_update action: adapt test_permissions to take into byrows update action. byrows_update action: adapt code to be django >= 1.4 comptatible. byrows_update action: add some tests. byrows_update action: add permission access. byrows_update action: provide option to include or exclude fields to appear in the byrows_update form: ...
- Loading branch information
Showing
62 changed files
with
996 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[bumpversion] | ||
current_version = 1.0.0 | ||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+) | ||
serialize = {major}.{minor}.{patch} | ||
commit = False | ||
tag = False | ||
|
||
[bumpversion:part:release] | ||
optional_value = final | ||
values = | ||
dev | ||
rc | ||
final | ||
|
||
|
||
;[bumpversion:file:src/admoinactions/version.py] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
charset = utf-8 | ||
|
||
# Use 2 spaces for the HTML files | ||
[*.html] | ||
indent_size = 2 | ||
|
||
# The JSON files contain newlines inconsistently | ||
[*.json] | ||
indent_size = 2 | ||
insert_final_newline = ignore | ||
|
||
[**/admin/js/vendor/**] | ||
indent_style = ignore | ||
indent_size = ignore | ||
|
||
# Minified JavaScript files shouldn't be changed | ||
[**.min.js] | ||
indent_style = ignore | ||
insert_final_newline = ignore | ||
|
||
# Makefiles always use tabs for indentation | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Batch files use tabs for indentation | ||
[*.bat] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import django | ||
from django.contrib import messages | ||
from django.contrib.admin import helpers | ||
from django.forms.models import modelform_factory | ||
from django.http import HttpResponseRedirect | ||
from django.shortcuts import render_to_response | ||
from django.template.context import RequestContext | ||
from django.utils.encoding import smart_text | ||
from django.utils.translation import ugettext as _ | ||
|
||
from adminactions.forms import GenericActionForm | ||
from adminactions.models import get_permission_codename | ||
|
||
if django.VERSION[:2] == (1, 7): | ||
from django.forms import modelformset_factory | ||
else: | ||
from django.forms.models import modelformset_factory | ||
|
||
|
||
def byrows_update(modeladmin, request, queryset): # noqa | ||
""" | ||
by rows update queryset | ||
:type modeladmin: ModelAdmin | ||
:type request: HttpRequest | ||
:type queryset: QuerySet | ||
""" | ||
|
||
opts = modeladmin.model._meta | ||
perm = "{0}.{1}".format(opts.app_label.lower(), get_permission_codename('adminactions_byrowsupdate', opts)) | ||
if not request.user.has_perm(perm): | ||
messages.error(request, _('Sorry you do not have rights to execute this action')) | ||
return | ||
|
||
class modelform(modeladmin.form): | ||
def __init__(self, *args, **kwargs): | ||
super(modeladmin.form, self).__init__(*args, **kwargs) | ||
if self.instance: | ||
readonly_fields = (modeladmin.model._meta.pk.name,) + modeladmin.get_readonly_fields(request) | ||
for fname in readonly_fields: | ||
if fname in self.fields: | ||
self.fields[fname].widget.attrs['readonly'] = 'readonly' | ||
self.fields[fname].widget.attrs['class'] = 'readonly' | ||
|
||
fields = byrows_update_get_fields(modeladmin) | ||
|
||
ActionForm = modelform_factory(modeladmin.model, | ||
form=GenericActionForm, | ||
fields=fields) | ||
|
||
MFormSet = modelformset_factory(modeladmin.model, form=modelform, fields=fields, extra=0) | ||
|
||
if 'apply' in request.POST: | ||
actionform = ActionForm(request.POST) | ||
formset = MFormSet(request.POST) | ||
if formset.is_valid(): | ||
formset.save() | ||
messages.info(request, _("Updated record(s)")) | ||
return HttpResponseRedirect(request.get_full_path()) | ||
else: | ||
action_form_initial = {'_selected_action': request.POST.getlist(helpers.ACTION_CHECKBOX_NAME), | ||
'select_across': request.POST.get('select_across') == '1', | ||
'action': 'byrows_update'} | ||
actionform = ActionForm(initial=action_form_initial, instance=None) | ||
formset = MFormSet(queryset=queryset) | ||
|
||
adminform = helpers.AdminForm( | ||
actionform, | ||
modeladmin.get_fieldsets(request), | ||
{}, | ||
[], | ||
model_admin=modeladmin) | ||
|
||
tpl = 'adminactions/byrows_update.html' | ||
ctx = { | ||
'adminform': adminform, | ||
'actionform': actionform, | ||
'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") | ||
|
||
|
||
def byrows_update_get_fields(modeladmin): | ||
""" | ||
Get fields names to be shown of the model rows formset considering the | ||
admin option: | ||
- adminactions_byrows_update_fields | ||
- adminactions_byrows_update_exclude | ||
""" | ||
out = getattr(modeladmin, 'adminactions_byrows_update_fields', | ||
[f.name for f in modeladmin.model._meta.fields if f.editable]) | ||
if hasattr(modeladmin, 'adminactions_byrows_update_exclude'): | ||
fields = modeladmin.adminactions_byrows_update_exclude | ||
out = [fname for fname in fields if fname not in modeladmin.adminactions_byrows_update_exclude] | ||
return out |
Oops, something went wrong.