diff --git a/api/tests.py b/api/tests.py index c8aab5ed..e008fc1a 100644 --- a/api/tests.py +++ b/api/tests.py @@ -15,6 +15,7 @@ from rest_framework_tracking.models import APIRequestLog from users.models import CustomUser, MemberService, NFCCard, ServiceSubscription from api.mulysaoauthvalidator import MulysaOAuth2Validator +from django.contrib.sites.models import Site class TestOAuthValidator(APITestCase): def setUp(self): @@ -226,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 10d25a92..dc5669f3 100644 --- a/drfx/settings.py +++ b/drfx/settings.py @@ -363,8 +363,6 @@ "Link to the guide for new members", str, ), - "SITENAME": (SITENAME, "Name of the hacklab", str), - "SITE_URL": (SITE_URL, "URL of this site", str), "PRIVACY_POLICY_URL": ( PRIVACY_POLICY_URL, "Link to privacy policy", diff --git a/emails/models.py b/emails/models.py index 435e2fc0..debc6a39 100644 --- a/emails/models.py +++ b/emails/models.py @@ -6,6 +6,7 @@ from django.utils.translation import gettext_lazy as _ from autoslug import AutoSlugField from mailer import send_mail +from django.contrib.sites.models import Site logger = logging.getLogger(__name__) @@ -62,12 +63,13 @@ def queue_to_recipients(self, qs): ) ) + site = Site.objects.get_current() context = { "user": user, "config": config, "email": self, - "SITENAME": config.SITENAME, - "SITE_URL": config.SITE_URL, + "SITENAME": site.name, + "SITE_URL": site.domain, } subject = self.subject from_email = config.NOREPLY_FROM_ADDRESS diff --git a/nordigenautomation/jobs/notify_expiring_requisitions.py b/nordigenautomation/jobs/notify_expiring_requisitions.py index 3919b2cc..994cecaa 100644 --- a/nordigenautomation/jobs/notify_expiring_requisitions.py +++ b/nordigenautomation/jobs/notify_expiring_requisitions.py @@ -6,6 +6,7 @@ from drfx import config from ..models import Requisition +from django.contrib.sites.models import Site class Job(DailyJob): @@ -17,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}", config.NOREPLY_FROM_ADDRESS, [config.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 ae382e5e..5cb8b392 100644 --- a/users/signals.py +++ b/users/signals.py @@ -10,6 +10,8 @@ from utils import referencenumber from . import models +from django.contrib.sites.models import Site + logger = logging.getLogger(__name__) # @@ -141,6 +143,7 @@ def send_application_received_email( context = { "user": instance.user, "config": config, + "site": Site.objects.get_current(), } translation.activate(instance.user.language) # TODO: maybe move this subject to settings? @@ -164,6 +167,7 @@ def send_new_application_waiting_processing_email( ) context = { "user": instance.user, + "site": Site.objects.get_current(), "config": config, } subject = _("New membership application received") @@ -183,7 +187,13 @@ def send_application_approved_email( instance, instance.user.language ) ) - context = {"user": instance.user, "config": config} + + 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") @@ -199,7 +209,9 @@ def send_application_denied_email( sender, instance: models.MembershipApplication, **kwargs ): logger.info("Application denied, sending bye bye email {}".format(instance)) + context = {"user": instance.user, "config": config} + translation.activate(instance.user.language) # TODO: maybe move this subject to settings? subject = _("Your application has been rejected") @@ -257,6 +269,7 @@ def notify_user_door_access_denied(sender, user: models.CustomUser, method, **kw "user": user, "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 d406de3c..7257cb78 100644 --- a/users/tests.py +++ b/users/tests.py @@ -17,6 +17,7 @@ from utils.businesslogic import BusinessLogic from . import models, signals +from django.contrib.sites.models import Site from drfx import config @@ -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 b6de09c5..96fd00cc 100644 --- a/www/context_processors.py +++ b/www/context_processors.py @@ -1,11 +1,13 @@ +from django.contrib.sites.models import Site from drfx import config def external_urls(request): + site = Site.objects.get_current() return { "ASSOCIATION_RULES_URL": config.ASSOCIATION_RULES_URL, "MEMBERS_GUIDE_URL": config.MEMBERS_GUIDE_URL, + "SITENAME": site.name, + "SITE_URL": site.domain, "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/banktransaction.html b/www/templates/www/banktransaction.html index 7d325715..fc1400da 100644 --- a/www/templates/www/banktransaction.html +++ b/www/templates/www/banktransaction.html @@ -46,7 +46,7 @@
- {% blocktrans with name=config.SITENAME %} + {% blocktrans with name=site.name %} Thank you and please tell your friends about {{ name }} :) {% endblocktrans %}