From c5662aa6b64c625875788b4138e7020c3368cd45 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 30 Sep 2020 17:28:31 +0200 Subject: [PATCH 2/4] lingo: move utils functions to file (#46503) --- combo/apps/lingo/utils.py | 28 ++++++++++++++++++++++++++++ combo/apps/lingo/views.py | 11 +---------- 2 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 combo/apps/lingo/utils.py diff --git a/combo/apps/lingo/utils.py b/combo/apps/lingo/utils.py new file mode 100644 index 00000000..91bc85ea --- /dev/null +++ b/combo/apps/lingo/utils.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# lingo - basket and payment system +# Copyright (C) 2020 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.core import signing + + +def signing_dumps(content): + serialization = signing.dumps(content) + return serialization.replace(':', '.') + + +def signing_loads(serialization): + serialization = serialization.replace('.', ':') + return signing.loads(serialization) diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py index 924788ba..d1a97463 100644 --- a/combo/apps/lingo/views.py +++ b/combo/apps/lingo/views.py @@ -48,6 +48,7 @@ from combo.public.views import publish_page from .models import (Regie, BasketItem, Transaction, TransactionOperation, LingoBasketCell, SelfDeclaredInvoicePayment, PaymentBackend, EXPIRED) +from .utils import signing_dumps, signing_loads class ErrorJsonResponse(JsonResponse): @@ -60,16 +61,6 @@ class BadRequestJsonResponse(ErrorJsonResponse): status_code = 400 -def signing_dumps(content): - serialization = signing.dumps(content) - return serialization.replace(':', '.') - - -def signing_loads(serialization): - serialization = serialization.replace('.', ':') - return signing.loads(serialization) - - def get_eopayment_object(request, regie_or_payment_backend, transaction_id=None): payment_backend = regie_or_payment_backend if isinstance(regie_or_payment_backend, Regie): -- 2.20.1