[WIP] [Objective] Nomenclature des champs, classes et attributs #43

This commit is contained in:
Trullemans Gregory 2021-06-20 18:19:33 +02:00
parent 088895ec43
commit f089b06f54
7 changed files with 169 additions and 84 deletions

View File

@ -6,7 +6,7 @@ from .models import (
TouchPosition,
Skill,
Routine,
Routine_Skill,
RoutineSkill,
Chrono,
)
from django_extensions.admin import ForeignKeyAutocompleteAdmin
@ -15,10 +15,10 @@ from django_extensions.admin import ForeignKeyAutocompleteAdmin
class TouchPositionAdmin(admin.ModelAdmin):
model = TouchPosition
list_display = ("longLabel", "shortLabel", "competition", "default")
ordering = ("longLabel", "shortLabel")
search_fields = ("longLabel", "shortLabel")
list_filter = ("competition",)
list_display = ("label", "short_label", "allowed_in_competition", "is_default")
ordering = ("label", "short_label")
search_fields = ("label", "short_label")
list_filter = ("allowed_in_competition",)
def duplicate_skill(self, SkillAdmin, request, queryset):
@ -31,16 +31,16 @@ class SkillAdmin(ForeignKeyAutocompleteAdmin):
model = Skill
# related_search_fields = {
# 'departure': ('longLabel', 'shortLabel'),
# 'landing': ('longLabel', 'shortLabel')
# 'departure': ('label', 'short_label'),
# 'landing': ('label', 'short_label')
# }
fields = (
"longLabel",
"shortLabel",
"label",
"short_label",
"information",
"departure",
"landing",
"rotationType",
"rotation_type",
"position",
"rotation",
"twist",
@ -48,41 +48,41 @@ class SkillAdmin(ForeignKeyAutocompleteAdmin):
"level",
"rank",
"notation",
"simplyNotation",
"simplified_notation",
"is_competitive",
"ageBoy",
"ageGirl",
"prerequisite",
"educative",
"age_boy",
"age_girl",
"prerequisites",
"educatives",
)
list_display = (
"longLabel",
"label",
"difficulty",
"is_competitive",
"level",
"rank",
"notation",
"ageBoy",
"ageGirl",
"age_boy",
"age_girl",
)
# list_display = ('longLabel', 'shortLabel', 'prerequisite')
ordering = ("longLabel", "shortLabel")
search_fields = ("rank", "longLabel", "shortLabel")
# list_display = ('label', 'short_label', 'prerequisite')
ordering = ("label", "short_label")
search_fields = ("rank", "label", "short_label")
list_filter = (
"is_competitive",
"departure",
"landing",
"rotationType",
"rotation_type",
"rank",
"rotation",
"level",
"difficulty",
"ageBoy",
"ageGirl",
"age_boy",
"age_girl",
)
filter_horizontal = ("educative", "prerequisite")
filter_horizontal = ("educatives", "prerequisites")
duplicate_skill.short_description = "Duplicate selected record"
@ -94,21 +94,21 @@ class RoutineAdmin(admin.ModelAdmin):
model = Routine
fields = (
"longLabel",
"shortLabel",
"label",
"short_label",
"difficulty",
"level",
"rank",
"educative",
"prerequisite",
"ageBoy",
"ageGirl",
"educatives",
"prerequisites",
"age_boy",
"age_girl",
"active",
"is_competitive",
)
list_display = (
"longLabel",
"shortLabel",
"label",
"short_label",
"is_competitive",
"active",
"level",
@ -117,11 +117,11 @@ class RoutineAdmin(admin.ModelAdmin):
)
list_filter = ("level", "difficulty", "is_competitive", "active")
search_fields = (
"longLabel",
"shortLabel",
"label",
"short_label",
)
filter_horizontal = ("educative",)
filter_horizontal = ("educatives",)
class Media:
js = ("js/routine.js",)
@ -134,12 +134,12 @@ class RoutineAdmin(admin.ModelAdmin):
class RoutineSkillAdmin(admin.ModelAdmin):
model = Routine_Skill
model = RoutineSkill
list_display = ("routine", "skill", "rank")
search_fields = (
"routine__longLabel",
"routine__shortLabel",
"routine__label",
"routine__short_label",
)
ordering = ("routine",)
@ -153,7 +153,7 @@ class ChronoAdmin(ForeignKeyAutocompleteAdmin):
related_search_fields = {
"gymnast": ("lastname", "firstname"),
"routine": ("longLabel", "shortLabel"),
"routine": ("label", "short_label"),
}
@ -161,5 +161,5 @@ class ChronoAdmin(ForeignKeyAutocompleteAdmin):
admin.site.register(TouchPosition, TouchPositionAdmin)
admin.site.register(Skill, SkillAdmin)
admin.site.register(Routine, RoutineAdmin)
admin.site.register(Routine_Skill, RoutineSkillAdmin)
admin.site.register(RoutineSkill, RoutineSkillAdmin)
admin.site.register(Chrono, ChronoAdmin)

