From a75aca148ba7db29e14e30f2e0707b1efac1ff94 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 2 Aug 2024 16:17:53 +0100 Subject: Refactored list template into includes to fix div hell. --- pyblackbird_cc/templates/resources/admin_bar.html | 28 ++++ .../templates/resources/resource_card.html | 42 +++++ .../templates/resources/resource_list.html | 177 ++++----------------- 3 files changed, 104 insertions(+), 143 deletions(-) create mode 100644 pyblackbird_cc/templates/resources/admin_bar.html create mode 100644 pyblackbird_cc/templates/resources/resource_card.html (limited to 'pyblackbird_cc/templates') diff --git a/pyblackbird_cc/templates/resources/admin_bar.html b/pyblackbird_cc/templates/resources/admin_bar.html new file mode 100644 index 0000000..5bddde6 --- /dev/null +++ b/pyblackbird_cc/templates/resources/admin_bar.html @@ -0,0 +1,28 @@ + {# admin block #} + {% if request.user.is_authenticated and request.user.is_staff %} +
+
Admin bar
+

+ Only you will see this bar - normal users will not see it. It allows us to + include buttons for adding new resources, etc. +

+
+
+
+ Add a new resource +
+
+ Logged in as + {{ request.user.email }} +
+
+
+ {% csrf_token %} + +
+
+
+
+
+ {% endif %} diff --git a/pyblackbird_cc/templates/resources/resource_card.html b/pyblackbird_cc/templates/resources/resource_card.html new file mode 100644 index 0000000..67807cc --- /dev/null +++ b/pyblackbird_cc/templates/resources/resource_card.html @@ -0,0 +1,42 @@ +{% load markdown_extras %} + + +
+ {{ resource.thumbnail_filename }} +
+ +
+ {{ resource.age_range }} +
+
+ {% if resource.main_resource_category_name == "English as a Foreign Language (EFL)" %} + EFL + {% else %} + {{ resource.main_resource_category_name }} + {% endif %} +
+ {% if request.user.is_authenticated and request.user.is_staff %} +
+ Feature slot: {{ resource.feature_slot }} +
+ {% endif %} + {% if resource.card_description %} +

{{ resource.card_description | markdown | safe }}

+ {% else %} +

{{ resource.description | markdown | safe }}

+ {% endif %} +
+ {% if request.user.is_authenticated and request.user.is_staff %} + + {% endif %} +
\ No newline at end of file diff --git a/pyblackbird_cc/templates/resources/resource_list.html b/pyblackbird_cc/templates/resources/resource_list.html index 2f137e0..7be49c6 100644 --- a/pyblackbird_cc/templates/resources/resource_list.html +++ b/pyblackbird_cc/templates/resources/resource_list.html @@ -1,161 +1,52 @@ {% extends "base.html" %} - {% load static %} {% load markdown_extras %} - {% block title %} - Joanna Lemon Learning - Resource List + Joanna Lemon Learning - Resource List {% endblock title %} {% block content %} - {# admin block #} - {% if request.user.is_authenticated and request.user.is_staff %} -
-
Admin bar
-

- Only you will see this bar - normal users will not see it. It allows us to - include buttons for adding new resources, etc. -

-
-
-
- Add a new resource -
-
- Logged in as - {{ request.user.email }} -
-
-
- {% csrf_token %} - -
-
+ {% include "resources/admin_bar.html" %} + + {# featured resources #} + {% if featured_resources %} +
+
Featured resources
-
-
- {% endif %} - {# featured resources#} -
-
- {% if featured_resources %} -
-
-
Featured resources
-
-
-
- {% for resource in featured_resources %} - {% if featured_resources|length == 1 %} -
- {% elif featured_resources|length == 2 %} -
- {% else %} -
- {% endif %} -
- {{ resource.thumbnail_filename }} -
-
{{ resource.name }}
-
-
- {% if resource.main_resource_category_name == "English as a Foreign Language (EFL)" %} - EFL - {% else %} - {{ resource.main_resource_category_name }} +
+ {% for featured_resource in featured_resources %} + {% if featured_resources|length == 1 %} +
+ {% elif featured_resources|length == 2 %} +
+ {% elif featured_resources|length == 3 %} +
{% endif %} -
-
- {{ resource.age_range }} -
- {% if request.user.is_authenticated and request.user.is_staff %} -
- Feature slot: {{ resource.feature_slot }} -
- {% endif %} + {% include "resources/resource_card.html" with resource=featured_resource %}
- {% if resource.card_description %} -

{{ resource.card_description | markdown | safe }}

- {% else %} -

{{ resource.description | markdown | safe }}

- {% endif %} -
- {% if request.user.is_authenticated and request.user.is_staff %} - -
+ {% endfor %}
- {% endfor %} - {% else %} -

There are no featured resources

- {% endif %} -
-
+ {% else %} +

There are no featured resources

+ {% endif %} -{# standard resources #} -
-
- {% if resource_list %} -
+{# standard resources #} +{% if resource_list %} +
-
Standard resources
+
Standard resources
-
-
+
+ +
{% for resource in resource_list %} - {#
#} -
- {{ resource.thumbnail_filename }} -
-
{{ resource.name }}
-
-
- {% if resource.main_resource_category_name == "English as a Foreign Language (EFL)" %} - EFL - {% else %} - {{ resource.main_resource_category_name }} - {% endif %} -
-
- {{ resource.age_range }} -
-
- {% if resource.card_description %} -

{{ resource.card_description | markdown | safe }}

- {% else %} -

{{ resource.description | markdown | safe }}

- {% endif %} +
+ {% include "resources/resource_card.html" with resource=resource %}
- {% if request.user.is_authenticated and request.user.is_staff %} - -
{% endfor %} -
-
- {% else %} -

There are no resources

- {% endif %} -
-
-{% endblock content %} +
+{% else %} +

There are no resources

+{% endif %} +{% endblock content %} \ No newline at end of file -- cgit v1.2.3