Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use sites feature in django admin for setting site url and name #435

Merged
merged 38 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c37156c
feat: add in-app settings panel using django-constance
braaar Feb 13, 2023
5231138
chore: run black
braaar Feb 13, 2023
2a3cad3
fix: revert irrelevant changes to settings
braaar Feb 13, 2023
f89153f
fix: add config to email contexts
braaar Feb 13, 2023
52da390
fix: remove unused import
braaar Feb 13, 2023
0c991c4
chore: run black
braaar Feb 13, 2023
c98af16
fix: remove SITE_URL and SITENAME from constance
braaar Feb 13, 2023
76d27bb
fix: undo changes to template code
braaar Mar 27, 2023
0b397d0
fix: small corrections to template
braaar Mar 27, 2023
030be9d
fix: additional corrections
braaar Mar 27, 2023
f77d070
fix: correct whitespace
braaar Mar 27, 2023
6e80df1
fix: make for statement single line
braaar Mar 27, 2023
6bc63d6
fix: revert irrelevant changes
braaar Mar 27, 2023
9944877
fix: typo
braaar Mar 27, 2023
3cd6368
fix: remove trailing space
braaar Mar 27, 2023
840a35d
feat: move account IBAN to constance
braaar Apr 1, 2023
c09306d
Merge branch 'constance-config' into sites
braaar Apr 1, 2023
ea16009
chore: run black formatter
braaar Apr 1, 2023
987e839
chore: run black formatter
braaar Apr 1, 2023
9862d9c
feat: add config accessor
braaar Jun 12, 2023
b1b63d1
fix: fix imports
braaar Jun 12, 2023
76f7b77
fix: format
braaar Jun 12, 2023
b7e39f8
Merge branch 'constance-config' into sites
braaar Jun 12, 2023
2a15b63
fix: run formatter
braaar Jun 12, 2023
69e2882
fix: indent
braaar Jun 12, 2023
50166a9
fix: revert bad format
braaar Jun 12, 2023
5857635
fix: make changes non-breaking
braaar Jun 13, 2023
eb30c0c
fix: formatting
braaar Jun 13, 2023
f2b154e
fix: comment
braaar Jun 13, 2023
f431a49
Merge branch 'constance-config' into sites
braaar Jun 13, 2023
6215a25
fix: revert whitespace change
braaar Jun 13, 2023
4b6770c
Merge branch 'constance-config' into sites
braaar Jun 13, 2023
3092e99
feat: make use of constance for basic things
braaar Jun 13, 2023
4f9295d
fix: format
braaar Jun 13, 2023
c2dc0d9
Merge branch 'constance-config' into sites
braaar Jun 13, 2023
0dfe603
Merge branch 'main' into sites
braaar Dec 4, 2023
86ace31
Merge branch 'main' into sites
braaar Dec 4, 2023
e6ec19b
Update banktransaction.html
braaar Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions drfx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion nordigenautomation/jobs/notify_expiring_requisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from drfx import config
from ..models import Requisition
from django.contrib.sites.models import Site


class Job(DailyJob):
Expand All @@ -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],
Expand Down
12 changes: 6 additions & 6 deletions users/locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 14 additions & 1 deletion users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from utils import referencenumber
from . import models

from django.contrib.sites.models import Site

logger = logging.getLogger(__name__)

#
Expand Down Expand Up @@ -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?
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion users/templates/mail/application_received.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion users/templates/mail/door_access_denied.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion users/templates/mail/new_application.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion users/templates/mail/welcome_and_next_steps.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from utils.businesslogic import BusinessLogic

from . import models, signals
from django.contrib.sites.models import Site
from drfx import config


Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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")


Expand Down
6 changes: 4 additions & 2 deletions www/context_processors.py
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 1 addition & 1 deletion www/templates/www/banktransaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2>{% trans 'Bank Transaction' %}</h2>

<div id="promoinfo">
<p>
{% blocktrans with name=config.SITENAME %}
{% blocktrans with name=site.name %}
Thank you and please tell your friends about {{ name }} :)
{% endblocktrans %}
</p>
Expand Down
Loading