trivial: apply black/isort

This commit is contained in:
Frédéric Péters 2022-03-29 15:05:26 +02:00
parent 0472d972ca
commit 982f109c17
5 changed files with 73 additions and 50 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):
@ -14,12 +14,25 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ImioLiegeLisrue',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
(
'id',
models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True),
),
('title', models.CharField(max_length=50)),
('slug', models.SlugField(unique=True)),
('description', models.TextField()),
('service_url', models.CharField(help_text='SIG Web Service URL (ex: https://e-services.liege.be:8443/)', max_length=128, verbose_name='Service URL')),
('verify_cert', models.BooleanField(default=True, verbose_name='Check HTTPS Certificate validity')),
(
'service_url',
models.CharField(
help_text='SIG Web Service URL (ex: https://e-services.liege.be:8443/)',
max_length=128,
verbose_name='Service URL',
),
),
(
'verify_cert',
models.BooleanField(default=True, verbose_name='Check HTTPS Certificate validity'),
),
('users', models.ManyToManyField(to='base.ApiUser', blank=True)),
],
options={

View File

@ -14,6 +14,19 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='imioliegelisrue',
name='log_level',
field=models.CharField(default=b'NOTSET', max_length=10, verbose_name='Log Level', choices=[(b'NOTSET', b'NOTSET'), (b'DEBUG', b'DEBUG'), (b'INFO', b'INFO'), (b'WARNING', b'WARNING'), (b'ERROR', b'ERROR'), (b'CRITICAL', b'CRITICAL'), (b'FATAL', b'FATAL')]),
field=models.CharField(
default=b'NOTSET',
max_length=10,
verbose_name='Log Level',
choices=[
(b'NOTSET', b'NOTSET'),
(b'DEBUG', b'DEBUG'),
(b'INFO', b'INFO'),
(b'WARNING', b'WARNING'),
(b'ERROR', b'ERROR'),
(b'CRITICAL', b'CRITICAL'),
(b'FATAL', b'FATAL'),
],
),
),
]

View File

@ -14,11 +14,26 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='imioliegelisrue',
name='profile',
field=models.CharField(default=b'Liege', max_length=100, choices=[(b'LIEGE', b'Liege'), (b'NAMUR', b'Namur')]),
field=models.CharField(
default=b'Liege', max_length=100, choices=[(b'LIEGE', b'Liege'), (b'NAMUR', b'Namur')]
),
),
migrations.AlterField(
model_name='imioliegelisrue',
name='log_level',
field=models.CharField(default=b'INFO', max_length=10, verbose_name='Log Level', choices=[(b'NOTSET', b'NOTSET'), (b'DEBUG', b'DEBUG'), (b'INFO', b'INFO'), (b'WARNING', b'WARNING'), (b'ERROR', b'ERROR'), (b'CRITICAL', b'CRITICAL'), (b'FATAL', b'FATAL')]),
field=models.CharField(
default=b'INFO',
max_length=10,
verbose_name='Log Level',
choices=[
(b'NOTSET', b'NOTSET'),
(b'DEBUG', b'DEBUG'),
(b'INFO', b'INFO'),
(b'WARNING', b'WARNING'),
(b'ERROR', b'ERROR'),
(b'CRITICAL', b'CRITICAL'),
(b'FATAL', b'FATAL'),
],
),
),
]
]

View File

