Skip to content

Commit

Permalink
Added 1.10, 1.11 and 2.0 django versions support
Browse files Browse the repository at this point in the history
  • Loading branch information
matllubos committed Mar 8, 2018
1 parent a355d54 commit ebd7c3e
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 105 deletions.
13 changes: 4 additions & 9 deletions .travis.yml
@@ -1,18 +1,13 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"

env:
- DJANGO_VERSION=1.8
- DJANGO_VERSION=1.9

matrix:
exclude:
- python: "3.3"
env: DJANGO_VERSION=1.9
- DJANGO_VERSION=1.10
- DJANGO_VERSION=1.11
- DJANGO_VERSION=2.0

# command to install dependencies
install:
Expand Down
4 changes: 2 additions & 2 deletions chamber/commands/__init__.py
Expand Up @@ -5,7 +5,7 @@
import pyprind


class ProgressBarStream(object):
class ProgressBarStream:
"""
OutputStream wrapper to remove default linebreak at line endings.
"""
Expand All @@ -29,7 +29,7 @@ def flush(self):
return self.stream.flush()


class ImportCSVCommandMixin(object):
class ImportCSVCommandMixin:

def handle(self, *args, **kwargs):
self.import_csv()
Expand Down
3 changes: 0 additions & 3 deletions chamber/exceptions/__init__.py
@@ -1,6 +1,3 @@
from __future__ import unicode_literals


class PersistenceException(Exception):

def __init__(self, message=None):
Expand Down
2 changes: 0 additions & 2 deletions chamber/formatters/__init__.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.utils import numberformat
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
Expand Down
2 changes: 0 additions & 2 deletions chamber/forms/fields.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms
from django.utils.translation import ugettext

Expand Down
12 changes: 4 additions & 8 deletions chamber/importers/__init__.py
@@ -1,11 +1,7 @@
from __future__ import unicode_literals

import csv
import io
import os

import six

from django.conf import settings

import pyprind
Expand All @@ -26,13 +22,13 @@ def simple_count(filename, encoding):
return lines


class DummyOutputStream(six.StringIO, object):
class DummyOutputStream(io.StringIO):

def write(self, *args, **kwargs):
super(DummyOutputStream, self).write(*args)


class AbstractCSVImporter(object):
class AbstractCSVImporter:
"""
Abstract CSV importer provides an easy way to implement loading a CSV file into a Django model.
* To alter or validate field value, define clean_field_name() method in a similar manner as in Django forms.
Expand Down Expand Up @@ -89,15 +85,15 @@ def get_skip_header(self):
return self.skip_header

def get_fields(self):
return tuple(f if isinstance(f, six.text_type) else six.u(f) for f in self.fields)
return self.fields

def get_fields_dict(self, row):
"""
Returns a dict of field name and cleaned value pairs to initialize the model.
Beware, it aligns the lists of fields and row values with Nones to allow for adding fields not found in the CSV.
Whitespace around the value of the cell is stripped.
"""
return {k: getattr(self, 'clean_{}'.format(k), lambda x: x)(v.strip() if isinstance(v, six.string_types)
return {k: getattr(self, 'clean_{}'.format(k), lambda x: x)(v.strip() if isinstance(v, str)
else None)
for k, v in zip_longest(self.get_fields(), row)}

Expand Down
17 changes: 5 additions & 12 deletions chamber/models/__init__.py
@@ -1,15 +1,9 @@
from __future__ import unicode_literals

import copy

import collections

from itertools import chain

import six

from six import python_2_unicode_compatible

from django.core.exceptions import ValidationError
from django.db import models, transaction
from django.db.models.base import ModelBase
Expand Down Expand Up @@ -65,8 +59,7 @@ def model_to_dict(instance, fields=None, exclude=None):
ValueChange = collections.namedtuple('ValueChange', ('initial', 'current'))


@python_2_unicode_compatible
class ChangedFields(object):
class ChangedFields:
"""
Class stores changed fields and its initial and current values.
"""
Expand Down Expand Up @@ -174,7 +167,7 @@ def current_values(self):
return self._current_dict


class ComparableModelMixin(object):
class ComparableModelMixin:

def equals(self, obj, comparator):
"""
Expand All @@ -183,7 +176,7 @@ def equals(self, obj, comparator):
return comparator.compare(self, obj)