View File

@ -2,19 +2,19 @@
from django import forms
from datetime import date
from .models import Routine, Routine_Skill, Chrono
from .models import Routine, RoutineSkill, Chrono
class RoutineForm(forms.ModelForm):
class Meta:
model = Routine
fields = ("longLabel", "shortLabel", "difficulty", "level", "active")
fields = ("label", "label", "difficulty", "level", "active")
widgets = {
# Champs obligatoires de la classe mère.
"longLabel": forms.TextInput(
"label": forms.TextInput(
attrs={"class": "form-control", "placeholder": "Routine's long name"}
),
"shortLabel": forms.TextInput(
"label": forms.TextInput(
attrs={"class": "form-control", "placeholder": "Routine's short name"}
),
"difficulty": forms.HiddenInput(),

View File

@ -0,0 +1,85 @@
# Generated by Django 3.2.2 on 2021-06-20 16:18
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('objective', '0016_rename_information_educative_content'),
]
operations = [
migrations.RenameModel(
old_name='Routine_Skill',
new_name='RoutineSkill',
),
migrations.AlterModelOptions(
name='educative',
options={'ordering': ['label', 'short_label'], 'verbose_name': 'Educatif', 'verbose_name_plural': 'Educatifs'},
),
migrations.AlterModelOptions(
name='touchposition',
options={'ordering': ['label', 'short_label', 'is_default', 'allowed_in_competition'], 'verbose_name': 'Landing', 'verbose_name_plural': 'Landings'},
),
migrations.RenameField(
model_name='educative',
old_name='ageBoy',
new_name='age_boy',
),
migrations.RenameField(
model_name='educative',
old_name='ageGirl',
new_name='age_girl',
),
migrations.RenameField(
model_name='educative',
old_name='educative',
new_name='educatives',
),
migrations.RenameField(
model_name='educative',
old_name='longLabel',
new_name='label',
),
migrations.RenameField(
model_name='educative',
old_name='prerequisite',
new_name='prerequisites',
),
migrations.RenameField(
model_name='educative',
old_name='shortLabel',
new_name='short_label',
),
migrations.RenameField(
model_name='skill',
old_name='rotationType',
new_name='rotation_type',
),
migrations.RenameField(
model_name='skill',
old_name='simplyNotation',
new_name='simplified_notation',
),
migrations.RenameField(
model_name='touchposition',
old_name='competition',
new_name='allowed_in_competition',
),
migrations.RenameField(
model_name='touchposition',
old_name='default',
new_name='is_default',
),
migrations.RenameField(
model_name='touchposition',
old_name='longLabel',
new_name='label',
),
migrations.RenameField(
model_name='touchposition',
old_name='shortLabel',
new_name='short_label',
),
]

View File

@ -15,25 +15,25 @@ class Educative(Markdownizable):
class Meta:
verbose_name = "Educatif"
verbose_name_plural = "Educatifs"
ordering = ["longLabel", "shortLabel"] # 'level',
ordering = ["label", "short_label"] # 'level',
longLabel = models.CharField(max_length = 255, verbose_name = "Long Name")
shortLabel = models.CharField(max_length = 255, verbose_name = "Short Name")
label = models.CharField(max_length = 255, verbose_name = "Long Name")
short_label = models.CharField(max_length = 255, verbose_name = "Short Name")
difficulty = models.DecimalField(
max_digits = 3, decimal_places = 1, verbose_name = "Difficulty"
)
level = models.PositiveSmallIntegerField(verbose_name = "Level", default = 0)
rank = models.PositiveSmallIntegerField(verbose_name = "Rank", default = 0)
educative = models.ManyToManyField(
educatives = models.ManyToManyField(
"self", related_name = "educativeOf", blank = True, symmetrical = False
)
prerequisite = models.ManyToManyField(
prerequisites = models.ManyToManyField(
"self", related_name = "prerequisiteOf", blank = True, symmetrical = False
)
ageBoy = models.PositiveSmallIntegerField(
age_boy = models.PositiveSmallIntegerField(
blank = True, null = True, verbose_name = "Boy's age"
)
ageGirl = models.PositiveSmallIntegerField(
age_girl = models.PositiveSmallIntegerField(
blank = True, null = True, verbose_name = "Girl's age"
)
@ -54,12 +54,12 @@ class TouchPosition(models.Model):
class Meta:
verbose_name = "Landing"
verbose_name_plural = "Landings"
ordering = ["longLabel", "shortLabel", "default", "competition"]
ordering = ["label", "short_label", "is_default", "allowed_in_competition"]
longLabel = models.CharField(max_length = 30, verbose_name = "Nom long")
shortLabel = models.CharField(max_length = 15, verbose_name = "Nom court")
competition = models.BooleanField(verbose_name = "Compétition")
default = models.BooleanField(verbose_name = "Défaut")
label = models.CharField(max_length = 30, verbose_name = "Nom long")
short_label = models.CharField(max_length = 15, verbose_name = "Nom court")
allowed_in_competition = models.BooleanField(verbose_name = "Compétition")
is_default = models.BooleanField(verbose_name = "Défaut")
def __str__(self):
return "%s" % (self.longLabel)
@ -119,18 +119,18 @@ class Skill(Educative):
verbose_name = "Landing position",
on_delete = models.CASCADE,
)
rotationType = models.PositiveSmallIntegerField(
rotation_type = models.PositiveSmallIntegerField(
choices = ROTATION_CHOICES, verbose_name = "Type de rotation"
)
rotation = models.PositiveSmallIntegerField(verbose_name = "1/4 de rotation")
twist = models.PositiveSmallIntegerField(verbose_name = "1/2 Vrille")
notation = models.CharField(max_length = 25)
simplyNotation = models.CharField(max_length = 25, verbose_name = "Notation simplifiée")
simplified_notation = models.CharField(max_length = 25, verbose_name = "Notation simplifiée")
is_competitive = models.BooleanField(default = False)
# importance = models.PositiveSmallIntegerField(default = 1)
def __str__(self):
return "%s (%s)" % (self.shortLabel, self.notation)
return "%s (%s)" % (self.short_label, self.notation)
class Routine(Educative):
@ -144,12 +144,12 @@ class Routine(Educative):
active = models.BooleanField()
jumps = models.ManyToManyField(
Skill, through = "Routine_Skill", verbose_name = "routine"
Skill, through = "RoutineSkill", verbose_name = "routine"
) # ceci n'est pas un vrai champ
is_competitive = models.BooleanField(default = False)
def __str__(self):
return "%s (%s)" % (self.shortLabel, self.shortLabel)
return "%s (%s)" % (self.label, self.short_label)
def contains_basic_jumps(self):
"""
@ -207,7 +207,7 @@ class Routine(Educative):
).exists()
class Routine_Skill(models.Model):
class RoutineSkill(models.Model):
"""
Classe de liaison permettant de liée une figure à une série. (relation n-n)
"""
@ -226,8 +226,8 @@ class Routine_Skill(models.Model):
def __str__(self):
return "%s - %s : %s" % (
self.rank,
self.routine.shortLabel,
self.skill.shortLabel,
self.routine.short_label,
self.skill.short_label,
)

View File

@ -13,9 +13,9 @@ skill_urlpatterns = [
),
path(r"lookup/", views.skill_lookup),
path(r"search/", views.skill_listing),
path(r"insert/", views.linkSkillGymnast),
path(r"insert/", views.link_skill_to_gymnast),
path(r"judge/training/", views.random_skill),
path(r"<int:skillid>/", views.skill_detail, name="skill_details"),
path(r"<int:skillid>/", views.skill_details, name="skill_details"),
# path(r'level/<int:level>', views.skill_listing, name='listing_by_level'),
path(r"", views.skill_listing, name="skill_list"),
]
@ -28,19 +28,19 @@ routine_urlpatterns = [
path(
r"edit/<int:routineid>/", views.routine_create_or_update, name="routine_update"
),
path(r"<int:routineid>", views.routine_detail, name="routine_details"),
path(r"<int:routineid>", views.routine_details, name="routine_details"),
path(r"", views.routine_listing, name="routine_list"),
path(r"compose/<int:routineid>/", views.routine_compose, name="routine_compose"),
path(r"compose/<int:routineid>/", views.compose_routine, name="compose_routine"),
path(
r"<int:routineid>/add_skill/<int:skillid>/order/<int:order>/",
views.link_skill_to_routine,
name="link_skill_to_routine",
),
# path(r'<int:routineid>/del_skill/<int:skillid>/order/<int:order>/', views.del_skill_from_routine, name="del_skill_from_routine"),
# path(r'<int:routineid>/del_skill/<int:skillid>/order/<int:order>/', views.delete_skill_from_routine, name="delete_skill_from_routine"),
path(
r"<int:routineid>/order/<int:order>/",
views.del_skill_from_routine,
name="del_skill_from_routine",
views.delete_skill_from_routine,
name="delete_skill_from_routine",
),
path(
r"suggest/",

View File

@ -13,7 +13,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt
import simplejson
from .models import Skill, Educative, Routine, Chrono, Routine_Skill
from .models import Skill, Educative, Routine, Chrono, RoutineSkill
from .forms import RoutineForm, ChronoForm
from people.models import Gymnast, CanDoRelation
@ -100,7 +100,7 @@ def skill_lookup(request):
@login_required
@require_http_methods(["GET"])
def skill_detail(request, skillid):
def skill_details(request, skillid):
"""
Récupère toutes les informations d'un skill.
@ -115,7 +115,7 @@ def skill_detail(request, skillid):
@login_required
@require_http_methods(["POST"])
def linkSkillGymnast(request):
def link_skill_to_gymnast(request):
"""
Lie un gymnast à une figure.
"""
@ -171,7 +171,7 @@ def routine_lookup(request):
@login_required
@require_http_methods(["GET"])
def routine_compose(request, routineid):
def compose_routine(request, routineid):
"""
Récupère une routine et les sauts associés.
"""
@ -183,7 +183,7 @@ def routine_compose(request, routineid):
"skill_link_list": routine.skill_links.all(),
"number_of_skill": number_of_skill,
}
return render(request, "routine_compose.html", context)
return render(request, "compose_routine.html", context)
# @login_required
@ -195,24 +195,24 @@ def link_skill_to_routine(request, routineid, skillid, order):
"""
routine = get_object_or_404(Routine, pk=routineid)
skill = get_object_or_404(Skill, pk=skillid)
link, created = Routine_Skill.objects.get_or_create(
link, created = RoutineSkill.objects.get_or_create(
routine=routine, skill=skill, rank=order
)
# context = {'link':link, 'created':created}
# return render(request, 'routine_compose.html', context)
# return render(request, 'compose_routine.html', context)
return HttpResponse(200, (link, created))
# except:
# return False
def del_skill_from_routine(request, routineid, order):
def delete_skill_from_routine(request, routineid, order):
"""
Recoit trois informations permettant de lier complètement un saut à une routine
"""
routine = get_object_or_404(Routine, pk=routineid)
try:
link = Routine_Skill.objects.get(routine=routine, rank=order).delete()
link = RoutineSkill.objects.get(routine=routine, rank=order).delete()
except:
return HttpResponse(409)
@ -230,7 +230,7 @@ def del_skill_from_routine(request, routineid, order):
@login_required
def routine_detail(request, routineid):
def routine_details(request, routineid):
"""
Récupère toutes les informations d'une routine (série).
@ -312,7 +312,7 @@ def routine_create_or_update(request, routine_id=None):
if form.is_valid():
routine = form.save()
# ici faire un FOR skill in form_skills_list:
# record.save() # ca sauve le record dans la table ROUTINE_SKILL
# record.save() # ca sauve le record dans la table RoutineSkill
# something like this : http://stackoverflow.com/questions/3074938/django-m2m-form-save-through-table
# TO_FRED : can you help me ?
return HttpResponseRedirect(reverse("routine_details", args=(routine.pk,)))

View File

@ -64,7 +64,7 @@
</a>
</div>
<div class="col-6 text-right">
<a href="{% url 'routine_compose' routine.id %}">
<a href="{% url 'compose_routine' routine.id %}">
<button type="submit" value="add" class="btn btn-icon btn-warning ">
<i class="tim-icons icon-molecule-40"></i>
</button>