Skip to content

Django 1.8 support #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ max-line-length = 100
# E12x continuation line indentation
# E251 no spaces around keyword / parameter equals
# E303 too many blank lines (3)
ignore = E12,E251,E303
ignore = E12,E251,E303,E402,E731,E501
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
- DJANGO_VERSION=1.3
- DJANGO_VERSION=1.4
- DJANGO_VERSION=1.5
- DJANGO_VERSION=1.6
- DJANGO_VERSION=1.7
- DJANGO_VERSION=1.8
install:
- "pip install django==$DJANGO_VERSION --use-mirrors"
- "pip install -r requirements.txt --use-mirrors"
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ include LICENSE
recursive-include django_settings/templates *
recursive-include django_settings/templates/admin *
recursive-include django_settings/templates/admin/django_settings *
recursive-include django_settings/migrations *
exclude example*
exclude tests*
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Supported versions
------------------

* Python: 2.6, 2.7 (python 2.6 requires importlib)
* Django: 1.3, 1.4, 1.5
* Django: 1.3, 1.4, 1.5, 1.6, 1.7, 1.8


API
Expand Down
2 changes: 1 addition & 1 deletion django_settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
VERSION = '1.3.12'
VERSION = '1.3.13'

__version__ = VERSION
__author__ = "Kuba Janoszek"
Expand Down
6 changes: 4 additions & 2 deletions django_settings/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.translation import ugettext as _
from django.http import Http404, HttpResponseRedirect

import django

# module local
from . import models, forms, dataapi
Expand Down Expand Up @@ -89,10 +90,11 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
def response_change(self, request, obj):
response = super(SettingAdmin, self).response_change(request, obj)
app_label = obj._meta.app_label
module_name = obj._meta.module_name
module_model = obj._meta.module_name if django.VERSION < (1, 5) else obj._meta.model_name
module_name = module_model

if '_addanother' in request.POST:
url_name = 'admin:%s_%s_add' % (app_label, module_name)
url_name = 'admin:%s_%s_add' % (app_label, module_model)
url = reverse(url_name, current_app=self.admin_site.name)
typename = self.get_setting_model(obj, request).__name__
return self._response_url(url, typename)
Expand Down
67 changes: 67 additions & 0 deletions django_settings/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
]

operations = [
migrations.CreateModel(
name='Email',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.EmailField(max_length=254)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Integer',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.IntegerField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='PositiveInteger',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.PositiveIntegerField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Setting',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('setting_id', models.PositiveIntegerField()),
('name', models.CharField(unique=True, max_length=255)),
('setting_type', models.ForeignKey(to='contenttypes.ContentType')),
],
options={
'verbose_name': 'Setting',
'verbose_name_plural': 'Settings',
},
),
migrations.CreateModel(
name='String',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.CharField(max_length=254)),
],
options={
'abstract': False,
},
),
]
Empty file.
8 changes: 6 additions & 2 deletions django_settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# framework
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
import django
if django.VERSION >= (1, 8):
from django.contrib.contenttypes import fields as generic_fields
else:
from django.contrib.contenttypes import generic as generic_fields
from django.utils.translation import ugettext_lazy as _
from django.dispatch import receiver
from django.db.models.signals import post_syncdb
Expand Down Expand Up @@ -59,7 +63,7 @@ class Meta:

setting_type = models.ForeignKey(ContentType)
setting_id = models.PositiveIntegerField()
setting_object = generic.GenericForeignKey('setting_type', 'setting_id')
setting_object = generic_fields.GenericForeignKey('setting_type', 'setting_id')

name = models.CharField(max_length=255, unique=conf.DJANGO_SETTINGS_UNIQUE_NAMES)

Expand Down
5 changes: 4 additions & 1 deletion django_settings/templatetags/settings_admin_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from django.core.urlresolvers import reverse
from django import template

import django

register = template.Library()


@register.filter
def add_url_for_setting_type(admin_change_list, type_name):
cl = admin_change_list
url_name = 'admin:%s_%s_%s' % (cl.opts.app_label, cl.opts.module_name, 'add')
param2 = cl.opts.module_name if django.VERSION < (1, 6) else cl.opts.model_name
url_name = 'admin:%s_%s_%s' % (cl.opts.app_label, param2, 'add')
query = "typename=%(type)s%(popup)s" % dict(
type=type_name,
popup='_popup=1' if cl.is_popup else '',
Expand Down
10 changes: 9 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
nose==1.3.0
argparse==1.2.1
flake8==2.0
mccabe==0.3
nose==1.3.0
pep8==1.6.2
py==1.4.26
pyflakes==0.8.1
tox==1.9.2
virtualenv==12.1.1
wsgiref==0.1.2
4 changes: 2 additions & 2 deletions tests/test_admin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_admin_settings_list(self):
def set_all_data():
for type_name, name, value in data:
django_settings.set(type_name, name, value)

self.assert_queries_count(len(data) * 4, set_all_data)
query_count = 4 if django.VERSION < (1, 6) else 6
self.assert_queries_count(len(data) * query_count, set_all_data)
# end

# run request and check number of quesries
Expand Down
6 changes: 5 additions & 1 deletion tests/test_admin/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import patterns, include
import django
if django.VERSION < (1, 6):
from django.conf.urls.defaults import patterns, include
else:
from django.conf.urls import patterns, include
from django.contrib import admin

admin.autodiscover()
Expand Down