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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.utils.text import slugify
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core import validators
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):
self.item_validator = item_validator
@ -41,7 +41,7 @@ class CommaSeparatedEmailField(forms.Field):
self.max_length = max_length
self.min_length = min_length
item_validators = [validators.EmailValidator()]
super(CommaSeparatedEmailField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for item_validator in item_validators:
self.validators.append(ListValidator(item_validator))
@ -69,7 +69,7 @@ class EncombrantsManagementForm(forms.ModelForm):
def save(self, commit=True):
if not self.instance.slug:
self.instance.slug = slugify(self.instance.title)
return super(EncombrantsManagementForm, self).save(commit=commit)
return super().save(commit=commit)
class EncombrantsManagementUpdateForm(EncombrantsManagementForm):
@ -96,7 +96,7 @@ class CommuneForm(forms.ModelForm):
fields = '__all__'
def save(self):
obj = super(CommuneForm, self).save()
obj = super().save()
if self.cleaned_data['streets']:
streets = self.cleaned_data['streets'].split('\n')
for street in streets:

View File

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
import urllib.parse
from datetime import datetime, timedelta
import requests
from datetime import datetime, timedelta
import urllib.parse
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from passerelle.base.signature import sign_url
from passerelle_montpellier_encombrants.utils import email_sectors
@ -47,6 +45,6 @@ class Command(BaseCommand):
if 'err' in response:
raise CommandError('Error while retrieving formdefs: %s' % r.json())
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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
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

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-01 16:06
from __future__ import unicode_literals
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
from __future__ import unicode_literals
from django.db import migrations

View File

@ -14,10 +14,9 @@
# 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/>.
from django.urls import reverse
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
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)
def __str__(self):
return u'%s (%s)' % (self.name, self.insee)
return '%s (%s)' % (self.name, self.insee)
class Street(models.Model):

View File

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

View File

@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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 passerelle.urls_utils import app_enabled, decorated_includes, required
from .views import *

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# passerelle-montpellier-encombrants
# Copyright (C) 2015 Entr'ouvert
#
@ -20,10 +18,10 @@
from collections import defaultdict
from io import BytesIO
from django.core.mail import EmailMessage
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.utils.translation import ugettext_lazy as _
from .models import Commune
from .ods import Workbook
@ -90,7 +88,7 @@ def email_sectors(formdatas, when):
subject = get_template('passerelle_montpellier_encombrants/email_subject.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)

View File

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

View File

@ -3,12 +3,12 @@
import os
import subprocess
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.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):
@ -29,7 +29,7 @@ def get_version():
tag exists, take 0.0- and add the length of the commit log.
"""
if os.path.exists('VERSION'):
with open('VERSION', 'r') as v:
with open('VERSION') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(

View File

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