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

Commit

Permalink
Merge 92f6f83 into 1a4f765
Browse files Browse the repository at this point in the history
  • Loading branch information
vthaian committed Dec 11, 2018
2 parents 1a4f765 + 92f6f83 commit b5556f6
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 85 deletions.
45 changes: 28 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
language: python
python: 3.5

# Use container based infrastructure
sudo: false

env:
# - TOX_ENV=flake8
- TOX_ENV=py35-dj19
- TOX_ENV=py35-dj18
- TOX_ENV=py34-dj19
- TOX_ENV=py34-dj18
- TOX_ENV=py33-dj18
- TOX_ENV=py27-dj19
- TOX_ENV=py27-dj18
- TOX_ENV=py34-dj17
- TOX_ENV=py33-dj17
- TOX_ENV=py27-dj17
- TOX_ENV=py33-dj16
- TOX_ENV=py27-dj16
matrix:
include:
# Django 1.11
- python: 2.7
env: DJANGO='dj111'
- python: 3.4
env: DJANGO='dj111'
- python: 3.5
env: DJANGO='dj111'
- python: 3.6
env: DJANGO='dj111'
# Django 2.0
- python: 3.4
env: DJANGO='dj20'
- python: 3.5
env: DJANGO='dj20'
- python: 3.6
env: DJANGO='dj20'
# Django 2.1
- python: 3.5
env: DJANGO='dj21'
- python: 3.6
env: DJANGO='dj21'

install:
- pip install --upgrade pip
- pip install tox coveralls
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PY_VER=py27; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then export PY_VER=py34; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export PY_VER=py35; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then export PY_VER=py36; fi"
- "if [[ ${DJANGO}z != 'z' ]]; then export TOX_ENV=$PY_VER-$DJANGO; fi"

script:
- tox -e $TOX_ENV
Expand Down
2 changes: 1 addition & 1 deletion addon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Aldryn Common",
"description": "Common utitilities",
"description": "Common utilities",
"url": "https://github.com/aldryn/aldryn-common",
"package-name": "aldryn-common",
"installed-apps": [
Expand Down
1 change: 0 additions & 1 deletion aldryn_common/admin_fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

33 changes: 12 additions & 21 deletions aldryn_common/admin_fields/sortedm2m.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from __future__ import absolute_import, unicode_literals

from itertools import chain

from django import forms
from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.models.query import QuerySet
from django.template.loader import render_to_string
from django.urls import NoReverseMatch, reverse
from django.utils.encoding import force_text
from django.utils.html import conditional_escape, escape
from django.utils.safestring import mark_safe
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
import django.db.models
import django.forms
from django.conf import settings

import sortedm2m.fields
import sortedm2m.forms

Expand All @@ -23,8 +19,10 @@ class SortedM2MWidget(sortedm2m.forms.SortedCheckboxSelectMultiple):

def render(self, name, value, attrs=None, choices=()):
# TODO: make a pull request to sortedm2m to make it easy to override the template
# TODO: make a pull request to sortedm2m to make it easy to add the addtional link to admin (or integrate this whole widget)
if value is None: value = []
# TODO: make a pull request to sortedm2m to make it easy to add the addtional
# TODO: link to admin (or integrate this whole widget)
if value is None:
value = []
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs, name=name)

Expand Down Expand Up @@ -83,7 +81,8 @@ def render(self, name, value, attrs=None, choices=()):
else:
unselected.append(item)

# re-order `selected` array according str_values which is a set of `option_value`s in the order they should be shown on screen
# re-order `selected` array according str_values which is a set of `option_value`s in the order they should
# be shown on screen
ordered = []
for value in str_values:
for select in selected:
Expand Down Expand Up @@ -114,11 +113,3 @@ def formfield(self, **kwargs):
}
defaults.update(kwargs)
return super(SortedM2MModelField, self).formfield(**defaults)

try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], [
"^aldryn_common\.admin_fields\.sortedm2m\.SortedM2MModelField"])
except:
# If South not installed, then we really don't need to have done this.
pass
11 changes: 0 additions & 11 deletions aldryn_common/compat.py

This file was deleted.

16 changes: 9 additions & 7 deletions aldryn_common/paginator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# original copy from https://djangosnippets.org/snippets/773/

import math
import functools
import math

from django.conf import settings
from django.core.paginator import Paginator, QuerySetPaginator, Page, InvalidPage

from django.core.paginator import (InvalidPage, Page, Paginator,
QuerySetPaginator)

