Skip to content

Commit

Permalink
Fix date of minutes entry having a wrong URL if minute is a draft
Browse files Browse the repository at this point in the history
  • Loading branch information
abc013 authored and jeriox committed Dec 21, 2023
1 parent 44c0e77 commit 7347956
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions myhpi/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db import models
from django.db.models import BooleanField, CharField, DateField, ForeignKey, Model, Q
from django.http import HttpResponseRedirect
from django.urls import reverse
from django_select2 import forms as s2forms
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey, ParentalManyToManyField
Expand Down Expand Up @@ -228,6 +229,14 @@ class Minutes(BasePage):

base_form_class = MinutesForm

# this function also fetches the correct draft url if the minute is still a draft
def get_valid_url(self):
return (
self.url
if self.live
else reverse("wagtailadmin_pages:view_draft", kwargs={"page_id": self.id})
)


class RootPage(InformationPage):
template = "core/information_page.html"
Expand Down
4 changes: 2 additions & 2 deletions myhpi/core/templates/core/minutes_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3 id="year{{ year }}">{{ year }}</h3>
<table class="table table-striped">
{% for minute in minutes %}
<tr>
<td><a href="{% pageurl minute %}">{{ minute.date|date:"d.m.Y" }}</a></td>
<td><a href="{{ minute.get_valid_url }}">{{ minute.date|date:"d.m.Y" }}</a></td>
<td>
{% if not minute.live %}
<span title={% translate "Draft" %} aria-hidden="true">⚠️</span>
Expand All @@ -18,7 +18,7 @@ <h3 id="year{{ year }}">{{ year }}</h3>
<td>
{% include "core/label.html" with minutes=minute %}
</td>
<td><a href="{% if minute.live %}{% pageurl minute %}{% else %}{% url "wagtailadmin_pages:view_draft" minute.id %}{% endif %}">{{ minute.title }}</a></td>
<td><a href="{{ minute.get_valid_url }}">{{ minute.title }}</a></td>
<td>
{% if minute.attachments.count > 0 %}
<span class="text-gray" data-toggle="tooltip" data-placement="left" data-container="body" title="{{ minute.attachments.all|join:', ' }}">
Expand Down

0 comments on commit 7347956

Please sign in to comment.