Skip to content

Commit

Permalink
Redesign month page, closes #469
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jul 16, 2024
1 parent 2b3d6b6 commit 6a81eda
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 48 deletions.
61 changes: 40 additions & 21 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,36 +249,55 @@ def archive_year(request, year):
)



def archive_month(request, year, month):
year = int(year)
month = MONTHS_3_REV[month.lower()]

def by_date(objs):
lookup = {}
for obj in objs:
lookup.setdefault(obj.created.date(), []).append(obj)
return lookup
items = []
from django.db import connection

entries = list(
Entry.objects.filter(created__year=year, created__month=month).order_by(
"created"
cursor = connection.cursor()
for model, content_type in (
(Entry, "entry"),
(Quotation, "quotation"),
(Blogmark, "blogmark"),
):
ids = model.objects.filter(
created__year=year, created__month=month
).values_list("id", flat=True)
items.extend(
[
{"type": content_type, "obj": obj}
for obj in list(
model.objects.prefetch_related("tags").in_bulk(ids).values()
)
]
)
)
blogmarks = list(Blogmark.objects.filter(created__year=year, created__month=month))
quotations = list(
Quotation.objects.filter(created__year=year, created__month=month)
)
# photos = list(Photo.objects.filter(
# created__year=year, created__month=month
# ))
# Extract non-de-duped list of ALL tags, for tag cloud
tags = []
for obj in entries + blogmarks + quotations:
tags.extend([t.tag for t in obj.tags.all()])
if not items:
raise Http404
items.sort(key=lambda x: x["obj"].created)
# Paginate it
paginator = Paginator(items, min(1000, int(request.GET.get("size") or "30")))
page_number = request.GET.get("page") or "1"
if page_number == "last":
page_number = paginator.num_pages
try:
page = paginator.page(page_number)
except PageNotAnInteger:
raise Http404
except EmptyPage:
raise Http404

return render(
request,
"archive_month.html",
{"date": datetime.date(year, month, 1), "entries": entries, "tags": tags},
{
"items": page.object_list,
"total": paginator.count,
"page": page,
"date": datetime.date(year, month, 1),
},
)


Expand Down
2 changes: 1 addition & 1 deletion static/css/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ div p.search-selections .filters {
padding-right: 0.6em;
}

.archive-tag-h2 {
.archive-h2 {
font-size: 1.4em;
}
h3.blog-mixed-list-year {
Expand Down
33 changes: 11 additions & 22 deletions templates/archive_month.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
{% extends "smallhead.html" %}
{% extends "smallhead.html" %}{% load humanize %}

{% block title %}Archive for {{ date|date:"F Y" }}{% endblock %}

{% block primary %}
<div class="entry">
<h2>{{ date|date:"F Y"}}</h2>

{% if entries %}
<h3>Blog entries</h3>
<ul>
{% for entry in entries %}
<li>{{ entry.created|date:"jS"}}: <strong><a href="{{ entry.get_absolute_url }}">{{ entry.title }}</a></strong></li>
{% endfor %}
</ul>
{% endif %}

{% if tags %}
<h3>Tags</h3>
<p id="tagcloud">
{% load tag_cloud %}
{% tag_cloud_for_tags tags %}
</p>
{% endif %}
</div>

<h2 class="archive-h2">{{ date|date:"F Y"}}</h2>

{% load blog_tags %}

{% blog_mixed_list_with_dates items %}

{% include "_pagination.html" %}

{% endblock %}

{% block secondary %}
Expand All @@ -31,4 +20,4 @@ <h3>Tags</h3>
{% load blog_calendar %}
{% render_calendar_month_only date %}
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/archive_series.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Simon Willison: {{ series }}{% endblock %}

{% block primary %}
<h2 class="archive-tag-h2"><a href="/series/">Series</a>: {{ series }}</h2>
<h2 class="archive-h2"><a href="/series/">Series</a>: {{ series }}</h2>

<p>{{ series.summary }}</p>

Expand Down
2 changes: 1 addition & 1 deletion templates/archive_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Simon Willison on {{ tags|join:" and " }}{% endblock %}

{% block primary %}
<h2 class="archive-tag-h2">{{ total|intcomma }} item{{ total|pluralize }} tagged “{{ tags|join:"” and “" }}”</h2>
<h2 class="archive-h2">{{ total|intcomma }} item{{ total|pluralize }} tagged “{{ tags|join:"” and “" }}”</h2>
<!-- Tag ID: {{ tag.pk }} -->
{% if tag.description %}
<div class="tag-description">{{ tag.description_rendered }}</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/projects/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block title %}Simon Willison’s Weblog: Projects{% endblock %}
{% block primary %}

<h2 class="archive-tag-h2">Projects</h2>
<h2 class="archive-h2">Projects</h2>

{% for project in projects %}
<h3>{{ project }}</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/series_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block title %}Simon Willison’s Weblog: Series of posts{% endblock %}
{% block primary %}

<h2 class="archive-tag-h2">Series of posts</h2>
<h2 class="archive-h2">Series of posts</h2>

{% for series in all_series %}
<h3><a href="/series/{{ series.slug }}/">{{ series.title }}</a></h3>
Expand Down

0 comments on commit 6a81eda

Please sign in to comment.