pylint: fix all warnings (#58764)

This commit is contained in:
Benjamin Dauvergne 2021-11-19 14:22:20 +01:00
parent 11d17843ca
commit 27d45e5b1d
20 changed files with 52 additions and 54 deletions

View File

@ -16,8 +16,6 @@
import csv
import os
import zipfile
from io import BytesIO
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
@ -65,7 +63,8 @@ def export_references_as_fodt(modeladmin, request, queryset):
output_filename = 'references.fodt'
mimetype = 'application/vnd.oasis.opendocument.text'
t = Template(open(template).read())
with open(template) as fd:
t = Template(fd.read())
export = t.render(Context(context)).encode('utf-8')
response = HttpResponse(content=export, content_type=mimetype)

View File

@ -73,7 +73,7 @@ class AnnuaireManager:
yield count, insert_count, update_count, len(obsolete)
def update_annuaire(self):
for stats in self._update_annuaire():
for _ in self._update_annuaire():
pass
def download_and_parse_annuaire(self):

View File

@ -37,15 +37,16 @@ class Command(BaseCommand):
except Exception:
return datetime.strptime(str, '%d/%m/%Y').date()
def load_one_file(self, csv_file_path):
def make_csv_reader(self, csv_file):
for delimiter in [";", "\t"]:
csv_file = open(csv_file_path, encoding='latin1')
csv_file.seek(0)
csv_lines = csv.reader(csv_file, delimiter=delimiter)
first_line = next(csv_lines)
if first_line == self.HEADER:
break
else:
raise CommandError("Invalid CSV file header")
return csv_lines
raise CommandError("Invalid CSV file header")
def load_one_file(self, csv_file_path, csv_lines):
counter = 0
loaded = 0
for line in csv_lines:
@ -74,4 +75,6 @@ class Command(BaseCommand):
@transaction.atomic
def handle(self, *args, **options):
for csv_file_path in args:
self.load_one_file(csv_file_path)
with open(csv_file_path, encoding='latin1') as csv_file:
csv_lines = self.make_csv_reader(csv_file)
self.load_one_file(csv_file_path, csv_lines)

View File

@ -19,7 +19,6 @@ from datetime import date
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils import six
def solde(t=None):

View File

@ -38,7 +38,7 @@ def month_before(date):
@cache
def finances(month=3):
dates = [date.today().replace(day=1)]
for i in range(1, month):
for _ in range(1, month):
dates.append(month_before(dates[-1]))
e = []
lignes = LigneBanquePop.objects.filter(date_valeur__gte=min(dates), montant__gt=0)

View File

@ -17,8 +17,8 @@
import datetime as dt
import django.http as http
from adminsortable2.admin import SortableInlineAdminMixin
from django import http
from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin.options import BaseModelAdmin

View File

@ -26,9 +26,6 @@ from django.utils.translation import ugettext_lazy as _
class PercentagePerYear(list):
def __init__(self, sequence):
super().__init__(sequence)
def __str__(self):
return ','.join(map(lambda p: ':'.join(map(str, [p[0], int(100 * p[1])])), self))
@ -107,7 +104,7 @@ class PercentagePerYearField(models.Field):
kwargs["max_length"] = 64
super().__init__(*args, **kwargs)
def from_db_value(self, value, expression, connection, context):
def from_db_value(self, value, expression, connection):
return self.to_python(value)
def to_python(self, value):

View File

@ -77,9 +77,10 @@ class RapidFactureForm(forms.Form):
errors.append(error)
if errors:
raise forms.ValidationError(errors)
else:
for ligne in lignes:
ligne.save()
for ligne in lignes:
ligne.save()
return self.cleaned_data

View File

@ -1,4 +1,3 @@
import datetime
from decimal import Decimal
import django.core.validators

View File

@ -28,7 +28,6 @@ from django.db.models import F, Q, Sum
from django.db.models.query import QuerySet
from django.db.models.signals import post_delete, post_save
from django.template.loader import get_template
from django.utils import six
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from weasyprint import HTML
@ -87,7 +86,7 @@ class Client(models.Model):
on_delete=models.SET_NULL,
)
def __str__(self):
def __str__(self): # pylint: disable=invalid-str-returned
return self.nom
def clean(self):
@ -154,7 +153,7 @@ class Contrat(models.Model):
def clean(self):
self.numero_marche = self.numero_marche.strip()
def __str__(self):
def __str__(self): # pylint: disable=invalid-str-returned
return self.intitule
class Meta:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.forms import ModelMultipleChoiceField, SelectMultiple
from taggit.managers import TaggableManager
from taggit.managers import TaggableManager as UpstreamTaggableManager
from taggit.models import Tag
@ -52,7 +52,7 @@ class TagField(ModelMultipleChoiceField):
return frozenset(value)
class TaggableManager(TaggableManager):
class TaggableManager(UpstreamTaggableManager):
# Use our own field/widget pair based using Select2 and a MultipleChoiceField
def formfield(self, form_class=TagField, **kwargs):
kwargs.setdefault('queryset', Tag.objects.all())

