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

View File

@ -2,19 +2,19 @@
from django import forms from django import forms
from datetime import date from datetime import date
from .models import Routine, Routine_Skill, Chrono from .models import Routine, RoutineSkill, Chrono
class RoutineForm(forms.ModelForm): class RoutineForm(forms.ModelForm):
class Meta: class Meta:
model = Routine model = Routine
fields = ("longLabel", "shortLabel", "difficulty", "level", "active") fields = ("label", "label", "difficulty", "level", "active")
widgets = { widgets = {
# Champs obligatoires de la classe mère. # Champs obligatoires de la classe mère.
"longLabel": forms.TextInput( "label": forms.TextInput(
attrs={"class": "form-control", "placeholder": "Routine's long name"} attrs={"class": "form-control", "placeholder": "Routine's long name"}
), ),
"shortLabel": forms.TextInput( "label": forms.TextInput(
attrs={"class": "form-control", "placeholder": "Routine's short name"} attrs={"class": "form-control", "placeholder": "Routine's short name"}
), ),
"difficulty": forms.HiddenInput(), "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: class Meta:
verbose_name = "Educatif" verbose_name = "Educatif"
verbose_name_plural = "Educatifs" verbose_name_plural = "Educatifs"
ordering = ["longLabel", "shortLabel"] # 'level', ordering = ["label", "short_label"] # 'level',
longLabel = models.CharField(max_length = 255, verbose_name = "Long Name") label = models.CharField(max_length = 255, verbose_name = "Long Name")
shortLabel = models.CharField(max_length = 255, verbose_name = "Short Name") short_label = models.CharField(max_length = 255, verbose_name = "Short Name")
difficulty = models.DecimalField( difficulty = models.DecimalField(
max_digits = 3, decimal_places = 1, verbose_name = "Difficulty" max_digits = 3, decimal_places = 1, verbose_name = "Difficulty"
) )
level = models.PositiveSmallIntegerField(verbose_name = "Level", default = 0) level = models.PositiveSmallIntegerField(verbose_name = "Level", default = 0)
rank = models.PositiveSmallIntegerField(verbose_name = "Rank", default = 0) rank = models.PositiveSmallIntegerField(verbose_name = "Rank", default = 0)
educative = models.ManyToManyField( educatives = models.ManyToManyField(
"self", related_name = "educativeOf", blank = True, symmetrical = False "self", related_name = "educativeOf", blank = True, symmetrical = False
) )
prerequisite = models.ManyToManyField( prerequisites = models.ManyToManyField(
"self", related_name = "prerequisiteOf", blank = True, symmetrical = False "self", related_name = "prerequisiteOf", blank = True, symmetrical = False
) )
ageBoy = models.PositiveSmallIntegerField( age_boy = models.PositiveSmallIntegerField(
blank = True, null = True, verbose_name = "Boy's age" 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" blank = True, null = True, verbose_name = "Girl's age"
) )
@ -54,12 +54,12 @@ class TouchPosition(models.Model):
class Meta: class Meta:
verbose_name = "Landing" verbose_name = "Landing"
verbose_name_plural = "Landings" 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") label = models.CharField(max_length = 30, verbose_name = "Nom long")
shortLabel = models.CharField(max_length = 15, verbose_name = "Nom court") short_label = models.CharField(max_length = 15, verbose_name = "Nom court")
competition = models.BooleanField(verbose_name = "Compétition") allowed_in_competition = models.BooleanField(verbose_name = "Compétition")
default = models.BooleanField(verbose_name = "Défaut") is_default = models.BooleanField(verbose_name = "Défaut")
def __str__(self): def __str__(self):
return "%s" % (self.longLabel) return "%s" % (self.longLabel)
@ -119,18 +119,18 @@ class Skill(Educative):
verbose_name = "Landing position", verbose_name = "Landing position",
on_delete = models.CASCADE, on_delete = models.CASCADE,
) )
rotationType = models.PositiveSmallIntegerField( rotation_type = models.PositiveSmallIntegerField(
choices = ROTATION_CHOICES, verbose_name = "Type de rotation" choices = ROTATION_CHOICES, verbose_name = "Type de rotation"
) )
rotation = models.PositiveSmallIntegerField(verbose_name = "1/4 de rotation") rotation = models.PositiveSmallIntegerField(verbose_name = "1/4 de rotation")
twist = models.PositiveSmallIntegerField(verbose_name = "1/2 Vrille") twist = models.PositiveSmallIntegerField(verbose_name = "1/2 Vrille")
notation = models.CharField(max_length = 25) 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) is_competitive = models.BooleanField(default = False)
# importance = models.PositiveSmallIntegerField(default = 1) # importance = models.PositiveSmallIntegerField(default = 1)
def __str__(self): def __str__(self):
return "%s (%s)" % (self.shortLabel, self.notation) return "%s (%s)" % (self.short_label, self.notation)
class Routine(Educative): class Routine(Educative):
@ -144,12 +144,12 @@ class Routine(Educative):
active = models.BooleanField() active = models.BooleanField()
jumps = models.ManyToManyField( jumps = models.ManyToManyField(
Skill, through = "Routine_Skill", verbose_name = "routine" Skill, through = "RoutineSkill", verbose_name = "routine"
) # ceci n'est pas un vrai champ ) # ceci n'est pas un vrai champ
is_competitive = models.BooleanField(default = False) is_competitive = models.BooleanField(default = False)
def __str__(self): def __str__(self):
return "%s (%s)" % (self.shortLabel, self.shortLabel) return "%s (%s)" % (self.label, self.short_label)
def contains_basic_jumps(self): def contains_basic_jumps(self):
""" """
@ -207,7 +207,7 @@ class Routine(Educative):
).exists() ).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) 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): def __str__(self):
return "%s - %s : %s" % ( return "%s - %s : %s" % (
self.rank, self.rank,
self.routine.shortLabel, self.routine.short_label,
self.skill.shortLabel, self.skill.short_label,
) )

View File

@ -13,9 +13,9 @@ skill_urlpatterns = [
), ),
path(r"lookup/", views.skill_lookup), path(r"lookup/", views.skill_lookup),
path(r"search/", views.skill_listing), 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"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'level/<int:level>', views.skill_listing, name='listing_by_level'),
path(r"", views.skill_listing, name="skill_list"), path(r"", views.skill_listing, name="skill_list"),
] ]
@ -28,19 +28,19 @@ routine_urlpatterns = [
path( path(
r"edit/<int:routineid>/", views.routine_create_or_update, name="routine_update" 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"", 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( path(
r"<int:routineid>/add_skill/<int:skillid>/order/<int:order>/", r"<int:routineid>/add_skill/<int:skillid>/order/<int:order>/",
views.link_skill_to_routine, views.link_skill_to_routine,
name="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( path(
r"<int:routineid>/order/<int:order>/", r"<int:routineid>/order/<int:order>/",
views.del_skill_from_routine, views.delete_skill_from_routine,
name="del_skill_from_routine", name="delete_skill_from_routine",
), ),
path( path(
r"suggest/", r"suggest/",

View File

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

View File

@ -64,7 +64,7 @@
</a> </a>
</div> </div>
<div class="col-6 text-right"> <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 "> <button type="submit" value="add" class="btn btn-icon btn-warning ">
<i class="tim-icons icon-molecule-40"></i> <i class="tim-icons icon-molecule-40"></i>
</button> </button>