Skip to content

Commit

Permalink
Move user_badge to forum module (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff128 authored Nov 29, 2024
1 parent 00f496b commit 44f554c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
30 changes: 0 additions & 30 deletions oioioi/contests/templatetags/get_user_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from oioioi.base.utils import get_user_display_name
from oioioi.contests.utils import can_see_personal_data, is_contest_basicadmin
from oioioi.forum.utils import is_forum_moderator
from django.utils.translation import gettext_lazy as _

register = template.Library()

Expand Down Expand Up @@ -79,31 +77,3 @@ def public_name(parser, token):
def full_name(parser, token):
(user, asvar) = _get_name(parser, token, "full_name")
return FullNameUserInfoLinkNode(user, asvar)


class BadgeNode(Node):
'''
Returns a badge for a user if they are a moderator.
'''
def __init__(self, target_user, asvar):
self.target_user = Variable(target_user)
self.asvar = asvar

def render(self, context):
user = self.target_user.resolve(context)
if is_forum_moderator(context['request'], user):
badge = _(" (moderator)")
else:
badge = ""

if self.asvar:
context[self.asvar] = str(badge)
return ""
else:
return str(badge)


@register.tag
def user_badge(parser, token):
(user, asvar) = _get_name(parser, token, "user_badge")
return BadgeNode(user, asvar)
1 change: 1 addition & 0 deletions oioioi/forum/templates/forum/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load check_perm %}
{% load get_user_name %}
{% load pagination_tags %}
{% load user_badge %}

{% block title %}{% trans "Category" %}: {{ category.name }}{% endblock %}

Expand Down
1 change: 1 addition & 0 deletions oioioi/forum/templates/forum/thread-element-footer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load check_perm %}
{% load get_user_name %}
{% load user_badge %}

{% url 'forum_post_edit' contest_id=contest.id category_id=category.id thread_id=thread.id post_id=post.id as forum_post_edit_url %}
{% url 'forum_post_delete' contest_id=contest.id category_id=category.id thread_id=thread.id post_id=post.id as forum_post_delete_url %}
Expand Down
Empty file.
37 changes: 37 additions & 0 deletions oioioi/forum/templatetags/user_badge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django import template
from django.template import Node, Variable
from django.utils.translation import gettext_lazy as _

from oioioi.contests.templatetags.get_user_name import _get_name
from oioioi.forum.utils import is_forum_moderator

register = template.Library()


class BadgeNode(Node):
'''
Returns a badge for a user if they are a moderator.
'''

def __init__(self, target_user, asvar):
self.target_user = Variable(target_user)
self.asvar = asvar

def render(self, context):
user = self.target_user.resolve(context)
if is_forum_moderator(context['request'], user):
badge = _(" (moderator)")
else:
badge = ""

if self.asvar:
context[self.asvar] = str(badge)
return ""
else:
return str(badge)


@register.tag
def user_badge(parser, token):
(user, asvar) = _get_name(parser, token, "user_badge")
return BadgeNode(user, asvar)

0 comments on commit 44f554c

Please sign in to comment.