weeks can be breaks

This commit is contained in:
j 2025-01-31 16:29:27 +05:30
commit 92460179f5
5 changed files with 57 additions and 12 deletions

View file

@ -0,0 +1,23 @@
# Generated by Django 5.1.5 on 2025-01-31 10:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("item", "0009_week_byline"),
]
operations = [
migrations.AddField(
model_name="week",
name="break_notice",
field=models.TextField(blank=True, default="", editable=False),
),
migrations.AddField(
model_name="week",
name="is_break",
field=models.BooleanField(default=False),
),
]

View file

@ -74,6 +74,9 @@ class Item(models.Model):
cal = now.date().isocalendar()
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo)
current_week = Week.objects.filter(monday=monday).first()
if current_week and current_week.is_break:
return current_week, qs
first_post = qs.filter(published__gt=monday).first()
if first_post and first_post.published < now:
week = qs.filter(published__gt=monday)
@ -192,6 +195,8 @@ class Week(models.Model):
title = models.CharField(max_length=2048, blank=True, default="")
byline = models.CharField(max_length=2048, blank=True, default="")
published = models.DateTimeField(null=True, default=None, blank=True, editable=False)
is_break = models.BooleanField(default=False)
break_notice = models.TextField(default="", blank=True)
def __str__(self):
return "%s (%s)" % (self.title, self.monday)

View file

@ -69,9 +69,12 @@ def index(request):
else:
now = None
week, archive = models.Item.public(now)
context['items'] = week
if archive.exists():
if archive and archive.exists():
context['archive'] = '/_%s/' % get_monday(get_now() - timedelta(days=7))
if isinstance(week, models.Week) and week.is_break:
context["break"] = week
else:
context['items'] = week
if now:
context['now'] = now
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
@ -89,9 +92,7 @@ def archive(request, year=None, month=None, day=None, week=None):
archive_week = archive.filter(year=year, week=week).order_by('published')
years = {}
context['weeks'] = get_weeks(archive)
years["2024"] = []
for week in get_weeks(archive):
print(week)
if week["year"] not in years:
years[week["year"]] = []
years[week["year"]].append(week)
@ -104,7 +105,7 @@ def archive(request, year=None, month=None, day=None, week=None):
})
context['this_week'] = date.strftime('%Y-%m-%d')
context['this_year'] = date.strftime('%Y')
extra = models.Week.objects.filter(monday=context['this_week']).first()
extra = models.Week.objects.filter(monday=context['this_week'], is_break=False).first()
if extra:
context['week_title'] = extra.title
context['week_byline'] = extra.byline

View file

@ -83,6 +83,14 @@ header {
}
.index {
.break {
display: flex;
min-height: 80vh;
div {
margin: auto;
text-align: center;
}
}
.item {
border-bottom: 1px solid blueviolet;
padding-bottom: 4px;

View file

@ -5,9 +5,17 @@
{% endblock %}
{% block content %}
<div class="index">
{% if break %}
<div class="break">
<div>
{{ break.break_notice | safe }}
</div>
</div>
{% else %}
{% for item in items %}
{% include "listitem.html" with item=item %}
{% endfor %}
{% endif %}
{% if archive %}
<div class="archive">
<a href="{{ archive }}">previous weeks</a>