View File

@ -106,9 +106,11 @@ def income():
invoiced_by_year_and_client[invoice.accounting_year][invoice.client.id] += montant
invoiced_clients_by_year = {}
for year in invoiced_by_year_and_client:
clients = sorted(
invoiced_by_year_and_client[year].keys(),
key=lambda x: -invoiced_by_year_and_client[year][x],
clients = list(
sorted(
invoiced_by_year_and_client[year].keys(),
key=lambda x, year=year: -invoiced_by_year_and_client[year][x],
)
)
invoiced_clients_by_year[year] = clients
contracted_by_year = defaultdict(lambda: Decimal(0))
@ -218,7 +220,7 @@ def income_by_clients(year=None):
clients = sorted(total_by_clients.keys(), key=lambda x: -total_by_clients[x])
running_total = Decimal(0)
# compute pareto index
pareto = dict()
pareto = {}
for client in clients:
running_total += percent_by_clients[client]
pareto[client] = running_total

View File

@ -27,9 +27,9 @@ logger = logging.getLogger('django.server')
@timer(300)
def update_cache(num):
from . import decorators # noqa: C0415
from .eo_banque.templatetags import eo_banque # noqa: F401, C0415
from .eo_facture.templatetags import eo_facture # noqa: F401, C0415
from . import decorators
from .eo_banque.templatetags import eo_banque # noqa pylint: disable=unused-import
from .eo_facture.templatetags import eo_facture # noqa pylint: disable=unused-import
logger.info('updating cache')
for func in decorators.cached_func:

View File

@ -139,22 +139,21 @@ class Workbook:
return ET.tostring(self.get_content_node(), "utf-8")
def save(self, output):
z = zipfile.ZipFile(output, "w")
z.writestr("content.xml", self.get_content())
z.writestr("styles.xml", self.get_styles())
z.writestr("mimetype", "application/vnd.oasis.opendocument.spreadsheet")
z.writestr(
"META-INF/manifest.xml",
"""<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
<manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
<manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="META-INF/manifest.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="mimetype" manifest:media-type="text/plain"/>
</manifest:manifest>""",
)
z.close()
with zipfile.ZipFile(output, "w") as z:
z.writestr("content.xml", self.get_content())
z.writestr("styles.xml", self.get_styles())
z.writestr("mimetype", "application/vnd.oasis.opendocument.spreadsheet")
z.writestr(
"META-INF/manifest.xml",
"""<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
<manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
<manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="META-INF/manifest.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="mimetype" manifest:media-type="text/plain"/>
</manifest:manifest>""",
)
class WorkSheet:

View File

@ -16,7 +16,6 @@
import os.path
import facturx
from django.conf import global_settings
# Django settings for facturation project.

View File

@ -11,6 +11,6 @@ import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eo_gestion.settings')
from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application # pylint: disable=wrong-import-position
application = get_wsgi_application()

View File

@ -27,7 +27,7 @@ def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
for data in DATA:
call_command("loaddata", data)
admin, created = User.objects.update_or_create(
admin, _ = User.objects.update_or_create(
username="admin",
defaults=dict(email="admin@example.com", is_superuser=True, is_staff=True),
)

View File

@ -31,7 +31,7 @@ def test_homepage(app):
contrat_2c210afd24c11596eeaf94bfb = contrats.click('2c210afd24c11596eeaf94bfb', href='change')
str(contrat_2c210afd24c11596eeaf94bfb)
ajouter_un_contrat = homepage.click("Ajouter un contrat")
str(ajouter_un_client)
str(ajouter_un_contrat)
compte_en_banque = homepage.click("Compte en banque")
str(compte_en_banque)
factures = homepage.click("Factures")

View File

@ -53,7 +53,7 @@ def test_add_facturx_from_bytes(fake_invoice_bytes):
'taux_tva': 20.0,
}
facturx_bytes = add_facturx_from_bytes(fake_invoice_bytes, facturx_ctx)
xml_filename, xml_str = facturx.get_facturx_xml_from_pdf(io.BytesIO(facturx_bytes))
_, xml_str = facturx.get_facturx_xml_from_pdf(io.BytesIO(facturx_bytes))
root = ET.fromstring(xml_str)
def helper(root):

View File

@ -52,6 +52,7 @@ commands =
#
[MASTER]
init-hook='import sys; sys.path.append("eo_gestion/vendor")'
profile=no
persistent=yes
cache-size=500