Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.8'
Browse files Browse the repository at this point in the history
* release/1.8:
  updates setup.py
  code clean
  updates README
  mixed improvements.
  update README
  update Makefile
  Describe imports in readme
  fixes wrong codecov url in README
  • Loading branch information
saxix committed Feb 1, 2018
2 parents 22188e2 + 0adf022 commit 53d1c13
Show file tree
Hide file tree
Showing 25 changed files with 362 additions and 275 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Release 1.8
-----------
* standard "post action redirect" now preserve existing filters
* check arguments of decorated methods
* fixes permission check using callable
* removed UploadMixin. It is now part of the demo app.

Release 1.7
-----------
* removed deprecated `has_permission`
Expand Down
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ include MANIFEST.in
include tox.ini
include setup.py
include setup.cfg

include tests/.coveragerc
recursive-include src/requirements *.pip
recursive-include docs *
recursive-include src/admin_extra_urls *
recursive-include tests *.py
recursive-include tests *
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ develop:

clean:
# cleaning
@rm -fr dist '~build'
@find . -name __pycache__ -o -name .eggs | xargs rm -rf
@find . -name "*.py?" -o -name ".DS_Store" -o -name "*.orig" -o -name "*.min.min.js" -o -name "*.min.min.css" -prune | xargs rm -rf
@rm -f coverage.xml flake.out pep8.out pytest.xml

fullclean:
@rm -rf .tox .cache dist build '~build'
@rm -rf .tox .cache
$(MAKE) clean
44 changes: 27 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ How to use it

.. code-block:: python
from admin_extra_urls.extras import ExtraUrlMixin, link, action
class MyModelModelAdmin(ExtraUrlMixin, admin.ModelAdmin):
@link() # /admin/myapp/mymodel/update_all/
Expand All @@ -46,7 +48,7 @@ How to use it
@action() # /admin/myapp/mymodel/update/10/
def update(self, request, pk):
...
obj = self.get_object(pk=pk)
...
You don't need to return a HttpResponse. The default behavior is:
Expand All @@ -66,21 +68,34 @@ link() / action() options
+------------+----------------------+----------------------------------------------------------------------------------------+
| icon | '' | icon for the button |
+------------+----------------------+----------------------------------------------------------------------------------------+
| permission | None | permission required to use the button. can be a callable (current object as argument). |
| permission | None | permission required to use the button. Can be a callable (current object as argument). |
+------------+----------------------+----------------------------------------------------------------------------------------+
| css_class | "btn btn-success" | extra css classes to use for the button |
+------------+----------------------+----------------------------------------------------------------------------------------+
| order | 999 | in case of multiple button the order to use |
+------------+----------------------+----------------------------------------------------------------------------------------+
| visible | lambda o: o and o.pk | callable or bool. By default do not display the button if in `add` mode |
+-----------------------------------+----------------------------------------------------------------------------------------+
| visible | lambda o: o and o.pk | callable or bool. By default do not display "action" button if in `add` mode |
+------------+----------------------+----------------------------------------------------------------------------------------+


*Note*

