<commit_before>from django.conf import settings
from django.contrib import admin
from geotrek.common.admin import MergeActionMixin
from geotrek.outdoor.models import Practice, SiteType, RatingScale, Rating

if 'modeltranslation' in settings.INSTALLED_APPS:
    from modeltranslation.admin import TranslationAdmin
else:
    TranslationAdmin = admin.ModelAdmin


@admin.register(Practice)
class PracticeAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(SiteType)
class SiteTypeAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'practice')
    list_filter = ('practice', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(RatingScale)
class RatingScaleAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'practice')
    list_filter = ('practice', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(Rating)
class RatingAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'scale', 'order', 'color')
    list_filter = ('scale', 'scale__practice')
    search_fields = ('name', 'description', 'scale__name')
    merge_field = 'name'<commit_msg>Show colors in ratings admin<commit_after>from django.conf import settings
from django.contrib import admin
from django.utils.html import format_html
from django.utils.translation import gettext as _
from geotrek.common.admin import MergeActionMixin
from geotrek.outdoor.models import Practice, SiteType, RatingScale, Rating

if 'modeltranslation' in settings.INSTALLED_APPS:
    from modeltranslation.admin import TranslationAdmin
else:
    TranslationAdmin = admin.ModelAdmin


@admin.register(Practice)
class PracticeAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(SiteType)
class SiteTypeAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'practice')
    list_filter = ('practice', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(RatingScale)
class RatingScaleAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'practice')
    list_filter = ('practice', )
    search_fields = ('name', )
    merge_field = 'name'


@admin.register(Rating)
class RatingAdmin(MergeActionMixin, TranslationAdmin):
    list_display = ('name', 'scale', 'order', 'color_markup')
    list_filter = ('scale', 'scale__practice')
    search_fields = ('name', 'description', 'scale__name')
    merge_field = 'name'

    def color_markup(self, obj):
        if not obj.color:
            return ''
        return format_html('<span style="color: {code};">⬤</span> {code}', code=obj.color)
    color_markup.short_description = _("Color")
{'fraction_non_alphanumeric': 0.11990067399787159, 'fraction_numerical': 0.0, 'mean_word_length': 5.038543897216274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5736644', 'n_tokens_mistral': 862, 'n_tokens_neox': 813, 'n_words': 195}