From dc6f5dcc5be6b06739fe634e0820366d46db14fc Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Thu, 16 Nov 2023 19:12:59 +0100 Subject: [PATCH 01/17] add recaptcha coe --- dynamicweb/settings/base.py | 3 +++ utils/forms.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 62fe2897..308c9029 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -56,6 +56,9 @@ dotenv.load_dotenv("{0}/.env".format(PROJECT_DIR)) from multisite import SiteID +RECAPTCHA_PUBLIC_KEY = env('RECAPTCHA_PUBLIC_KEY') +RECAPTCHA_PRIVATE_KEY = env('RECAPTCHA_PRIVATE_KEY') + UNGLEICH_BLOG_SITE_ID = int_env("UNGLEICH_BLOG_SITE_ID") SITE_ID = SiteID(default=(UNGLEICH_BLOG_SITE_ID if UNGLEICH_BLOG_SITE_ID > 0 else 1)) diff --git a/utils/forms.py b/utils/forms.py index f35c90f4..92b442af 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -4,6 +4,8 @@ from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ +from captcha.fields import ReCaptchaField + from membership.models import CustomUser from .models import ContactMessage, BillingAddress, UserBillingAddress @@ -188,6 +190,7 @@ class UserBillingAddressForm(forms.ModelForm): class ContactUsForm(forms.ModelForm): error_css_class = 'autofocus' + captcha = ReCaptchaField() class Meta: model = ContactMessage From 9f74c0286e30d2ac68af477d81eb7183426d83f7 Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Thu, 16 Nov 2023 19:24:59 +0100 Subject: [PATCH 02/17] Add installed app --- dynamicweb/settings/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 308c9029..f03042dc 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -128,6 +128,7 @@ INSTALLED_APPS = ( 'djangocms_file', 'djangocms_picture', 'djangocms_video', + 'django_recaptcha', # 'djangocms_flash', # 'djangocms_googlemap', # 'djangocms_inherit', From c5f8660c5532481fa43b4f2ff23542752548abd0 Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:29:10 +0100 Subject: [PATCH 03/17] Disable all saving of contact us form and send emails --- alplora/views.py | 6 +++--- digitalglarus/views.py | 6 +++--- ungleich_page/views.py | 6 +++--- utils/forms.py | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/alplora/views.py b/alplora/views.py index 0a10b4e0..9fcbbc2f 100644 --- a/alplora/views.py +++ b/alplora/views.py @@ -31,9 +31,9 @@ class ContactView(FormView): return context def form_valid(self, form): - form.save() - form.send_email(email_to='info@alplora.ch') - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email(email_to='info@alplora.ch') + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return render(self.request, 'alplora/contact_success.html', {}) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 299327e6..ba1a59f7 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -835,9 +835,9 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): - form.save() - form.send_email() - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email() + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) diff --git a/ungleich_page/views.py b/ungleich_page/views.py index e5a99d8d..372afb86 100644 --- a/ungleich_page/views.py +++ b/ungleich_page/views.py @@ -25,9 +25,9 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): - form.save() - form.send_email() - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email() + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) def get_context_data(self, **kwargs): diff --git a/utils/forms.py b/utils/forms.py index 92b442af..3cc57578 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -4,7 +4,7 @@ from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ -from captcha.fields import ReCaptchaField +from django_recaptcha.fields import ReCaptchaField from membership.models import CustomUser from .models import ContactMessage, BillingAddress, UserBillingAddress @@ -209,11 +209,12 @@ class ContactUsForm(forms.ModelForm): } def send_email(self, email_to='info@digitalglarus.ch'): - text_content = render_to_string( - 'emails/contact.txt', {'data': self.cleaned_data}) - html_content = render_to_string( - 'emails/contact.html', {'data': self.cleaned_data}) - email = EmailMultiAlternatives('Subject', text_content) - email.attach_alternative(html_content, "text/html") - email.to = [email_to] - email.send() + pass + #text_content = render_to_string( + # 'emails/contact.txt', {'data': self.cleaned_data}) + #html_content = render_to_string( + # 'emails/contact.html', {'data': self.cleaned_data}) + #email = EmailMultiAlternatives('Subject', text_content) + #email.attach_alternative(html_content, "text/html") + #email.to = [email_to] + #email.send() From 3c3c614b6b1d0c5993460dd1e21b6f05fb0e2d3c Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:39:12 +0100 Subject: [PATCH 04/17] Debug --- alplora/views.py | 1 + digitalglarus/views.py | 1 + ungleich_page/views.py | 1 + 3 files changed, 3 insertions(+) diff --git a/alplora/views.py b/alplora/views.py index 9fcbbc2f..d628cffc 100644 --- a/alplora/views.py +++ b/alplora/views.py @@ -31,6 +31,7 @@ class ContactView(FormView): return context def form_valid(self, form): + print("alplora contactusform") #form.save() #form.send_email(email_to='info@alplora.ch') #messages.add_message(self.request, messages.SUCCESS, self.success_message) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index ba1a59f7..bf3ed2c6 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -835,6 +835,7 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): + print("digital glarus contactusform") #form.save() #form.send_email() #messages.add_message(self.request, messages.SUCCESS, self.success_message) diff --git a/ungleich_page/views.py b/ungleich_page/views.py index 372afb86..01d1138d 100644 --- a/ungleich_page/views.py +++ b/ungleich_page/views.py @@ -25,6 +25,7 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): + print("ungleich_page contactusform") #form.save() #form.send_email() #messages.add_message(self.request, messages.SUCCESS, self.success_message) From 325d1ffcb94add403cc7c9b60d354d9a16b6ef5e Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:43:49 +0100 Subject: [PATCH 05/17] Ignore more contact f --- datacenterlight/views.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 5bf68e0a..5c333a63 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -63,23 +63,23 @@ class ContactUsView(FormView): ) def form_valid(self, form): - form.save() - from_emails = { - 'glasfaser': 'glasfaser@ungleich.ch' - } - from_page = self.request.POST.get('from_page') - email_data = { - 'subject': "{dcl_text} Message from {sender}".format( - dcl_text=settings.DCL_TEXT, - sender=form.cleaned_data.get('email') - ), - 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, - 'to': [from_emails.get(from_page, 'support@ungleich.ch')], - 'body': "\n".join( - ["%s=%s" % (k, v) for (k, v) in form.cleaned_data.items()]), - 'reply_to': [form.cleaned_data.get('email')], - } - send_plain_email_task.delay(email_data) + #form.save() + #from_emails = { + # 'glasfaser': 'glasfaser@ungleich.ch' + #} + #from_page = self.request.POST.get('from_page') + #email_data = { + # 'subject': "{dcl_text} Message from {sender}".format( + # dcl_text=settings.DCL_TEXT, + # sender=form.cleaned_data.get('email') + # ), + # 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, + # 'to': [from_emails.get(from_page, 'support@ungleich.ch')], + # 'body': "\n".join( + # ["%s=%s" % (k, v) for (k, v) in form.cleaned_data.items()]), + # 'reply_to': [form.cleaned_data.get('email')], + #} + #send_plain_email_task.delay(email_data) if self.request.is_ajax(): return self.render_to_response( self.get_context_data(success=True, contact_form=form)) From a492c3de1bbccab4553ab268a7e8156d1cc51329 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 6 Dec 2023 15:34:23 +0530 Subject: [PATCH 06/17] Add management command --- .../commands/change_ch_vatrate_2023.py | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 hosting/management/commands/change_ch_vatrate_2023.py diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py new file mode 100644 index 00000000..568ba78c --- /dev/null +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -0,0 +1,93 @@ +from django.core.management.base import BaseCommand +import datetime +import csv +import stripe +from hosting.models import VATRates +from utils.hosting_utils import get_vat_rate_for_country +from django.conf import settings + +stripe.api_key = settings.STRIPE_API_PRIVATE_KEY + + +class Command(BaseCommand): + help = '''CH vat rate changes on 2024-01-01 from 7.7% to 8.1%. This commands makes the necessary changes''' + + def handle(self, *args, **options): + MAKE_MODIFS=False + try: + country_to_change = 'CH' + currency_to_change = 'CHF' + new_rate = 0.081 + user_country_vat_rate = get_vat_rate_for_country(country_to_change) + logger.debug("Existing VATRate for %s %s " % (country_to_change, user_country_vat_rate)) + vat_rate = VATRates.objects.get( + territory_codes=country_to_change, start_date__isnull=False, stop_date=None + ) + logger.debug("VAT rate for %s is %s" % (country, vat_rate.rate)) + logger.debug("vat_rate object = %s" % vat_rate) + logger.debug("Create end date for the VATRate %s" % vat_rate.id) + if MAKE_MODIFS: + vat_rate.stop_date = datetime.date(2023, 12, 31) + vat_rate.save() + print("Creating a new VATRate for CH") + obj, created = VATRates.objects.get_or_create( + start_date=datetime.date(2024, 1, 1), + stop_date=None, + territory_codes=country_to_change, + currency_code=currency_to_change, + rate=new_rate, + rate_type="standard", + description="Switzerland standard VAT (added manually on %s)" % datetime.datetime.now() + ) + if created: + logger.debug("Created new VAT Rate for %s with the new rate %s" % (country_to_change, new_rate)) + logger.debug(obj) + else: + logger.debug("VAT Rate for %s already exists with the rate %s" % (country_to_change, new_rate)) + + logger.debug("Getting all subscriptions of %s that need a VAT Rate change") + subscriptions = stripe.Subscription.list(limit=100) # Increase the limit to 100 per page (maximum) + ch_subs = [] + + while subscriptions: + for subscription in subscriptions: + if len(subscription.default_tax_rates) > 0 and subscription.default_tax_rates[0].jurisdiction and subscription.default_tax_rates[0].jurisdiction.lower() == 'ch': + ch_subs.append(subscription) + elif len(subscription.default_tax_rates) > 0: + print("subscription %s belongs to %s" % (subscription.id, subscription.default_tax_rates[0].jurisdiction)) + else: + print("subscription %s does not have a tax rate" % subscription.id) + if subscriptions.has_more: + print("FETCHING MORE") + subscriptions = stripe.Subscription.list(limit=100, starting_after=subscriptions.data[-1]) + else: + break + logger.debug("There are %s ch subscription that need VAT rate update" % len(ch_subs)) + + if MAKE_MODIFS: + print("Making modifications now") + tax_rate_obj = stripe.TaxRate.create( + display_name="VAT", + description="VAT for %s" % country_to_change, + jurisdiction=country_to_change, + percentage=new_rate, + inclusive=False, + ) + stripe_tax_rate = StripeTaxRate.objects.create( + display_name=tax_rate_obj.display_name, + description=tax_rate_obj.description, + jurisdiction=tax_rate_obj.jurisdiction, + percentage=tax_rate_obj.percentage, + inclusive=False, + tax_rate_id=tax_rate_obj.id + ) + + for ch_sub in ch_subs: + ch_sub.default_tax_rates = [stripe_tax_rate.tax_rate_id] + ch_sub.save() + logger.debug("Default tax rate updated for %s" % ch_sub.id) + else: + print("Not making any modifications because MAKE_MODIFS=False") + + except Exception as e: + print(" *** Error occurred. Details {}".format(str(e))) From 5530b48d0dedff5dfc5901fbf6e815fb4fdb6a75 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 11:23:01 +0530 Subject: [PATCH 07/17] Save subscriptions to be changed in a csv --- .../commands/change_ch_vatrate_2023.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 568ba78c..2740be9c 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -64,6 +64,44 @@ class Command(BaseCommand): break logger.debug("There are %s ch subscription that need VAT rate update" % len(ch_subs)) + # CSV column headers + csv_headers = [ + "customer_name", + "subscription_id", + "subscription_name", + "amount", + "vat_rate" + ] + # CSV file name + csv_filename = "ch_subscriptions_change_2024.csv" + # Write subscription data to CSV file + with open(csv_filename, mode='w', newline='') as csv_file: + writer = csv.DictWriter(csv_file, fieldnames=csv_headers) + writer.writeheader() + + for subscription in subscriptions: + subscription_id = subscription["id"] + customer_name = subscription.get("customer", "") + items = subscription.get("items", {}).get("data", []) + + for item in items: + subscription_name = item.get("plan", {}).get("id", "") + amount = item.get("plan", {}).get("amount", "") + vat_rates = item.get("tax_rates", []) + + # Convert amount to a proper format (e.g., cents to dollars) + amount_in_chf = amount / 100 # Adjust this conversion as needed + + # Writing to CSV + writer.writerow({ + "customer_name": customer_name, + "subscription_id": subscription_id, + "subscription_name": subscription_name, + "amount": amount_in_chf, + "vat_rate": ", ".join(vat_rates) # Fill in VAT rate if available + }) + + if MAKE_MODIFS: print("Making modifications now") tax_rate_obj = stripe.TaxRate.create( From ea4ff961c2eb149bb3f469a6690d939881a8e017 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 11:43:29 +0530 Subject: [PATCH 08/17] add missing logging --- hosting/management/commands/change_ch_vatrate_2023.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 2740be9c..d6e2ef05 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand import datetime import csv +import logging import stripe from hosting.models import VATRates from utils.hosting_utils import get_vat_rate_for_country @@ -8,6 +9,7 @@ from django.conf import settings stripe.api_key = settings.STRIPE_API_PRIVATE_KEY +logger = logging.getLogger(__name__) class Command(BaseCommand): help = '''CH vat rate changes on 2024-01-01 from 7.7% to 8.1%. This commands makes the necessary changes''' From a0ade926fb71955435b5c42eae26b76095d55025 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 11:44:52 +0530 Subject: [PATCH 09/17] Fix variable name typo --- hosting/management/commands/change_ch_vatrate_2023.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index d6e2ef05..43cb1d92 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -25,7 +25,7 @@ class Command(BaseCommand): vat_rate = VATRates.objects.get( territory_codes=country_to_change, start_date__isnull=False, stop_date=None ) - logger.debug("VAT rate for %s is %s" % (country, vat_rate.rate)) + logger.debug("VAT rate for %s is %s" % (country_to_change, vat_rate.rate)) logger.debug("vat_rate object = %s" % vat_rate) logger.debug("Create end date for the VATRate %s" % vat_rate.id) if MAKE_MODIFS: From 92e525467968bbf7f9d7156f5ca6c541d89a0565 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:14:48 +0530 Subject: [PATCH 10/17] Fix customer name and vat rate --- .../management/commands/change_ch_vatrate_2023.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 43cb1d92..cbf77060 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -6,6 +6,7 @@ import stripe from hosting.models import VATRates from utils.hosting_utils import get_vat_rate_for_country from django.conf import settings +from membership.models import CustomUser, StripeCustomer stripe.api_key = settings.STRIPE_API_PRIVATE_KEY @@ -81,15 +82,17 @@ class Command(BaseCommand): writer = csv.DictWriter(csv_file, fieldnames=csv_headers) writer.writeheader() - for subscription in subscriptions: + for subscription in ch_subs: subscription_id = subscription["id"] - customer_name = subscription.get("customer", "") + stripe_customer_id = subscription.get("customer", "") + vat_rate = subscription.get("tax_percent", "") + c_user = CustomUser.objects.get( + id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) + customer_name = "%s - %s - %s" % (c_user.name, c_user.email, stripe_customer_id) items = subscription.get("items", {}).get("data", []) - for item in items: subscription_name = item.get("plan", {}).get("id", "") amount = item.get("plan", {}).get("amount", "") - vat_rates = item.get("tax_rates", []) # Convert amount to a proper format (e.g., cents to dollars) amount_in_chf = amount / 100 # Adjust this conversion as needed @@ -100,7 +103,7 @@ class Command(BaseCommand): "subscription_id": subscription_id, "subscription_name": subscription_name, "amount": amount_in_chf, - "vat_rate": ", ".join(vat_rates) # Fill in VAT rate if available + "vat_rate": vat_rate # Fill in VAT rate if available }) From f31838dbe5189c434e7c35e831185b044ccc7eee Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:22:34 +0530 Subject: [PATCH 11/17] Separate fields --- hosting/management/commands/change_ch_vatrate_2023.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index cbf77060..45ec70d9 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -88,7 +88,8 @@ class Command(BaseCommand): vat_rate = subscription.get("tax_percent", "") c_user = CustomUser.objects.get( id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) - customer_name = "%s - %s - %s" % (c_user.name, c_user.email, stripe_customer_id) + customer_name = c_user.name.encode('utf-8') + customer_email = c.user_email items = subscription.get("items", {}).get("data", []) for item in items: subscription_name = item.get("plan", {}).get("id", "") @@ -100,6 +101,8 @@ class Command(BaseCommand): # Writing to CSV writer.writerow({ "customer_name": customer_name, + "customer_email": customer_email, + "stripe_customer_id": stripe_customer_id, "subscription_id": subscription_id, "subscription_name": subscription_name, "amount": amount_in_chf, From 10c167e76bdf3e5e76e4fe2b68498750e195ac18 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:23:52 +0530 Subject: [PATCH 12/17] Fix typo --- hosting/management/commands/change_ch_vatrate_2023.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 45ec70d9..f979ad71 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -89,7 +89,7 @@ class Command(BaseCommand): c_user = CustomUser.objects.get( id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) customer_name = c_user.name.encode('utf-8') - customer_email = c.user_email + customer_email = c_user.user_email items = subscription.get("items", {}).get("data", []) for item in items: subscription_name = item.get("plan", {}).get("id", "") From 3c4881154898438a740be13397ba84563850696d Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:25:07 +0530 Subject: [PATCH 13/17] Fix typo --- hosting/management/commands/change_ch_vatrate_2023.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index f979ad71..f96b36d2 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -89,7 +89,7 @@ class Command(BaseCommand): c_user = CustomUser.objects.get( id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) customer_name = c_user.name.encode('utf-8') - customer_email = c_user.user_email + customer_email = c_user.email items = subscription.get("items", {}).get("data", []) for item in items: subscription_name = item.get("plan", {}).get("id", "") From 36b091700e643a4efe79af0e61514bc6aa4455e3 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:28:03 +0530 Subject: [PATCH 14/17] Fix headers --- hosting/management/commands/change_ch_vatrate_2023.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index f96b36d2..93920904 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -70,6 +70,8 @@ class Command(BaseCommand): # CSV column headers csv_headers = [ "customer_name", + "customer_email", + "stripe_customer_id", "subscription_id", "subscription_name", "amount", From 94a81fc976243a4847fda83a50fa56b0f6d31c1c Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2023 19:49:50 +0530 Subject: [PATCH 15/17] Fix obtaining correct CustomUSer --- hosting/management/commands/change_ch_vatrate_2023.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 93920904..e397a208 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -89,7 +89,7 @@ class Command(BaseCommand): stripe_customer_id = subscription.get("customer", "") vat_rate = subscription.get("tax_percent", "") c_user = CustomUser.objects.get( - id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) + id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].user.id) customer_name = c_user.name.encode('utf-8') customer_email = c_user.email items = subscription.get("items", {}).get("data", []) From 4d3da3387ae7d53fa3e1383ef0bce784d6b6d00f Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2023 20:36:59 +0530 Subject: [PATCH 16/17] Print case where CustomUser is not found in the datbase from Stripe customer id --- .../commands/change_ch_vatrate_2023.py | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index e397a208..46ca2312 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -90,26 +90,29 @@ class Command(BaseCommand): vat_rate = subscription.get("tax_percent", "") c_user = CustomUser.objects.get( id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].user.id) - customer_name = c_user.name.encode('utf-8') - customer_email = c_user.email - items = subscription.get("items", {}).get("data", []) - for item in items: - subscription_name = item.get("plan", {}).get("id", "") - amount = item.get("plan", {}).get("amount", "") + if c_user: + customer_name = c_user.name.encode('utf-8') + customer_email = c_user.email + items = subscription.get("items", {}).get("data", []) + for item in items: + subscription_name = item.get("plan", {}).get("id", "") + amount = item.get("plan", {}).get("amount", "") - # Convert amount to a proper format (e.g., cents to dollars) - amount_in_chf = amount / 100 # Adjust this conversion as needed + # Convert amount to a proper format (e.g., cents to dollars) + amount_in_chf = amount / 100 # Adjust this conversion as needed - # Writing to CSV - writer.writerow({ - "customer_name": customer_name, - "customer_email": customer_email, - "stripe_customer_id": stripe_customer_id, - "subscription_id": subscription_id, - "subscription_name": subscription_name, - "amount": amount_in_chf, - "vat_rate": vat_rate # Fill in VAT rate if available - }) + # Writing to CSV + writer.writerow({ + "customer_name": customer_name, + "customer_email": customer_email, + "stripe_customer_id": stripe_customer_id, + "subscription_id": subscription_id, + "subscription_name": subscription_name, + "amount": amount_in_chf, + "vat_rate": vat_rate # Fill in VAT rate if available + }) + else: + print("No customuser for %s %s" % (stripe_customer_id, subscription_id)) if MAKE_MODIFS: From 4e891ed0bbcd8602402521a939cfc0797bb39f28 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 29 Dec 2023 08:50:58 +0530 Subject: [PATCH 17/17] Update countries list --- utils/fields.py | 88 ++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/utils/fields.py b/utils/fields.py index 48a606cc..ca1115de 100644 --- a/utils/fields.py +++ b/utils/fields.py @@ -1,7 +1,8 @@ from django.utils.translation import ugettext as _ from django.db import models -# http://xml.coverpages.org/country3166.html +# Old: http://xml.coverpages.org/country3166.html +# 2023-12-29: Updated list of countries from https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes COUNTRIES = ( ('AD', _('Andorra')), ('AE', _('United Arab Emirates')), @@ -10,7 +11,6 @@ COUNTRIES = ( ('AI', _('Anguilla')), ('AL', _('Albania')), ('AM', _('Armenia')), - ('AN', _('Netherlands Antilles')), ('AO', _('Angola')), ('AQ', _('Antarctica')), ('AR', _('Argentina')), @@ -18,6 +18,7 @@ COUNTRIES = ( ('AT', _('Austria')), ('AU', _('Australia')), ('AW', _('Aruba')), + ('AX', _('Aland Islands')), ('AZ', _('Azerbaijan')), ('BA', _('Bosnia and Herzegovina')), ('BB', _('Barbados')), @@ -28,11 +29,13 @@ COUNTRIES = ( ('BH', _('Bahrain')), ('BI', _('Burundi')), ('BJ', _('Benin')), + ('BL', _('St. Barts')), ('BM', _('Bermuda')), - ('BN', _('Brunei Darussalam')), + ('BN', _('Brunei')), ('BO', _('Bolivia')), + ('BQ', _('Caribbean Netherlands')), ('BR', _('Brazil')), - ('BS', _('Bahama')), + ('BS', _('Bahamas')), ('BT', _('Bhutan')), ('BV', _('Bouvet Island')), ('BW', _('Botswana')), @@ -40,11 +43,12 @@ COUNTRIES = ( ('BZ', _('Belize')), ('CA', _('Canada')), ('CC', _('Cocos (Keeling) Islands')), + ('CD', _('Congo - Kinshasa')), ('CF', _('Central African Republic')), - ('CG', _('Congo')), + ('CG', _('Congo - Brazzaville')), ('CH', _('Switzerland')), ('CI', _('Ivory Coast')), - ('CK', _('Cook Iislands')), + ('CK', _('Cook Islands')), ('CL', _('Chile')), ('CM', _('Cameroon')), ('CN', _('China')), @@ -52,9 +56,10 @@ COUNTRIES = ( ('CR', _('Costa Rica')), ('CU', _('Cuba')), ('CV', _('Cape Verde')), + ('CW', _('Curacao')), ('CX', _('Christmas Island')), ('CY', _('Cyprus')), - ('CZ', _('Czech Republic')), + ('CZ', _('Czechia')), ('DE', _('Germany')), ('DJ', _('Djibouti')), ('DK', _('Denmark')), @@ -70,16 +75,16 @@ COUNTRIES = ( ('ET', _('Ethiopia')), ('FI', _('Finland')), ('FJ', _('Fiji')), - ('FK', _('Falkland Islands (Malvinas)')), + ('FK', _('Falkland Islands')), ('FM', _('Micronesia')), ('FO', _('Faroe Islands')), ('FR', _('France')), - ('FX', _('France, Metropolitan')), ('GA', _('Gabon')), - ('GB', _('United Kingdom (Great Britain)')), + ('GB', _('United Kingdom')), ('GD', _('Grenada')), ('GE', _('Georgia')), ('GF', _('French Guiana')), + ('GG', _('Guernsey')), ('GH', _('Ghana')), ('GI', _('Gibraltar')), ('GL', _('Greenland')), @@ -93,7 +98,7 @@ COUNTRIES = ( ('GU', _('Guam')), ('GW', _('Guinea-Bissau')), ('GY', _('Guyana')), - ('HK', _('Hong Kong')), + ('HK', _('Hong Kong SAR China')), ('HM', _('Heard & McDonald Islands')), ('HN', _('Honduras')), ('HR', _('Croatia')), @@ -102,12 +107,14 @@ COUNTRIES = ( ('ID', _('Indonesia')), ('IE', _('Ireland')), ('IL', _('Israel')), + ('IM', _('Isle of Man')), ('IN', _('India')), ('IO', _('British Indian Ocean Territory')), ('IQ', _('Iraq')), - ('IR', _('Islamic Republic of Iran')), + ('IR', _('Iran')), ('IS', _('Iceland')), ('IT', _('Italy')), + ('JE', _('Jersey')), ('JM', _('Jamaica')), ('JO', _('Jordan')), ('JP', _('Japan')), @@ -117,14 +124,14 @@ COUNTRIES = ( ('KI', _('Kiribati')), ('KM', _('Comoros')), ('KN', _('St. Kitts and Nevis')), - ('KP', _('Korea, Democratic People\'s Republic of')), - ('KR', _('Korea, Republic of')), + ('KP', _('North Korea')), + ('KR', _('South Korea')), ('KW', _('Kuwait')), ('KY', _('Cayman Islands')), ('KZ', _('Kazakhstan')), - ('LA', _('Lao People\'s Democratic Republic')), + ('LA', _('Laos')), ('LB', _('Lebanon')), - ('LC', _('Saint Lucia')), + ('LC', _('St. Lucia')), ('LI', _('Liechtenstein')), ('LK', _('Sri Lanka')), ('LR', _('Liberia')), @@ -132,20 +139,23 @@ COUNTRIES = ( ('LT', _('Lithuania')), ('LU', _('Luxembourg')), ('LV', _('Latvia')), - ('LY', _('Libyan Arab Jamahiriya')), + ('LY', _('Libya')), ('MA', _('Morocco')), ('MC', _('Monaco')), - ('MD', _('Moldova, Republic of')), + ('MD', _('Moldova')), + ('ME', _('Montenegro')), + ('MF', _('St. Martin')), ('MG', _('Madagascar')), ('MH', _('Marshall Islands')), + ('MK', _('North Macedonia')), ('ML', _('Mali')), + ('MM', _('Myanmar (Burma)')), ('MN', _('Mongolia')), - ('MM', _('Myanmar')), - ('MO', _('Macau')), + ('MO', _('Macao SAR China')), ('MP', _('Northern Mariana Islands')), ('MQ', _('Martinique')), ('MR', _('Mauritania')), - ('MS', _('Monserrat')), + ('MS', _('Montserrat')), ('MT', _('Malta')), ('MU', _('Mauritius')), ('MV', _('Maldives')), @@ -174,15 +184,17 @@ COUNTRIES = ( ('PK', _('Pakistan')), ('PL', _('Poland')), ('PM', _('St. Pierre & Miquelon')), - ('PN', _('Pitcairn')), + ('PN', _('Pitcairn Islands')), ('PR', _('Puerto Rico')), + ('PS', _('Palestinian Territories')), ('PT', _('Portugal')), ('PW', _('Palau')), ('PY', _('Paraguay')), ('QA', _('Qatar')), ('RE', _('Reunion')), ('RO', _('Romania')), - ('RU', _('Russian Federation')), + ('RS', _('Serbia')), + ('RU', _('Russia')), ('RW', _('Rwanda')), ('SA', _('Saudi Arabia')), ('SB', _('Solomon Islands')), @@ -192,17 +204,19 @@ COUNTRIES = ( ('SG', _('Singapore')), ('SH', _('St. Helena')), ('SI', _('Slovenia')), - ('SJ', _('Svalbard & Jan Mayen Islands')), + ('SJ', _('Svalbard and Jan Mayen')), ('SK', _('Slovakia')), ('SL', _('Sierra Leone')), ('SM', _('San Marino')), ('SN', _('Senegal')), ('SO', _('Somalia')), ('SR', _('Suriname')), + ('SS', _('South Sudan')), ('ST', _('Sao Tome & Principe')), ('SV', _('El Salvador')), - ('SY', _('Syrian Arab Republic')), - ('SZ', _('Swaziland')), + ('SX', _('Sint Maarten')), + ('SY', _('Syria')), + ('SZ', _('Eswatini')), ('TC', _('Turks & Caicos Islands')), ('TD', _('Chad')), ('TF', _('French Southern Territories')), @@ -210,36 +224,34 @@ COUNTRIES = ( ('TH', _('Thailand')), ('TJ', _('Tajikistan')), ('TK', _('Tokelau')), + ('TL', _('Timor-Leste')), ('TM', _('Turkmenistan')), ('TN', _('Tunisia')), ('TO', _('Tonga')), - ('TP', _('East Timor')), ('TR', _('Turkey')), ('TT', _('Trinidad & Tobago')), ('TV', _('Tuvalu')), - ('TW', _('Taiwan, Province of China')), - ('TZ', _('Tanzania, United Republic of')), + ('TW', _('Taiwan')), + ('TZ', _('Tanzania')), ('UA', _('Ukraine')), ('UG', _('Uganda')), - ('UM', _('United States Minor Outlying Islands')), - ('US', _('United States of America')), + ('UM', _('U.S. Outlying Islands')), + ('US', _('United States')), ('UY', _('Uruguay')), ('UZ', _('Uzbekistan')), - ('VA', _('Vatican City State (Holy See)')), - ('VC', _('St. Vincent & the Grenadines')), + ('VA', _('Vatican City')), + ('VC', _('St. Vincent & Grenadines')), ('VE', _('Venezuela')), ('VG', _('British Virgin Islands')), - ('VI', _('United States Virgin Islands')), - ('VN', _('Viet Nam')), + ('VI', _('U.S. Virgin Islands')), + ('VN', _('Vietnam')), ('VU', _('Vanuatu')), - ('WF', _('Wallis & Futuna Islands')), + ('WF', _('Wallis & Futuna')), ('WS', _('Samoa')), ('YE', _('Yemen')), ('YT', _('Mayotte')), - ('YU', _('Yugoslavia')), ('ZA', _('South Africa')), ('ZM', _('Zambia')), - ('ZR', _('Zaire')), ('ZW', _('Zimbabwe')), )