BO 1.15 faq, training plans
This commit is contained in:
@@ -8,4 +8,5 @@ from .tutorial import TutorialAdmin
|
||||
from .evaluation import EvaluationAdmin, EvaluationAttributeAdmin
|
||||
from .exercise_plan import ExercisePlanAdmin
|
||||
from .description import DescriptionAdmin
|
||||
|
||||
from .training_plan import TrainingPlanAdmin, TrainingPlanDetailAdmin
|
||||
from .faq import FaqAdmin
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models.faq import Faq, FaqTranslation
|
||||
|
||||
|
||||
class FaqDescriptionInline(admin.TabularInline):
|
||||
model = FaqTranslation
|
||||
fields = ('language_code', 'name_translation', 'description_translation')
|
||||
extra = 0
|
||||
|
||||
|
||||
class FaqAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
fields = ('name','description')
|
||||
|
||||
inlines = [
|
||||
FaqDescriptionInline,
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(Faq, FaqAdmin)
|
||||
admin.autodiscover()
|
||||
@@ -0,0 +1,84 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from ..models.training_plan import TrainingPlan, TrainingPlanDetail
|
||||
|
||||
|
||||
class TrainingPlanAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
fields = ('name',)
|
||||
|
||||
|
||||
class TrainingPlanDetailAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'training_plan', 'exercise_type', 'sort', 'set', 'repeats', 'max', 'weight', 'calc',
|
||||
'resting_time', 'parallel', 'day')
|
||||
list_filter = ('training_plan__name', 'exercise_type__name')
|
||||
list_editable = (
|
||||
'exercise_type', 'sort', 'set', 'repeats', 'weight', 'resting_time', 'parallel', 'day')
|
||||
ordering = ('sort',)
|
||||
|
||||
def repeat_max(self, obj):
|
||||
if obj.repeat_max:
|
||||
obj.repeats = -1
|
||||
else:
|
||||
obj.repeats = 0
|
||||
|
||||
def get_training_plan_info_info(self):
|
||||
first_row = _("Special cases: Weight = -1 IF the Weight should be calculated.")
|
||||
second_row = _("Repeats = -1 IF the repeats should be maximized")
|
||||
return first_row + second_row
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
response = super(TrainingPlanDetailAdmin, self).changelist_view(request, extra_context)
|
||||
extra_context = {
|
||||
'extra_hint': self.get_training_plan_info_info()
|
||||
}
|
||||
try:
|
||||
response.context_data.update(extra_context)
|
||||
except Exception as e:
|
||||
pass
|
||||
return response
|
||||
|
||||
def copy_attributes(self, request, queryset):
|
||||
for objectAttr in reversed(queryset):
|
||||
objectAttr.pk = None
|
||||
objectAttr.sort = objectAttr.sort + 1
|
||||
objectAttr.save()
|
||||
copy_attributes.short_description = _("Clone the selected Training Plan Detail")
|
||||
|
||||
def select_max_repeat(self, request, queryset):
|
||||
for obj in queryset:
|
||||
obj.repeats = -1
|
||||
obj.save()
|
||||
select_max_repeat.short_description = _("Select the exercises with MAX repeats")
|
||||
|
||||
def select_weight_calc(self, request, queryset):
|
||||
for obj in queryset:
|
||||
obj.weight = -1
|
||||
obj.save()
|
||||
select_weight_calc.short_description = _("Select the exercises CALCULATED weight")
|
||||
|
||||
def max(self, obj):
|
||||
color_code = "000000"
|
||||
if obj.repeats and obj.repeats == -1:
|
||||
color_code = 'C20000'
|
||||
|
||||
html = '<span style="color: #{};font-size:32px">{}</span>'.format(color_code, "*")
|
||||
return format_html(html)
|
||||
|
||||
def calc(self, obj):
|
||||
color_code = "000000"
|
||||
if obj.weight == -1:
|
||||
color_code = 'C20000'
|
||||
|
||||
html = '<span style="color: #{};font-size:32px">{}</span>'.format(color_code, "*")
|
||||
return format_html(html)
|
||||
|
||||
actions = [copy_attributes, select_max_repeat, select_weight_calc]
|
||||
|
||||
|
||||
admin.site.register(TrainingPlan, TrainingPlanAdmin)
|
||||
admin.site.register(TrainingPlanDetail, TrainingPlanDetailAdmin)
|
||||
admin.autodiscover()
|
||||
Reference in New Issue
Block a user