diff --git a/src/admin/templatetags/__init__.py b/src/admin/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/admin/templatetags/template_extras.py b/src/admin/templatetags/template_extras.py new file mode 100644 index 00000000..ce4c23ae --- /dev/null +++ b/src/admin/templatetags/template_extras.py @@ -0,0 +1,9 @@ +from django.template import Library, loader + +register = Library() + + +@register.filter(name='center', is_safe=True, needs_autoescape=False) +def center(value, arg=""): + template = loader.get_template("components/center.html") + return template.render({"value": value, "pad": arg}) diff --git a/src/admin/tests.py b/src/admin/tests.py index c58d54db..69d02c55 100644 --- a/src/admin/tests.py +++ b/src/admin/tests.py @@ -1,8 +1,8 @@ import hashlib -from django.urls import reverse -from django.test import TestCase from django.core import mail +from django.test import TestCase +from django.urls import reverse from rest_framework.test import APITestCase from challenge.models import Category, Challenge diff --git a/src/templates/2fa_removed.html b/src/templates/2fa_removed.html index 3381cf3c..32ba673e 100644 --- a/src/templates/2fa_removed.html +++ b/src/templates/2fa_removed.html @@ -1,10 +1,10 @@ {% extends "bases/base.html" %} -{% import "bases/macros.html" as m %} +{% load template_extras %} {% block body %} - {% call m.center() %} + {% filter center %} 2FA has been disabled on your account.
If this was you, you can safely ignore this email.

If this wasn't you, request a password reset or raise a support ticket.
- {% endcall %} + {% endfilter %} {% endblock %} diff --git a/src/templates/2fa_removed.txt b/src/templates/2fa_removed.txt index f3150c44..871ed65d 100644 --- a/src/templates/2fa_removed.txt +++ b/src/templates/2fa_removed.txt @@ -1,3 +1,3 @@ 2FA has been disabled on your account. If this was you, you can safely ignore this email. -If this wasn't you, request a password reset or raise a support ticket. \ No newline at end of file +If this wasn't you, request a password reset or raise a support ticket. diff --git a/src/templates/bases/macros.html b/src/templates/bases/macros.html deleted file mode 100644 index f695a9b4..00000000 --- a/src/templates/bases/macros.html +++ /dev/null @@ -1,24 +0,0 @@ -{% macro button(text, url) -%} - - -
- {{ text }} -
-{%- endmacro %} - -{% macro space(height) -%} - -{%- endmacro %} - -{% macro center(pad=0) -%} - - {{ caller() }} - -{%- endmacro %} diff --git a/src/templates/components/button.html b/src/templates/components/button.html new file mode 100644 index 00000000..3d1fe027 --- /dev/null +++ b/src/templates/components/button.html @@ -0,0 +1,15 @@ + + + +
+ {{ text }} +
+
diff --git a/src/templates/components/center.html b/src/templates/components/center.html new file mode 100644 index 00000000..67685ff7 --- /dev/null +++ b/src/templates/components/center.html @@ -0,0 +1,5 @@ + + + {{ value }} + + diff --git a/src/templates/components/space.html b/src/templates/components/space.html new file mode 100644 index 00000000..593eb7dc --- /dev/null +++ b/src/templates/components/space.html @@ -0,0 +1,3 @@ + + + diff --git a/src/templates/mail_list.html b/src/templates/mail_list.html index 51a0daab..930cb19d 100644 --- a/src/templates/mail_list.html +++ b/src/templates/mail_list.html @@ -14,7 +14,7 @@

{{ email.subject }}

{{ email.body }}


- {% else %} + {% empty %}

No emails have been sent

{% endfor %} diff --git a/src/templates/password_reset.html b/src/templates/password_reset.html index fc5cdd8b..73232033 100644 --- a/src/templates/password_reset.html +++ b/src/templates/password_reset.html @@ -1,21 +1,21 @@ {% extends "bases/base.html" %} -{% import "bases/macros.html" as m %} +{% load template_extras %} {% block body %} - {% call m.center() %} + {% filter center %} A password reset has been requested for your account.
If this was you, click the link below to continue with the password reset.
If this wasn't you, you can safely ignore this email.

This link is valid for 1 hour since the reset was requested. - {% endcall %} - {{ m.space(24) }} - {% call m.center(24) -%} - {{ m.button("RESET PASSWORD", url) }} - {%- endcall %} - {{ m.space(16) }} - {% call m.center(16) -%} + {% endfilter %} + {% include "components/space.html" with heights=24 %} + {% filter center:24 %} + {% include "components/button.html" with text="RESET PASSWORD" url=url %} + {% endfilter %} + {% include "components/space.html" with height=16 %} + {% filter center:16 %} Button not working? Navigate to {{ url }} in a browser. - {%- endcall %} + {% endfilter %} {% endblock %} diff --git a/src/templates/verify.html b/src/templates/verify.html index 4114fc56..a0172c5a 100644 --- a/src/templates/verify.html +++ b/src/templates/verify.html @@ -1,19 +1,19 @@ {% extends "bases/base.html" %} -{% import "bases/macros.html" as m %} +{% load template_extras %} {% block body %} - {% call m.center() %} + {% filter center %} Thank you for signing up to {{ event_name }}.
Before you can start capturing flags, you need to verify your account! - {% endcall %} - {{ m.space(24) }} - {% call m.center(24) -%} - {{ m.button("VERIFY MY ACCOUNT", url) }} - {%- endcall %} - {{ m.space(16) }} - {% call m.center(16) -%} + {% endfilter %} + {% include "components/space.html" with heights=24 %} + {% filter center:24 %} + {% include "components/button.html" with text="VERIFY MY ACCOUNT" url=url %} + {% endfilter %} + {% include "components/space.html" with height=16 %} + {% filter center:16 %} Button not working? Navigate to {{ url }} in a browser. - {%- endcall %} + {% endfilter %} {% endblock %}