class Comparator(object):
class Comparator:

def compare(self, a, b):
"""
Expand All @@ -203,7 +196,7 @@ class Meta:
abstract = True


class Signal(object):
class Signal:

def __init__(self, obj):
self.connected_functions = []
Expand Down Expand Up @@ -248,7 +241,7 @@ def __new__(cls, name, bases, attrs):
return new_cls


class SmartModel(six.with_metaclass(SmartModelBase, AuditModel)):
class SmartModel(AuditModel, metaclass=SmartModelBase):

objects = SmartQuerySet.as_manager()

Expand Down
4 changes: 1 addition & 3 deletions chamber/models/dispatchers.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from collections import defaultdict

from django.core.exceptions import ImproperlyConfigured
Expand All @@ -11,7 +9,7 @@
from .signals import dispatcher_post_save


class BaseDispatcher(object):
class BaseDispatcher:
"""
Base dispatcher class that can be subclassed to call a handler based on a change in some a SmartModel.
If you subclass, be sure the __call__ method does not change signature.
Expand Down
12 changes: 5 additions & 7 deletions chamber/models/fields.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import mimetypes
import os
from decimal import Decimal
Expand Down Expand Up @@ -53,7 +51,7 @@ def formfield(self, **kwargs):
return super(DecimalField, self).formfield(**defaults)


class RestrictedFileValidator(object):
class RestrictedFileValidator:

def __init__(self, max_upload_size):
self.max_upload_size = max_upload_size
Expand All @@ -70,7 +68,7 @@ def __call__(self, data):
return data


class AllowedContentTypesByFilenameFileValidator(object):
class AllowedContentTypesByFilenameFileValidator:

def __init__(self, content_types):
self.content_types = content_types
Expand All @@ -84,7 +82,7 @@ def __call__(self, data):
return data


class AllowedContentTypesByContentFileValidator(object):
class AllowedContentTypesByContentFileValidator:

def __init__(self, content_types):
self.content_types = content_types
Expand All @@ -99,7 +97,7 @@ def __call__(self, data):
return data


