Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
* 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
saxix committed Apr 22, 2016
2 parents ffca9c4 + cc27a01 commit b4cb43e
Show file tree
Hide file tree
Showing 62 changed files with 996 additions and 475 deletions.
17 changes: 17 additions & 0 deletions .bumpversion.cfg
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]

37 changes: 37 additions & 0 deletions .editorconfig
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
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
language: python
sudo: false
python:
- 3.5

cache:
directories:
- $HOME/.cache/pip

env:
- TOXENV=py27-d14
- TOXENV=py27-d15
- TOXENV=py27-d16
- TOXENV=py27-d17
- TOXENV=py27-d18
- TOXENV=py27-d19

- TOXENV=py33-d17
- TOXENV=py33-d18

- TOXENV=py34-d17
- TOXENV=py34-d18
- TOXENV=py34-d19

- TOXENV=py35-d18
- TOXENV=py35-d19

- TOXENV=pypy-d17
- TOXENV=pypy-d18
- TOXENV=pypy-d19



install:
- pip install tox "coverage<4.0" python-coveralls>=2.5 coveralls>=0.5 codecov

script:
- tox -e $TOXENV -- tests -vv --capture=no --cov=adminactions --cov-report=xml --cov-config=tests/.coveragerc
- tox -e $TOXENV -- py.test tests -vv --capture=no --cov=adminactions --cov-report=xml --cov-config=tests/.coveragerc

before_success:
- coverage erase
Expand Down
16 changes: 13 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Release 1.0 (dev)
=================
Release 1.1
===========
* merge :ghissue:`91` - add french translation
* merge :ghissue:`88` - Display required columns in byrows_update formset
* merge :ghissue:`87` - Add AdminSite.each_context() to templates context.
* merge :ghissue:`86` - Compilemessages failed for Spanish translation
* merge :ghissue:`83` - byrows_update action: adapt test_permissions to take into byrows update action.
* merge :ghissue:`79` - Permissions don't work



Release 1.0
===========
* minor refactoring
* official support for django 1.4 to 1.9
* official support for python 2.7, 3.3, 3.5
Expand All @@ -12,7 +23,6 @@ Release 1.0 (dev)
* new `upper` and `lower` modifiers available for EmailField in mass update.



Release 0.8.5
=============
* repackage due broken version in 0.8.4
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ include setup.cfg
include tox.ini
include *.py
include Makefile

exclude .editorconfig

recursive-include docs *
recursive-include src *.css
recursive-include src *.js
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ demo:
PYTHONPATH=${PWD}:${PWD}/tests:${PWD}/src django-admin.py loaddata adminactions.json demoproject.json --settings=demo.settings
PYTHONPATH=${PWD}:${PWD}/tests:${PWD}/src django-admin.py runserver --settings=demo.settings

qa:
flake8 src/ tests/
isort -rc src tests --check-only
check-manifest

clean:
rm -fr ${BUILDDIR} dist *.egg-info .coverage coverage.xml pytest.xml .cache MANIFEST
Expand Down
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ django-adminactions
Collection of useful actions to use with
django.contrib.admin.ModelAdmin and/or django.contrib.admin.AdminSite

**Requires Django>=1.4**

Please see the changelog at http://django-adminactions.readthedocs.org/en/latest/changes.html

Actions
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ line_length=80
known_future_library=future,pies
known_standard_library = six
known_third_party = django
known_first_party = adminactions
known_first_party = adminactions,demo
multi_line_output = 0
not_skip = __init__.py
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
Expand Down
22 changes: 15 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pylint: disable=W,I,C
from __future__ import absolute_import

import imp
import os
import sys
from distutils import log
Expand All @@ -12,18 +13,25 @@
from setuptools.command.test import test as TestCommand

ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__)))
sys.path.insert(0, os.path.join(ROOT, 'src'))
app = __import__('adminactions')

rel = lambda fname: os.path.join(os.path.dirname(__file__),
'src',
'adminactions',
'requirements', fname)
init = os.path.join(ROOT, 'src', 'adminactions', '__init__.py')

if sys.version_info[0] == 2:
reqs = 'install.py2.pip'
app = imp.load_source('adminactions', init)
elif sys.version_info[0] == 3:
reqs = 'install.py3.pip'
if sys.version_info[1] in [3,4]:
from importlib.machinery import SourceFileLoader
app = SourceFileLoader("adminactions", init).load_module()
elif sys.version_info[1] in [5]:
import importlib.util
spec = importlib.util.spec_from_file_location("adminactions", init)
app = importlib.util.module_from_spec(spec)
spec.loader.exec_module(app)

rel = lambda fname: os.path.join(os.path.dirname(__file__),
'src',
'requirements', fname)


class Clean(CleanCommand):
Expand Down
6 changes: 2 additions & 4 deletions src/adminactions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import absolute_import

import subprocess
import datetime
import os
import subprocess

VERSION = __version__ = (1, 1, 0, 'final', 0)
NAME = 'django-adminactions'
VERSION = __version__ = (1, 0, 0, 'final', 0)


def get_version(version=None):
Expand Down
4 changes: 3 additions & 1 deletion src/adminactions/actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable-msg= W0611
from __future__ import absolute_import, unicode_literals

from .byrows_update import byrows_update
from .export import (export_as_csv, export_as_fixture, export_as_xls,
export_delete_tree,)
from .graph import graph_queryset
Expand All @@ -12,7 +13,8 @@
export_as_xls,
export_delete_tree,
merge, mass_update,
graph_queryset]
graph_queryset,
byrows_update]


def add_to_site(site, exclude=None):
Expand Down
5 changes: 3 additions & 2 deletions src/adminactions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def merge(master, other, fields=None, commit=False, m2m=None, related=None): #

if related == ALL_FIELDS:
related = [rel.get_accessor_name()
for rel in master._meta.get_all_related_objects(False, False, False)]
for rel in compat.get_all_related_objects(master)]
# for rel in master._meta.get_all_related_objects(False, False, False)]

if m2m == ALL_FIELDS:
m2m = [field.name for field in master._meta.many_to_many]
Expand Down Expand Up @@ -276,7 +277,7 @@ def _get_qs_formats(queryset):
if hasattr(queryset, 'model'):
for i, fieldname in enumerate(fields):
try:
f, __, __, __, = queryset.model._meta.get_field_by_name(fieldname)
f, __, __, __, = compat.get_field_by_name(queryset.model, fieldname)
fmt = xls_options_default.get(f.name, xls_options_default.get(f.__class__.__name__, 'general'))
formats[i] = fmt
except FieldDoesNotExist:
Expand Down
110 changes: 110 additions & 0 deletions src/adminactions/byrows_update.py
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

0 comments on commit b4cb43e

Please sign in to comment.