<commit_before>#
#   Copyright 2013 by <NAME> <<EMAIL>>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from copy import deepcopy

from django.contrib import admin
from mezzanine.core.admin import DisplayableAdmin, OwnableAdmin
from mezzanine.conf import settings

from .models import Workout, WorkoutCategory

fieldsets = list(deepcopy(DisplayableAdmin.fieldsets))
fieldsets[0][1]['fields'].insert(1, 'categories')
fieldsets[0][1]['fields'].extend(['content'])
fieldsets.insert(1, (
    'Workout Data', {
        'fields': [
            'avg_heart_rate', 'avg_speed',
            'max_heart_rate', 'max_speed',
            'total_ascent', 'total_calories', 'total_distance',
            'total_elapsed_time', 'total_timer_time',
        ]
    }
))
list_filter = deepcopy(DisplayableAdmin.list_filter) + ('categories',)


class WorkoutAdmin(DisplayableAdmin, OwnableAdmin):
    fieldsets = fieldsets
    list_filter = list_filter


class WorkoutCategoryAdmin(admin.ModelAdmin):
    """
    Admin class for workout categories. Hides itself from the admin menu
    unless explicitly specified.
    """

    fieldsets = ((None, {"fields": ("title",)}),)

    def in_menu(self):
        """
        Hide from the admin menu unless explicitly set in ``ADMIN_MENU_ORDER``.
        """
        for (name, items) in settings.ADMIN_MENU_ORDER:
            if "workout.WorkoutCategory" in items:
                return True
        return False

admin.site.register(Workout, WorkoutAdmin)
admin.site.register(WorkoutCategory, WorkoutCategoryAdmin)
<commit_msg>better columns in the admin-interface for workouts<commit_after>#
#   Copyright 2013 by <NAME> <<EMAIL>>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from copy import deepcopy

from django.contrib import admin
from mezzanine.core.admin import DisplayableAdmin, OwnableAdmin
from mezzanine.conf import settings

from .models import Workout, WorkoutCategory

fieldsets = list(deepcopy(DisplayableAdmin.fieldsets))
fieldsets[0][1]['fields'].insert(1, 'categories')
fieldsets[0][1]['fields'].extend(['content'])
fieldsets.insert(1, (
    'Workout Data', {
        'fields': [
            'avg_heart_rate', 'avg_speed',
            'max_heart_rate', 'max_speed',
            'total_ascent', 'total_calories', 'total_distance',
            'total_elapsed_time', 'total_timer_time',
        ]
    }
))
list_filter = deepcopy(DisplayableAdmin.list_filter) + ('categories',)


class WorkoutAdmin(DisplayableAdmin, OwnableAdmin):
    fieldsets = fieldsets
    list_filter = list_filter
    list_display = ['publish_date', 'title', 'user', 'distance', 'total_time', 'speed', 'heartrate', 'status', 'admin_link']

    def distance(self, instance):
        if instance.total_distance is not None:
            return '%.1f km' % (instance.total_distance/1000.)
        return ''

    def total_time(self, instance):
        if instance.total_timer_time is not None:
            seconds = instance.total_timer_time
            minutes = seconds // 60
            hours = minutes // 60
            return "%i:%02i:%02i" % (hours, minutes%60, seconds%60)

    def speed(self, instance):
        if instance.avg_speed is not None:
            return '%.1f km/h' % (instance.avg_speed*1000/360)
        return ''

    def heartrate(self, instance):
        if instance.avg_heart_rate is not None:
            return '%i bpm' % instance.avg_heart_rate
        return ''


class WorkoutCategoryAdmin(admin.ModelAdmin):
    """
    Admin class for workout categories. Hides itself from the admin menu
    unless explicitly specified.
    """

    fieldsets = ((None, {"fields": ("title",)}),)

    def in_menu(self):
        """
        Hide from the admin menu unless explicitly set in ``ADMIN_MENU_ORDER``.
        """
        for (name, items) in settings.ADMIN_MENU_ORDER:
            if "workout.WorkoutCategory" in items:
                return True
        return False

admin.site.register(Workout, WorkoutAdmin)
admin.site.register(WorkoutCategory, WorkoutCategoryAdmin)

{'fraction_non_alphanumeric': 0.10474112279309661, 'fraction_numerical': 0.010513786947034318, 'mean_word_length': 3.3057216054654144, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3551898', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1415, 'n_words': 442}