weeks can be breaks
This commit is contained in:
parent
e44e8b3c35
commit
92460179f5
5 changed files with 57 additions and 12 deletions
23
app/item/migrations/0010_week_break_notice_week_is_break.py
Normal file
23
app/item/migrations/0010_week_break_notice_week_is_break.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -74,6 +74,9 @@ class Item(models.Model):
|
||||||
cal = now.date().isocalendar()
|
cal = now.date().isocalendar()
|
||||||
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
|
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
|
||||||
monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo)
|
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()
|
first_post = qs.filter(published__gt=monday).first()
|
||||||
if first_post and first_post.published < now:
|
if first_post and first_post.published < now:
|
||||||
week = qs.filter(published__gt=monday)
|
week = qs.filter(published__gt=monday)
|
||||||
|
|
@ -192,6 +195,8 @@ class Week(models.Model):
|
||||||
title = models.CharField(max_length=2048, blank=True, default="")
|
title = models.CharField(max_length=2048, blank=True, default="")
|
||||||
byline = 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)
|
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):
|
def __str__(self):
|
||||||
return "%s (%s)" % (self.title, self.monday)
|
return "%s (%s)" % (self.title, self.monday)
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,16 @@ def index(request):
|
||||||
else:
|
else:
|
||||||
now = None
|
now = None
|
||||||
week, archive = models.Item.public(now)
|
week, archive = models.Item.public(now)
|
||||||
context['items'] = week
|
if archive and archive.exists():
|
||||||
if archive.exists():
|
|
||||||
context['archive'] = '/_%s/' % get_monday(get_now() - timedelta(days=7))
|
context['archive'] = '/_%s/' % get_monday(get_now() - timedelta(days=7))
|
||||||
if now:
|
if isinstance(week, models.Week) and week.is_break:
|
||||||
context['now'] = now
|
context["break"] = week
|
||||||
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
|
else:
|
||||||
context['next_week'] = (now + timedelta(days=7)).strftime(TS_FORMAT)
|
context['items'] = week
|
||||||
|
if now:
|
||||||
|
context['now'] = now
|
||||||
|
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
|
||||||
|
context['next_week'] = (now + timedelta(days=7)).strftime(TS_FORMAT)
|
||||||
return render(request, 'index.html', context)
|
return render(request, 'index.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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')
|
archive_week = archive.filter(year=year, week=week).order_by('published')
|
||||||
years = {}
|
years = {}
|
||||||
context['weeks'] = get_weeks(archive)
|
context['weeks'] = get_weeks(archive)
|
||||||
years["2024"] = []
|
|
||||||
for week in get_weeks(archive):
|
for week in get_weeks(archive):
|
||||||
print(week)
|
|
||||||
if week["year"] not in years:
|
if week["year"] not in years:
|
||||||
years[week["year"]] = []
|
years[week["year"]] = []
|
||||||
years[week["year"]].append(week)
|
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_week'] = date.strftime('%Y-%m-%d')
|
||||||
context['this_year'] = date.strftime('%Y')
|
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:
|
if extra:
|
||||||
context['week_title'] = extra.title
|
context['week_title'] = extra.title
|
||||||
context['week_byline'] = extra.byline
|
context['week_byline'] = extra.byline
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,14 @@ header {
|
||||||
}
|
}
|
||||||
|
|
||||||
.index {
|
.index {
|
||||||
|
.break {
|
||||||
|
display: flex;
|
||||||
|
min-height: 80vh;
|
||||||
|
div {
|
||||||
|
margin: auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
.item {
|
.item {
|
||||||
border-bottom: 1px solid blueviolet;
|
border-bottom: 1px solid blueviolet;
|
||||||
padding-bottom: 4px;
|
padding-bottom: 4px;
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,17 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="index">
|
<div class="index">
|
||||||
{% for item in items %}
|
{% if break %}
|
||||||
{% include "listitem.html" with item=item %}
|
<div class="break">
|
||||||
{% endfor %}
|
<div>
|
||||||
|
{{ break.break_notice | safe }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% for item in items %}
|
||||||
|
{% include "listitem.html" with item=item %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% if archive %}
|
{% if archive %}
|
||||||
<div class="archive">
|
<div class="archive">
|
||||||
<a href="{{ archive }}">previous weeks</a>
|
<a href="{{ archive }}">previous weeks</a>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue