Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix template cache #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ephios/core/forms/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from crispy_forms.layout import Field, Layout, Submit
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.template.loader import render_to_string
Expand Down Expand Up @@ -201,6 +203,11 @@ class Meta:
fields = ["title", "can_grant_qualification", "color"]
widgets = {"color": ColorInput()}

def save(self, commit=True):
cache_key = make_template_fragment_key("eventtype_colors")
cache.delete(cache_key)
return super().save(commit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a post_save signal? To me, the place where the css is generated seems like a more fitting place for this to live.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't get this to work, the cache is not invalidated with the same code that works here.


def clean_color(self):
regex = re.compile(r"#[a-fA-F\d]{6}")
if not regex.match(self.cleaned_data["color"]):
Expand Down
4 changes: 2 additions & 2 deletions ephios/core/templates/core/event_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

{% block html_head %}
<style nonce="{{ request.csp_nonce }}">
{% cache 900 "single_eventtype_color" event.type.pk %}
{{ event.type|color_css }}
{% cache 900 "eventtype_colors" %}
{% eventtype_colors %}
{% endcache %}
</style>
{% endblock %}
Expand Down
6 changes: 3 additions & 3 deletions ephios/core/templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ <h5 class="card-title">{% trans "Events with requested participations" %}</h5>
<li class="list-group-item flex-column">
<div class="d-flex w-100 justify-content-between align-items-center">
<span>{{ shift.event.title }} ({{ shift.get_start_end_time_display }})</span>
<div>
<a class="btn btn-outline-secondary btn-sm" href="{% url "core:event_detail" shift.event.pk shift.event.get_canonical_slug %}"><span
<div class="d-flex">
<a class="btn btn-outline-secondary btn-sm ml-1" href="{% url "core:event_detail" shift.event.pk shift.event.get_canonical_slug %}"><span
class="fa fa-eye"></span> <span class="d-none d-md-inline">{% translate "View" %}</span></a>
<a class="btn btn-outline-primary btn-sm" href="{% url "core:shift_disposition" shift.pk %}"><span
<a class="btn btn-outline-primary btn-sm ml-1" href="{% url "core:shift_disposition" shift.pk %}"><span
class="fas fa-hand-point-right"></span> <span class="d-none d-md-inline">{% translate "Disposition" %}</span></a>
</div>
</div>
Expand Down