From 5481a73269fb5a7f936144692939d9be1059976f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 14 Mar 2021 18:17:40 +0100 Subject: [PATCH] trivial: apply black --- combo_plugin_nanterre/__init__.py | 3 ++ combo_plugin_nanterre/urls.py | 27 +++++++---- combo_plugin_nanterre/views.py | 76 +++++++++++++++---------------- setup.py | 23 ++++++---- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/combo_plugin_nanterre/__init__.py b/combo_plugin_nanterre/__init__.py index 23e556a..7cc2780 100644 --- a/combo_plugin_nanterre/__init__.py +++ b/combo_plugin_nanterre/__init__.py @@ -22,12 +22,15 @@ class Plugin(object): def get_apps(self): return [__name__] + class AppConfig(django.apps.AppConfig): name = __name__ verbose_name = _('Nanterre extension') def get_after_urls(self): from . import urls + return urls.urlpatterns + default_app_config = __name__ + '.AppConfig' diff --git a/combo_plugin_nanterre/urls.py b/combo_plugin_nanterre/urls.py index 2cc08e5..00545c7 100644 --- a/combo_plugin_nanterre/urls.py +++ b/combo_plugin_nanterre/urls.py @@ -16,16 +16,23 @@ from django.conf.urls import url -from .views import (saga_transaction, saga_retour_asynchrone, - saga_retour_synchrone, qf_carte_famille) +from .views import saga_transaction, saga_retour_asynchrone, saga_retour_synchrone, qf_carte_famille urlpatterns = [ - url('^_plugin/nanterre/saga-transaction/*$', saga_transaction, - name='nanterre-saga-transaction'), - url('^_plugin/nanterre/saga-retour-asynchrone/*$', saga_retour_asynchrone, - name='nanterre-saga-retour-asynchrone'), - url('^_plugin/nanterre/saga-retour-synchrone/*$', saga_retour_synchrone, - name='nanterre-saga-retour-synchrone'), - url('^_plugin/nanterre/qf-carte-famille/(?P\w+)/$', qf_carte_famille, - name='nanterre-qf-carte-famille'), + url('^_plugin/nanterre/saga-transaction/*$', saga_transaction, name='nanterre-saga-transaction'), + url( + '^_plugin/nanterre/saga-retour-asynchrone/*$', + saga_retour_asynchrone, + name='nanterre-saga-retour-asynchrone', + ), + url( + '^_plugin/nanterre/saga-retour-synchrone/*$', + saga_retour_synchrone, + name='nanterre-saga-retour-synchrone', + ), + url( + '^_plugin/nanterre/qf-carte-famille/(?P\w+)/$', + qf_carte_famille, + name='nanterre-qf-carte-famille', + ), ] diff --git a/combo_plugin_nanterre/views.py b/combo_plugin_nanterre/views.py index 70b11bd..058ee4d 100644 --- a/combo_plugin_nanterre/views.py +++ b/combo_plugin_nanterre/views.py @@ -29,8 +29,7 @@ from django.views.decorators.csrf import csrf_exempt from combo.utils import requests, get_templated_url -ERROR_MESSAGE = ("Le système de paiement n'est pas disponible, " - "veuillez essayer ultérieurement.") +ERROR_MESSAGE = "Le système de paiement n'est pas disponible, " "veuillez essayer ultérieurement." MESSAGE_BY_STATE = { 'paye': (messages.SUCCESS, "Le paiement a bien été effectué."), 'abandon': (messages.WARNING, "Le paiement a été annulé."), @@ -57,10 +56,8 @@ def saga_transaction(request): if 'saga_retour_synchrone' in request.session: del request.session['saga_retour_synchrone'] - urlretour_asynchrone = request.build_absolute_uri( - reverse('nanterre-saga-retour-asynchrone')).rstrip('/') - urlretour_synchrone = request.build_absolute_uri( - reverse('nanterre-saga-retour-synchrone')).rstrip('/') + urlretour_asynchrone = request.build_absolute_uri(reverse('nanterre-saga-retour-asynchrone')).rstrip('/') + urlretour_synchrone = request.build_absolute_uri(reverse('nanterre-saga-retour-synchrone')).rstrip('/') payload = { 'num_factures': num_factures, @@ -71,40 +68,49 @@ def saga_transaction(request): try: saga = rsu_post(request, 'saga/[user_nameid]/transaction/', payload) except: - logger.exception('[rsu/saga] failed to create transaction ' - 'for num_factures=%s', num_factures) + logger.exception('[rsu/saga] failed to create transaction ' 'for num_factures=%s', num_factures) messages.error(request, ERROR_MESSAGE) return HttpResponseRedirect(error_url) if not isinstance(saga, dict): - logger.error('[rsu/saga] failed to create transaction ' - 'for num_factures=%s, received bad response=%r', - num_factures, saga) + logger.error( + '[rsu/saga] failed to create transaction ' 'for num_factures=%s, received bad response=%r', + num_factures, + saga, + ) messages.error(request, ERROR_MESSAGE) return HttpResponseRedirect(error_url) if saga.get('errors'): - logger.warning('[rsu/saga] failed to create transaction ' - 'for num_factures=%s, errors=%r', - num_factures, saga['errors']) + logger.warning( + '[rsu/saga] failed to create transaction ' 'for num_factures=%s, errors=%r', + num_factures, + saga['errors'], + ) for error in saga['errors']: messages.error(request, error) return HttpResponseRedirect(error_url) if saga.get('err') != 0: - logger.warning('[rsu/saga] failed to create transaction ' - 'for num_factures=%s, unknown error, code=%r', - num_factures, saga['err']) + logger.warning( + '[rsu/saga] failed to create transaction ' 'for num_factures=%s, unknown error, code=%r', + num_factures, + saga['err'], + ) messages.error(request, ERROR_MESSAGE) return HttpResponseRedirect(error_url) if not saga.get('data', {}).get('url'): - logger.error('[rsu/saga] failed to create transaction ' - 'for num_factures=%s, response without url: %r', - num_factures, saga) + logger.error( + '[rsu/saga] failed to create transaction ' 'for num_factures=%s, response without url: %r', + num_factures, + saga, + ) messages.error(request, ERROR_MESSAGE) return HttpResponseRedirect(error_url) # finally, response seems good! redirect to payment system URL - logger.info('[rsu/saga] new transaction created ' - 'for num_factures=%s, redirect to %s', - num_factures, saga['data']['url']) + logger.info( + '[rsu/saga] new transaction created ' 'for num_factures=%s, redirect to %s', + num_factures, + saga['data']['url'], + ) return HttpResponseRedirect(saga['data']['url']) @@ -123,8 +129,7 @@ def saga_retour_synchrone(request): return HttpResponseRedirect(next_url) # add a result message and redirect - if (isinstance(saga, dict) and saga.get('err') == 0 and - saga.get('data', {}).get('etat')): + if isinstance(saga, dict) and saga.get('err') == 0 and saga.get('data', {}).get('etat'): etat = saga['data']['etat'] if etat == 'paye': logger.info('[rsu/saga] retour-synchrone: idop=%s etat=%s', idop, etat) @@ -137,12 +142,10 @@ def saga_retour_synchrone(request): logger.info('[rsu/saga] retour-synchrone: idop=%s etat=%s', idop, etat) messages.add_message(request, *MESSAGE_BY_STATE[etat]) else: - logger.error('[rsu/saga] retour-synchrone: idop=%s ' - 'receive unknown etat=%s', idop, etat) + logger.error('[rsu/saga] retour-synchrone: idop=%s ' 'receive unknown etat=%s', idop, etat) messages.error(request, ERROR_MESSAGE) else: - logger.error('[rsu/saga] retour-synchrone: idop=%s ' - 'receive bad response=%r', idop, saga) + logger.error('[rsu/saga] retour-synchrone: idop=%s ' 'receive bad response=%r', idop, saga) messages.error(request, ERROR_MESSAGE) return HttpResponseRedirect(next_url) @@ -162,20 +165,16 @@ def saga_retour_asynchrone(request): err = 1 logger.error('[rsu/saga] retour-asynchrone: cannot post idop=%s', idop) else: - if (isinstance(saga, dict) and saga.get('err') == 0 and - saga.get('data', {}).get('etat')): + if isinstance(saga, dict) and saga.get('err') == 0 and saga.get('data', {}).get('etat'): etat = saga['data']['etat'] if etat in MESSAGE_BY_STATE: - logger.info('[rsu/saga] retour-asynchrone: idop=%s etat=%s', - idop, etat) + logger.info('[rsu/saga] retour-asynchrone: idop=%s etat=%s', idop, etat) else: err = 1 - logger.error('[rsu/saga] retour-asynchrone: idop=%s ' - 'receive unknown etat=%s', idop, etat) + logger.error('[rsu/saga] retour-asynchrone: idop=%s ' 'receive unknown etat=%s', idop, etat) else: err = 1 - logger.error('[rsu/saga] retour-asynchrone: idop=%s ' - 'receive bad response=%r', idop, saga) + logger.error('[rsu/saga] retour-asynchrone: idop=%s ' 'receive bad response=%r', idop, saga) response = HttpResponse(content_type='application/json') response.write(json.dumps({'err': err})) return response @@ -209,8 +208,7 @@ def qf_carte_famille(request, qf_id): logger.warning('fail to get PDF on %s, got JSON: %r', url, carte.content) raise Http404 if content_type != 'application/pdf': - logger.warning('fail to get PDF on %s, got %s: %r', url, content_type, - carte.content[200:]) + logger.warning('fail to get PDF on %s, got %s: %r', url, content_type, carte.content[200:]) raise Http404 filename = 'carte-famille-%s.pdf' % qf_id logger.debug('return %s obtained from %s', filename, url) diff --git a/setup.py b/setup.py index 735bce8..2eeacec 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ from distutils.command.sdist import sdist from distutils.cmd import Command from setuptools import setup, find_packages + class eo_sdist(sdist): def run(self): if os.path.exists('VERSION'): @@ -24,26 +25,28 @@ class eo_sdist(sdist): if os.path.exists('VERSION'): os.remove('VERSION') + def get_version(): 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 - if '-' in result: # not a tagged version + result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v + if '-' in result: # not a tagged version real_number, commit_count, commit_hash = result.split('-', 2) version = '%s.post%s+%s' % (real_number, commit_count, commit_hash) else: 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' @@ -60,6 +63,7 @@ class compile_translations(Command): def run(self): try: from django.core.management import call_command + for path, dirs, files in os.walk('combo_plugin_nanterre'): if 'locale' not in dirs: continue @@ -100,7 +104,8 @@ setup( 'Programming Language :: Python', 'Programming Language :: Python :: 2', ], - install_requires=['django>=1.8, <1.12', + install_requires=[ + 'django>=1.8, <1.12', ], zip_safe=False, entry_points={ @@ -111,5 +116,5 @@ setup( 'compile_translations': compile_translations, 'install_lib': install_lib, 'sdist': eo_sdist, - } + }, )