__all__ = (
'InvalidPage',
Expand Down Expand Up @@ -203,7 +203,7 @@ def __init__(self, *args, **kwargs):
max_padding = int(math.ceil(self.body/2.0)-1)
self.padding = kwargs.pop('padding', min(4, max_padding))
if self.padding > max_padding:
raise ValueError('padding too large for body (max %d)'%max_padding)
raise ValueError('padding too large for body (max %d)' % max_padding)
super(DiggPaginator, self).__init__(*args, **kwargs)

def page(self, number, *args, **kwargs):
Expand All @@ -212,7 +212,7 @@ def page(self, number, *args, **kwargs):
"""

page = super(DiggPaginator, self).page(number, *args, **kwargs)
number = int(number) # we know this will work
number = int(number) # we know this will work

# easier access
num_pages, body, tail, padding, margin = \
Expand Down Expand Up @@ -276,8 +276,10 @@ def page(self, number, *args, **kwargs):
page.main_range = list(range(main_range[0], main_range[1]+1))
page.leading_range = leading
page.trailing_range = trailing
page.page_range = functools.reduce(lambda x, y: x+((x and y) and [False])+y,
[page.leading_range, page.main_range, page.trailing_range])
page.page_range = functools.reduce(
lambda x, y: x+((x and y) and [False])+y,
[page.leading_range, page.main_range, page.trailing_range]
)

page.__class__ = DiggPage
return page
Expand Down
1 change: 1 addition & 0 deletions aldryn_common/templatetags/date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ def do_date_range(parser, token):
chunks[3] if len(chunks) == 4 else False
)


register.tag('date_range', do_date_range)
2 changes: 1 addition & 1 deletion aldryn_common/templatetags/html_filter_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django import template
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.utils.safestring import mark_safe
from django.utils.html import escape
from django.utils.safestring import mark_safe

register = template.Library()

Expand Down
10 changes: 5 additions & 5 deletions aldryn_common/templatetags/query_string_tools.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import re

from django.template import Library, Node, TemplateSyntaxError
from django.http import QueryDict
from django.template import Library, Node, TemplateSyntaxError
from django.utils.encoding import smart_str

import six
Expand Down Expand Up @@ -92,7 +92,7 @@ def render(self, context):
qdict = None
# Internally work only with QueryDict
qdict = self._get_initial_query_dict(qdict)
#assert isinstance(qdict, QueryDict)
# assert isinstance(qdict, QueryDict)
for k, op, v in mods:
qdict.setlist(k, self._process_list(qdict.getlist(k), op, v))
qstring = qdict.urlencode()
Expand All @@ -117,7 +117,7 @@ def _get_initial_query_dict(self, qdict):
# Accept any old dict or list of pairs.
try:
pairs = qdict.items()
except:
except Exception:
pairs = qdict
qdict = QueryDict(None, mutable=True)
# Enter each pair into QueryDict object:
Expand All @@ -130,7 +130,7 @@ def _get_initial_query_dict(self, qdict):
qdict.appendlist(k, six.text_type(e))
else:
qdict.appendlist(k, six.text_type(v))
except:
except Exception:
# Wrong data structure, qdict remains empty.
pass
return qdict
Expand All @@ -145,7 +145,7 @@ def _process_list(self, current_list, op, val):
if not isinstance(val, (list, tuple)):
val = [val]
val = [six.text_type(v) for v in val]
# Remove
# Remove
if op == '-':
for v in val:
while v in current_list:
Expand Down
1 change: 0 additions & 1 deletion aldryn_common/templatetags/string_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from django import template


register = template.Library()


Expand Down
6 changes: 3 additions & 3 deletions aldryn_common/timesince.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from django.utils.timezone import is_aware, utc
from django.utils.translation import ungettext, ugettext
from django.utils.translation import ugettext, ungettext


def timesince_data(d, now=None, reverse=False):
Expand All @@ -26,8 +26,8 @@ def timesince_data(d, now=None, reverse=False):
chunks = (
(60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)),
(60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)),
(60 * 60 * 24 * 7, lambda n : ungettext('week', 'weeks', n)),
(60 * 60 * 24, lambda n : ungettext('day', 'days', n)),
(60 * 60 * 24 * 7, lambda n: ungettext('week', 'weeks', n)),
(60 * 60 * 24, lambda n: ungettext('day', 'days', n)),
(60 * 60, lambda n: ungettext('hour', 'hours', n)),
(60, lambda n: ungettext('minute', 'minutes', n))
)
Expand Down
1 change: 1 addition & 0 deletions aldryn_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from aldryn_client import forms


class Form(forms.BaseForm):
paginator_paginate_by = forms.CharField('Paginator: item per page count', required=False)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
universal=1

[flake8]
max-line-length = 80
max-line-length = 120
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
from aldryn_common import __version__
from setuptools import find_packages, setup

REQUIREMENTS = [
'aldryn-boilerplates',
'django-sortedm2m>=1.2.2,!=1.3.0,!=1.3.1',
'django-sortedm2m',
'six',
]

CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
Expand All @@ -20,19 +23,19 @@
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
]

setup(
name='aldryn-common',
version=__version__,
description='Common utitilities',
description='Common utilities',
author='Divio AG',
author_email='info@divio.ch',
url='https://github.com/aldryn/aldryn-common',
packages=find_packages(),
packages=find_packages(exclude=['tests']),
license='LICENSE.txt',
platforms=['OS Independent'],
install_requires=REQUIREMENTS,
Expand Down
6 changes: 5 additions & 1 deletion test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from __future__ import unicode_literals


def noop_gettext(s):
return s


gettext = noop_gettext


Expand Down Expand Up @@ -54,7 +56,7 @@ def noop_gettext(s):
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
},
'MIDDLEWARE_CLASSES': [
'MIDDLEWARE': [
'django.middleware.http.ConditionalGetMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand All @@ -65,9 +67,11 @@ def noop_gettext(s):
],
}


def run():
from djangocms_helper import runner
runner.run('aldryn_common', extra_args=[])


if __name__ == "__main__":
run()
18 changes: 8 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[tox]
envlist =
;flake8
py{35,34,27}-dj19
py{35,34,33,27}-dj18
py{34,33,27}-dj{17}
py{33,27}-dj16
py{27,34,35,36}-dj111
py{34,35,36}-dj20
py{35,36}-dj21

toxworkdir = {homedir}/.toxenvs/aldryn-common

[testenv]
deps =
coverage
djangocms-helper>=0.9.4,<0.10
dj19: Django>=1.9,<1.9.999
dj18: Django>=1.8,<1.8.999
dj17: Django>=1.7,<1.7.999
dj16: Django>=1.6,<1.6.999
djangocms-helper
dj111: Django>=1.11,<2.0
dj20: Django>=2.0,<2.1
dj21: Django>=2.1,<2.2
commands =
{envpython} --version
- coverage erase
Expand Down

0 comments on commit b5556f6

Please sign in to comment.