From 0ffaeae32918d959e94e2d94e0a020458a409a3a Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 24 Jul 2019 14:57:34 +0200 Subject: [PATCH] The prolong command. --- src/club/management/__init__.py | 0 src/club/management/commands/__init__.py | 0 src/club/management/commands/prolong.py | 12 ++++++++++++ src/club/payment_methods.py | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/club/management/__init__.py create mode 100644 src/club/management/commands/__init__.py create mode 100644 src/club/management/commands/prolong.py diff --git a/src/club/management/__init__.py b/src/club/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/club/management/commands/__init__.py b/src/club/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/club/management/commands/prolong.py b/src/club/management/commands/prolong.py new file mode 100644 index 000000000..9bc5e68cb --- /dev/null +++ b/src/club/management/commands/prolong.py @@ -0,0 +1,12 @@ +from datetime import timedelta +from django.core.management.base import BaseCommand, CommandError +from django.utils.timezone import now +from club.models import Schedule + + +class Command(BaseCommand): + def handle(self, *args, **options): + for s in Schedule.objects.filter(is_cancelled=False, expires_at__lt=now() + timedelta(1)): + print(s, s.email, s.expires_at) + s.pay(None) + diff --git a/src/club/payment_methods.py b/src/club/payment_methods.py index ca34ace48..a71a67b9a 100644 --- a/src/club/payment_methods.py +++ b/src/club/payment_methods.py @@ -45,9 +45,13 @@ class PayURe(PaymentMethod): def pay(self, request, schedule): # Create order, put it and see what happens next. from .models import PayUOrder + if request is not None: + ip = request.META['REMOTE_ADDR'] + else: + ip = '127.0.0.1' order = PayUOrder.objects.create( pos_id=self.pos_id, - customer_ip=request.META['REMOTE_ADDR'], + customer_ip=ip, schedule=schedule, ) return order.put() -- 2.20.1