Caching and refactors

This commit is contained in:
cuom1999 2024-04-13 17:02:54 -05:00
parent 67b06d7856
commit 8f1c8d6c96
33 changed files with 485 additions and 381 deletions

View file

@ -22,6 +22,7 @@ from . import (
social,
spaceless,
timedelta,
comment,
)
from . import registry

12
judge/jinja2/comment.py Normal file
View file

@ -0,0 +1,12 @@
from . import registry
from django.contrib.contenttypes.models import ContentType
from judge.models.comment import get_visible_comment_count
from judge.caching import cache_wrapper
@registry.function
def comment_count(obj):
content_type = ContentType.objects.get_for_model(obj)
return get_visible_comment_count(content_type, obj.pk)

View file

@ -155,16 +155,14 @@ def item_title(item):
@registry.function
@registry.render_with("user/link.html")
def link_user(user):
def link_user(user, show_image=False):
if isinstance(user, Profile):
profile = user
elif isinstance(user, AbstractUser):
profile = user.profile
elif type(user).__name__ == "ContestRankingProfile":
profile = user
else:
raise ValueError("Expected profile or user, got %s" % (type(user),))
return {"profile": profile}
return {"profile": profile, "show_image": show_image}
@registry.function