trivial: apply new pre-commit configuration (isort & pyupgrade)

This commit is contained in:
Frédéric Péters 2022-08-10 09:00:46 +02:00
parent be137a39c3
commit 6ced0d2180
21 changed files with 50 additions and 94 deletions

View File

@ -14,16 +14,16 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.utils.text import slugify
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core import validators from django.core import validators
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
from .models import EncombrantsManagement, Commune, Street, Sector from .models import Commune, EncombrantsManagement, Sector, Street
class ListValidator(object): class ListValidator:
def __init__(self, item_validator): def __init__(self, item_validator):
self.item_validator = item_validator self.item_validator = item_validator
@ -41,7 +41,7 @@ class CommaSeparatedEmailField(forms.Field):
self.max_length = max_length self.max_length = max_length
self.min_length = min_length self.min_length = min_length
item_validators = [validators.EmailValidator()] item_validators = [validators.EmailValidator()]
super(CommaSeparatedEmailField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
for item_validator in item_validators: for item_validator in item_validators:
self.validators.append(ListValidator(item_validator)) self.validators.append(ListValidator(item_validator))
@ -69,7 +69,7 @@ class EncombrantsManagementForm(forms.ModelForm):
def save(self, commit=True): def save(self, commit=True):
if not self.instance.slug: if not self.instance.slug:
self.instance.slug = slugify(self.instance.title) self.instance.slug = slugify(self.instance.title)
return super(EncombrantsManagementForm, self).save(commit=commit) return super().save(commit=commit)
class EncombrantsManagementUpdateForm(EncombrantsManagementForm): class EncombrantsManagementUpdateForm(EncombrantsManagementForm):
@ -96,7 +96,7 @@ class CommuneForm(forms.ModelForm):
fields = '__all__' fields = '__all__'
def save(self): def save(self):
obj = super(CommuneForm, self).save() obj = super().save()
if self.cleaned_data['streets']: if self.cleaned_data['streets']:
streets = self.cleaned_data['streets'].split('\n') streets = self.cleaned_data['streets'].split('\n')
for street in streets: for street in streets:

View File

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*- import urllib.parse
from datetime import datetime, timedelta
import requests import requests
from datetime import datetime, timedelta
import urllib.parse
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from passerelle.base.signature import sign_url from passerelle.base.signature import sign_url
from passerelle_montpellier_encombrants.utils import email_sectors from passerelle_montpellier_encombrants.utils import email_sectors
@ -47,6 +45,6 @@ class Command(BaseCommand):
if 'err' in response: if 'err' in response:
raise CommandError('Error while retrieving formdefs: %s' % r.json()) raise CommandError('Error while retrieving formdefs: %s' % r.json())
response = [ response = [
x for x in response if x.get('workflow', {}).get('status', {}).get('name') != u'Annulé' x for x in response if x.get('workflow', {}).get('status', {}).get('name') != 'Annulé'
] ]
email_sectors(response, tomorrow) email_sectors(response, tomorrow)

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- from django.db import migrations, models
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- from django.db import migrations, models
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- from django.db import migrations, models
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -13,6 +10,6 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='collectday', name='collectday',
unique_together=set([('sector', 'date')]), unique_together={('sector', 'date')},
), ),
] ]

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- from django.db import migrations, models
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- from django.db import migrations, models
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-01 16:06 # Generated by Django 1.11.8 on 2018-01-01 16:06
from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-11-19 13:51 # Generated by Django 1.11.12 on 2018-11-19 13:51
from __future__ import unicode_literals
from django.db import migrations from django.db import migrations

View File

