From 5894145414f353add1608cfbd900a616a22c5841 Mon Sep 17 00:00:00 2001 From: Deep-Chill Date: Mon, 26 Feb 2024 01:38:56 -0800 Subject: [PATCH 1/3] [Work-in-Progress] Conditionally display Group Buy --- saas/forms.py | 19 ++++++++++--------- saas/settings.py | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/saas/forms.py b/saas/forms.py index 3c80c3ab..95195cd2 100644 --- a/saas/forms.py +++ b/saas/forms.py @@ -208,15 +208,16 @@ def __init__(self, *args, **kwargs): if not self.fields['country'].initial: self.fields['country'].initial = country.code self.add_postal_region(country=country) - if 'is_bulk_buyer' in self.initial: - initial = self.initial['is_bulk_buyer'] - if self.instance: - initial = self.instance.is_bulk_buyer - self.fields['is_bulk_buyer'] = forms.BooleanField(required=False, - initial=initial, - label=mark_safe(_("Enable GroupBuy (what is it?)" - ))) + if settings.DISPLAY_GROUP_BUY: + if 'is_bulk_buyer' in self.initial: + initial = self.initial['is_bulk_buyer'] + if self.instance: + initial = self.instance.is_bulk_buyer + self.fields['is_bulk_buyer'] = forms.BooleanField(required=False, + initial=initial, + label=mark_safe(_("Enable GroupBuy (what is it?)" + ))) if 'is_provider' in self.initial: initial = self.initial['is_provider'] if self.instance: diff --git a/saas/settings.py b/saas/settings.py index 9033fbfb..9e32bbdc 100644 --- a/saas/settings.py +++ b/saas/settings.py @@ -98,6 +98,7 @@ 'static', 'data', 'currencies.json'), 'DEFAULT_UNIT': 'usd', 'DISABLE_UPDATES': False, + 'DISPLAY_GROUP_BUY': False, 'EXPIRE_NOTICE_DAYS': [15], 'EXTRA_MIXIN': object, 'EXTRA_FIELD': None, @@ -180,6 +181,7 @@ CREDIT_ON_CREATE = _SETTINGS.get('CREDIT_ON_CREATE') DEFAULT_UNIT = _SETTINGS.get('DEFAULT_UNIT') DISABLE_UPDATES = _SETTINGS.get('DISABLE_UPDATES') +DISPLAY_GROUP_BUY = _SETTINGS.get('DISPLAY_GROUP_BUY') EXPIRE_NOTICE_DAYS = _SETTINGS.get('EXPIRE_NOTICE_DAYS') EXTRA_MIXIN = _SETTINGS.get('EXTRA_MIXIN') INACTIVITY_DAYS = _SETTINGS.get('INACTIVITY_DAYS') From 8b94384a3e6b33734a4af46b6de01fe7901d8702 Mon Sep 17 00:00:00 2001 From: Deep-Chill Date: Mon, 26 Feb 2024 19:26:08 -0800 Subject: [PATCH 2/3] Update settings.py --- saas/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saas/settings.py b/saas/settings.py index 9e32bbdc..627f2400 100644 --- a/saas/settings.py +++ b/saas/settings.py @@ -98,7 +98,7 @@ 'static', 'data', 'currencies.json'), 'DEFAULT_UNIT': 'usd', 'DISABLE_UPDATES': False, - 'DISPLAY_GROUP_BUY': False, + 'DISPLAY_GROUP_BUY': True, 'EXPIRE_NOTICE_DAYS': [15], 'EXTRA_MIXIN': object, 'EXTRA_FIELD': None, From 4b5ab6d4c97981c54eceb6e02ac69d6ab84598e8 Mon Sep 17 00:00:00 2001 From: Deep-Chill Date: Mon, 18 Mar 2024 15:37:01 -0700 Subject: [PATCH 3/3] Changed conditional settings Moved bulk buyer logic to view and changed conditional settings --- saas/forms.py | 19 +++++++++---------- saas/settings.py | 4 ++-- saas/views/profile.py | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/saas/forms.py b/saas/forms.py index 95195cd2..3c80c3ab 100644 --- a/saas/forms.py +++ b/saas/forms.py @@ -208,16 +208,15 @@ def __init__(self, *args, **kwargs): if not self.fields['country'].initial: self.fields['country'].initial = country.code self.add_postal_region(country=country) - if settings.DISPLAY_GROUP_BUY: - if 'is_bulk_buyer' in self.initial: - initial = self.initial['is_bulk_buyer'] - if self.instance: - initial = self.instance.is_bulk_buyer - self.fields['is_bulk_buyer'] = forms.BooleanField(required=False, - initial=initial, - label=mark_safe(_("Enable GroupBuy (what is it?)" - ))) + if 'is_bulk_buyer' in self.initial: + initial = self.initial['is_bulk_buyer'] + if self.instance: + initial = self.instance.is_bulk_buyer + self.fields['is_bulk_buyer'] = forms.BooleanField(required=False, + initial=initial, + label=mark_safe(_("Enable GroupBuy (what is it?)" + ))) if 'is_provider' in self.initial: initial = self.initial['is_provider'] if self.instance: diff --git a/saas/settings.py b/saas/settings.py index 627f2400..4341545f 100644 --- a/saas/settings.py +++ b/saas/settings.py @@ -98,7 +98,7 @@ 'static', 'data', 'currencies.json'), 'DEFAULT_UNIT': 'usd', 'DISABLE_UPDATES': False, - 'DISPLAY_GROUP_BUY': True, + 'DISPLAY_BULK_BUYER_TOGGLE': False, 'EXPIRE_NOTICE_DAYS': [15], 'EXTRA_MIXIN': object, 'EXTRA_FIELD': None, @@ -181,7 +181,7 @@ CREDIT_ON_CREATE = _SETTINGS.get('CREDIT_ON_CREATE') DEFAULT_UNIT = _SETTINGS.get('DEFAULT_UNIT') DISABLE_UPDATES = _SETTINGS.get('DISABLE_UPDATES') -DISPLAY_GROUP_BUY = _SETTINGS.get('DISPLAY_GROUP_BUY') +DISPLAY_BULK_BUYER_TOGGLE = _SETTINGS.get('DISPLAY_BULK_BUYER_TOGGLE') EXPIRE_NOTICE_DAYS = _SETTINGS.get('EXPIRE_NOTICE_DAYS') EXTRA_MIXIN = _SETTINGS.get('EXTRA_MIXIN') INACTIVITY_DAYS = _SETTINGS.get('INACTIVITY_DAYS') diff --git a/saas/views/profile.py b/saas/views/profile.py index 3234fb8a..9eda24c2 100644 --- a/saas/views/profile.py +++ b/saas/views/profile.py @@ -452,7 +452,7 @@ def get_form_class(self): def get_initial(self): kwargs = super(OrganizationProfileView, self).get_initial() - if Plan.objects.exists(): + if Plan.objects.exists() and settings.DISPLAY_BULK_BUYER_TOGGLE: # Do not display the bulk buying option if there are no plans. kwargs.update({'is_bulk_buyer': self.object.is_bulk_buyer}) if _valid_manager(self.request, [get_broker()]):