From 1bf938c33ecc531de52b7e9fb37c05aa168cd6c6 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 13 Oct 2022 18:20:30 +0100 Subject: [PATCH] Make Stripe configurable --- app/local_settings.py | 2 + app/settings.py | 1 + core/models.py | 7 ++- core/templates/base.html | 10 ++-- core/util/django_settings_export.py | 78 +++++++++++++++++++++++++++++ core/views/base.py | 8 +++ 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 core/util/django_settings_export.py diff --git a/app/local_settings.py b/app/local_settings.py index c03f517..2129eec 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -38,3 +38,5 @@ if DEBUG: "127.0.0.1", "10.0.2.2", ] + +SETTINGS_EXPORT = ["STRIPE_ENABLED"] diff --git a/app/settings.py b/app/settings.py index c89b4b4..dda8222 100644 --- a/app/settings.py +++ b/app/settings.py @@ -72,6 +72,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "core.util.django_settings_export.settings_export", ], }, }, diff --git a/core/models.py b/core/models.py index 4045178..a78614f 100644 --- a/core/models.py +++ b/core/models.py @@ -1,9 +1,10 @@ import logging import stripe +from django.conf import settings from django.contrib.auth.models import AbstractUser from django.db import models -from django.conf import settings + from core.lib.customers import get_or_create, update_customer_fields logger = logging.getLogger(__name__) @@ -37,7 +38,9 @@ class User(AbstractUser): """ if settings.STRIPE_ENABLED: if not self.stripe_id: # stripe ID not stored - self.stripe_id = get_or_create(self.email, self.first_name, self.last_name) + self.stripe_id = get_or_create( + self.email, self.first_name, self.last_name + ) to_update = {} if self.email != self._original.email: diff --git a/core/templates/base.html b/core/templates/base.html index ad1acf9..7843324 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -201,10 +201,12 @@ Home - {% if user.is_authenticated %} - - Billing - + {% if settings.STRIPE_ENABLED %} + {% if user.is_authenticated %} + + Billing + + {% endif %} {% endif %} {% if user.is_superuser %}