Skip to content

Commit

Permalink
Migrate to Django Templating
Browse files Browse the repository at this point in the history
This doesn't work yet, the tag gets stripped. Pushing on request from @jchristgit
  • Loading branch information
thebeanogamer committed Jan 30, 2022
1 parent 72bd1f0 commit 87cd0ba
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 51 deletions.
Empty file.
9 changes: 9 additions & 0 deletions src/admin/templatetags/template_extras.py
Original file line number Diff line number Diff line change
@@ -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})
4 changes: 2 additions & 2 deletions src/admin/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/templates/2fa_removed.html
Original file line number Diff line number Diff line change
@@ -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.<br>
If this was you, you can safely ignore this email.<br><br>
If this wasn't you, request a password reset or raise a support ticket.<br>
{% endcall %}
{% endfilter %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/templates/2fa_removed.txt
Original file line number Diff line number Diff line change
@@ -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.
If this wasn't you, request a password reset or raise a support ticket.
24 changes: 0 additions & 24 deletions src/templates/bases/macros.html

This file was deleted.

15 changes: 15 additions & 0 deletions src/templates/components/button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="{{ url }}" style="margin-top:24px;margin-bottom:8px;height:56px;v-text-anchor:middle;width:300px;padding:0 64px;" arcsize="50%" stroke="f" fillcolor="#161422">
<w:anchorlock/>
<center style="color:#ffffff;font-family:sans-serif;font-size:16px;font-weight:bold;">
{{ text }}
</center>
</v:roundrect>
<![endif]-->
<!--[if !mso]> <!-->
<a href="{{ url }}">
<div style="display:inline-block;line-height:56px;height:56px;border-radius:28px;padding:0 64px;background-color:#161422;color:#fff;text-decoration:none;"
href="{{ url }}">
{{ text }}
</div>
</a><!-- <![endif]-->
5 changes: 5 additions & 0 deletions src/templates/components/center.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<tr>
<td align="center" cellpadding="{{ pad }}">
{{ value }}
</td>
</tr>
3 changes: 3 additions & 0 deletions src/templates/components/space.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<tr>
<td height="{{ height }}"></td>
</tr>
2 changes: 1 addition & 1 deletion src/templates/mail_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>{{ email.subject }}</h1>
<p>{{ email.body }}</p>

<hr>
{% else %}
{% empty %}
<p>No emails have been sent</p>
{% endfor %}
</body>
Expand Down
20 changes: 10 additions & 10 deletions src/templates/password_reset.html
Original file line number Diff line number Diff line change
@@ -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.<br>
If this was you, click the link below to continue with the password reset.<br>
If this wasn't you, you can safely ignore this email.<br><br>
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 %}
<i style="font-size:80%;">
Button not working? Navigate to <a style="color:#e53935;text-decoration:none;" href="{{ url }}">{{ url }}</a> in a browser.
</i>
{%- endcall %}
{% endfilter %}
{% endblock %}
20 changes: 10 additions & 10 deletions src/templates/verify.html
Original file line number Diff line number Diff line change
@@ -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 }}.<br>
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 %}
<i style="font-size:80%;">
Button not working? Navigate to <a style="color:#e53935;text-decoration:none;" href="{{ url }}">{{ url }}</a> in a browser.
</i>
{%- endcall %}
{% endfilter %}
{% endblock %}

0 comments on commit 87cd0ba

Please sign in to comment.