Skip to content

Commit

Permalink
Merge pull request #431 from arthur-wsw/django_1_8
Browse files Browse the repository at this point in the history
Django 1.8 and 1.9 compatibility
  • Loading branch information
galuszkak committed May 25, 2016
2 parents ac531c3 + 38198c2 commit d9b3d2c
Show file tree
Hide file tree
Showing 66 changed files with 874 additions and 696 deletions.
6 changes: 6 additions & 0 deletions .eggs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins.

This directory caches those eggs to prevent repeated downloads.

However, it is safe to delete this directory.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ logfile

# test media upload
media

# PyCharm
.idea/

.cache
63 changes: 22 additions & 41 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
sudo: false
language: python
python: "2.7"
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
env:
matrix:
- TOX_ENV=py27-dj1.6.x
- TOX_ENV=py27-dj1.7.x
- TOX_ENV=py27-dj1.8.x
- TOX_ENV=py27-dj1.9.x
- TOX_ENV=py33-dj1.6.x
- TOX_ENV=py33-dj1.7.x
- TOX_ENV=py33-dj1.8.x
- TOX_ENV=py33-dj1.9.x
- TOX_ENV=py34-dj1.6.x
- TOX_ENV=py34-dj1.7.x
- TOX_ENV=py34-dj1.8.x
- TOX_ENV=py34-dj1.9.x
- TOX_ENV=pypy-dj1.6.x
- TOX_ENV=pypy-dj1.7.x
- TOX_ENV=pypy-dj1.8.x
- TOX_ENV=pypy-dj1.9.x
- TOX_ENV=pypy3-dj1.6.x
- TOX_ENV=pypy3-dj1.8.x
- TOX_ENV=pypy3-dj1.9.x
- DJANGO=1.8
- DJANGO=1.9
- DJANGO=master
matrix:
exclude:
- python: "3.3"
env: DJANGO=1.9
- python: "3.3"
env: DJANGO=master
allow_failures:
- python: "2.7"
env: DJANGO=master
- python: "3.4"
env: DJANGO=master
- python: "3.5"
env: DJANGO=master
install:
- pip install tox
script:
- tox -e $TOX_ENV
# for now commented. We have to figure which version use for coverage
# and coveralls
#after_success:
# - coverage report
# - pip install --quiet python-coveralls
# - coveralls
matrix:
allow_failures:
- env: TOX_ENV=py27-dj1.8.x
- env: TOX_ENV=py27-dj1.9.x
- env: TOX_ENV=py33-dj1.8.x
- env: TOX_ENV=py33-dj1.9.x
- env: TOX_ENV=py34-dj1.8.x
- env: TOX_ENV=py34-dj1.9.x
- env: TOX_ENV=pypy-dj1.8.x
- env: TOX_ENV=pypy-dj1.9.x
- env: TOX_ENV=pypy3-dj1.8.x
- env: TOX_ENV=pypy3-dj1.9.x
- env: TOX_ENV=pypy3-dj1.9.x
- tox -e py${TRAVIS_PYTHON_VERSION//[.]/}-$DJANGO
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Developers
* marangonico
* Kamil Gałuszka (@galuszkak / galuszkak@gmail.com)
* Germano Gabbianelli (@tyrion)
* Arthur (@arthur-wsw / arthur@wallstreetweb.net)

Translators
-----------
Expand Down
14 changes: 14 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
History
=========

0.6.2 (?)

* Fix Django 1.8 issues and add 1.9 compatibility
* Update all dependancies (DRF, floppyforms, filters, ...)
* Regenerate example project to make it django 1.9 compatible
* Update tox and travis and add flake8
* Rename AdminModel2Mixin to Admin2ModelMixin
* Add migrations
* Replace IPAddressField with GenericIPAddressField
* Fix password link in user admin
* Fix user logout on password change
* Fix tests


0.6.1 (2014-02-26)

* Fix empty form display
Expand Down
16 changes: 2 additions & 14 deletions djadmin2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals


__version__ = '0.6.1'

__author__ = 'Daniel Greenfeld & Contributors'
Expand All @@ -10,17 +11,4 @@
# Default datetime input and output formats
ISO_8601 = 'iso-8601'

from . import core
from . import types


default = core.Admin2()
ModelAdmin2 = types.ModelAdmin2
Admin2TabularInline = types.Admin2TabularInline
Admin2StackedInline = types.Admin2StackedInline

# Utility to make migration between versions easier
sites = default
ModelAdmin = ModelAdmin2
AdminInline = Admin2TabularInline
Admin2Inline = Admin2TabularInline
default_app_config = "djadmin2.apps.Djadmin2Config"
16 changes: 9 additions & 7 deletions djadmin2/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from __future__ import division, absolute_import, unicode_literals

from django.contrib import messages
from django.views.generic import TemplateView
from django.db import router
from django.utils.encoding import force_text
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy, ungettext, pgettext_lazy
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy, ungettext, pgettext_lazy
from django.views.generic import TemplateView

from . import permissions, utils
from .viewmixins import AdminModel2Mixin
from .viewmixins import Admin2ModelMixin


def get_description(action):
Expand All @@ -21,7 +22,7 @@ def get_description(action):
return capfirst(action.__name__.replace('_', ' '))


class BaseListAction(AdminModel2Mixin, TemplateView):
class BaseListAction(Admin2ModelMixin, TemplateView):

permission_classes = (permissions.IsStaffPermission,)

Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(self, queryset, *args, **kwargs):
super(BaseListAction, self).__init__(*args, **kwargs)

def get_queryset(self):
""" Replaced `get_queryset` from `AdminModel2Mixin`"""
""" Replaced `get_queryset` from `Admin2ModelMixin`"""
return self.queryset

def description(self):
Expand Down Expand Up @@ -94,7 +95,9 @@ def _format_callback(obj):
return '%s: %s' % (force_text(capfirst(opts.verbose_name)),
force_text(obj))

collector = utils.NestedObjects(using=None)
using = router.db_for_write(self.model)

collector = utils.NestedObjects(using=using)
collector.collect(self.queryset)

context.update({
Expand Down Expand Up @@ -166,7 +169,6 @@ def post(self, request):
# objects, so render a template asking for their confirmation.
return self.get(request)


def process_queryset(self):
# The user has confirmed that they want to delete the objects.
self.get_queryset().delete()
24 changes: 12 additions & 12 deletions djadmin2/admin2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
from django.conf import settings
from django.contrib.auth.models import Group, User
from django.contrib.sites.models import Site

from rest_framework.relations import PrimaryKeyRelatedField

import djadmin2
from djadmin2.forms import UserCreationForm, UserChangeForm
from djadmin2.apiviews import Admin2APISerializer
from djadmin2.forms import UserCreationForm, UserChangeForm
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2


class GroupSerializer(Admin2APISerializer):
permissions = PrimaryKeyRelatedField(many=True)
permissions = PrimaryKeyRelatedField(many=True, read_only=True)

class Meta:
model = Group


class GroupAdmin2(djadmin2.ModelAdmin2):
class GroupAdmin2(ModelAdmin2):
api_serializer_class = GroupSerializer


class UserSerializer(Admin2APISerializer):
user_permissions = PrimaryKeyRelatedField(many=True)
user_permissions = PrimaryKeyRelatedField(many=True, read_only=True)

class Meta:
model = User
exclude = ('passwords',)
exclude = ('password',)


class UserAdmin2(djadmin2.ModelAdmin2):
class UserAdmin2(ModelAdmin2):
create_form_class = UserCreationForm
update_form_class = UserChangeForm
search_fields = ('username', 'groups__name', 'first_name', 'last_name',
Expand All @@ -43,15 +43,15 @@ class UserAdmin2(djadmin2.ModelAdmin2):


# Register each model with the admin
djadmin2.default.register(User, UserAdmin2)
djadmin2.default.register(Group, GroupAdmin2)
djadmin2_site.register(User, UserAdmin2)
djadmin2_site.register(Group, GroupAdmin2)


# Register the sites app if it's been activated in INSTALLED_APPS
if "django.contrib.sites" in settings.INSTALLED_APPS:

class SiteAdmin2(djadmin2.ModelAdmin2):
class SiteAdmin2(ModelAdmin2):
list_display = ('domain', 'name')
search_fields = ('domain', 'name')

djadmin2.default.register(Site, SiteAdmin2)
djadmin2_site.register(Site, SiteAdmin2)
24 changes: 21 additions & 3 deletions djadmin2/apiviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import division, absolute_import, unicode_literals

from django.utils.encoding import force_str

from rest_framework import fields, generics, serializers
from rest_framework.response import Response
from rest_framework.reverse import reverse
Expand All @@ -17,11 +16,30 @@
class Admin2APISerializer(serializers.HyperlinkedModelSerializer):
_default_view_name = 'admin2:%(app_label)s_%(model_name)s_api_detail'

pk = fields.Field(source='pk')
__unicode__ = fields.Field(source='__str__')
pk = fields.ReadOnlyField()
__unicode__ = fields.ReadOnlyField(source='__str__')

def get_extra_kwargs(self):
extra_kwargs = super(Admin2APISerializer, self).get_extra_kwargs()
extra_kwargs.update({
'url': {'view_name': self._get_default_view_name(self.Meta.model)}
})
return extra_kwargs

def _get_default_view_name(self, model):
"""
Return the view name to use if 'view_name' is not specified in 'Meta'
"""
model_meta = model._meta
format_kwargs = {
'app_label': model_meta.app_label,
'model_name': model_meta.object_name.lower()
}
return self._default_view_name % format_kwargs


class Admin2APIMixin(Admin2Mixin):
model = None
raise_exception = True

def get_serializer_class(self):
Expand Down
14 changes: 14 additions & 0 deletions djadmin2/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.utils.translation import ugettext_lazy as _

from djadmin2.permissions import create_view_permissions


class Djadmin2Config(AppConfig):
name = 'djadmin2'
verbose_name = _("Django Admin2")

def ready(self):
post_migrate.connect(create_view_permissions,
dispatch_uid="django-admin2.djadmin2.permissions.create_view_permissions")
18 changes: 7 additions & 11 deletions djadmin2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
"""
from __future__ import division, absolute_import, unicode_literals

from django.conf.urls import patterns, include, url
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from importlib import import_module

from django.conf import settings
from django.conf.urls import include, url
from django.core.exceptions import ImproperlyConfigured

from . import apiviews
from . import types
Expand Down Expand Up @@ -160,8 +159,7 @@ def get_api_index_kwargs(self):
}

def get_urls(self):
urlpatterns = patterns(
'',
urlpatterns = [
url(regex=r'^$',
view=self.index_view.as_view(**self.get_index_kwargs()),
name='dashboard'
Expand All @@ -188,11 +186,10 @@ def get_urls(self):
**self.get_api_index_kwargs()),
name='api_index'
),
)
]
for model, model_admin in self.registry.items():
model_options = utils.model_options(model)
urlpatterns += patterns(
'',
urlpatterns += [
url('^{}/{}/'.format(
model_options.app_label,
model_options.object_name.lower()),
Expand All @@ -201,11 +198,10 @@ def get_urls(self):
model_options.app_label,
model_options.object_name.lower()),
include(model_admin.api_urls)),
)
]
return urlpatterns

@property
def urls(self):
# We set the application and instance namespace here
return self.get_urls(), self.name, self.name

0 comments on commit d9b3d2c

Please sign in to comment.