class RestrictedFileFieldMixin(object):
class RestrictedFileFieldMixin:
"""
Same as FileField, but you can specify:
* allowed_content_types - list of allowed content types. Example: ['application/json', 'image/jpeg']
Expand Down Expand Up @@ -200,7 +198,7 @@ def validate(self, value, model_instance):
self._raise_error_if_value_not_allowed(value, self._get_subvalue(model_instance), model_instance)


class EnumSequenceFieldMixin(object):
class EnumSequenceFieldMixin:

# TODO Once SmartWidget mixin is not in is-core, add formfield method with the appropriate widget
def __init__(self, *args, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions chamber/multidomains/auth/backends.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib.auth.backends import ModelBackend as OridginModelBackend
from django.contrib.auth.models import Permission

Expand Down
2 changes: 0 additions & 2 deletions chamber/multidomains/auth/middleware.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.utils.functional import SimpleLazyObject

from is_core.config import settings as is_core_settings # pylint: disable=E0401
Expand Down
4 changes: 1 addition & 3 deletions chamber/multidomains/domain.py
@@ -1,9 +1,7 @@
from __future__ import unicode_literals

from django.core.exceptions import ImproperlyConfigured


class Domain(object):
class Domain:

def __init__(self, name, protocol, hostname, urlconf, user_model, port=None):
self.name = name
Expand Down
13 changes: 8 additions & 5 deletions chamber/multidomains/urlresolvers.py
@@ -1,9 +1,12 @@
from __future__ import unicode_literals

from six.moves.urllib.parse import urlencode
from urllib.parse import urlencode

from django.conf import settings
from django.core import urlresolvers

try:
from django.core.urlresolvers import reverse as django_reverse
except ImportError:
from django.urls import reverse as django_reverse



def reverse(viewname, site_id=None, add_domain=False, urlconf=None, args=None, kwargs=None, current_app=None,
Expand All @@ -16,4 +19,4 @@ def reverse(viewname, site_id=None, add_domain=False, urlconf=None, args=None, k
site_id = settings.SITE_ID if site_id is None else site_id
domain = get_domain(site_id).url if add_domain else ''
qs = '?{}'.format(urlencode(qs_kwargs)) if qs_kwargs else ''
return ''.join((domain, urlresolvers.reverse(viewname, urlconf, args, kwargs, current_app), qs))
return ''.join((domain, django_reverse(viewname, urlconf, args, kwargs, current_app), qs))
8 changes: 2 additions & 6 deletions chamber/patch.py
@@ -1,12 +1,8 @@
from __future__ import unicode_literals

import six

from django.db.models import Model
from django.db.models.fields import Field


class OptionsLazy(object):
class OptionsLazy:

def __init__(self, name, klass):
self.name = name
Expand All @@ -24,7 +20,7 @@ def __new__(cls, *args, **kwargs):
return new_class


class Options(six.with_metaclass(OptionsBase, object)):
class Options(metaclass=OptionsBase):

meta_class_name = None
meta_name = None
Expand Down
2 changes: 0 additions & 2 deletions chamber/shortcuts.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from datetime import date, datetime, time

from django.http.response import Http404
Expand Down
8 changes: 3 additions & 5 deletions chamber/utils/datastructures.py
@@ -1,10 +1,8 @@
from __future__ import unicode_literals

from collections import MutableSet, OrderedDict
from itertools import chain


class AbstractEnum(object):
class AbstractEnum:

def _has_attr(self, name):
return name in self.container
Expand Down Expand Up @@ -57,7 +55,7 @@ def _get_attr_val(self, name):
return self.container[name]


class AbstractChoicesEnum(object):
class AbstractChoicesEnum:

def _get_labels_dict(self):
return dict(self._get_choices())
Expand Down Expand Up @@ -157,7 +155,7 @@ def get_allowed_states(self, category):
return self.categories.get(category, ())


class SequenceChoicesEnumMixin(object):
class SequenceChoicesEnumMixin:

def __init__(self, items, initial_states=None):
assert len(items) > 0
Expand Down
2 changes: 0 additions & 2 deletions chamber/utils/datetimes.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from copy import copy
from datetime import datetime, time, timedelta

Expand Down
2 changes: 0 additions & 2 deletions chamber/utils/decorators.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from functools import wraps

from django.conf import settings
Expand Down
2 changes: 0 additions & 2 deletions chamber/utils/forms.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django import forms


Expand Down
2 changes: 0 additions & 2 deletions chamber/utils/http.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from collections import OrderedDict

from django.http.request import QueryDict
Expand Down
9 changes: 3 additions & 6 deletions chamber/utils/migrations/fixtures.py
@@ -1,15 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os

from six.moves import cStringIO
from io import StringIO

from django.core.management import call_command
from django.core.serializers import base, python


class MigrationLoadFixture(object):
class MigrationLoadFixture:

def __init__(self, migration_file, fixture_dir=None, fixture_filename=None, fixture_type='json'):
self.migration_file = migration_file
Expand All @@ -33,5 +30,5 @@ def _get_model(model_identifier):
file = os.path.join(self.fixture_dir, self.fixture_filename)
if not os.path.isfile(file):
raise IOError('File "%s" does not exists' % file)
call_command('loaddata', file, stdout=cStringIO())
call_command('loaddata', file, stdout=StringIO())
python._get_model = get_model_tmp # pylint: disable=W0212

0 comments on commit ebd7c3e

Please sign in to comment.