@ -14,10 +14,9 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.urls import reverse
from django.db import models from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from passerelle.base.models import BaseResource from passerelle.base.models import BaseResource
@ -64,7 +63,7 @@ class Commune(models.Model):
sector = models.ForeignKey(Sector, verbose_name=_('Sector'), on_delete=models.CASCADE) sector = models.ForeignKey(Sector, verbose_name=_('Sector'), on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return u'%s (%s)' % (self.name, self.insee) return '%s (%s)' % (self.name, self.insee)
class Street(models.Model): class Street(models.Model):

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# #
# w.c.s. - web application for online forms # w.c.s. - web application for online forms
# Copyright (C) 2005-2013 Entr'ouvert # Copyright (C) 2005-2013 Entr'ouvert
@ -16,8 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>. # along with this program; if not, see <http://www.gnu.org/licenses/>.
import zipfile
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import zipfile
OFFICE_NS = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0' OFFICE_NS = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'
TABLE_NS = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0' TABLE_NS = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'
@ -25,7 +24,7 @@ TEXT_NS = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'
XLINK_NS = 'http://www.w3.org/1999/xlink' XLINK_NS = 'http://www.w3.org/1999/xlink'
class Workbook(object): class Workbook:
def __init__(self, encoding='utf-8'): def __init__(self, encoding='utf-8'):
self.sheets = [] self.sheets = []
self.encoding = encoding self.encoding = encoding
@ -72,7 +71,7 @@ class Workbook(object):
z.close() z.close()
class WorkSheet(object): class WorkSheet:
def __init__(self, workbook, name): def __init__(self, workbook, name):
self.cells = {} self.cells = {}
self.name = name self.name = name
@ -98,7 +97,7 @@ class WorkSheet(object):
return root return root
class WorkCell(object): class WorkCell:
def __init__(self, worksheet, value, hint=None): def __init__(self, worksheet, value, hint=None):
if value is None: if value is None:
value = '' value = ''

View File

@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls import include, url from django.conf.urls import include, url
from passerelle.urls_utils import decorated_includes, required, app_enabled
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from passerelle.urls_utils import app_enabled, decorated_includes, required
from .views import * from .views import *

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# passerelle-montpellier-encombrants # passerelle-montpellier-encombrants
# Copyright (C) 2015 Entr'ouvert # Copyright (C) 2015 Entr'ouvert
# #
@ -20,10 +18,10 @@
from collections import defaultdict from collections import defaultdict
from io import BytesIO from io import BytesIO
from django.core.mail import EmailMessage
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.core.mail import EmailMessage
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.translation import ugettext_lazy as _
from .models import Commune from .models import Commune
from .ods import Workbook from .ods import Workbook
@ -90,7 +88,7 @@ def email_sectors(formdatas, when):
subject = get_template('passerelle_montpellier_encombrants/email_subject.txt') subject = get_template('passerelle_montpellier_encombrants/email_subject.txt')
message = get_template('passerelle_montpellier_encombrants/email_body.txt') message = get_template('passerelle_montpellier_encombrants/email_body.txt')
header = ('Commune', u'Prénom', 'Nom', 'Numero', 'Voie', 'Date', u'Téléphone', 'Commentaire') header = ('Commune', 'Prénom', 'Nom', 'Numero', 'Voie', 'Date', 'Téléphone', 'Commentaire')
sectors = defaultdict(list) sectors = defaultdict(list)

View File

@ -16,25 +16,24 @@
import datetime import datetime
from django.db import transaction
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.views.generic.base import View from django.views.generic.base import View
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
from django.db import transaction
from passerelle import utils as passerelle_utils from passerelle import utils as passerelle_utils
from .models import EncombrantsManagement, Sector, Commune, CollectDay, Street
from .forms import ( from .forms import (
CommuneForm,
EncombrantsManagementForm, EncombrantsManagementForm,
EncombrantsManagementUpdateForm, EncombrantsManagementUpdateForm,
CommuneForm,
StreetsForm,
NoStreetsCommuneForm, NoStreetsCommuneForm,
SectorForm,
StreetsForm,
) )
from .forms import SectorForm from .models import CollectDay, Commune, EncombrantsManagement, Sector, Street
from .utils import prefix_cleanup, get_sector from .utils import get_sector, prefix_cleanup
class EncombrantsManagementDetailView(DetailView): class EncombrantsManagementDetailView(DetailView):
@ -66,7 +65,7 @@ class SectorListView(ListView):
model = Sector model = Sector
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(SectorListView, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['object'] = EncombrantsManagement.objects.all()[0] context['object'] = EncombrantsManagement.objects.all()[0]
return context return context
@ -95,7 +94,7 @@ class CommuneListView(ListView):
model = Commune model = Commune
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CommuneListView, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['object'] = EncombrantsManagement.objects.all()[0] context['object'] = EncombrantsManagement.objects.all()[0]
return context return context
@ -111,7 +110,7 @@ class CommuneView(DetailView):
model = Commune model = Commune
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CommuneView, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['object'] = EncombrantsManagement.objects.all()[0] context['object'] = EncombrantsManagement.objects.all()[0]
context['commune'] = self.object context['commune'] = self.object
context['streets'] = self.object.street_set.all() context['streets'] = self.object.street_set.all()
@ -135,7 +134,7 @@ class CollectDayListView(ListView):
model = CollectDay model = CollectDay
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CollectDayListView, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['object'] = EncombrantsManagement.objects.all()[0] context['object'] = EncombrantsManagement.objects.all()[0]
return context return context
@ -204,4 +203,4 @@ class StreetEditView(FormView):
Street.objects.create(commune=c, name=s) Street.objects.create(commune=c, name=s)
except Commune.DoesNotExist: except Commune.DoesNotExist:
pass pass
return super(StreetEditView, self).form_valid(form) return super().form_valid(form)

View File

@ -3,12 +3,12 @@
import os import os
import subprocess import subprocess
import sys import sys
from distutils.cmd import Command
from distutils.command.build import build as _build
from setuptools import find_packages, setup
from setuptools.command.install_lib import install_lib as _install_lib from setuptools.command.install_lib import install_lib as _install_lib
from setuptools.command.sdist import sdist from setuptools.command.sdist import sdist
from distutils.command.build import build as _build
from distutils.cmd import Command
from setuptools import setup, find_packages
class eo_sdist(sdist): class eo_sdist(sdist):
@ -29,7 +29,7 @@ def get_version():
tag exists, take 0.0- and add the length of the commit log. tag exists, take 0.0- and add the length of the commit log.
""" """
if os.path.exists('VERSION'): if os.path.exists('VERSION'):
with open('VERSION', 'r') as v: with open('VERSION') as v:
return v.read() return v.read()
if os.path.exists('.git'): if os.path.exists('.git'):
p = subprocess.Popen( p = subprocess.Popen(

View File

@ -1,20 +1,17 @@
# -*- coding: utf-8 -*-
import json
import datetime import datetime
import json
from random import randint from random import randint
from django.test import TestCase from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.urls import reverse from django.urls import reverse
from django.utils.encoding import force_text from django.utils.encoding import force_text
from passerelle_montpellier_encombrants.models import ( from passerelle_montpellier_encombrants.models import (
EncombrantsManagement,
Commune,
Sector,
CollectDay, CollectDay,
Commune,
EncombrantsManagement,
Sector,
Street, Street,
) )