Skip to content

Commit

Permalink
Stop emailing me about Planet of the Monsters.
Browse files Browse the repository at this point in the history
This is a temporary workaround. We probably want a more permanent
placeholder anime graphic.
  • Loading branch information
colons committed Feb 15, 2024
1 parent e2bd5af commit 528d305
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion nkdsu/apps/vote/placeholder_avatars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from .voter import Voter


__all__ = ['placeholder_avatar_for']
__all__ = ['placeholder_art_for', 'placeholder_avatar_for']


def placeholder_art_for(string: str) -> str:
hashed: int = crc32(string.encode())
return _static_path_from_filename(AVATAR_FILENAMES[hashed % len(AVATAR_FILENAMES)])


def placeholder_avatar_for(voter: Voter) -> str:
Expand Down
9 changes: 8 additions & 1 deletion nkdsu/apps/vote/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.forms import BaseForm
from django.http import Http404, HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.templatetags.static import static
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.dateparse import parse_duration
Expand All @@ -29,6 +30,7 @@
TemplateView,
UpdateView,
)
from requests.exceptions import RequestException

from nkdsu.mixins import MarkdownView
from ..anime import get_anime, suggest_anime
Expand All @@ -43,6 +45,7 @@
TwitterUser,
Vote,
)
from ..placeholder_avatars import placeholder_art_for
from ..templatetags.vote_tags import eligible_for
from ..utils import BrowsableItem, BrowsableYear, vote_edit_cutoff
from ..voter import Voter
Expand Down Expand Up @@ -554,7 +557,11 @@ def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
if anime_data is None:
raise Http404()
if not anime_data.picture_is_cached():
anime_data.cache_picture()
try:
anime_data.cache_picture()
except RequestException:
return redirect(static(placeholder_art_for(anime_data.picture)))

return redirect(anime_data.cached_picture_url())


Expand Down

0 comments on commit 528d305

Please sign in to comment.