From c37156c679a677213b7e2ba24ddb7b31e7035f5e Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 21:50:09 +0200 Subject: [PATCH 01/31] feat: add in-app settings panel using django-constance --- Pipfile | 1 + Pipfile.lock | 42 ++++++++++++--- api/tests.py | 4 +- drfx/settings.py | 36 +++++++------ emails/models.py | 5 +- .../jobs/notify_expiring_requisitions.py | 4 +- users/locale/fi/LC_MESSAGES/django.po | 12 ++--- users/signals.py | 2 + users/templates/mail/application_received.txt | 2 +- users/templates/mail/door_access_denied.txt | 2 +- users/templates/mail/new_application.txt | 2 +- .../templates/mail/welcome_and_next_steps.txt | 2 +- users/tests.py | 12 ++--- www/context_processors.py | 12 ++--- www/templates/www/banktransaction.html | 52 ++++++++----------- www/views.py | 3 +- 16 files changed, 112 insertions(+), 81 deletions(-) diff --git a/Pipfile b/Pipfile index d4f552c4..0631f8fd 100644 --- a/Pipfile +++ b/Pipfile @@ -44,6 +44,7 @@ django-admin-rangefilter = "*" django-oauth-toolkit = ">=1.5.0" dateparser = "*" nordigen = "*" +django-constance = {extras = ["database"], version = "*"} [requires] python_version = "3.9" diff --git a/Pipfile.lock b/Pipfile.lock index 6e15be06..fad8310e 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "34445016f7af6899df54892f8cb13ed94bc654a02fa2753963cd4b83c3939bbc" + "sha256": "58792feb940f48963090423e6f95a5322a7c905d60eb2aded8d5fad6cda897df" }, "pipfile-spec": 6, "requires": { @@ -29,7 +29,7 @@ "sha256:0e79446b10b3ecb499c1556f7e228a53e64a2bfcebd455f370d8927cb5b59e39", "sha256:bc4bdda6717de5a2987436fb8d72f45dc90dd856bdfd512a1314ce90349a0106" ], - "markers": "python_version >= '3.6'", + "markers": "python_full_version >= '3.6.0'", "version": "==4.11.2" }, "certifi": { @@ -309,6 +309,17 @@ "index": "pypi", "version": "==22.3" }, + "django-constance": { + "extras": [ + "database" + ], + "hashes": [ + "sha256:4c6a96a5f2cbce1bc3fa41aa20566b6ee26fbd896c9f91f996518a3a0904f6c8", + "sha256:bf0b392efa18a1f3f464eddb7eb36ac5c02598354a5e31d0d4ce4fc8b535694b" + ], + "index": "pypi", + "version": "==2.9.1" + }, "django-extensions": { "hashes": [ "sha256:2a4f4d757be2563cd1ff7cfdf2e57468f5f931cc88b23cf82ca75717aae504a4", @@ -349,6 +360,13 @@ "index": "pypi", "version": "==2.2.0" }, + "django-picklefield": { + "hashes": [ + "sha256:c786cbeda78d6def2b43bff4840d19787809c8909f7ad683961703060398d356", + "sha256:d77c504df7311e8ec14e8b779f10ca6fec74de6c7f8e2c136e1ef60cf955125d" + ], + "version": "==3.1" + }, "django-rest-auth-forked": { "hashes": [ "sha256:23aa7fafde3eb10b934d8a1ae2d8d7d0d8a69769d2fafd8c02c19715d424d4ce", @@ -537,19 +555,19 @@ }, "openpyxl": { "hashes": [ - "sha256:24d7d361025d186ba91eff58135d50855cf035a84371b891e58fb6eb5125660f", - "sha256:eccedbe1cdd8b2494057e73959b496821141038dbb7eb9266ea59e3f34208231" + "sha256:a0266e033e65f33ee697254b66116a5793c15fc92daf64711080000df4cfe0a8", + "sha256:f06d44e2c973781068bce5ecf860a09bcdb1c7f5ce1facd5e9aa82c92c93ae72" ], "index": "pypi", - "version": "==3.1.0" + "version": "==3.1.1" }, "phonenumbers": { "hashes": [ - "sha256:2e3fd1f3fde226b289489275517c76edf223eafd9f43a2c2c36498a44b73d4b0", - "sha256:6eb2faf29c19f946baf10f1c977a1f856cab90819fe7735b8e141d5407420c4a" + "sha256:1531b42c8c49a1f06b08598441bf1f11fe2618f707c6fc96b581b44aa4f2b0e3", + "sha256:f8bd92975ba7463b7828ae2f95e1037b7e0ab8f023e9e8ffb7c560fd7f5d66d7" ], "index": "pypi", - "version": "==8.13.5" + "version": "==8.13.6" }, "pycparser": { "hashes": [ @@ -864,6 +882,14 @@ } }, "develop": { + "appnope": { + "hashes": [ + "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24", + "sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e" + ], + "markers": "sys_platform == 'darwin'", + "version": "==0.1.3" + }, "astroid": { "hashes": [ "sha256:86b0a340a512c65abf4368b80252754cda17c02cdbbd3f587dddf98112233e7b", diff --git a/api/tests.py b/api/tests.py index 0a606759..876c2794 100644 --- a/api/tests.py +++ b/api/tests.py @@ -15,7 +15,7 @@ from rest_framework_tracking.models import APIRequestLog from users.models import CustomUser, MemberService, NFCCard, ServiceSubscription from api.mulysaoauthvalidator import MulysaOAuth2Validator - +from constance import config class TestOAuthValidator(APITestCase): def setUp(self): @@ -227,7 +227,7 @@ def test_access_phone_notok(self, mock): mail.outbox[0].body, "first ss state", ) - self.assertIn(settings.SITE_URL, mail.outbox[0].body, "siteurl") + self.assertIn(config.SITE_URL, mail.outbox[0].body, "siteurl") self.assertEqual(response.status_code, 481) @override_settings( diff --git a/drfx/settings.py b/drfx/settings.py index e6ccd504..b05e4290 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -35,23 +35,8 @@ # https://docs.djangoproject.com/en/4.1/ref/settings/ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") -# Sitename -SITENAME = "Mulysa" -SITE_URL = "https://mulysa.tld" -PRIVACY_POLICY_URL = "https://example.com/privacy_policy.html" - - -# these are for the receipt functionality -RECEIPTNAME = "Mulysa ry" -RECEIPTREGID = "1234567-8" -RECEIPTSTREET = "Street 12, Somewhere Finland" - # External urls, like links to members guide and rules -ASSOCIATION_RULES_URL = ( - "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/" -) -MEMBERS_GUIDE_URL = "https://wiki.tampere.hacklab.fi/member_s_guide" GITHUB_URL = "https://github.com/TampereHacklab/mulysa" # Application definition @@ -85,6 +70,9 @@ "rangefilter", # ready made registration please # todo: we probably want to write our own + # constance settings manager + "constance.backends.database", + "constance", "rest_auth.registration", # our api and other apps "api", @@ -343,3 +331,21 @@ from .settings_local import * # noqa except ImportError: pass + +# Constance config - configure settings for the app that are editable in django admin +CONSTANCE_CONFIG = { + 'ASSOCIATION_RULES_URL': ("https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", "Link to the rules of the association", str), + "MEMBERS_GUIDE_URL": ("https://wiki.tampere.hacklab.fi/member_s_guide", "Link to the guide for new members", str), + "SITENAME": ("Hacklab Mulysa", 'Name of the hacklab', str), + "SITE_URL": ("https://mulysa.tld", "URL of this site", str), + "PRIVACY_POLICY_URL": ("https://example.com/privacy_policy.html", "Link to privacy policy", str), + # Receipt functionality configuration + "RECEIPT_NAME": ("Mulysa ry", "Name of the association to show on receipts", str), + "RECEIPT_REGID": ("1234567-8", "ID of the association to show on receipts", str), + "RECEIPT_ADDRESS": ("Street 12, Somewhere Finland", "Address to show on receipts", str) +} +CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" + +SESSION_COOKIE_NAME = '__NotReallyHost-sessionid' +LANGUAGE_COOKIE_NAME = '__NotReallyHost-language' +CSRF_COOKIE_NAME = '__NotReallyHost-csrf' diff --git a/emails/models.py b/emails/models.py index 39aa4435..861bc7c2 100644 --- a/emails/models.py +++ b/emails/models.py @@ -8,6 +8,7 @@ from autoslug import AutoSlugField from mailer import send_mail +from constance import config logger = logging.getLogger(__name__) @@ -68,8 +69,8 @@ def queue_to_recipients(self, qs): "user": user, "settings": settings, "email": self, - "SITENAME": settings.SITENAME, - "SITE_URL": settings.SITE_URL, + "SITENAME": config.SITENAME, + "SITE_URL": config.SITE_URL, } subject = self.subject from_email = settings.NOREPLY_FROM_ADDRESS diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index f02544c1..b73809e9 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -6,7 +6,7 @@ from drfx import settings from ..models import Requisition - +from constance import config class Job(DailyJob): help = "Send notifications if there are requisitions that are about to expire" @@ -17,7 +17,7 @@ def execute(self): for r in Requisition.active.filter(valid_until__lte=in_fourteen_days): print("sending alert") send_mail( - f"[{settings.SITENAME}] Requisition about to expire", + f"[{config.SITENAME}] Requisition about to expire", f"Please update the requisition for config: {r.config.id}. It is valid until: {r.valid_until}", settings.NOREPLY_FROM_ADDRESS, [settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS], diff --git a/users/locale/fi/LC_MESSAGES/django.po b/users/locale/fi/LC_MESSAGES/django.po index d4d22bff..4525e69c 100644 --- a/users/locale/fi/LC_MESSAGES/django.po +++ b/users/locale/fi/LC_MESSAGES/django.po @@ -602,14 +602,14 @@ msgstr "" #~ msgid "BIC" #~ msgstr "BIC" -#~ msgid "Best regards %(settings.SITENAME)s hackers!" -#~ msgstr "Terveisin %(settings.SITENAME)s!" +#~ msgid "Best regards %(config.SITENAME)s hackers!" +#~ msgstr "Terveisin %(config.SITENAME)s!" -#~ msgid "Your application to %(settings.SITENAME)s has been rejected." -#~ msgstr "Hakemuksesi %(settings.SITENAME)s:n on hylätty" +#~ msgid "Your application to %(config.SITENAME)s has been rejected." +#~ msgstr "Hakemuksesi %(config.SITENAME)s:n on hylätty" -#~ msgid "New membership application in %(settings.SITENAME)s" -#~ msgstr "Uusi jäsenhakemus vastaanotettu %(settings.SITENAME)s:n" +#~ msgid "New membership application in %(config.SITENAME)s" +#~ msgstr "Uusi jäsenhakemus vastaanotettu %(config.SITENAME)s:n" #~ msgid "Format: DD.MM.YYYY" #~ msgstr "Muoto: PP.KK.VVVV" diff --git a/users/signals.py b/users/signals.py index 0e3a33c1..19555343 100644 --- a/users/signals.py +++ b/users/signals.py @@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _ from utils import referencenumber +from constance import config from . import models @@ -144,6 +145,7 @@ def send_application_received_email( context = { "user": instance.user, "settings": settings, + "config": config, } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? diff --git a/users/templates/mail/application_received.txt b/users/templates/mail/application_received.txt index ee6c4723..b2866246 100644 --- a/users/templates/mail/application_received.txt +++ b/users/templates/mail/application_received.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with siteurl=settings.SITE_URL wikiurl=settings.MEMBERS_GUIDE_URL %} +{% blocktrans with siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} Thank you for applying for membership! We will check your application and get back to you after your application has diff --git a/users/templates/mail/door_access_denied.txt b/users/templates/mail/door_access_denied.txt index 988f19f1..3c5b976f 100644 --- a/users/templates/mail/door_access_denied.txt +++ b/users/templates/mail/door_access_denied.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with first_name=user.first_name method=method siteurl=settings.SITE_URL wikiurl=settings.MEMBERS_GUIDE_URL %} +{% blocktrans with first_name=user.first_name method=method siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} Hi {{first_name}}! We noticed that you tried to access the door by using {{method}} to open it. diff --git a/users/templates/mail/new_application.txt b/users/templates/mail/new_application.txt index 64c15325..43126d78 100644 --- a/users/templates/mail/new_application.txt +++ b/users/templates/mail/new_application.txt @@ -6,7 +6,7 @@ {{user.first_name}} {{user.last_name}} {# TODO: the url should go to the correct application (Or maybe even to accept reject directly ? #} -{{settings.SITE_URL}}{%url 'applications' %} +{{config.SITE_URL}}{%url 'applications' %} {# TODO: show rest of the application information here #} {% endblock %} diff --git a/users/templates/mail/welcome_and_next_steps.txt b/users/templates/mail/welcome_and_next_steps.txt index 230ba6ca..590ad9ce 100644 --- a/users/templates/mail/welcome_and_next_steps.txt +++ b/users/templates/mail/welcome_and_next_steps.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with first_name=user.first_name siteurl=settings.SITE_URL wikiurl=settings.MEMBERS_GUIDE_URL %} +{% blocktrans with first_name=user.first_name siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} Welcome aboard {{first_name}}! Great to have you onboard! Your membership application has been diff --git a/users/tests.py b/users/tests.py index d274f9ef..f522fd6f 100644 --- a/users/tests.py +++ b/users/tests.py @@ -18,7 +18,7 @@ from utils.businesslogic import BusinessLogic from . import models, signals - +from constance import config class TestBusinessLogicSubscriptionExpiries(TestCase): def setUp(self): @@ -220,12 +220,12 @@ def test_emails(self): len(mail.outbox), 2 ) # because this sends one email to the member and one to admins self.assertIn("Kiitos jäsenhakemuksestasi", mail.outbox[0].body, "Thanks") - self.assertIn(settings.SITE_URL, mail.outbox[0].body, "siteurl") - self.assertIn(settings.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") + self.assertIn(config.SITE_URL, mail.outbox[0].body, "siteurl") + self.assertIn(config.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") # for completenes sake, check the admin email also self.assertIn("FirstName LastName", mail.outbox[1].body, "Admin notification") - self.assertIn(settings.SITE_URL, mail.outbox[1].body, "admin url") + self.assertIn(config.SITE_URL, mail.outbox[1].body, "admin url") # empty mailbox for next test mail.outbox = [] @@ -247,8 +247,8 @@ def test_emails(self): mail.outbox[0].body, "phone number found", ) - self.assertIn(settings.SITE_URL, mail.outbox[0].body, "url") - self.assertIn(settings.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") + self.assertIn(config.SITE_URL, mail.outbox[0].body, "url") + self.assertIn(config.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") class ServiceSubscriptionTests(TestCase): diff --git a/www/context_processors.py b/www/context_processors.py index 404cf0e9..554520aa 100644 --- a/www/context_processors.py +++ b/www/context_processors.py @@ -1,12 +1,12 @@ from django.conf import settings - +from constance import config def external_urls(request): return { - "ASSOCIATION_RULES_URL": settings.ASSOCIATION_RULES_URL, - "MEMBERS_GUIDE_URL": settings.MEMBERS_GUIDE_URL, + "ASSOCIATION_RULES_URL": config.ASSOCIATION_RULES_URL, + "MEMBERS_GUIDE_URL": config.MEMBERS_GUIDE_URL, "GITHUB_URL": settings.GITHUB_URL, - "SITENAME": settings.SITENAME, - "SITE_URL": settings.SITE_URL, - "PRIVACY_POLICY_URL": settings.PRIVACY_POLICY_URL, + "SITENAME": config.SITENAME, + "SITE_URL": config.SITE_URL, + "PRIVACY_POLICY_URL": config.PRIVACY_POLICY_URL, } diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index ae247aeb..304d6cd5 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,54 +1,48 @@ -{% extends "www/base.html" %} -{% load i18n %} -{% load bootstrap4 %} -{% block content %} -{% load verbose_names %} +{% extends "www/base.html" %} {% load i18n %} {% load bootstrap4 %} {% block +content %} {% load verbose_names %}

{% trans 'Bank Transaction' %}

- {{ settings.RECEIPTNAME }}
- {{ settings.RECEIPTSTREET}}
- {% trans 'Business ID' %}: {{ settings.RECEIPTREGID}}
+ {{config.RECEIPT_NAME }}
+ {{config.RECEIPT_ADDRESS}}
+ {% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

- {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
+ {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date + }}
{% trans 'Transaction id' %}: {{ banktransaction.id }}
- {% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
- {% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
- {% get_verbose_field_name banktransaction "sender" %}: {{ banktransaction.sender }}
+ {% get_verbose_field_name banktransaction "reference_number" %}: {{ + banktransaction.reference_number }}
+ {% get_verbose_field_name banktransaction "archival_reference" %}: {{ + banktransaction.archival_reference }}
+ {% get_verbose_field_name banktransaction "sender" %}: {{ + banktransaction.sender }}
{% trans 'User' %}: {{ banktransaction.user }}

-

- {% trans 'Grand total' %}: {{ banktransaction.amount }}€ -

+

{% trans 'Grand total' %}: {{ banktransaction.amount }}€

- {# This might require tweaking... for now it seems to be #} - {# enough that it is mentioned that everything is VAT 0% #} -

- {% blocktrans %} - Seller not VAT-liable - {% endblocktrans %} -

+ {# This might require tweaking... for now it seems to be #} {# enough that it + is mentioned that everything is VAT 0% #} +

{% blocktrans %} Seller not VAT-liable {% endblocktrans %}

- {% blocktrans with name=settings.SITENAME %} - Thank you and please tell your friends about {{ name }} :) - {% endblocktrans %} + {% blocktrans with name=config.SITENAME %} Thank you and please tell your + friends about {{ name }} :) {% endblocktrans %}

diff --git a/www/views.py b/www/views.py index d9f24587..5cda0ff6 100644 --- a/www/views.py +++ b/www/views.py @@ -40,7 +40,7 @@ RegistrationUserForm, ) from .decorators import self_or_staff_member_required - +from constance import config class AuthenticatedTemplateView(LoginRequiredMixin, TemplateView): pass @@ -499,6 +499,7 @@ def banktransaction_view(request, banktransactionid): { "banktransaction": banktransaction, "settings": settings, + "config": config, }, ) From 5231138816d66782dce8998463ea4550f5bb917d Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 22:06:42 +0200 Subject: [PATCH 02/31] chore: run black --- drfx/settings.py | 32 ++++++++++++++----- .../jobs/notify_expiring_requisitions.py | 1 + users/tests.py | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index b05e4290..bd14ab3e 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -334,18 +334,34 @@ # Constance config - configure settings for the app that are editable in django admin CONSTANCE_CONFIG = { - 'ASSOCIATION_RULES_URL': ("https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", "Link to the rules of the association", str), - "MEMBERS_GUIDE_URL": ("https://wiki.tampere.hacklab.fi/member_s_guide", "Link to the guide for new members", str), - "SITENAME": ("Hacklab Mulysa", 'Name of the hacklab', str), + "ASSOCIATION_RULES_URL": ( + "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", + "Link to the rules of the association", + str, + ), + "MEMBERS_GUIDE_URL": ( + "https://wiki.tampere.hacklab.fi/member_s_guide", + "Link to the guide for new members", + str, + ), + "SITENAME": ("Hacklab Mulysa", "Name of the hacklab", str), "SITE_URL": ("https://mulysa.tld", "URL of this site", str), - "PRIVACY_POLICY_URL": ("https://example.com/privacy_policy.html", "Link to privacy policy", str), + "PRIVACY_POLICY_URL": ( + "https://example.com/privacy_policy.html", + "Link to privacy policy", + str, + ), # Receipt functionality configuration "RECEIPT_NAME": ("Mulysa ry", "Name of the association to show on receipts", str), "RECEIPT_REGID": ("1234567-8", "ID of the association to show on receipts", str), - "RECEIPT_ADDRESS": ("Street 12, Somewhere Finland", "Address to show on receipts", str) + "RECEIPT_ADDRESS": ( + "Street 12, Somewhere Finland", + "Address to show on receipts", + str, + ), } CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" -SESSION_COOKIE_NAME = '__NotReallyHost-sessionid' -LANGUAGE_COOKIE_NAME = '__NotReallyHost-language' -CSRF_COOKIE_NAME = '__NotReallyHost-csrf' +SESSION_COOKIE_NAME = "__NotReallyHost-sessionid" +LANGUAGE_COOKIE_NAME = "__NotReallyHost-language" +CSRF_COOKIE_NAME = "__NotReallyHost-csrf" diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index b73809e9..5970a81a 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -8,6 +8,7 @@ from ..models import Requisition from constance import config + class Job(DailyJob): help = "Send notifications if there are requisitions that are about to expire" diff --git a/users/tests.py b/users/tests.py index f522fd6f..fdd4b0e8 100644 --- a/users/tests.py +++ b/users/tests.py @@ -20,6 +20,7 @@ from . import models, signals from constance import config + class TestBusinessLogicSubscriptionExpiries(TestCase): def setUp(self): self.user = get_user_model().objects.create_customuser( From 2a3cad3dffd7d5386593eaf7ab1f475487c2de0a Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 22:28:50 +0200 Subject: [PATCH 03/31] fix: revert irrelevant changes to settings --- drfx/settings.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index bd14ab3e..cf08d2d6 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -361,7 +361,3 @@ ), } CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" - -SESSION_COOKIE_NAME = "__NotReallyHost-sessionid" -LANGUAGE_COOKIE_NAME = "__NotReallyHost-language" -CSRF_COOKIE_NAME = "__NotReallyHost-csrf" From f89153f8b4747f24dfdac949c473fd457758d3a3 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 22:33:48 +0200 Subject: [PATCH 04/31] fix: add config to email contexts --- emails/models.py | 1 + users/signals.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/emails/models.py b/emails/models.py index 861bc7c2..48e7a008 100644 --- a/emails/models.py +++ b/emails/models.py @@ -68,6 +68,7 @@ def queue_to_recipients(self, qs): context = { "user": user, "settings": settings, + "config": config, "email": self, "SITENAME": config.SITENAME, "SITE_URL": config.SITE_URL, diff --git a/users/signals.py b/users/signals.py index 19555343..c18d2448 100644 --- a/users/signals.py +++ b/users/signals.py @@ -170,6 +170,7 @@ def send_new_application_waiting_processing_email( context = { "user": instance.user, "settings": settings, + "config": config, } subject = _("New membership application received") from_email = settings.NOREPLY_FROM_ADDRESS @@ -191,6 +192,7 @@ def send_application_approved_email( context = { "user": instance.user, "settings": settings, + "config": config } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? @@ -210,6 +212,7 @@ def send_application_denied_email( context = { "user": instance.user, "settings": settings, + "config": config } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? @@ -268,6 +271,7 @@ def notify_user_door_access_denied(sender, user: models.CustomUser, method, **kw "user": user, "settings": settings, "method": method, + "config": config, } translation.activate(user.language) subject = _("Door access denied") From 52da39013f83b2c31ad432fa372e3f1583ace4e4 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 22:33:51 +0200 Subject: [PATCH 05/31] fix: remove unused import --- users/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/users/tests.py b/users/tests.py index fdd4b0e8..df9a794b 100644 --- a/users/tests.py +++ b/users/tests.py @@ -13,7 +13,6 @@ from mailer.models import Message from rest_framework import status from rest_framework.test import APITestCase -from drfx import settings from utils.businesslogic import BusinessLogic From 0c991c4d1a20853b6b15c9363ed4973664a9d599 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 22:36:51 +0200 Subject: [PATCH 06/31] chore: run black --- users/signals.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/users/signals.py b/users/signals.py index c18d2448..4d25258e 100644 --- a/users/signals.py +++ b/users/signals.py @@ -189,11 +189,7 @@ def send_application_approved_email( instance, instance.user.language ) ) - context = { - "user": instance.user, - "settings": settings, - "config": config - } + context = {"user": instance.user, "settings": settings, "config": config} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been approved") @@ -209,11 +205,7 @@ def send_application_denied_email( sender, instance: models.MembershipApplication, **kwargs ): logger.info("Application denied, sending bye bye email {}".format(instance)) - context = { - "user": instance.user, - "settings": settings, - "config": config - } + context = {"user": instance.user, "settings": settings, "config": config} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been rejected") From c98af16b7a2553fdc042759aa2df042445ca1ac3 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 13 Feb 2023 23:54:47 +0200 Subject: [PATCH 07/31] fix: remove SITE_URL and SITENAME from constance --- api/tests.py | 4 ++-- drfx/settings.py | 2 -- emails/models.py | 6 ++++-- .../jobs/notify_expiring_requisitions.py | 4 ++-- users/locale/fi/LC_MESSAGES/django.po | 12 +++++------ users/signals.py | 21 +++++++++++-------- users/templates/mail/application_received.txt | 2 +- users/templates/mail/door_access_denied.txt | 2 +- users/templates/mail/new_application.txt | 2 +- .../templates/mail/welcome_and_next_steps.txt | 2 +- users/tests.py | 8 ++++--- www/context_processors.py | 6 ++++-- www/templates/www/banktransaction.html | 4 ++-- 13 files changed, 41 insertions(+), 34 deletions(-) diff --git a/api/tests.py b/api/tests.py index 876c2794..6292d1f5 100644 --- a/api/tests.py +++ b/api/tests.py @@ -15,7 +15,7 @@ from rest_framework_tracking.models import APIRequestLog from users.models import CustomUser, MemberService, NFCCard, ServiceSubscription from api.mulysaoauthvalidator import MulysaOAuth2Validator -from constance import config +from django.contrib.sites.models import Site class TestOAuthValidator(APITestCase): def setUp(self): @@ -227,7 +227,7 @@ def test_access_phone_notok(self, mock): mail.outbox[0].body, "first ss state", ) - self.assertIn(config.SITE_URL, mail.outbox[0].body, "siteurl") + self.assertIn(Site.objects.get_current().domain, mail.outbox[0].body, "siteurl") self.assertEqual(response.status_code, 481) @override_settings( diff --git a/drfx/settings.py b/drfx/settings.py index cf08d2d6..16cb5671 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -344,8 +344,6 @@ "Link to the guide for new members", str, ), - "SITENAME": ("Hacklab Mulysa", "Name of the hacklab", str), - "SITE_URL": ("https://mulysa.tld", "URL of this site", str), "PRIVACY_POLICY_URL": ( "https://example.com/privacy_policy.html", "Link to privacy policy", diff --git a/emails/models.py b/emails/models.py index 48e7a008..3f704f70 100644 --- a/emails/models.py +++ b/emails/models.py @@ -9,6 +9,7 @@ from autoslug import AutoSlugField from mailer import send_mail from constance import config +from django.contrib.sites.models import Site logger = logging.getLogger(__name__) @@ -65,13 +66,14 @@ def queue_to_recipients(self, qs): ) ) + site = Site.objects.get_current() context = { "user": user, "settings": settings, "config": config, "email": self, - "SITENAME": config.SITENAME, - "SITE_URL": config.SITE_URL, + "SITENAME": site.name, + "SITE_URL": site.domain, } subject = self.subject from_email = settings.NOREPLY_FROM_ADDRESS diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index 5970a81a..bae9fa27 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -6,7 +6,7 @@ from drfx import settings from ..models import Requisition -from constance import config +from django.contrib.sites.models import Site class Job(DailyJob): @@ -18,7 +18,7 @@ def execute(self): for r in Requisition.active.filter(valid_until__lte=in_fourteen_days): print("sending alert") send_mail( - f"[{config.SITENAME}] Requisition about to expire", + f"[{Site.objects.get_current().name}] Requisition about to expire", f"Please update the requisition for config: {r.config.id}. It is valid until: {r.valid_until}", settings.NOREPLY_FROM_ADDRESS, [settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS], diff --git a/users/locale/fi/LC_MESSAGES/django.po b/users/locale/fi/LC_MESSAGES/django.po index 4525e69c..7bad88ab 100644 --- a/users/locale/fi/LC_MESSAGES/django.po +++ b/users/locale/fi/LC_MESSAGES/django.po @@ -602,14 +602,14 @@ msgstr "" #~ msgid "BIC" #~ msgstr "BIC" -#~ msgid "Best regards %(config.SITENAME)s hackers!" -#~ msgstr "Terveisin %(config.SITENAME)s!" +#~ msgid "Best regards %(site.name)s hackers!" +#~ msgstr "Terveisin %(site.name)s!" -#~ msgid "Your application to %(config.SITENAME)s has been rejected." -#~ msgstr "Hakemuksesi %(config.SITENAME)s:n on hylätty" +#~ msgid "Your application to %(site.name)s has been rejected." +#~ msgstr "Hakemuksesi %(site.name)s:n on hylätty" -#~ msgid "New membership application in %(config.SITENAME)s" -#~ msgstr "Uusi jäsenhakemus vastaanotettu %(config.SITENAME)s:n" +#~ msgid "New membership application in %(site.name)s" +#~ msgstr "Uusi jäsenhakemus vastaanotettu %(site.name)s:n" #~ msgid "Format: DD.MM.YYYY" #~ msgstr "Muoto: PP.KK.VVVV" diff --git a/users/signals.py b/users/signals.py index 4d25258e..244cea37 100644 --- a/users/signals.py +++ b/users/signals.py @@ -14,6 +14,8 @@ from . import models +from django.contrib.sites.models import Site + logger = logging.getLogger(__name__) # @@ -142,11 +144,7 @@ def send_application_received_email( happens next. """ logger.info("Sending thanks for applying membership email to {}".format(instance)) - context = { - "user": instance.user, - "settings": settings, - "config": config, - } + context = {"config": config, "site": Site.objects.get_current()} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Thank you for applying membership and next steps") @@ -170,7 +168,7 @@ def send_new_application_waiting_processing_email( context = { "user": instance.user, "settings": settings, - "config": config, + "site": Site.objects.get_current(), } subject = _("New membership application received") from_email = settings.NOREPLY_FROM_ADDRESS @@ -189,7 +187,12 @@ def send_application_approved_email( instance, instance.user.language ) ) - context = {"user": instance.user, "settings": settings, "config": config} + context = { + "user": instance.user, + "settings": settings, + "config": config, + "site": Site.objects.get_current(), + } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been approved") @@ -205,7 +208,7 @@ def send_application_denied_email( sender, instance: models.MembershipApplication, **kwargs ): logger.info("Application denied, sending bye bye email {}".format(instance)) - context = {"user": instance.user, "settings": settings, "config": config} + context = {"user": instance.user, "settings": settings} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been rejected") @@ -261,9 +264,9 @@ def send_user_activated(sender, instance: models.CustomUser, raw, **kwargs): def notify_user_door_access_denied(sender, user: models.CustomUser, method, **kwargs): context = { "user": user, - "settings": settings, "method": method, "config": config, + "site": Site.objects.get_current(), } translation.activate(user.language) subject = _("Door access denied") diff --git a/users/templates/mail/application_received.txt b/users/templates/mail/application_received.txt index b2866246..29da9b07 100644 --- a/users/templates/mail/application_received.txt +++ b/users/templates/mail/application_received.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} +{% blocktrans with siteurl=site.domain wikiurl=config.MEMBERS_GUIDE_URL %} Thank you for applying for membership! We will check your application and get back to you after your application has diff --git a/users/templates/mail/door_access_denied.txt b/users/templates/mail/door_access_denied.txt index 3c5b976f..bfbbfd2d 100644 --- a/users/templates/mail/door_access_denied.txt +++ b/users/templates/mail/door_access_denied.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with first_name=user.first_name method=method siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} +{% blocktrans with first_name=user.first_name method=method siteurl=site.domain wikiurl=config.MEMBERS_GUIDE_URL %} Hi {{first_name}}! We noticed that you tried to access the door by using {{method}} to open it. diff --git a/users/templates/mail/new_application.txt b/users/templates/mail/new_application.txt index 43126d78..6ebd1801 100644 --- a/users/templates/mail/new_application.txt +++ b/users/templates/mail/new_application.txt @@ -6,7 +6,7 @@ {{user.first_name}} {{user.last_name}} {# TODO: the url should go to the correct application (Or maybe even to accept reject directly ? #} -{{config.SITE_URL}}{%url 'applications' %} +{{site.domain}}{%url 'applications' %} {# TODO: show rest of the application information here #} {% endblock %} diff --git a/users/templates/mail/welcome_and_next_steps.txt b/users/templates/mail/welcome_and_next_steps.txt index 590ad9ce..ba3312d3 100644 --- a/users/templates/mail/welcome_and_next_steps.txt +++ b/users/templates/mail/welcome_and_next_steps.txt @@ -1,7 +1,7 @@ {% extends 'mail/email_base.txt' %} {% load i18n %} {% block content %} -{% blocktrans with first_name=user.first_name siteurl=config.SITE_URL wikiurl=config.MEMBERS_GUIDE_URL %} +{% blocktrans with first_name=user.first_name siteurl=site.domain wikiurl=config.MEMBERS_GUIDE_URL %} Welcome aboard {{first_name}}! Great to have you onboard! Your membership application has been diff --git a/users/tests.py b/users/tests.py index df9a794b..ed00a027 100644 --- a/users/tests.py +++ b/users/tests.py @@ -18,6 +18,7 @@ from . import models, signals from constance import config +from django.contrib.sites.models import Site class TestBusinessLogicSubscriptionExpiries(TestCase): @@ -212,6 +213,7 @@ def setUp(self): def test_emails(self): mail.outbox = [] + site = Site.objects.get_current() # create new application for our user self.application = models.MembershipApplication.objects.create( user=self.user, agreement=True @@ -220,12 +222,12 @@ def test_emails(self): len(mail.outbox), 2 ) # because this sends one email to the member and one to admins self.assertIn("Kiitos jäsenhakemuksestasi", mail.outbox[0].body, "Thanks") - self.assertIn(config.SITE_URL, mail.outbox[0].body, "siteurl") + self.assertIn(site.domain, mail.outbox[0].body, "siteurl") self.assertIn(config.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") # for completenes sake, check the admin email also self.assertIn("FirstName LastName", mail.outbox[1].body, "Admin notification") - self.assertIn(config.SITE_URL, mail.outbox[1].body, "admin url") + self.assertIn(site.domain, mail.outbox[1].body, "admin url") # empty mailbox for next test mail.outbox = [] @@ -247,7 +249,7 @@ def test_emails(self): mail.outbox[0].body, "phone number found", ) - self.assertIn(config.SITE_URL, mail.outbox[0].body, "url") + self.assertIn(site.domain, mail.outbox[0].body, "url") self.assertIn(config.MEMBERS_GUIDE_URL, mail.outbox[0].body, "wikiurl") diff --git a/www/context_processors.py b/www/context_processors.py index 554520aa..200f1f24 100644 --- a/www/context_processors.py +++ b/www/context_processors.py @@ -1,12 +1,14 @@ from django.conf import settings from constance import config +from django.contrib.sites.models import Site def external_urls(request): + site = Site.objects.get_current() return { "ASSOCIATION_RULES_URL": config.ASSOCIATION_RULES_URL, "MEMBERS_GUIDE_URL": config.MEMBERS_GUIDE_URL, "GITHUB_URL": settings.GITHUB_URL, - "SITENAME": config.SITENAME, - "SITE_URL": config.SITE_URL, + "SITENAME": site.name, + "SITE_URL": site.domain, "PRIVACY_POLICY_URL": config.PRIVACY_POLICY_URL, } diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 304d6cd5..18460001 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -41,8 +41,8 @@

{% trans 'Bank Transaction' %}

- {% blocktrans with name=config.SITENAME %} Thank you and please tell your - friends about {{ name }} :) {% endblocktrans %} + {% blocktrans with name=site.name %} Thank you and please tell your friends + about {{ name }} :) {% endblocktrans %}

From 76d27bb50f7be56fc6ad32071edc503d660d648c Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:49:52 +0300 Subject: [PATCH 08/31] fix: undo changes to template code --- www/templates/www/banktransaction.html | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 304d6cd5..fe27bfd4 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,5 +1,8 @@ -{% extends "www/base.html" %} {% load i18n %} {% load bootstrap4 %} {% block -content %} {% load verbose_names %} +{% extends "www/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% blockcontent %} +{% load verbose_names %}

{% trans 'Bank Transaction' %}

@@ -10,23 +13,23 @@

{% trans 'Bank Transaction' %}

{% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

- {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date - }}
+ {% get_verbose_field_name banktransaction "date" %}: + {{ banktransaction.date }}
{% trans 'Transaction id' %}: {{ banktransaction.id }}
- {% get_verbose_field_name banktransaction "reference_number" %}: {{ - banktransaction.reference_number }}
- {% get_verbose_field_name banktransaction "archival_reference" %}: {{ - banktransaction.archival_reference }}
- {% get_verbose_field_name banktransaction "sender" %}: {{ - banktransaction.sender }}
+ {% get_verbose_field_name banktransaction "reference_number" %}: + {{ banktransaction.reference_number }}
+ {% get_verbose_field_name banktransaction "archival_reference" %}: + {{ banktransaction.archival_reference }}
+ {% get_verbose_field_name banktransaction "sender" %}: + {{ banktransaction.sender }}
{% trans 'User' %}: {{ banktransaction.user }}

    {% for servicesubscription in banktransaction.servicesubscription_set.all %}
  • {{servicesubscription.service.name}}
  • - {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all - %} + {% endfor %} + {% for custominvoice in banktransaction.custominvoice_set.all %}
  • {{custominvoice.subscription.service.name}}
  • {% endfor %}
From 0b397d00dc6f4d9323c01b7fdb5befab161997f5 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:50:35 +0300 Subject: [PATCH 09/31] fix: small corrections to template --- www/templates/www/banktransaction.html | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index fe27bfd4..31cceaa6 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -13,15 +13,11 @@

{% trans 'Bank Transaction' %}

{% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

- {% get_verbose_field_name banktransaction "date" %}: - {{ banktransaction.date }}
+ {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
{% trans 'Transaction id' %}: {{ banktransaction.id }}
- {% get_verbose_field_name banktransaction "reference_number" %}: - {{ banktransaction.reference_number }}
- {% get_verbose_field_name banktransaction "archival_reference" %}: - {{ banktransaction.archival_reference }}
- {% get_verbose_field_name banktransaction "sender" %}: - {{ banktransaction.sender }}
+ {% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
+ {% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
+ {% get_verbose_field_name banktransaction "sender" %}: {{ banktransaction.sender }}
{% trans 'User' %}: {{ banktransaction.user }}

From 030be9d9039f0ac7f5e63d29c170161e20d5ea1e Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:53:17 +0300 Subject: [PATCH 10/31] fix: additional corrections --- www/templates/www/banktransaction.html | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 31cceaa6..9f8a828b 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -22,26 +22,34 @@

{% trans 'Bank Transaction' %}

    - {% for servicesubscription in banktransaction.servicesubscription_set.all %} -
  • {{servicesubscription.service.name}}
  • + {% for servicesubscription in +banktransaction.servicesubscription_set.all %} +
  • {{servicesubscription.service.name}}
  • {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all %} -
  • {{custominvoice.subscription.service.name}}
  • +
  • {{custominvoice.subscription.service.name}}
  • {% endfor %}
-

{% trans 'Grand total' %}: {{ banktransaction.amount }}€

+

+ {% trans 'Grand total' %}: {{ banktransaction.amount }}€ +

- {# This might require tweaking... for now it seems to be #} {# enough that it - is mentioned that everything is VAT 0% #} -

{% blocktrans %} Seller not VAT-liable {% endblocktrans %}

+ {# This might require tweaking... for now it seems to be #} + {# enough that it is mentioned that everything is VAT 0% #} +

+ {% blocktrans %} + Seller not VAT-liable + {% endblocktrans %} +

- {% blocktrans with name=config.SITENAME %} Thank you and please tell your - friends about {{ name }} :) {% endblocktrans %} + {% blocktrans with name=config.SITENAME %} + Thank you and please tell your friends about {{ name }} :) + {% endblocktrans %}

From f77d0708dbefc9de2ecc48c7d114f43ce17cc151 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:54:30 +0300 Subject: [PATCH 11/31] fix: correct whitespace --- www/templates/www/banktransaction.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 9f8a828b..1edbd908 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,7 +1,7 @@ -{% extends "www/base.html" %} -{% load i18n %} -{% load bootstrap4 %} -{% blockcontent %} +{% extends "www/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block content %} {% load verbose_names %}

{% trans 'Bank Transaction' %}

@@ -13,7 +13,7 @@

{% trans 'Bank Transaction' %}

{% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

- {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
+ {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
{% trans 'Transaction id' %}: {{ banktransaction.id }}
{% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
{% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
@@ -25,7 +25,7 @@

{% trans 'Bank Transaction' %}

{% for servicesubscription in banktransaction.servicesubscription_set.all %}
  • {{servicesubscription.service.name}}
  • - {% endfor %} + {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all %}
  • {{custominvoice.subscription.service.name}}
  • {% endfor %} @@ -36,18 +36,18 @@

    {% trans 'Bank Transaction' %}

    - {# This might require tweaking... for now it seems to be #} + {# This might require tweaking... for now it seems to be #} {# enough that it is mentioned that everything is VAT 0% #}

    {% blocktrans %} - Seller not VAT-liable + Seller not VAT-liable {% endblocktrans %}

    - {% blocktrans with name=config.SITENAME %} + {% blocktrans with name=config.SITENAME %} Thank you and please tell your friends about {{ name }} :) {% endblocktrans %}

    From 6e80df12c41be0c15d4ee88e4b5f9cd361743d81 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:55:46 +0300 Subject: [PATCH 12/31] fix: make for statement single line --- www/templates/www/banktransaction.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 1edbd908..da26c52f 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -22,8 +22,7 @@

    {% trans 'Bank Transaction' %}

      - {% for servicesubscription in -banktransaction.servicesubscription_set.all %} + {% for servicesubscription in banktransaction.servicesubscription_set.all %}
    • {{servicesubscription.service.name}}
    • {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all %} From 6bc63d6d9bcdebbf136442d304867ecf646f5612 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:57:54 +0300 Subject: [PATCH 13/31] fix: revert irrelevant changes --- www/templates/www/banktransaction.html | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 18460001..73c6cad9 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,5 +1,8 @@ -{% extends "www/base.html" %} {% load i18n %} {% load bootstrap4 %} {% block -content %} {% load verbose_names %} +{% extends "www/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block content %} +{% load verbose_names %}

      {% trans 'Bank Transaction' %}

      @@ -10,39 +13,42 @@

      {% trans 'Bank Transaction' %}

      {% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

      - {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date - }}
      + {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
      {% trans 'Transaction id' %}: {{ banktransaction.id }}
      - {% get_verbose_field_name banktransaction "reference_number" %}: {{ - banktransaction.reference_number }}
      - {% get_verbose_field_name banktransaction "archival_reference" %}: {{ - banktransaction.archival_reference }}
      - {% get_verbose_field_name banktransaction "sender" %}: {{ - banktransaction.sender }}
      + {% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
      + {% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
      + {% get_verbose_field_name banktransaction "sender" %}: {{ banktransaction.sender }}
      {% trans 'User' %}: {{ banktransaction.user }}

        {% for servicesubscription in banktransaction.servicesubscription_set.all %} -
      • {{servicesubscription.service.name}}
      • - {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all - %} -
      • {{custominvoice.subscription.service.name}}
      • +
      • {{servicesubscription.service.name}}
      • + {% endfor %} + {% for custominvoice in banktransaction.custominvoice_set.all %} +
      • {{custominvoice.subscription.service.name}}
      • {% endfor %}
      -

      {% trans 'Grand total' %}: {{ banktransaction.amount }}€

      +

      + {% trans 'Grand total' %}: {{ banktransaction.amount }}€ +

    - {# This might require tweaking... for now it seems to be #} {# enough that it - is mentioned that everything is VAT 0% #} -

    {% blocktrans %} Seller not VAT-liable {% endblocktrans %}

    + {# This might require tweaking... for now it seems to be #} + {# enough that it is mentioned that everything is VAT 0% #} +

    + {% blocktrans %} + Seller not VAT-liable + {% endblocktrans %} +

    - {% blocktrans with name=site.name %} Thank you and please tell your friends - about {{ name }} :) {% endblocktrans %} + {% blocktrans with name=site.nameE %} + Thank you and please tell your friends about {{ name }} :) + {% endblocktrans %}

    From 99448774b785592d69499cf213b4cf32aed27d4b Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:58:27 +0300 Subject: [PATCH 14/31] fix: typo --- www/templates/www/banktransaction.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 73c6cad9..fc1400da 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -46,8 +46,8 @@

    {% trans 'Bank Transaction' %}

    - {% blocktrans with name=site.nameE %} - Thank you and please tell your friends about {{ name }} :) + {% blocktrans with name=site.name %} + Thank you and please tell your friends about {{ name }} :) {% endblocktrans %}

    From 3cd63682a8f5ea8f2fcad7b0e1a8e60ae7d1b7ce Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 27 Mar 2023 07:58:48 +0300 Subject: [PATCH 15/31] fix: remove trailing space --- www/templates/www/banktransaction.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index da26c52f..7d325715 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -47,7 +47,7 @@

    {% trans 'Bank Transaction' %}

    {% blocktrans with name=config.SITENAME %} - Thank you and please tell your friends about {{ name }} :) + Thank you and please tell your friends about {{ name }} :) {% endblocktrans %}

    From 840a35da8baf11002f30b3866d92e89847680493 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Sat, 1 Apr 2023 18:11:42 +0300 Subject: [PATCH 16/31] feat: move account IBAN to constance --- drfx/settings.py | 4 +--- www/templates/www/custominvoice.html | 2 +- www/views.py | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index cf08d2d6..ed11ce3f 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -13,9 +13,6 @@ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "qv*o1&&x%#jtsn)5((g+yw#%3_a$ykfof6b-)j^i$1a8se*7c8" -ACCOUNT_BIC = "BICCODE" -ACCOUNT_IBAN = "FI12 3456 789" -ACCOUNT_NAME = "Account name" # The service ID that opens hacklab door. Avoid using in code. DEFAULT_ACCOUNT_SERVICE = 2 @@ -359,5 +356,6 @@ "Address to show on receipts", str, ), + "ACCOUNT_IBAN":("FI12 3456 789", "IBAN of the association's bank account"), } CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" diff --git a/www/templates/www/custominvoice.html b/www/templates/www/custominvoice.html index 138de2ef..54d6290f 100644 --- a/www/templates/www/custominvoice.html +++ b/www/templates/www/custominvoice.html @@ -41,7 +41,7 @@

    {% trans 'Pending invoices'%}

    {% endfor %} -

    {% blocktrans with bank_iban=settings.ACCOUNT_IBAN %} Custominvoices are paid with the custominvoice specific amount and reference number to bank account: {{bank_iban}}. If the amount or reference number does not match the payment wont be registered. {% endblocktrans %}

    +

    {% blocktrans with bank_iban=config.ACCOUNT_IBAN %} Custominvoices are paid with the custominvoice specific amount and reference number to bank account: {{bank_iban}}. If the amount or reference number does not match the payment wont be registered. {% endblocktrans %}

    {% trans 'Paid invoices'%}

    diff --git a/www/views.py b/www/views.py index 5cda0ff6..cd7490ac 100644 --- a/www/views.py +++ b/www/views.py @@ -237,7 +237,7 @@ def userdetails(request, id): "www/user.html", { "userdetails": userdetails, - "bank_iban": settings.ACCOUNT_IBAN, + "bank_iban": config.ACCOUNT_IBAN, "last_transaction": latest_transaction.date if latest_transaction else "-", }, ) @@ -457,7 +457,7 @@ def custominvoice(request): "days": days, "amount": amount, "servicename": servicename, - "settings": settings, + "config": config, }, ) From ea1600938c71d7d6172d5e48cd9f23c8a1a32880 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Sat, 1 Apr 2023 20:21:53 +0300 Subject: [PATCH 17/31] chore: run black formatter --- drfx/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drfx/settings.py b/drfx/settings.py index ed11ce3f..91a94627 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -356,6 +356,6 @@ "Address to show on receipts", str, ), - "ACCOUNT_IBAN":("FI12 3456 789", "IBAN of the association's bank account"), + "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), } CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" From 987e839535eaae7bd5971ce98fe92add0d6ee304 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Sat, 1 Apr 2023 20:22:11 +0300 Subject: [PATCH 18/31] chore: run black formatter --- drfx/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drfx/settings.py b/drfx/settings.py index 686fc4e6..0b9681c3 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -354,6 +354,6 @@ "Address to show on receipts", str, ), - "ACCOUNT_IBAN":("FI12 3456 789", "IBAN of the association's bank account"), + "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), } CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" From 9862d9c414e698d86ef07cd35f7a071ab605c0e8 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 10:27:31 +0300 Subject: [PATCH 19/31] feat: add config accessor --- api/tests.py | 3 +-- api/views.py | 4 ++-- drfx/__init__.py | 3 +++ drfx/config_accessor.py | 11 +++++++++++ drfx/settings.py | 3 +++ emails/models.py | 2 +- .../jobs/notify_expiring_requisitions.py | 3 +-- users/management/commands/genreferences.py | 2 +- users/models/custom_user.py | 10 ++++------ users/signals.py | 2 +- users/tests.py | 2 +- utils/businesslogic.py | 2 +- www/context_processors.py | 5 ++--- www/templates/www/custominvoice.html | 2 +- www/views.py | 4 ++-- 15 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 drfx/config_accessor.py diff --git a/api/tests.py b/api/tests.py index 876c2794..c9ae391f 100644 --- a/api/tests.py +++ b/api/tests.py @@ -8,14 +8,13 @@ from django.http import HttpRequest from api.models import AccessDevice -from drfx import settings +from drfx import config from rest_framework import status from rest_framework.authtoken.models import Token from rest_framework.test import APITestCase from rest_framework_tracking.models import APIRequestLog from users.models import CustomUser, MemberService, NFCCard, ServiceSubscription from api.mulysaoauthvalidator import MulysaOAuth2Validator -from constance import config class TestOAuthValidator(APITestCase): def setUp(self): diff --git a/api/views.py b/api/views.py index 90e5f6e7..a43d8337 100644 --- a/api/views.py +++ b/api/views.py @@ -3,7 +3,7 @@ from django.shortcuts import get_object_or_404 from api.serializers import AccessDataSerializer, UserAccessSerializer -from drfx import settings as drfx_settings +from drfx import config as config from rest_framework import mixins, status, viewsets from rest_framework.decorators import action from rest_framework.response import Response @@ -110,7 +110,7 @@ def phone_list(self, request, format=None): users_with_door_access = [] for ss in ( ServiceSubscription.objects.select_related("user") - .filter(service=drfx_settings.DEFAULT_ACCOUNT_SERVICE) + .filter(service=config.DEFAULT_ACCOUNT_SERVICE) .filter(state=ServiceSubscription.ACTIVE) ): users_with_door_access.append(ss.user) diff --git a/drfx/__init__.py b/drfx/__init__.py index e69de29b..be27a183 100644 --- a/drfx/__init__.py +++ b/drfx/__init__.py @@ -0,0 +1,3 @@ +from drfx.config_accessor import ConfigAccessor + +config = ConfigAccessor() diff --git a/drfx/config_accessor.py b/drfx/config_accessor.py new file mode 100644 index 00000000..e617c6cf --- /dev/null +++ b/drfx/config_accessor.py @@ -0,0 +1,11 @@ +from drfx import config +from django.conf import settings + +# A class that accesses configuration variables from constance or settings +class ConfigAccessor(object): + def __getattr__(self, key): + try: + value = getattr(config, key, None) + return value if value is not None else getattr(settings, key) + except: + raise AttributeError(f"Config variable {key} not found in constance configuration or local settings") diff --git a/drfx/settings.py b/drfx/settings.py index 91a94627..ee76536c 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -323,6 +323,9 @@ # from utils import businesslogic +# Uncomment this if you wish to set the IBAN through the settings file instead of Constance +# ACCOUNT_IBAN = "FI12 3456 789" + # Load non-default settings from settings_local.py if it exists try: from .settings_local import * # noqa diff --git a/emails/models.py b/emails/models.py index 48e7a008..ec5d98bf 100644 --- a/emails/models.py +++ b/emails/models.py @@ -8,7 +8,7 @@ from autoslug import AutoSlugField from mailer import send_mail -from constance import config +from drfx import config logger = logging.getLogger(__name__) diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index 5970a81a..755061e8 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -4,9 +4,8 @@ from django.utils import timezone from django.core.mail import send_mail -from drfx import settings +from drfx import config from ..models import Requisition -from constance import config class Job(DailyJob): diff --git a/users/management/commands/genreferences.py b/users/management/commands/genreferences.py index df2ea596..a06febaf 100644 --- a/users/management/commands/genreferences.py +++ b/users/management/commands/genreferences.py @@ -1,6 +1,6 @@ from django.core.management.base import BaseCommand -from drfx import settings +from drfx import config from users.models import ServiceSubscription from utils import referencenumber diff --git a/users/models/custom_user.py b/users/models/custom_user.py index d710d7a2..6ef96cfd 100644 --- a/users/models/custom_user.py +++ b/users/models/custom_user.py @@ -7,10 +7,8 @@ from users.custom_user_manager import CustomUserManager from users.models.service_subscription import ServiceSubscription from users.models.users_log import UsersLog - from users.validators import validate_mxid, validate_phone - -from drfx import settings as drfx_settings +from drfx import config logger = logging.getLogger(__name__) @@ -107,8 +105,8 @@ class Meta: max_length=10, verbose_name=_("Language"), help_text=_("Language preferred by user"), - choices=drfx_settings.LANGUAGES, - default=drfx_settings.LANGUAGE_CODE, + choices=config.LANGUAGES, + default=config.LANGUAGE_CODE, ) # some datetime bits @@ -165,7 +163,7 @@ def has_door_access(self): return False try: subscription = self.servicesubscription_set.get( - service=drfx_settings.DEFAULT_ACCOUNT_SERVICE + service=config.DEFAULT_ACCOUNT_SERVICE ) if subscription.state == ServiceSubscription.ACTIVE: return True diff --git a/users/signals.py b/users/signals.py index 4d25258e..f0d1477b 100644 --- a/users/signals.py +++ b/users/signals.py @@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _ from utils import referencenumber -from constance import config +from drfx import config from . import models diff --git a/users/tests.py b/users/tests.py index df9a794b..d406de3c 100644 --- a/users/tests.py +++ b/users/tests.py @@ -17,7 +17,7 @@ from utils.businesslogic import BusinessLogic from . import models, signals -from constance import config +from drfx import config class TestBusinessLogicSubscriptionExpiries(TestCase): diff --git a/utils/businesslogic.py b/utils/businesslogic.py index 99d46609..997aeb53 100644 --- a/utils/businesslogic.py +++ b/utils/businesslogic.py @@ -6,7 +6,7 @@ from django.utils import timezone, translation from django.utils.translation import gettext as _ -from drfx import settings +from drfx import config from mailer import send_mail from users.models import ( BankTransaction, diff --git a/www/context_processors.py b/www/context_processors.py index 554520aa..b6de09c5 100644 --- a/www/context_processors.py +++ b/www/context_processors.py @@ -1,11 +1,10 @@ -from django.conf import settings -from constance import config +from drfx import config def external_urls(request): return { "ASSOCIATION_RULES_URL": config.ASSOCIATION_RULES_URL, "MEMBERS_GUIDE_URL": config.MEMBERS_GUIDE_URL, - "GITHUB_URL": settings.GITHUB_URL, + "GITHUB_URL": config.GITHUB_URL, "SITENAME": config.SITENAME, "SITE_URL": config.SITE_URL, "PRIVACY_POLICY_URL": config.PRIVACY_POLICY_URL, diff --git a/www/templates/www/custominvoice.html b/www/templates/www/custominvoice.html index 54d6290f..ee332656 100644 --- a/www/templates/www/custominvoice.html +++ b/www/templates/www/custominvoice.html @@ -41,7 +41,7 @@

    {% trans 'Pending invoices'%}

    {% endfor %} -

    {% blocktrans with bank_iban=config.ACCOUNT_IBAN %} Custominvoices are paid with the custominvoice specific amount and reference number to bank account: {{bank_iban}}. If the amount or reference number does not match the payment wont be registered. {% endblocktrans %}

    +

    {% blocktrans with bank_iban=account_iban %} Custominvoices are paid with the custominvoice specific amount and reference number to bank account: {{bank_iban}}. If the amount or reference number does not match the payment wont be registered. {% endblocktrans %}

    {% trans 'Paid invoices'%}

    diff --git a/www/views.py b/www/views.py index cd7490ac..4654cd20 100644 --- a/www/views.py +++ b/www/views.py @@ -15,7 +15,7 @@ from django.utils.safestring import mark_safe from api.models import DeviceAccessLogEntry -from drfx import settings +from drfx import config from users.models import ( BankTransaction, CustomInvoice, @@ -40,7 +40,6 @@ RegistrationUserForm, ) from .decorators import self_or_staff_member_required -from constance import config class AuthenticatedTemplateView(LoginRequiredMixin, TemplateView): pass @@ -457,6 +456,7 @@ def custominvoice(request): "days": days, "amount": amount, "servicename": servicename, + "account_iban": config.ACCOUNT_IBAN, "config": config, }, ) From b1b63d10cd8f2dc88d9d0b37863cd996769b116f Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 11:06:11 +0300 Subject: [PATCH 20/31] fix: fix imports --- .../0005_deviceaccesslogentry_claimed_by.py | 7 ++-- api/migrations/0006_auto_20201201_1558.py | 7 ++-- api/tests.py | 4 +-- drfx/__init__.py | 1 + drfx/config_accessor.py | 8 +++-- emails/models.py | 8 ++--- .../jobs/notify_expiring_requisitions.py | 4 +-- users/management/commands/genreferences.py | 2 +- users/middleware/language.py | 4 +-- users/migrations/0001_initial.py | 10 +++--- users/migrations/0003_custominvoice.py | 4 +-- users/migrations/0012_nfccard.py | 4 +-- users/migrations/0019_auto_20200616_1207.py | 4 +-- users/signals.py | 35 ++++++++----------- utils/businesslogic.py | 6 ++-- www/views.py | 3 +- 16 files changed, 52 insertions(+), 59 deletions(-) diff --git a/api/migrations/0005_deviceaccesslogentry_claimed_by.py b/api/migrations/0005_deviceaccesslogentry_claimed_by.py index ef687c9b..628628a8 100644 --- a/api/migrations/0005_deviceaccesslogentry_claimed_by.py +++ b/api/migrations/0005_deviceaccesslogentry_claimed_by.py @@ -1,6 +1,6 @@ # Generated by Django 3.0.11 on 2020-11-30 23:23 -from django.conf import settings +from drfx import config from django.db import migrations, models import django.db.models.deletion @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), + migrations.swappable_dependency(config.AUTH_USER_MODEL), ('api', '0004_deviceaccesslogentry'), ] @@ -16,6 +16,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='deviceaccesslogentry', name='claimed_by', - field=models.ForeignKey(help_text='Who claimed this entry', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='User who claimed this'), + field=models.ForeignKey(help_text='Who claimed this entry', null=True, on_delete=django.db.models.deletion.SET_NULL, + to=config.AUTH_USER_MODEL, verbose_name='User who claimed this'), ), ] diff --git a/api/migrations/0006_auto_20201201_1558.py b/api/migrations/0006_auto_20201201_1558.py index 3a77e934..370d55d6 100644 --- a/api/migrations/0006_auto_20201201_1558.py +++ b/api/migrations/0006_auto_20201201_1558.py @@ -1,6 +1,6 @@ # Generated by Django 3.0.7 on 2020-12-01 15:58 -from django.conf import settings +from drfx import config from django.db import migrations, models import django.db.models.deletion @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), + migrations.swappable_dependency(config.AUTH_USER_MODEL), ('api', '0005_deviceaccesslogentry_claimed_by'), ] @@ -16,6 +16,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='deviceaccesslogentry', name='claimed_by', - field=models.ForeignKey(help_text='Who claimed this entry', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='Claimed by'), + field=models.ForeignKey(help_text='Who claimed this entry', null=True, on_delete=django.db.models.deletion.SET_NULL, + to=config.AUTH_USER_MODEL, verbose_name='Claimed by'), ), ] diff --git a/api/tests.py b/api/tests.py index c9ae391f..c8aab5ed 100644 --- a/api/tests.py +++ b/api/tests.py @@ -106,7 +106,7 @@ def setUp(self): # add subscription for the user self.ok_subscription = ServiceSubscription.objects.create( user=self.ok_user, - service=MemberService.objects.get(pk=settings.DEFAULT_ACCOUNT_SERVICE), + service=MemberService.objects.get(pk=config.DEFAULT_ACCOUNT_SERVICE), state=ServiceSubscription.ACTIVE, ) self.ok_subscription.save() @@ -134,7 +134,7 @@ def setUp(self): # with suspended service self.fail_subscription = ServiceSubscription.objects.create( user=self.fail_user, - service=MemberService.objects.get(pk=settings.DEFAULT_ACCOUNT_SERVICE), + service=MemberService.objects.get(pk=config.DEFAULT_ACCOUNT_SERVICE), state=ServiceSubscription.SUSPENDED, ) # and a test card for fail case diff --git a/drfx/__init__.py b/drfx/__init__.py index be27a183..0312690f 100644 --- a/drfx/__init__.py +++ b/drfx/__init__.py @@ -1,3 +1,4 @@ from drfx.config_accessor import ConfigAccessor + config = ConfigAccessor() diff --git a/drfx/config_accessor.py b/drfx/config_accessor.py index e617c6cf..306d7914 100644 --- a/drfx/config_accessor.py +++ b/drfx/config_accessor.py @@ -1,4 +1,4 @@ -from drfx import config +from constance import config from django.conf import settings # A class that accesses configuration variables from constance or settings @@ -7,5 +7,7 @@ def __getattr__(self, key): try: value = getattr(config, key, None) return value if value is not None else getattr(settings, key) - except: - raise AttributeError(f"Config variable {key} not found in constance configuration or local settings") + except AttributeError: + raise AttributeError( + f"Config variable {key} not found in constance configuration or local settings" + ) diff --git a/emails/models.py b/emails/models.py index ec5d98bf..435e2fc0 100644 --- a/emails/models.py +++ b/emails/models.py @@ -1,14 +1,11 @@ import logging from django.utils import timezone - -from django.conf import settings +from drfx import config from django.db import models from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ - from autoslug import AutoSlugField from mailer import send_mail -from drfx import config logger = logging.getLogger(__name__) @@ -67,14 +64,13 @@ def queue_to_recipients(self, qs): context = { "user": user, - "settings": settings, "config": config, "email": self, "SITENAME": config.SITENAME, "SITE_URL": config.SITE_URL, } subject = self.subject - from_email = settings.NOREPLY_FROM_ADDRESS + from_email = config.NOREPLY_FROM_ADDRESS to = user.email plaintext_content = render_to_string("mail/email.txt", context) send_mail(subject, plaintext_content, from_email, [to]) diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index 755061e8..3919b2cc 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -19,7 +19,7 @@ def execute(self): send_mail( f"[{config.SITENAME}] Requisition about to expire", f"Please update the requisition for config: {r.config.id}. It is valid until: {r.valid_until}", - settings.NOREPLY_FROM_ADDRESS, - [settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS], + config.NOREPLY_FROM_ADDRESS, + [config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS], fail_silently=False, ) diff --git a/users/management/commands/genreferences.py b/users/management/commands/genreferences.py index a06febaf..d9b5eacc 100644 --- a/users/management/commands/genreferences.py +++ b/users/management/commands/genreferences.py @@ -17,6 +17,6 @@ def handle(self, *args, **options): if not subscription.reference_number: print(f"Generating ref for service subscription {subscription}") subscription.reference_number = referencenumber.generate( - settings.SERVICE_INVOICE_REFERENCE_BASE + subscription.id + config.SERVICE_INVOICE_REFERENCE_BASE + subscription.id ) subscription.save() diff --git a/users/middleware/language.py b/users/middleware/language.py index aea595f8..161bbeaf 100644 --- a/users/middleware/language.py +++ b/users/middleware/language.py @@ -1,4 +1,4 @@ -from django.conf import settings +from drfx import config from django.utils import translation @@ -37,6 +37,6 @@ def process_response(self, request, response): return response translation.activate(user_language) - response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language) + response.set_cookie(config.LANGUAGE_COOKIE_NAME, user_language) return response diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py index dd0c669f..e6649833 100644 --- a/users/migrations/0001_initial.py +++ b/users/migrations/0001_initial.py @@ -1,6 +1,6 @@ # Generated by Django 3.0.2 on 2020-01-11 19:45 -from django.conf import settings +from drfx import config import django.core.validators from django.db import migrations, models import django.db.models.deletion @@ -314,7 +314,7 @@ class Migration(migrations.Migration): models.ForeignKey( null=True, on_delete=django.db.models.deletion.SET_NULL, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], @@ -422,7 +422,7 @@ class Migration(migrations.Migration): "user", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], @@ -482,7 +482,7 @@ class Migration(migrations.Migration): "user", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], @@ -519,7 +519,7 @@ class Migration(migrations.Migration): "user", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], diff --git a/users/migrations/0003_custominvoice.py b/users/migrations/0003_custominvoice.py index 1b0bc027..4baac073 100644 --- a/users/migrations/0003_custominvoice.py +++ b/users/migrations/0003_custominvoice.py @@ -1,6 +1,6 @@ # Generated by Django 3.0.2 on 2020-01-12 20:53 -from django.conf import settings +from drfx import config from django.db import migrations, models import django.db.models.deletion @@ -70,7 +70,7 @@ class Migration(migrations.Migration): "user", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], diff --git a/users/migrations/0012_nfccard.py b/users/migrations/0012_nfccard.py index b00ea45a..597fb7ce 100644 --- a/users/migrations/0012_nfccard.py +++ b/users/migrations/0012_nfccard.py @@ -1,6 +1,6 @@ # Generated by Django 3.0.3 on 2020-03-07 13:58 -from django.conf import settings +from drfx import config from django.db import migrations, models import django.db.models.deletion @@ -60,7 +60,7 @@ class Migration(migrations.Migration): "user", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, + to=config.AUTH_USER_MODEL, ), ), ], diff --git a/users/migrations/0019_auto_20200616_1207.py b/users/migrations/0019_auto_20200616_1207.py index 005c0aa8..72eee1cd 100644 --- a/users/migrations/0019_auto_20200616_1207.py +++ b/users/migrations/0019_auto_20200616_1207.py @@ -1,7 +1,7 @@ # Generated by Django 3.0.6 on 2020-06-16 12:07 from django.db import migrations -from django.conf import settings +from drfx import config from utils import referencenumber @@ -9,7 +9,7 @@ def generate_missing_custominvoice_reference_numbers(apps, schema_editor): CustomInvoice = apps.get_model('users', 'CustomInvoice') for invoice in CustomInvoice.objects.all(): if invoice.reference_number is None: - invoice.reference_number = referencenumber.generate(settings.CUSTOM_INVOICE_REFERENCE_BASE + invoice.id) + invoice.reference_number = referencenumber.generate(config.CUSTOM_INVOICE_REFERENCE_BASE + invoice.id) invoice.save() diff --git a/users/signals.py b/users/signals.py index f0d1477b..ae382e5e 100644 --- a/users/signals.py +++ b/users/signals.py @@ -1,6 +1,5 @@ import logging - -from django.conf import settings +from drfx import config from django.contrib.auth.forms import PasswordResetForm from django.core.mail import send_mail from django.db.models.signals import post_save, pre_save @@ -8,10 +7,7 @@ from django.template.loader import render_to_string from django.utils import translation from django.utils.translation import gettext_lazy as _ - from utils import referencenumber -from drfx import config - from . import models logger = logging.getLogger(__name__) @@ -65,7 +61,7 @@ def service_subscription_create( if created: if instance.reference_number is None: refnum = referencenumber.generate( - settings.SERVICE_INVOICE_REFERENCE_BASE + instance.id + config.SERVICE_INVOICE_REFERENCE_BASE + instance.id ) instance.reference_number = refnum instance.save() @@ -80,7 +76,7 @@ def send_reset_password_email(sender, instance: models.CustomUser, **kwargs): When user is created send the reset password email """ form = PasswordResetForm({"email": instance.email}) - from_email = getattr(settings, "NOREPLY_FROM_ADDRESS", "noreply@tampere.hacklab.fi") + from_email = config.NOREPLY_FROM_ADDRESS template = "registration/password_reset_email.html" form.is_valid() form.save(from_email=from_email, email_template_name=template) @@ -122,7 +118,7 @@ def custominvoice_create( if created: if instance.reference_number is None: refnum = referencenumber.generate( - settings.CUSTOM_INVOICE_REFERENCE_BASE + instance.id + config.CUSTOM_INVOICE_REFERENCE_BASE + instance.id ) instance.reference_number = refnum instance.save() @@ -144,13 +140,12 @@ def send_application_received_email( logger.info("Sending thanks for applying membership email to {}".format(instance)) context = { "user": instance.user, - "settings": settings, "config": config, } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Thank you for applying membership and next steps") - from_email = settings.NOREPLY_FROM_ADDRESS + from_email = config.NOREPLY_FROM_ADDRESS to = instance.user.email plaintext_content = render_to_string("mail/application_received.txt", context) @@ -169,12 +164,11 @@ def send_new_application_waiting_processing_email( ) context = { "user": instance.user, - "settings": settings, "config": config, } subject = _("New membership application received") - from_email = settings.NOREPLY_FROM_ADDRESS - to = settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS + from_email = config.NOREPLY_FROM_ADDRESS + to = config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS plaintext_content = render_to_string("mail/new_application.txt", context) send_mail(subject, plaintext_content, from_email, [to]) @@ -189,12 +183,12 @@ def send_application_approved_email( instance, instance.user.language ) ) - context = {"user": instance.user, "settings": settings, "config": config} + context = {"user": instance.user, "config": config} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been approved") - from_email = settings.NOREPLY_FROM_ADDRESS - to = [instance.user.email, settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] + from_email = config.NOREPLY_FROM_ADDRESS + to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] plaintext_content = render_to_string("mail/welcome_and_next_steps.txt", context) send_mail(subject, plaintext_content, from_email, to) @@ -205,12 +199,12 @@ def send_application_denied_email( sender, instance: models.MembershipApplication, **kwargs ): logger.info("Application denied, sending bye bye email {}".format(instance)) - context = {"user": instance.user, "settings": settings, "config": config} + context = {"user": instance.user, "config": config} translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been rejected") - from_email = settings.NOREPLY_FROM_ADDRESS - to = [instance.user.email, settings.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] + from_email = config.NOREPLY_FROM_ADDRESS + to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] plaintext_content = render_to_string("mail/application_rejected.txt", context) send_mail(subject, plaintext_content, from_email, to) @@ -261,13 +255,12 @@ def send_user_activated(sender, instance: models.CustomUser, raw, **kwargs): def notify_user_door_access_denied(sender, user: models.CustomUser, method, **kwargs): context = { "user": user, - "settings": settings, "method": method, "config": config, } translation.activate(user.language) subject = _("Door access denied") - from_email = settings.NOREPLY_FROM_ADDRESS + from_email = config.NOREPLY_FROM_ADDRESS to = [user.email] plaintext_content = render_to_string("mail/door_access_denied.txt", context) send_mail(subject, plaintext_content, from_email, to, fail_silently=True) diff --git a/utils/businesslogic.py b/utils/businesslogic.py index 997aeb53..ba018917 100644 --- a/utils/businesslogic.py +++ b/utils/businesslogic.py @@ -64,11 +64,11 @@ def notify_expiring_service_subscriptions(qs: QuerySet): subject = _("Your subscription %(service_name)s is about to expire") % { "service_name": ss.service.name } - from_email = settings.NOREPLY_FROM_ADDRESS + from_email = config.NOREPLY_FROM_ADDRESS to = ss.user.email context = { "user": ss.user, - "settings": settings, + "config": config, "subscription": ss, } # note, this template will be found from users app @@ -206,7 +206,7 @@ def create_servicesubscription(user, service, state): subscription = ServiceSubscription(user=user, service=service, state=state) subscription.save() subscription.reference_number = referencenumber.generate( - settings.SERVICE_INVOICE_REFERENCE_BASE + subscription.id + config.SERVICE_INVOICE_REFERENCE_BASE + subscription.id ) subscription.save() return subscription diff --git a/www/views.py b/www/views.py index 4654cd20..95b5d235 100644 --- a/www/views.py +++ b/www/views.py @@ -438,7 +438,7 @@ def custominvoice(request): ) invoice.save() invoice.reference_number = referencenumber.generate( - settings.CUSTOM_INVOICE_REFERENCE_BASE + invoice.id + config.CUSTOM_INVOICE_REFERENCE_BASE + invoice.id ) invoice.save() else: @@ -498,7 +498,6 @@ def banktransaction_view(request, banktransactionid): "www/banktransaction.html", { "banktransaction": banktransaction, - "settings": settings, "config": config, }, ) From 76f7b773edcfd15c2e8516b8ecc8a20b3ec93455 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 11:39:20 +0300 Subject: [PATCH 21/31] fix: format --- drfx/config_accessor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/drfx/config_accessor.py b/drfx/config_accessor.py index 306d7914..8eb6d43f 100644 --- a/drfx/config_accessor.py +++ b/drfx/config_accessor.py @@ -1,6 +1,7 @@ from constance import config from django.conf import settings + # A class that accesses configuration variables from constance or settings class ConfigAccessor(object): def __getattr__(self, key): From 2a15b63135b23633fdc6ba342051134aa98c3321 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 14:05:00 +0300 Subject: [PATCH 22/31] fix: run formatter --- users/signals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/signals.py b/users/signals.py index 022d851a..19b9749a 100644 --- a/users/signals.py +++ b/users/signals.py @@ -143,7 +143,7 @@ def send_application_received_email( context = { "user": instance.user, "config": config, - "site": Site.objects.get_current() + "site": Site.objects.get_current(), } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? From 69e2882161b0c7ef73ea2d82fe3c2a736ebdba96 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 14:09:48 +0300 Subject: [PATCH 23/31] fix: indent --- users/signals.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/users/signals.py b/users/signals.py index 19b9749a..5cb8b392 100644 --- a/users/signals.py +++ b/users/signals.py @@ -188,21 +188,20 @@ def send_application_approved_email( ) ) + context = { + "user": instance.user, + "config": config, + "site": Site.objects.get_current(), + } -context = { - "user": instance.user, - "config": config, - "site": Site.objects.get_current(), -} - -translation.activate(instance.user.language) -# TODO: maybe move this subject to settings? -subject = _("Your application has been approved") -from_email = config.NOREPLY_FROM_ADDRESS -to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] -plaintext_content = render_to_string("mail/welcome_and_next_steps.txt", context) + translation.activate(instance.user.language) + # TODO: maybe move this subject to settings? + subject = _("Your application has been approved") + from_email = config.NOREPLY_FROM_ADDRESS + to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] + plaintext_content = render_to_string("mail/welcome_and_next_steps.txt", context) -send_mail(subject, plaintext_content, from_email, to) + send_mail(subject, plaintext_content, from_email, to) @receiver(application_denied, sender=models.MembershipApplication) @@ -211,17 +210,16 @@ def send_application_denied_email( ): logger.info("Application denied, sending bye bye email {}".format(instance)) + context = {"user": instance.user, "config": config} -context = {"user": instance.user, "config": config} - -translation.activate(instance.user.language) -# TODO: maybe move this subject to settings? -subject = _("Your application has been rejected") -from_email = config.NOREPLY_FROM_ADDRESS -to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] -plaintext_content = render_to_string("mail/application_rejected.txt", context) + translation.activate(instance.user.language) + # TODO: maybe move this subject to settings? + subject = _("Your application has been rejected") + from_email = config.NOREPLY_FROM_ADDRESS + to = [instance.user.email, config.MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS] + plaintext_content = render_to_string("mail/application_rejected.txt", context) -send_mail(subject, plaintext_content, from_email, to) + send_mail(subject, plaintext_content, from_email, to) @receiver(pre_save, sender=models.CustomUser) From 50166a9f365275eb8599b7598f0d52ee14e686f7 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 12 Jun 2023 14:44:08 +0300 Subject: [PATCH 24/31] fix: revert bad format --- www/templates/www/banktransaction.html | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 18460001..fc1400da 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,5 +1,8 @@ -{% extends "www/base.html" %} {% load i18n %} {% load bootstrap4 %} {% block -content %} {% load verbose_names %} +{% extends "www/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block content %} +{% load verbose_names %}

    {% trans 'Bank Transaction' %}

    @@ -10,39 +13,42 @@

    {% trans 'Bank Transaction' %}

    {% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

    - {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date - }}
    + {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
    {% trans 'Transaction id' %}: {{ banktransaction.id }}
    - {% get_verbose_field_name banktransaction "reference_number" %}: {{ - banktransaction.reference_number }}
    - {% get_verbose_field_name banktransaction "archival_reference" %}: {{ - banktransaction.archival_reference }}
    - {% get_verbose_field_name banktransaction "sender" %}: {{ - banktransaction.sender }}
    + {% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
    + {% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
    + {% get_verbose_field_name banktransaction "sender" %}: {{ banktransaction.sender }}
    {% trans 'User' %}: {{ banktransaction.user }}

      {% for servicesubscription in banktransaction.servicesubscription_set.all %} -
    • {{servicesubscription.service.name}}
    • - {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all - %} -
    • {{custominvoice.subscription.service.name}}
    • +
    • {{servicesubscription.service.name}}
    • + {% endfor %} + {% for custominvoice in banktransaction.custominvoice_set.all %} +
    • {{custominvoice.subscription.service.name}}
    • {% endfor %}
    -

    {% trans 'Grand total' %}: {{ banktransaction.amount }}€

    +

    + {% trans 'Grand total' %}: {{ banktransaction.amount }}€ +

    - {# This might require tweaking... for now it seems to be #} {# enough that it - is mentioned that everything is VAT 0% #} -

    {% blocktrans %} Seller not VAT-liable {% endblocktrans %}

    + {# This might require tweaking... for now it seems to be #} + {# enough that it is mentioned that everything is VAT 0% #} +

    + {% blocktrans %} + Seller not VAT-liable + {% endblocktrans %} +

    - {% blocktrans with name=site.name %} Thank you and please tell your friends - about {{ name }} :) {% endblocktrans %} + {% blocktrans with name=site.name %} + Thank you and please tell your friends about {{ name }} :) + {% endblocktrans %}

    From 585763546bb3c4d0c8ff93d8a8e3c514f757d9a4 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 21:56:57 +0300 Subject: [PATCH 25/31] fix: make changes non-breaking --- drfx/settings.py | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index ee76536c..4de3ee0c 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -13,6 +13,9 @@ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "qv*o1&&x%#jtsn)5((g+yw#%3_a$ykfof6b-)j^i$1a8se*7c8" +ACCOUNT_BIC = "BICCODE" +ACCOUNT_IBAN = "FI12 3456 789" +ACCOUNT_NAME = "Account name" # The service ID that opens hacklab door. Avoid using in code. DEFAULT_ACCOUNT_SERVICE = 2 @@ -32,8 +35,22 @@ # https://docs.djangoproject.com/en/4.1/ref/settings/ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") +# Sitename +SITENAME = "Mulysa" +SITE_URL = "https://mulysa.tld" +PRIVACY_POLICY_URL = "https://example.com/privacy_policy.html" + + +# these are for the receipt functionality +RECEIPTNAME = "Mulysa ry" +RECEIPTREGID = "1234567-8" +RECEIPTSTREET = "Street 12, Somewhere Finland" # External urls, like links to members guide and rules +ASSOCIATION_RULES_URL = ( + "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/" +) +MEMBERS_GUIDE_URL = "https://wiki.tampere.hacklab.fi/member_s_guide" GITHUB_URL = "https://github.com/TampereHacklab/mulysa" # Application definition @@ -323,16 +340,19 @@ # from utils import businesslogic -# Uncomment this if you wish to set the IBAN through the settings file instead of Constance -# ACCOUNT_IBAN = "FI12 3456 789" - -# Load non-default settings from settings_local.py if it exists -try: - from .settings_local import * # noqa -except ImportError: - pass +CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" # Constance config - configure settings for the app that are editable in django admin +# Edit as desired to start using constance config! +# See https://django-constance.readthedocs.io/en/latest/index.html#configuration + +CONSTANCE_CONFIG = { + "THE_ANSWER": (42, "Answer to the Ultimate Question of Life, " + "The Universe, and Everything"), +} + +# Example Constance config +''' CONSTANCE_CONFIG = { "ASSOCIATION_RULES_URL": ( "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", @@ -359,6 +379,12 @@ "Address to show on receipts", str, ), - "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), + "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), } -CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" +''' + +# Load non-default settings from settings_local.py if it exists +try: + from .settings_local import * # noqa +except ImportError: + pass From eb30c0c9bb117cd6ae80f70990f83ba25a1d3dca Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 22:17:55 +0300 Subject: [PATCH 26/31] fix: formatting --- drfx/settings.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index 4de3ee0c..58833e82 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -347,12 +347,14 @@ # See https://django-constance.readthedocs.io/en/latest/index.html#configuration CONSTANCE_CONFIG = { - "THE_ANSWER": (42, "Answer to the Ultimate Question of Life, " - "The Universe, and Everything"), + "THE_ANSWER": ( + 42, + "Answer to the Ultimate Question of Life, " "The Universe, and Everything", + ), } # Example Constance config -''' +""" CONSTANCE_CONFIG = { "ASSOCIATION_RULES_URL": ( "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", @@ -379,9 +381,9 @@ "Address to show on receipts", str, ), - "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), + "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), } -''' +""" # Load non-default settings from settings_local.py if it exists try: From f2b154ef23f5737af845c0bb5f05f43f9cff8d32 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 22:18:24 +0300 Subject: [PATCH 27/31] fix: comment --- drfx/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drfx/settings.py b/drfx/settings.py index 58833e82..b6912407 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -342,7 +342,7 @@ CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" -# Constance config - configure settings for the app that are editable in django admin +# Constance config - settings for the app that are editable in django admin # Edit as desired to start using constance config! # See https://django-constance.readthedocs.io/en/latest/index.html#configuration From 6215a255dd4af655c2faba5a2d08c0e6c8d00de9 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 22:20:01 +0300 Subject: [PATCH 28/31] fix: revert whitespace change --- drfx/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/drfx/settings.py b/drfx/settings.py index b6912407..62fc706d 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -46,6 +46,7 @@ RECEIPTREGID = "1234567-8" RECEIPTSTREET = "Street 12, Somewhere Finland" + # External urls, like links to members guide and rules ASSOCIATION_RULES_URL = ( "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/" From 3092e9921901ce7ea24155e4b2ebbde93068a1c2 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 22:40:13 +0300 Subject: [PATCH 29/31] feat: make use of constance for basic things --- drfx/settings.py | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/drfx/settings.py b/drfx/settings.py index 62fc706d..7594bc9f 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -340,54 +340,48 @@ # Import just to get in the translation context # from utils import businesslogic +# Load non-default settings from settings_local.py if it exists +try: + from .settings_local import * # noqa +except ImportError: + pass CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" # Constance config - settings for the app that are editable in django admin -# Edit as desired to start using constance config! +# Edit as desired to change what can be configured in the GUI # See https://django-constance.readthedocs.io/en/latest/index.html#configuration -CONSTANCE_CONFIG = { - "THE_ANSWER": ( - 42, - "Answer to the Ultimate Question of Life, " "The Universe, and Everything", - ), -} - -# Example Constance config -""" CONSTANCE_CONFIG = { "ASSOCIATION_RULES_URL": ( - "https://tampere.hacklab.fi/pages/yhdistyksen-s%C3%A4%C3%A4nn%C3%B6t/", + ASSOCIATION_RULES_URL, "Link to the rules of the association", str, ), "MEMBERS_GUIDE_URL": ( - "https://wiki.tampere.hacklab.fi/member_s_guide", + MEMBERS_GUIDE_URL, "Link to the guide for new members", str, ), - "SITENAME": ("Hacklab Mulysa", "Name of the hacklab", str), - "SITE_URL": ("https://mulysa.tld", "URL of this site", str), + "SITENAME": (SITENAME, "Name of the hacklab", str), + "SITE_URL": (SITE_URL, "URL of this site", str), "PRIVACY_POLICY_URL": ( - "https://example.com/privacy_policy.html", + PRIVACY_POLICY_URL, "Link to privacy policy", str, ), # Receipt functionality configuration - "RECEIPT_NAME": ("Mulysa ry", "Name of the association to show on receipts", str), - "RECEIPT_REGID": ("1234567-8", "ID of the association to show on receipts", str), + "RECEIPT_NAME": (RECEIPTNAME, "Name of the association to show on receipts", str), + "RECEIPT_REGID": (RECEIPTREGID, "ID of the association to show on receipts", str), "RECEIPT_ADDRESS": ( - "Street 12, Somewhere Finland", + RECEIPTSTREET, "Address to show on receipts", str, ), - "ACCOUNT_IBAN": ("FI12 3456 789", "IBAN of the association's bank account"), -} -""" + "GITHUB_URL": (GITHUB_URL, "Link to the github repository", str), -# Load non-default settings from settings_local.py if it exists -try: - from .settings_local import * # noqa -except ImportError: - pass + # Uncomment this if you would like to be able to edit the bank account details in the admin panel + # "ACCOUNT_IBAN": (ACCOUNT_IBAN, "IBAN of the association's bank account"), + # "ACCOUNT_BIC": (ACCOUNT_BIC, "BIC of the association's bank account"), + # "ACCOUNT_NAME": (ACCOUNT_NAME, "Name of the association's bank account"), +} From 4f9295ddd8a41d41e889d661b7d714103c2e27a4 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Tue, 13 Jun 2023 22:44:20 +0300 Subject: [PATCH 30/31] fix: format --- drfx/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/drfx/settings.py b/drfx/settings.py index 7594bc9f..10d25a92 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -379,7 +379,6 @@ str, ), "GITHUB_URL": (GITHUB_URL, "Link to the github repository", str), - # Uncomment this if you would like to be able to edit the bank account details in the admin panel # "ACCOUNT_IBAN": (ACCOUNT_IBAN, "IBAN of the association's bank account"), # "ACCOUNT_BIC": (ACCOUNT_BIC, "BIC of the association's bank account"), From e6ec19b48858d780a2b08dceafc4699f844904fd Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Mon, 4 Dec 2023 08:25:59 +0200 Subject: [PATCH 31/31] Update banktransaction.html --- www/templates/www/banktransaction.html | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/www/templates/www/banktransaction.html b/www/templates/www/banktransaction.html index 18460001..fc1400da 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -1,5 +1,8 @@ -{% extends "www/base.html" %} {% load i18n %} {% load bootstrap4 %} {% block -content %} {% load verbose_names %} +{% extends "www/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block content %} +{% load verbose_names %}

    {% trans 'Bank Transaction' %}

    @@ -10,39 +13,42 @@

    {% trans 'Bank Transaction' %}

    {% trans 'Business ID' %}: {{config.RECEIPT_REGID}}

    - {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date - }}
    + {% get_verbose_field_name banktransaction "date" %}: {{ banktransaction.date }}
    {% trans 'Transaction id' %}: {{ banktransaction.id }}
    - {% get_verbose_field_name banktransaction "reference_number" %}: {{ - banktransaction.reference_number }}
    - {% get_verbose_field_name banktransaction "archival_reference" %}: {{ - banktransaction.archival_reference }}
    - {% get_verbose_field_name banktransaction "sender" %}: {{ - banktransaction.sender }}
    + {% get_verbose_field_name banktransaction "reference_number" %}: {{ banktransaction.reference_number }}
    + {% get_verbose_field_name banktransaction "archival_reference" %}: {{ banktransaction.archival_reference }}
    + {% get_verbose_field_name banktransaction "sender" %}: {{ banktransaction.sender }}
    {% trans 'User' %}: {{ banktransaction.user }}

      {% for servicesubscription in banktransaction.servicesubscription_set.all %} -
    • {{servicesubscription.service.name}}
    • - {% endfor %} {% for custominvoice in banktransaction.custominvoice_set.all - %} -
    • {{custominvoice.subscription.service.name}}
    • +
    • {{servicesubscription.service.name}}
    • + {% endfor %} + {% for custominvoice in banktransaction.custominvoice_set.all %} +
    • {{custominvoice.subscription.service.name}}
    • {% endfor %}
    -

    {% trans 'Grand total' %}: {{ banktransaction.amount }}€

    +

    + {% trans 'Grand total' %}: {{ banktransaction.amount }}€ +

    - {# This might require tweaking... for now it seems to be #} {# enough that it - is mentioned that everything is VAT 0% #} -

    {% blocktrans %} Seller not VAT-liable {% endblocktrans %}

    + {# This might require tweaking... for now it seems to be #} + {# enough that it is mentioned that everything is VAT 0% #} +

    + {% blocktrans %} + Seller not VAT-liable + {% endblocktrans %} +

    - {% blocktrans with name=site.name %} Thank you and please tell your friends - about {{ name }} :) {% endblocktrans %} + {% blocktrans with name=site.name %} + Thank you and please tell your friends about {{ name }} :) + {% endblocktrans %}