Skip to content
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

Add pre-commit config and lint files #161

Open
wants to merge 16 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 .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ exclude_lines =
def __repr__
raise NotImplementedError
if __name__ == .__main__.:
def parse_args
def parse_args
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ build
dist
*.egg-info
.coverage*
.eggs/
.env
example/example.db
example/app/migrations
.tox

24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.20.0
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
args: [--ignore=E501]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
=========
development (unreleased)
-------------------

* Update syntax for targeted versions of Python and Django. (`#161 <https://github.com/goinnn/django-multiselectfield/pull/161>`_)

0.1.13 (2024-06-30)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion COPYING.LGPLv3
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation.
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Library.
1 change: 0 additions & 1 deletion example/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = 'app.apps.AppAppConfig'
5 changes: 1 addition & 4 deletions example/app/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand All @@ -19,8 +18,6 @@
from .models import Book


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'categories', 'tags', 'published_in')


admin.site.register(Book, BookAdmin)
28 changes: 14 additions & 14 deletions example/app/fixtures/app_data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"pk": 1,
"model": "app.book",
"pk": 1,
"model": "app.book",
"fields": {
"title": "My book 1",
"tags": "sex,work,happy",
Expand All @@ -11,20 +11,20 @@
}
},
{
"pk": 1,
"model": "auth.user",
"pk": 1,
"model": "auth.user",
"fields": {
"username": "admin",
"first_name": "Pablo",
"last_name": "Martin",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2013-10-17T08:04:29.582Z",
"groups": [],
"username": "admin",
"first_name": "Pablo",
"last_name": "Martin",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2013-10-17T08:04:29.582Z",
"groups": [],
"user_permissions": [],
"password": "sha1$1ad04$868abf5737e05d3b68f5cb972fda1e227cc4f7d7",
"email": "",
"password": "sha1$1ad04$868abf5737e05d3b68f5cb972fda1e227cc4f7d7",
"email": "",
"date_joined": "2013-10-17T08:04:29.582Z"
}
}
Expand Down
1 change: 0 additions & 1 deletion example/app/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion example/app/test_msf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand Down
3 changes: 2 additions & 1 deletion example/app/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand All @@ -14,11 +13,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <https://www.gnu.org/licenses/>.

from django.contrib import admin
from django.urls import path

from .views import app_index


urlpatterns = [
path('', app_index, name='app_index'),
path('admin/', admin.site.urls),
]
8 changes: 1 addition & 7 deletions example/app/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand All @@ -14,16 +13,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <https://www.gnu.org/licenses/>.

from django import VERSION
from django.conf import settings
from django.contrib.auth import login
from django.contrib.auth import get_user_model
from django.http import HttpResponseRedirect

if VERSION >= (2, 0):
from django.urls import reverse
else:
from django.core.urlresolvers import reverse
from django.urls import reverse


def app_index(request):
Expand Down
17 changes: 5 additions & 12 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -44,7 +43,7 @@

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/5.0/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['localhost']
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

# Local time zone for this installation. Choices can be found here:
# https://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand All @@ -62,10 +61,6 @@
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

Expand Down Expand Up @@ -106,7 +101,7 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'lwfo1o9r^+x8xwec=6$a&m(dmg$1t%8)g6hr%&b4%)%_ualb8s'

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -153,13 +148,11 @@
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django.contrib.admin',
'django.contrib.admindocs',

'multiselectfield',
'app'
'app',
)


Expand Down
63 changes: 12 additions & 51 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
# This software is free software: you can redistribute it and/or modify
Expand All @@ -14,56 +13,18 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <https://www.gnu.org/licenses/>.

from django import VERSION
from django.conf import settings
from django.urls import include, path, re_path
from django.views.static import serve


try:
from django.conf.urls import include, url

# Compatibility for Django > 1.8
def patterns(prefix, *args):
if VERSION < (1, 9):
from django.conf.urls import patterns as django_patterns
return django_patterns(prefix, *args)
elif prefix != '':
raise NotImplementedError("You need to update your URLConf for "
"Django 1.10, or tweak it to remove the "
"prefix parameter")
else:
return list(args)
except ImportError: # Django < 1.4
if VERSION < (1, 4):
from django.conf.urls.defaults import include, patterns, url
elif VERSION < (4, 0):
from django.urls import include, url
else:
from django.urls import re_path as url