@ -17,7 +17,6 @@
import unicodedata
import requests
from django.db import models
from django.utils.encoding import force_str
from django.utils.translation import ugettext_lazy as _
@ -38,16 +37,12 @@ class ImioLiegeLisrue(BaseResource):
help_text=_("SIG Web Service URL (ex: https://e-services.liege.be:8443/)"),
)
profile = models.CharField(max_length=100, choices=PROFILE_CHOICES, default="Liege")
include_all_of_belgium = models.BooleanField(
default=True, verbose_name=_("Include all of Belgium")
)
include_all_of_belgium = models.BooleanField(default=True, verbose_name=_("Include all of Belgium"))
street_with_postal_code = models.BooleanField(
default=False, verbose_name=_("Return street with postal code")
)
verify_cert = models.BooleanField(
default=True, verbose_name=_("Check HTTPS Certificate validity")
)
verify_cert = models.BooleanField(default=True, verbose_name=_("Check HTTPS Certificate validity"))
category = _("Geographic information system")
@ -83,13 +78,9 @@ class ImioLiegeLisrue(BaseResource):
# url += "jsonlisrue2"
url += "jsonlgrue12/"
if q:
q = force_str(unicodedata.normalize("NFKD", request.GET["q"]).encode(
"ascii", "ignore"
))
q = force_str(unicodedata.normalize("NFKD", request.GET["q"]).encode("ascii", "ignore"))
url += q.lower()
result = requests.get(
url, headers={"Accept": "application/json"}, verify=self.verify_cert
).json()
result = requests.get(url, headers={"Accept": "application/json"}, verify=self.verify_cert).json()
if "data" in result:
result["rues"] = result.pop("data")
if isinstance(result["rues"], list):
@ -117,9 +108,7 @@ class ImioLiegeLisrue(BaseResource):
continue
known_street_labels[street_label] = True
if self.street_with_postal_code:
street_label = u"{} - {}".format(
street_label, str(item.get("codePostal"))
).strip()
street_label = u"{} - {}".format(street_label, str(item.get("codePostal"))).strip()
else:
street_label = street_label.strip()
@ -132,21 +121,16 @@ class ImioLiegeLisrue(BaseResource):
}
)
elif (
(item.get("statutVO") is not None
and item.get("statutVO").get("code") == 1) or "jsonlgrue12" in url
):
item.get("statutVO") is not None and item.get("statutVO").get("code") == 1
) or "jsonlgrue12" in url:
streets.append(
{
"id": item.get("codeRue") or item.get("codeStreet"),
"text": street_label,
"codeCommissariat": item.get("commissariat").get(
"codeCommissariat"
)
"codeCommissariat": item.get("commissariat").get("codeCommissariat")
if item.get("commissariat")
else "",
"libelleCommissariat": item.get("commissariat").get(
"libelleCommissariat"
)
"libelleCommissariat": item.get("commissariat").get("libelleCommissariat")
if item.get("commissariat")
else "",
}
@ -169,14 +153,10 @@ class ImioLiegeLisrue(BaseResource):
else:
url = self.service_url
url = "{}?outSrid=31370".format(url)
q = force_str(unicodedata.normalize("NFKD", request.GET["q"]).encode(
"ascii", "ignore"
))
q = force_str(unicodedata.normalize("NFKD", request.GET["q"]).encode("ascii", "ignore"))
url = "{}&q={}".format(url, q.lower())
result = requests.get(
url, headers={"Accept": "application/json"}, verify=self.verify_cert
).json()
result = requests.get(url, headers={"Accept": "application/json"}, verify=self.verify_cert).json()
streets = []
for item in result:
if item.get("postCode") == postCode or postCode is None:

View File

@ -4,12 +4,12 @@
import os
import subprocess
import sys
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.cmd import Command
from distutils.command.build import build as _build
from distutils.command.sdist import sdist
from distutils.cmd import Command
from setuptools import setup, find_packages
from setuptools import find_packages, setup
from setuptools.command.install_lib import install_lib as _install_lib
class eo_sdist(sdist):
@ -27,14 +27,17 @@ class eo_sdist(sdist):
def get_version():
'''Use the VERSION, if absent generates a version with git describe, if not
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'):
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(
['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
result = p.communicate()[0]
if p.returncode == 0:
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
@ -45,9 +48,7 @@ def get_version():
version = result
return version
else:
return '0.0.post%s' % len(
subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
return '0.0'
@ -64,6 +65,7 @@ class compile_translations(Command):
def run(self):
try:
from django.core.management import call_command
for path, dirs, files in os.walk('passerelle_imio_liege_lisrue'):
if 'locale' not in dirs:
continue
@ -109,5 +111,5 @@ setup(
'compile_translations': compile_translations,
'install_lib': install_lib,
'sdist': eo_sdist,
}
},
)