Skip to content

Commit

Permalink
use correct fragment cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt committed Jul 6, 2023
1 parent 4e3fee3 commit 4498292
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ephios/core/forms/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django import forms
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.template.loader import render_to_string
Expand All @@ -24,6 +23,7 @@
from ephios.core.models import Event, EventType, LocalParticipation, Shift, UserProfile
from ephios.core.signup.methods import enabled_signup_methods, signup_method_from_slug
from ephios.core.widgets import MultiUserProfileWidget
from ephios.extra.colors import clear_eventtype_color_css_fragment_cache
from ephios.extra.crispy import AbortLink
from ephios.extra.permissions import get_groups_with_perms
from ephios.extra.widgets import ColorInput, CustomDateInput, CustomTimeInput
Expand Down Expand Up @@ -249,7 +249,7 @@ def clean_color(self):
return self.cleaned_data["color"]

def save(self, commit=True):
cache.delete("eventtype_colors_css")
clear_eventtype_color_css_fragment_cache()
return super().save(commit=commit)


Expand Down
2 changes: 1 addition & 1 deletion ephios/core/templates/core/event_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{% block content %}
<style nonce="{{ request.csp_nonce }}">
{% cache 900 "eventtype_colors_css" %}
{% cache 900 eventtype_colors_css %}
{% eventtype_colors %}
{% endcache %}
</style>
Expand Down
2 changes: 1 addition & 1 deletion ephios/core/templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="page-header">
</h1>

<style nonce="{{ request.csp_nonce }}">
{% cache 900 "eventtype_colors_css" %}
{% cache 900 eventtype_colors_css %}
{% eventtype_colors %}
{% endcache %}
</style>
Expand Down
8 changes: 8 additions & 0 deletions ephios/extra/colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# inspired by https://jfelix.info/blog/how-to-make-a-text-color-fit-any-background-color
from math import sqrt

from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key

from ephios.core.models import EventType


Expand Down Expand Up @@ -30,3 +33,8 @@ def get_eventtype_color_style(eventtype: EventType):
return (
f".eventtype-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}"
)


def clear_eventtype_color_css_fragment_cache():
key = make_template_fragment_key("eventtype_colors_css", vary_on=None)
cache.delete(key)

0 comments on commit 4498292

Please sign in to comment.