js_info_dict = {
'packages': ('django.conf',),
}

if VERSION < (1, 11):
urlpatterns = patterns(
'',
url(r'^', include('app.urls')),
)
urlpatterns += patterns(
'',
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:]),
)
else:
urlpatterns = [
url(r'^', include('app.urls')),
url(
r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
serve,
{
'document_root': settings.MEDIA_ROOT,
'show_indexes': True,
},
),
]
urlpatterns = [
path('', include('app.urls')),
re_path(
r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
serve,
{
'document_root': settings.MEDIA_ROOT,
'show_indexes': True,
},
),
]
1 change: 0 additions & 1 deletion example/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2013 by Pablo Martín <[email protected]>
#
Expand Down
3 changes: 0 additions & 3 deletions multiselectfield/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
from multiselectfield.db.fields import MultiSelectField # noqa: F401
from multiselectfield.forms.fields import MultiSelectFormField # noqa: F401


default_app_config = 'multiselectfield.apps.MultiSelectFieldConfig'
13 changes: 6 additions & 7 deletions multiselectfield/db/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2012 by Pablo Martín <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -42,7 +41,7 @@ class MultiSelectField(models.CharField):
def __init__(self, *args, **kwargs):
self.min_choices = kwargs.pop('min_choices', None)
self.max_choices = kwargs.pop('max_choices', None)
super(MultiSelectField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.max_length = get_max_length(self.choices, self.max_length)
self.validators.append(MaxValueMultiFieldValidator(self.max_length))
if self.min_choices is not None:
Expand All @@ -52,9 +51,9 @@ def __init__(self, *args, **kwargs):

def _get_flatchoices(self):
if VERSION >= (5,):
flat_choices = super(MultiSelectField, self).flatchoices
flat_choices = super().flatchoices
else:
flat_choices = super(MultiSelectField, self)._get_flatchoices()
flat_choices = super()._get_flatchoices()

class MSFFlatchoices(list):
# Used to trick django.contrib.admin.utils.display_for_field into
Expand Down Expand Up @@ -85,7 +84,7 @@ def value_to_string(self, obj):
try:
value = self._get_val_from_obj(obj)
except AttributeError:
value = super(MultiSelectField, self).value_from_object(obj)
value = super().value_from_object(obj)
return self.get_prep_value(value)

def validate(self, value, model_instance):
Expand All @@ -95,7 +94,7 @@ def validate(self, value, model_instance):
raise exceptions.ValidationError(self.error_messages['invalid_choice'] % {"value": value})

def get_default(self):
default = super(MultiSelectField, self).get_default()
default = super().get_default()
if isinstance(default, int):
default = str(default)
return default
Expand Down Expand Up @@ -141,7 +140,7 @@ def from_db_value(self, value, expression, connection):
return self.to_python(value)

def contribute_to_class(self, cls, name):
super(MultiSelectField, self).contribute_to_class(cls, name)
super().contribute_to_class(cls, name)
if self.choices:
def get_list(obj):
fieldname = name
Expand Down
5 changes: 2 additions & 3 deletions multiselectfield/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2012 by Pablo Martín <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -28,7 +27,7 @@ def __init__(self, *args, **kwargs):
self.max_choices = kwargs.pop('max_choices', None)
self.max_length = kwargs.pop('max_length', None)
self.flat_choices = kwargs.pop('flat_choices')
super(MultiSelectFormField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.max_length = get_max_length(self.choices, self.max_length)
self.validators.append(MaxValueMultiFieldValidator(self.max_length))
if self.max_choices is not None:
Expand All @@ -37,4 +36,4 @@ def __init__(self, *args, **kwargs):
self.validators.append(MinChoicesValidator(self.min_choices))

def to_python(self, value):
return MSFList(dict(self.flat_choices), super(MultiSelectFormField, self).to_python(value))
return MSFList(dict(self.flat_choices), super().to_python(value))
Loading
Loading