Adding new functionnalities and code refactoring
This commit is contained in:
parent
583e94de98
commit
c2c536464a
|
@ -16,6 +16,7 @@ from objective.models import Routine
|
|||
|
||||
from profiles.models import Profile
|
||||
from followup.models import Accident, Skill, MindState, Point
|
||||
from location.models import Place, Club
|
||||
from people.models import Gymnast
|
||||
from planning.models import Event
|
||||
from tools.models import get_number_of_weeks_between
|
||||
|
@ -65,6 +66,16 @@ def logout(request):
|
|||
return HttpResponseRedirect("/login/")
|
||||
|
||||
|
||||
def next_birthdays(request, number_of_birthday):
|
||||
"""
|
||||
Renvoie la liste des `number_of_birthday` prochains anniversaires.
|
||||
"""
|
||||
birthday_list = sorted(
|
||||
Gymnast.objects.all(), key=lambda t: t.next_birthday_in_days
|
||||
)[:number_of_birthday]
|
||||
return birthday_list
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET"])
|
||||
def home(request):
|
||||
|
@ -88,6 +99,8 @@ def home(request):
|
|||
nb_score = Point.objects.all().count()
|
||||
percentage_week = int((get_number_of_weeks_between(datetime(2021, 9, 1), datetime.now()) / 52) * 100)
|
||||
|
||||
birthday_list = next_birthdays(request, 5)
|
||||
|
||||
context = {
|
||||
'event_list': event_list,
|
||||
'last_updated_gymnast': last_updated_gymnast,
|
||||
|
@ -96,7 +109,8 @@ def home(request):
|
|||
'nb_skill': nb_skill,
|
||||
'nb_routine': nb_routine,
|
||||
'nb_score': nb_score,
|
||||
'percentage_week': percentage_week
|
||||
'percentage_week': percentage_week,
|
||||
'birthday_list': birthday_list
|
||||
}
|
||||
return render(request, "ultron/dashboard/dashboard.html", context)
|
||||
|
||||
|
@ -119,12 +133,19 @@ def search(request):
|
|||
event_list = Event.objects.filter(
|
||||
Q(name__icontains=pattern) | Q(place__name__icontains=pattern)
|
||||
)
|
||||
# Ajouter place ?
|
||||
place_list = Place.objects.filter(
|
||||
Q(name__icontains=pattern) | Q(city__icontains=pattern)
|
||||
)
|
||||
club_list = Club.objects.filter(
|
||||
Q(name__icontains=pattern) | Q(place__name__icontains=pattern) | Q(place__city__icontains=pattern)
|
||||
)
|
||||
|
||||
context = {
|
||||
'gymnast_list': gymnast_list,
|
||||
'skill_list': skill_list,
|
||||
'event_list': event_list,
|
||||
'place_list': place_list,
|
||||
'club_list': club_list,
|
||||
'pattern': pattern
|
||||
}
|
||||
else:
|
||||
|
|
|
@ -33,7 +33,32 @@ class Gymnast(Markdownizable):
|
|||
|
||||
def __str__(self):
|
||||
return u"%s, %s" % (self.last_name, self.first_name)
|
||||
|
||||
|
||||
@property
|
||||
def next_birthday(self):
|
||||
"""Définit la prochaine date (de fête) d'anniversaire pour cette personne.
|
||||
|
||||
Returns:
|
||||
Soit le jour/mois pour cette année
|
||||
Soit le jour/mois pour l'année prochaine.
|
||||
|
||||
Examples: en supposant qu'on soit le 23/05/2019
|
||||
>>> from datetime import date
|
||||
>>> gregg = Gymnast(name='Tru', firstname='Gregg', birthdate=date(1982, 2, 5))
|
||||
>>> gregg.next_birthday()
|
||||
Date(2020, 2, 5)
|
||||
"""
|
||||
|
||||
now = pendulum.now()
|
||||
|
||||
this_year_birthday = pendulum.date(
|
||||
now.year, self.birthdate.month, self.birthdate.day
|
||||
)
|
||||
|
||||
if this_year_birthday.is_past():
|
||||
return pendulum.date(now.year + 1, self.birthdate.month, self.birthdate.day)
|
||||
return this_year_birthday
|
||||
|
||||
@property
|
||||
def next_birthday_in_days(self):
|
||||
now = pendulum.now()
|
||||
|
|
|
@ -73,11 +73,11 @@
|
|||
|
||||
<!-- {{ nb_known_skill }} known skills on {{ nb_skill }} skills. -->
|
||||
{% if gymnast_nb_known_skills %}
|
||||
{% for skill in percentages %}
|
||||
{% if skill.2 > 0 %}
|
||||
{% for level in percentages %}
|
||||
{% if level.2 > 0 %}
|
||||
<div class="progress-container progress-warning mt-2">
|
||||
<div class="progress" style="height: 10px;">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: {% widthratio skill.2 skill.1 100 %}%;"> Level {{ skill.0 }}</div>
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: {% widthratio level.2 level.1 100 %}%;"> Level {{ level.0 }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<h4 class=""><i class="icon-primary fal fa-laugh-wink"></i> Hi {{ user.username }} !</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
Welcome to Ultron v0.26<br />
|
||||
Welcome to Ultron v0.27<br />
|
||||
This application is there to help us manage the gymnasts (evolution, evaluation, ...). It is not perfect so feel free to make improvement proposals, bug reports, … by sending me an <a href="mailto:gregory@flyingacrobaticstrampoline.be">email</a>.
|
||||
</div>
|
||||
</div>
|
||||
|
@ -96,7 +96,19 @@
|
|||
<h4><i class="fal fa-birthday-cake"></i> Next birthday</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
(Under construction)
|
||||
{% if birthday_list %}
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="gymnast_table">
|
||||
{% for gymnast in birthday_list %}
|
||||
<tr>
|
||||
<td class="text-left"><a href="{% url 'gymnast_details' gymnast.id %}">{{ gymnast.first_name }}</a></td>
|
||||
<td class="">{{ gymnast.birthdate | date:"j M"}}</td>
|
||||
<td class="text-right">{{ gymnast.next_age }} years</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
No next birtday (it's a bug).
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
{% block content %}
|
||||
<div class="card mb-0">
|
||||
{% if gymnast_list or skill_list or event_list %}
|
||||
{% if gymnast_list or skill_list or event_list or place_list or club_list %}
|
||||
{% if gymnast_list %}
|
||||
<div class="card-header">
|
||||
<h4 class="card-title"> Gymnasts results</h4>
|
||||
<div class="card- pt-1">
|
||||
<h4 class="mb-0"> Gymnasts results</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<div class="card-body pt-1 pb-1">
|
||||
<div class="table-responsive pb-0">
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="gymnast_table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -46,11 +46,11 @@
|
|||
{% endif %}
|
||||
|
||||
{% if skill_list %}
|
||||
<div class="card-header">
|
||||
<h4 class="card-title"> Skills results</h4>
|
||||
<div class="card-header pt-1">
|
||||
<h4 class="mb-0"> Skills results</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<div class="card-body pt-1 pb-1">
|
||||
<div class="table-responsive pb-0">
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="skill_table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -78,11 +78,11 @@
|
|||
{% endif %}
|
||||
|
||||
{% if event_list %}
|
||||
<div class="card-header">
|
||||
<h4 class="card-title"> Events results</h4>
|
||||
<div class="card-header pt-1">
|
||||
<h4 class="mb-0"> Events results</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<div class="card-body pt-1 pb-1">
|
||||
<div class="table-responsive pb-0">
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="event_table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -117,9 +117,76 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if place_list %}
|
||||
<div class="card-header pt-1">
|
||||
<h4 class="mb-0"> Places results</h4>
|
||||
</div>
|
||||
<div class="card-body pt-1 pb-1">
|
||||
<div class="table-responsive pb-0">
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="place_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 3%"></th>
|
||||
<th class="header text-left" style="width: 27%">Name</th>
|
||||
<th class="header text-left" style="width: 35%">Address</th>
|
||||
<th class="header text-center" style="width: 10%">Zip</th>
|
||||
<th class="header text-left" style="width: 15%">City</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for place in place_list %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'place_update' place.id %}">
|
||||
<button type="button" rel="tooltip" class="btn btn-link btn-sm btn-icon">
|
||||
<span class="tim-icons icon-pencil text-warning"></span>
|
||||
</button>
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-left"><a href="{% url 'place_details' place.id %}">{{ place.name }}</a></td>
|
||||
<td class="text-left">{{ place.address }}</td>
|
||||
<td class="text-left">{{ place.postal}}</td>
|
||||
<td class="text-left">{{ place.city }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if club_list %}
|
||||
<div class="card-header pt-1">
|
||||
<h4 class="mb-0"> Clubs results</h4>
|
||||
</div>
|
||||
<div class="card-body pt-1 pb-1">
|
||||
<div class="table-responsive pb-0">
|
||||
<table class="table tablesorter table-striped table-condensed" data-sort="table" id="club_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="header text-left" style="width: 35%">Name</th>
|
||||
<th class="header text-left" style="width: 10%">Acronym</th>
|
||||
<th class="header text-left" style="width: 35%">City</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for club in club_list %}
|
||||
<tr>
|
||||
<td class="text-left"> {{ club.name }}</td>
|
||||
<td class="text-left">{{ club.acronym }}</td>
|
||||
<td class="text-left">{{ club.place.city }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% else %}
|
||||
<div class="card-header">
|
||||
<h4 class="card-title"> Search results</h4>
|
||||
<h4 class="mb-0"> Search results</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>There are no items corresponding to your criterias : "{{ pattern }}"</p>
|
||||
|
|
Loading…
Reference in New Issue