Skip to content

Commit

Permalink
Template updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmaxwell committed May 1, 2024
1 parent 699887a commit 1e53d40
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 51 deletions.
23 changes: 22 additions & 1 deletion config/settings_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,25 @@
from .settings import * # noqa: F403, F401, RUF100

# Use an in-memory database for testing
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
},
}

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
10 changes: 4 additions & 6 deletions djpress/templates/djpress/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ <h1>{{ post.title }}</h1>
</footer>
</article>

{% endif %}

{% comment %}If we get multiple posts, then show the truncated content.{% endcomment %}
{% if posts %}
{% elif posts %}

{% comment %}If we get posts for a category, then we can show the category header.{% endcomment %}
{% if category %}
Expand Down Expand Up @@ -73,11 +71,11 @@ <h1><a href="{% url 'djpress:content_detail' post.slug %}">{{ post.title }}</a><
</footer>
</article>

{% empty %}
{% endfor %}

<p>No posts available.</p>
{% else %}

{% endfor %}
<p>No posts available.</p>

{% endif %}

Expand Down
12 changes: 6 additions & 6 deletions djpress/test_category_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_get_cached_categories():
Category.objects.create(name="Category 2")

# Call the get_cached_categories method
queryset = Category.objects.get_cached_categories()
queryset = Category.objects._get_cached_categories()

# Assert that the queryset is cached
cached_queryset = cache.get(CATEGORY_CACHE_KEY)
Expand All @@ -26,7 +26,7 @@ def test_get_cached_categories():
assert len(cached_queryset) == 2

# Assert that subsequent calls retrieve the queryset from cache
queryset2 = Category.objects.get_cached_categories()
queryset2 = Category.objects._get_cached_categories()
assert list(queryset2) == list(cached_queryset)


Expand All @@ -36,7 +36,7 @@ def test_cache_invalidation_on_save():
category = Category.objects.create(name="Category 1")

# Call the get_cached_categories method
queryset = Category.objects.get_cached_categories()
queryset = Category.objects._get_cached_categories()

# Assert that the queryset is cached
cached_queryset = cache.get(CATEGORY_CACHE_KEY)
Expand All @@ -52,7 +52,7 @@ def test_cache_invalidation_on_save():
assert cached_queryset is None

# Call the get_cached_categories method again
queryset2 = Category.objects.get_cached_categories()
queryset2 = Category.objects._get_cached_categories()

# Assert that the queryset is cached again with the updated data
cached_queryset2 = cache.get(CATEGORY_CACHE_KEY)
Expand All @@ -67,7 +67,7 @@ def test_cache_invalidation_on_delete():
category = Category.objects.create(name="Category 1")

# Call the get_cached_categories method
queryset = Category.objects.get_cached_categories()
queryset = Category.objects._get_cached_categories()

# Assert that the queryset is cached
cached_queryset = cache.get(CATEGORY_CACHE_KEY)
Expand All @@ -82,7 +82,7 @@ def test_cache_invalidation_on_delete():
assert cached_queryset is None

# Call the get_cached_categories method again
queryset2 = Category.objects.get_cached_categories()
queryset2 = Category.objects._get_cached_categories()

# Assert that the queryset is cached again with the updated data
cached_queryset2 = cache.get(CATEGORY_CACHE_KEY)
Expand Down
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% load static %}
{% load djpress_tags %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}stuartm.nz{% endblock %}</title>
<title>{% spaceless %}{% block title %}{% get_blog_title %}{% endblock %}{% endspaceless %}</title>
<link rel="alternate" type="application/rss+xml" title="Latest Posts" href="{% url 'djpress:rss_feed' %}">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="{% static "css/pygments/nord.min.css" %}" rel="stylesheet">
Expand Down
14 changes: 0 additions & 14 deletions templates/djpress/category_posts.html

This file was deleted.

38 changes: 26 additions & 12 deletions templates/djpress/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
{% extends 'base.html' %}
{% load djpress_tags %}

{% block title %}Home{% endblock %}

{% block content %}
{% block title %}

{% if slug %}
{% comment %} If there's a slug, we only display a single post. {% endcomment %}
{% if post %}

{% get_single_published_content slug as post %}
{{ post.title }} - {% get_blog_title %}

{% include "djpress/snippets/content_detail.html" %}
{% elif category %}

{{ category.name }} - {% get_blog_title %}

{% else %}
{% comment %} If there's no slug, we loop through recent published content. {% endcomment %}

{% get_recent_published_content as posts %}
{% get_blog_title %}

{% endif %}

{% endblock title %}


{% block content %}

{% if post %}

{% include "djpress/snippets/content_detail.html" %}

{% elif posts %}

<h1>The posts go here.</h1>

{% for post in posts %}

{% include "djpress/snippets/content_summary.html" %}

{% empty %}
{% endfor %}

<p>No posts available.</p>
{% else %}

{% endfor %}
<p>No posts available.</p>

{% endif %}

{% endblock %}
{% endblock content %}
11 changes: 0 additions & 11 deletions templates/djpress/post.html

This file was deleted.

0 comments on commit 1e53d40

Please sign in to comment.