show= links show the correct page & permalink button

This commit is contained in:
MatthiasSaihttam 2021-10-12 12:47:35 -04:00
parent b2241c6ab9
commit 9d49698394
4 changed files with 63 additions and 23 deletions

View File

@ -13,9 +13,39 @@ class Page:
pass
# Okay we're going to use some wack seasons here hold on
# Let's go meteorological seasons
# 1 - jan -> 1, 0
# 2 - feb -> 2, 0
# 3 - mar -> 3, 1, spring
# 4 - apl -> 4, 1
# 5 - may -> 5, 1
# 6 - jun -> 6, 2, summer
# 7 - jul -> 7, 2
# 8 - aug -> 8, 2
# 9 - sep -> 9, 3, fall
# 10 - oct -> 10, 3
# 11 - nov -> 11, 3
# 12 - dec -> 0, 0, winter
def season_for_date(date):
return (date.month % 12) // 3
def season_year_for_date(date):
return season_for_date(date), date.year - (1 if date.month in [1, 2] else 0)
def formatted_name_for_season_year(current_season, current_year):
return ["Winter", "Spring", "Summer", "Fall"][current_season] + " " + str(current_year)
def get_page_slug(thought):
return slugify(formatted_name_for_season_year(*season_year_for_date(thought.posted)))
class SeasonPage(Page):
def __init__(self, current_season, current_year):
super().__init__(["Winter", "Spring", "Summer", "Fall"][current_season] + " " + str(current_year))
super().__init__(formatted_name_for_season_year(current_season, current_year))
self.first_day_of_season = datetime.date(
current_year,
@ -48,23 +78,6 @@ def season_pages():
first_thought = ordered_thoughts.first()
last_thought = ordered_thoughts.last()
# Okay we're going to use some wack seasons here hold on
# Let's go meteorological seasons
# 1 - jan -> 1, 0
# 2 - feb -> 2, 0
# 3 - mar -> 3, 1, spring
# 4 - apl -> 4, 1
# 5 - may -> 5, 1
# 6 - jun -> 6, 2, summer
# 7 - jul -> 7, 2
# 8 - aug -> 8, 2
# 9 - sep -> 9, 3, fall
# 10 - oct -> 10, 3
# 11 - nov -> 11, 3
# 12 - dec -> 0, 0, winter
def season_for_date(date):
return (date.month % 12) // 3
current_year = first_thought.posted.year
current_season = season_for_date(first_thought.posted)
while current_year < last_thought.posted.year or current_season != season_for_date(last_thought.posted):
@ -77,7 +90,6 @@ def season_pages():
yield SeasonPage(current_season, current_year)
def get_all_pages():
pages = list(season_pages())
pages.reverse()

View File

@ -154,6 +154,8 @@ a {
.thought-end {
overflow: auto;
font-size: 14px;
color: var(--accent-color);
}
.thought hr {
@ -162,10 +164,23 @@ a {
border-bottom: 1px var(--accent-color) solid;
}
.timestamp {
.timestamp, .permalink {
float: right;
font-size: 14px;
}
.permalink {
margin-right: 6px;
color: var(--text-color)
}
.permalink .button, .permalink .button:visited {
color: var(--accent-color);
margin-right: 4px;
}
.permalink .button:hover {
text-decoration: underline;
}
.permalink::after {
content: "•"
}
/* Navbar styles */

View File

@ -18,7 +18,7 @@
{% load tz %}
{% for thought in thoughts %}
<div class="thought{% if thought.uuid == highlighted %} highlighted{% endif %}" id="{{thought.uuid}}">
<div class="thought{% if thought.uuid == highlighted %} highlighted{% endif %}" id="{{ thought.uuid }}">
<div class="main">
<span class="main-text text">{{thought.text}}</span>
</div>
@ -49,6 +49,9 @@
{{ thought.get_season }}
{% endtimezone %}
</span>
<span class="permalink">
<a class="button" href="/?show={{thought.uuid}}">Permalink</a>
</span>
</div>
<hr>
</div>

View File

@ -10,7 +10,7 @@ from django.utils.crypto import constant_time_compare
from whispermaphone import settings
from .models import Thought, ThoughtForm, ALLOWED_MEDIA_TYPES
from .pagination import get_all_pages
from .pagination import get_all_pages, get_page_slug
def check_authenticated(request):
authenticated = False
@ -30,11 +30,21 @@ def index(request):
except ValueError:
highlighted_uuid = ""
# Figure out what page we're viewing
pages = get_all_pages()
# First item in pages should be listed first
requested_page = pages[0]
requested_slug = request.GET.get("page", default=requested_page.slug)
# show=uuid takes priority over page
if highlighted_uuid:
try:
highlighted_thought = Thought.objects.get(uuid=highlighted_uuid)
requested_slug = get_page_slug(highlighted_thought)
except Thought.DoesNotExist:
pass
if requested_page.slug != requested_slug:
for p in pages:
if p.slug == requested_slug: