Skip to content

Commit

Permalink
Merge pull request #15 from stuartmaxwell/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmaxwell authored Jun 16, 2024
2 parents 50599ce + 8623cbc commit 05a9ee0
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 103 deletions.
32 changes: 0 additions & 32 deletions djpress/templates/djpress/base.html

This file was deleted.

91 changes: 57 additions & 34 deletions djpress/templates/djpress/index.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
{% extends "djpress/base.html" %}
{% load static %}
{% load djpress_tags %}

{% block main %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% blog_page_title post_text="| " %}{% blog_title %}</title>
<link rel="stylesheet" href="{% static 'djpress/css/style.css' %}">
</head>
<body>
<header>
<h1>{% blog_title_link %}</h1>
{% blog_pages %}
</header>

{% category_name "h1" pre_text="View Posts in the " post_text=" Category" %}
{% author_name "h1" pre_text="View Posts by " %}
<main>

{% if post %}
{% category_name "h1" pre_text="View Posts in the " post_text=" Category" %}
{% author_name "h1" pre_text="View Posts by " %}

<article>
<header>
<h1>{% post_title_link %}</h1>
<p>By {% post_author_link %}. {% post_date_link %}</p>
</header>
<section>
{% post_content %}
</section>
<footer>
<p>Categories: {% post_categories_link "span" "badge" %}</p>
</footer>
</article>
{% if post %}

{% else %}
<article>
<header>
<h1>{% post_title_link %}</h1>
<p>By {% post_author_link %}. {% post_date_link %}</p>
</header>
<section>
{% post_content %}
</section>
<footer>
<p>Categories: {% post_categories_link "span" "badge" %}</p>
</footer>
</article>

{% for post in posts %}
{% else %}

<article>
<header>
<h1>{% post_title_link %}</h1>
<p>By {% post_author_link %}. {% post_date_link %}</p>
</header>
<section>
{% post_content %}
</section>
</article>
{% for post in posts %}

{% empty %}
<article>
<header>
<h1>{% post_title_link %}</h1>
<p>By {% post_author_link %}. {% post_date_link %}</p>
</header>
<section>
{% post_content %}
</section>
</article>

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

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

{% endif %}
{% endfor %}

{% endif %}

{% posts_nav_links %}
{% pagination_links %}

{% endblock main %}
</main>

<footer>
<p>Powered by
<a href="https://www.djangoproject.com/" title="The web framework for perfectionists with deadlines">Django</a>
and
<a href="#">DJPress</a>
</p>
</footer>
</body>
</html>
21 changes: 0 additions & 21 deletions djpress/templates/djpress/single.html

This file was deleted.

53 changes: 52 additions & 1 deletion djpress/templatetags/djpress_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,58 @@ def post_categories_link(


@register.simple_tag(takes_context=True)
def posts_nav_links(
def is_paginated(context: Context) -> bool:
"""Return whether the posts are paginated.
Args:
context: The context.
Returns:
bool: Whether the posts are paginated.
"""
posts: Page | None = context.get("posts")
if not posts or not isinstance(posts, Page):
return False

return True


@register.simple_tag(takes_context=True)
def get_pagination_range(context: Context) -> range:
"""Return the range of pagination pages.
Args:
context: The context.
Returns:
range: The pagination pages.
"""
page: Page | None = context.get("posts")
if not page or not isinstance(page, Page):
return range(0)

return page.paginator.page_range


@register.simple_tag(takes_context=True)
def get_pagination_current_page(context: Context) -> int:
"""Return the current page number.
Args:
context: The context.
Returns:
int: The current page number.
"""
page: Page | None = context.get("posts")
if not page or not isinstance(page, Page):
return 0

return page.number


@register.simple_tag(takes_context=True)
def pagination_links(
context: Context,
) -> str:
"""Return the previous and next post links.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "djpress"
version = "0.6.0"
version = "0.7.0"
authors = [{ name = "Stuart Maxwell", email = "[email protected]" }]
description = "A blog application for Django sites, inspired by classic WordPress."
readme = "README.md"
Expand Down
Loading

0 comments on commit 05a9ee0

Please sign in to comment.