The package contains a ``UploadMixin`` to manage custom file uploads
(simply set `upload_handler` to a function.
This can be checked to see how to create wizard with an intermediate form.
Integration with other libraries
--------------------------------

django-import-export
~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
@admin.register(Rule)
class RuleAdmin(ExtraUrlMixin, ImportExportMixin, BaseModelAdmin):
@link(label='Export')
def _export(self, request):
return self.export_action(request)
@link(label='Import')
def _import(self, request):
return self.import_action(request)
Links
Expand All @@ -102,15 +117,14 @@ Links
.. |master-build| image:: https://secure.travis-ci.org/saxix/django-admin-extra-urls.png?branch=master
:target: http://travis-ci.org/saxix/django-admin-extra-urls/

.. |master-cov| image:: https://coveralls.io/repos/saxix/django-admin-extra-urls/badge.png?branch=master
:target: https://coveralls.io/r/saxix/django-admin-extra-urls

.. |master-cov| image:: https://codecov.io/gh/saxix/django-admin-extra-urls/branch/master/graph/badge.svg
:target: https://codecov.io/gh/saxix/django-admin-extra-urls

.. |dev-build| image:: https://secure.travis-ci.org/saxix/django-admin-extra-urls.png?branch=develop
:target: http://travis-ci.org/saxix/django-admin-extra-urls/

.. |dev-cov| image:: https://coveralls.io/repos/saxix/django-admin-extra-urls/badge.png?branch=develop
:target: https://coveralls.io/r/saxix/django-admin-extra-urls
.. |dev-cov| image:: https://codecov.io/gh/saxix/django-admin-extra-urls/branch/develop/graph/badge.svg
:target: https://codecov.io/gh/saxix/django-admin-extra-urls


.. |python| image:: https://pypip.in/py_versions/admin-extra-urls/badge.svg
Expand All @@ -125,10 +139,6 @@ Links
:target: https://pypi.python.org/pypi/admin-extra-urls/
:alt: License

.. image:: https://pypip.in/wheel/admin-extra-urls/badge.svg
:target: https://pypi.python.org/pypi/admin-extra-urls/
:alt: Wheel Status

.. |travis| image:: https://travis-ci.org/saxix/django-admin-extra-urls.svg?branch=develop
:target: https://travis-ci.org/saxix/django-admin-extra-urls

Expand Down
18 changes: 13 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/usr/bin/env python
import ast
import codecs
import os
import sys

import re
from setuptools import find_packages, setup
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'))
init = os.path.join(ROOT, 'src', 'admin_extra_urls', '__init__.py')

app = __import__('admin_extra_urls')

_version_re = re.compile(r'__version__\s+=\s+(.*)')
_name_re = re.compile(r'NAME\s+=\s+(.*)')

with open(init, 'rb') as f:
content = f.read().decode('utf-8')
version = str(ast.literal_eval(_version_re.search(content).group(1)))
name = str(ast.literal_eval(_name_re.search(content).group(1)))

def read(*parts):
here = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -43,8 +51,8 @@ def run_tests(self):


setup(
name=app.NAME,
version=app.get_version(),
name=name,
version=version,
url='https://github.com/saxix/django-admin-extra-urls',
download_url='https://pypi.python.org/pypi/admin-extra-urls',

Expand All @@ -66,10 +74,10 @@ def run_tests(self):
'Environment :: Web Environment',
'Operating System :: OS Independent',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
Expand Down
52 changes: 2 additions & 50 deletions src/admin_extra_urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
import subprocess
import datetime
import os

NAME = 'admin-extra-urls'
VERSION = __version__ = (1, 7, 0, 'final', 0)
NAME = "admin-extra-urls"
VERSION = __version__ = "1.8.0"
__author__ = 'sax'


def get_version(): # pragma: no cover
"""Derives a PEP386-compliant version number from VERSION."""
assert len(VERSION) == 5
assert VERSION[3] in ('alpha', 'beta', 'rc', 'final')

parts = 2 if VERSION[2] == 0 else 3
main = '.'.join(str(x) for x in VERSION[:parts])

sub = ''
if VERSION[3] == 'alpha' and VERSION[4] == 0:
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset

elif VERSION[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[VERSION[3]] + str(VERSION[4])
elif VERSION[3] == 'final':
if VERSION[4] > 0:
sub += '-%s' % VERSION[4]

return main + sub


def get_git_changeset(): # pragma: no cover
"""Returns a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
"""
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, cwd=repo_dir,
universal_newlines=True)
timestamp = git_log.communicate()[0]
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')
21 changes: 21 additions & 0 deletions src/admin_extra_urls/comapt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import inspect

import django
import six

DJANGO2 = django.VERSION[0] == 2
DJANGO1 = django.VERSION[0] == 1

if six.PY3:
getfullargspec = inspect.getfullargspec
else:
getfullargspec = inspect.getargspec

# MONITOR THIS: DJANGO version compatibility code:
if DJANGO2:
from django.urls import reverse # noqa
else:
from django.core.urlresolvers import reverse # noqa

0 comments on commit 53d1c13

Please sign in to comment.