Skip to content

Commit

Permalink
Merge pull request #444 from segir187/AggregatedTagsInSettings
Browse files Browse the repository at this point in the history
Show aggregated tags in settings
  • Loading branch information
segir187 authored Jan 20, 2025
2 parents 56d0d4c + fb3b594 commit 7291229
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions oioioi/base/utils/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def get_tag_prefix(tag):
'OriginInfoValue': 'origin',
'AlgorithmTag': 'algorithm',
'DifficultyTag': 'difficulty',
'AlgorithmTagProposal': 'algorithm-proposal',
'DifficultyTagProposal': 'difficulty-proposal',
'AggregatedAlgorithmTagProposal': 'algorithm-proposal',
'AggregatedDifficultyTagProposal': 'difficulty-proposal',
}

return prefixes[tag.__class__.__name__]
Expand Down
6 changes: 4 additions & 2 deletions oioioi/problems/problem_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from oioioi.problems.models import (
AlgorithmTagProposal,
DifficultyTagProposal,
AggregatedAlgorithmTagProposal,
AggregatedDifficultyTagProposal,
Problem,
ProblemAttachment,
ProblemPackage,
Expand Down Expand Up @@ -250,10 +252,10 @@ def problem_site_settings(request, problem):
model_solutions = generate_model_solutions_context(request, problem_instance)
extra_actions = problem.controller.get_extra_problem_site_actions(problem)
algorithm_tag_proposals = (
AlgorithmTagProposal.objects.all().filter(problem=problem).order_by('-pk')[:25]
AggregatedAlgorithmTagProposal.objects.all().filter(problem=problem).order_by('-amount')[:25]
)
difficulty_tag_proposals = (
DifficultyTagProposal.objects.all().filter(problem=problem).order_by('-pk')[:25]
AggregatedDifficultyTagProposal.objects.all().filter(problem=problem).order_by('-amount')[:25]
)

return TemplateResponse(
Expand Down
10 changes: 10 additions & 0 deletions oioioi/problems/static/common/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@
background-color: #2DB941;
color: #fff;
}

.tag-label-algorithm-proposal {
background-color: #91c5f5;
color: #000;
}

.tag-label-difficulty-proposal {
background-color: #90EE90;
color: #000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ <h4 class="text-center item-title">{% trans "Current tags" %}</h4>
<hr class="separator">
<h4 class="text-center item-title">{% trans "Users algorithms proposals" %}</h4>
{% for proposal in algorithm_tag_proposals %}
{% tag_label proposal.tag %}
{% aggregated_tag_label proposal %}
{% endfor %}
{% endif %}

{% if difficulty_tag_proposals %}
<hr class="separator">
<h4 class="text-center item-title">{% trans "Users difficulty proposals" %}</h4>
{% for proposal in difficulty_tag_proposals %}
{% tag_label proposal.tag %}
{% aggregated_tag_label proposal %}
{% endfor %}
{% endif %}

Expand Down
18 changes: 16 additions & 2 deletions oioioi/problems/templatetags/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def prefetch_tags(problems):
def tag_label(tag):
prefix = get_tag_prefix(tag)
return format_html(
u'<a title="{tooltip}" class="badge tag-label tag-label-{cls}" href="{href}" '
'<a title="{tooltip}" class="badge tag-label tag-label-{cls}" href="{href}" '
'>{name}</a>',
tooltip=getattr(tag, 'full_name', tag.name),
name=get_tag_name(tag),
Expand All @@ -32,11 +32,25 @@ def tag_label(tag):
)


@register.simple_tag
def aggregated_tag_label(aggregated_tag):
prefix = get_tag_prefix(aggregated_tag)
return format_html(
'<a title="{tooltip}" class="badge tag-label tag-label-{cls}" href="{href}" '
'>{name} | {amount}</a>',
tooltip=getattr(aggregated_tag.tag, 'full_name', aggregated_tag.tag.name),
name=get_tag_name(aggregated_tag.tag),
cls=prefix,
amount=str(aggregated_tag.amount),
href="?" + prefix + "=" + aggregated_tag.tag.name,
)


@register.simple_tag
def origininfo_label(info):
prefix = get_tag_prefix(info)
return format_html(
u'<a title="{tooltip}" class="badge tag-label tag-label-{cls}" href="{href}" '
'<a title="{tooltip}" class="badge tag-label tag-label-{cls}" href="{href}" '
'>{name}</a>',
tooltip=info.full_name,
name=info.value,
Expand Down

0 comments on commit 7291229

Please sign in to comment.