mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-09-25 19:08:18 +02:00
Compare commits
53 Commits
0c259155a8
...
family
Author | SHA1 | Date | |
---|---|---|---|
|
6eb192b823 | ||
|
bcd6444ff2 | ||
|
2a638e7b32 | ||
|
bb06206a9b | ||
|
55be3c9836 | ||
|
2ac19ab7be | ||
|
7d359dec13 | ||
|
1015a5dba1 | ||
|
8f9f650826 | ||
|
99a90867cc | ||
|
0d69695b00 | ||
|
92f6d11cb5 | ||
|
1fdb30d7d2 | ||
|
6975ed6df6 | ||
|
4da87872bd | ||
|
c25f6ca2c1 | ||
|
4d567cdcc7 | ||
|
61057b71ba | ||
|
80f28aa771 | ||
|
f13a44702a | ||
|
85b857976a | ||
|
68e5f280b4 | ||
|
251bb933da | ||
|
4fbbfd2365 | ||
|
0ac719b1f6 | ||
|
e55a6ae407 | ||
|
59a502d624 | ||
|
312ab6dac4 | ||
|
cf53b480db | ||
|
d1aa1edd09 | ||
|
d6f9a9c5b0 | ||
|
fc0071144e | ||
|
573f2d8a22 | ||
|
da30382f41 | ||
|
8e98d62b69 | ||
|
3b7f8b87c4 | ||
|
023fc1db84 | ||
|
d50bb2134a | ||
|
0992a8a7ee | ||
|
97597eb103 | ||
|
bfa5734d55 | ||
|
296d021d54 | ||
|
6e348b995b | ||
|
12477b33cb | ||
|
8c3ae338ea | ||
|
1274315cde | ||
|
4975c1ab6f | ||
|
61999a31a5 | ||
|
b217f7ceec | ||
|
2755a5f7ab | ||
|
9ab4df94e6 | ||
|
edb6abfff5 | ||
|
03c1bb41b6 |
@@ -32,7 +32,7 @@ class ActivityForm(forms.ModelForm):
|
||||
def clean_organizer(self):
|
||||
organizer = self.cleaned_data['organizer']
|
||||
if not organizer.note.is_active:
|
||||
self.add_error('organiser', _('The note of this club is inactive.'))
|
||||
self.add_error('organizer', _('The note of this club is inactive.'))
|
||||
return organizer
|
||||
|
||||
def clean_date_end(self):
|
||||
|
@@ -75,13 +75,24 @@ class BatchAchievementsAPIView(APIView):
|
||||
challenge_ids = request.data.get('challenges')
|
||||
families = Family.objects.filter(id__in=family_ids)
|
||||
challenges = Challenge.objects.filter(id__in=challenge_ids)
|
||||
results = []
|
||||
for family in families:
|
||||
for challenge in challenges:
|
||||
a = Achievement(family=family, challenge=challenge)
|
||||
a.save(update_score=False)
|
||||
|
||||
a, created = Achievement.objects.get_or_create(family=family, challenge=challenge)
|
||||
if created:
|
||||
results.append({
|
||||
'family': family.name,
|
||||
'challenge': challenge.name,
|
||||
'status': 'created'
|
||||
})
|
||||
else:
|
||||
results.append({
|
||||
'family': family.name,
|
||||
'challenge': challenge.name,
|
||||
'status': 'existed',
|
||||
})
|
||||
for family in families:
|
||||
family.update_score()
|
||||
Family.update_ranking()
|
||||
|
||||
return Response({'status': 'ok'}, status=status.HTTP_201_CREATED)
|
||||
return Response({'results': results}, status=status.HTTP_201_CREATED)
|
||||
|
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-13 20:26
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('family', '0004_remove_challenge_obtained'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='achievement',
|
||||
unique_together={('challenge', 'family')},
|
||||
),
|
||||
]
|
@@ -170,6 +170,7 @@ class Achievement(models.Model):
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('challenge', 'family',)
|
||||
verbose_name = _('achievement')
|
||||
verbose_name_plural = _('achievements')
|
||||
|
||||
|
@@ -25,11 +25,6 @@ $(document).ready(function () {
|
||||
location.hash = this.getAttribute('href')
|
||||
})
|
||||
|
||||
|
||||
// Ensure we begin in single consumption. Fix issue with TurboLinks and BootstrapJS
|
||||
|
||||
|
||||
document.getElementById("consume_all").addEventListener('click', consumeAll)
|
||||
})
|
||||
|
||||
notes = []
|
||||
@@ -140,13 +135,25 @@ function consumeAll () {
|
||||
headers: {
|
||||
'X-CSRFToken': CSRF_TOKEN
|
||||
},
|
||||
success: function () {
|
||||
success: function (data) {
|
||||
reset()
|
||||
addMsg("Défis validés pour les familles !", 'success', 5000)
|
||||
},
|
||||
error: function (e) {
|
||||
reset()
|
||||
addMsg("Erreur lors de la création des achievements.",'danger',5000)
|
||||
data.results.forEach(function (result) {
|
||||
if (result.status === 'created') {
|
||||
addMsg(
|
||||
interpolate(gettext('Invalid achievement for challenge %s ' +
|
||||
'and family %s created.'), [result.challenge, result.family]),
|
||||
'success',
|
||||
5000
|
||||
)
|
||||
} else {
|
||||
addMsg(
|
||||
interpolate(gettext('An achievement for challenge %s ' +
|
||||
'and family %s already exists.'), [result.challenge, result.family]),
|
||||
'danger',
|
||||
8000
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -16,9 +16,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<a href="#" class="btn btn-sm btn-outline-primary active">
|
||||
{% trans "Challenges" %}
|
||||
</a>
|
||||
{% if can_manage %}
|
||||
<a href="{% url "family:manage" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Manage" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% load i18n perms %}
|
||||
|
||||
{% block profile_content %}
|
||||
{% if member_list.data %}
|
||||
<div class="card">
|
||||
<div class="card-header position-relative" id="clubListHeading">
|
||||
<i class="fa fa-users"></i> {% trans "Family members" %}
|
||||
@@ -15,11 +16,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</div>
|
||||
|
||||
<div class="my-4"></div>
|
||||
{% endif %}
|
||||
|
||||
{% if achievement_list.data %}
|
||||
<div class="card">
|
||||
<div class="card-header position-relative">
|
||||
<i class="fa fa-trophy"></i> {% trans "Completed challenges" %}
|
||||
</div>
|
||||
{% render_table achievement_list %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@@ -16,9 +16,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<a href="{% url "family:challenge_list" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Challenges" %}
|
||||
</a>
|
||||
{% if can_manage %}
|
||||
<a href="{% url "family:manage" %}" class="btn btn-sm btn-outline-primary">
|
||||
{% trans "Manage" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -26,6 +26,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class='col-sm-5 col-xl-6' id="infos_div">
|
||||
{% if can_add_achievement %}
|
||||
<div class="row justify-content-center justify-content-md-end">
|
||||
{# Family details column #}
|
||||
<div class="col picture-col">
|
||||
@@ -81,8 +82,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Create family/challenge buttons #}
|
||||
{% if can_add_family or can_add_challenge %}
|
||||
<div class="card bg-light border-success mb-4">
|
||||
<h3 class="card-header font-weight-bold text-center">
|
||||
{% trans "Create a family or challenge" %}
|
||||
@@ -100,10 +103,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# Buttons column #}
|
||||
<div class="col">
|
||||
{% if can_add_achievement %}
|
||||
<div class="card bg-light border-primary text-center mb-4">
|
||||
{# Tabs for list and search #}
|
||||
<div class="card-header">
|
||||
@@ -149,10 +154,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# achievement history #}
|
||||
{% if table.data %}
|
||||
<div class="card">
|
||||
<div class="card-header position-relative" id="historyListHeading">
|
||||
<a class="stretched-link font-weight-bold"
|
||||
@@ -170,20 +177,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content border-success">
|
||||
<div class="modal-header bg-success text-white">
|
||||
<h5 class="modal-title" id="validationModalLabel">{% trans "Challenge validated" %}</h5>
|
||||
<h5 class="modal-title" id="validationModalLabel">{% trans "Confirmation" %}</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><strong>Are you sure you want to validate this challenge?</strong></p>
|
||||
<p>To have your challenge officially validated, please send a message with:</p>
|
||||
<ul>
|
||||
<li>The name of the family</li>
|
||||
<li>The name of the challenge</li>
|
||||
<li>A photo or video as proof</li>
|
||||
</ul>
|
||||
<p><strong>Send it via WhatsApp to:<a href="tel:+33630211244"></strong> +33 6 30 21 12 44</a></p>
|
||||
<p><strong>{% trans "Are you sure you want to validate this challenge?" %}</strong></p>
|
||||
<p>{% trans "To have your challenge officially validated, please send a message with:" %}</p>
|
||||
<ul>
|
||||
<li>{% trans "The name of the family" %}</li>
|
||||
<li>{% trans "The name of the challenge" %}</li>
|
||||
<li>{% trans "A photo or video as proof" %}</li>
|
||||
</ul>
|
||||
<p>
|
||||
<strong>{% trans "Send it via WhatsApp to:" %}</strong>
|
||||
{% if phone_numbers %}"
|
||||
{% for num in phone_numbers %}
|
||||
<a href="https://wa.me/{{ num }}" target="_blank">{{ num }}</a>{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">{% trans "OK" %}</button>
|
||||
@@ -191,7 +205,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -215,6 +229,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
document.getElementById("consume_all").addEventListener("click", function () {
|
||||
$('#validationModal').modal('show');
|
||||
});
|
||||
|
||||
$('#validationModal .btn-primary').on('click', function () {
|
||||
consumeAll();
|
||||
});
|
||||
|
||||
{% if user_family %}
|
||||
document.getElementById("select_my_family").addEventListener("click", function () {
|
||||
|
@@ -239,6 +239,12 @@ class TestBatchAchievements(APITestCase):
|
||||
Challenge.objects.create(name=f'Challenge {i}', description='', points=50) for i in range(3)
|
||||
]
|
||||
|
||||
self.achievement = Achievement.objects.create(
|
||||
family=self.families[0],
|
||||
challenge=self.challenges[0],
|
||||
valid=False,
|
||||
)
|
||||
|
||||
self.url = reverse("family:api:batch_achievements")
|
||||
|
||||
def test_batch_achievement_creation(self):
|
||||
@@ -254,7 +260,11 @@ class TestBatchAchievements(APITestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 201)
|
||||
self.assertEqual(response.data['status'], 'ok')
|
||||
for result in response.data['results']:
|
||||
if result['family'] == self.families[0].name and result['challenge'] == self.challenges[0].name:
|
||||
self.assertEqual(result['status'], 'existed')
|
||||
else:
|
||||
self.assertEqual(result['status'], 'created')
|
||||
|
||||
expected_count = len(family_ids) * len(challenge_ids)
|
||||
self.assertEqual(Achievement.objects.count(), expected_count)
|
||||
|
@@ -6,6 +6,7 @@ from datetime import date
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.views.generic import DetailView, UpdateView, ListView
|
||||
from django.views.generic.edit import DeleteView, FormMixin
|
||||
@@ -16,6 +17,7 @@ from permission.backends import PermissionBackend
|
||||
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
||||
from django.urls import reverse_lazy
|
||||
from member.forms import ImageForm
|
||||
import phonenumbers
|
||||
|
||||
from .models import Family, Challenge, FamilyMembership, User, Achievement
|
||||
from .tables import FamilyTable, ChallengeTable, FamilyMembershipTable, AchievementTable, FamilyAchievementTable
|
||||
@@ -51,6 +53,24 @@ class FamilyListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||
table_class = FamilyTable
|
||||
extra_context = {"title": _('Families list')}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
fake_family = Family(name="", description="")
|
||||
fake_challenge = Challenge(name="", description="", points=0)
|
||||
can_add_family = PermissionBackend.check_perm(self.request, "family.add_family", fake_family)
|
||||
can_add_challenge = PermissionBackend.check_perm(self.request, "family.add_challenge", fake_challenge)
|
||||
|
||||
if Family.objects.exists() and Challenge.objects.exists():
|
||||
fake_achievement = Achievement(family=Family.objects.first(), challenge=Challenge.objects.first(), valid=False)
|
||||
can_add_achievement = PermissionBackend.check_perm(self.request, "family.add_achievement", fake_achievement)
|
||||
else:
|
||||
can_add_achievement = False
|
||||
|
||||
context["can_manage"] = can_add_family or can_add_challenge or can_add_achievement
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class FamilyDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
"""
|
||||
@@ -231,6 +251,24 @@ class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVie
|
||||
table_class = ChallengeTable
|
||||
extra_context = {"title": _('Challenges list')}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
fake_family = Family(name="", description="")
|
||||
fake_challenge = Challenge(name="", description="", points=0)
|
||||
can_add_family = PermissionBackend.check_perm(self.request, "family.add_family", fake_family)
|
||||
can_add_challenge = PermissionBackend.check_perm(self.request, "family.add_challenge", fake_challenge)
|
||||
|
||||
if Family.objects.exists() and Challenge.objects.exists():
|
||||
fake_achievement = Achievement(family=Family.objects.first(), challenge=Challenge.objects.first(), valid=False)
|
||||
can_add_achievement = PermissionBackend.check_perm(self.request, "family.add_achievement", fake_achievement)
|
||||
else:
|
||||
can_add_achievement = False
|
||||
|
||||
context["can_manage"] = can_add_family or can_add_challenge or can_add_achievement
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ChallengeDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
"""
|
||||
@@ -283,6 +321,11 @@ class FamilyManageView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
||||
if not request.user.is_authenticated:
|
||||
return self.handle_no_permission()
|
||||
|
||||
perm = PermissionBackend.has_model_perm(self.request, Achievement(), "add")
|
||||
perm = perm or PermissionBackend.has_model_perm(self.request, Challenge(), "add")
|
||||
perm = perm or PermissionBackend.has_model_perm(self.request, Family(), "add")
|
||||
if not perm:
|
||||
raise PermissionDenied(_("You are not able to manage families and challenges."))
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
@@ -298,8 +341,9 @@ class FamilyManageView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
||||
PermissionBackend.filter_queryset(self.request, Challenge, "view")
|
||||
).order_by('name')
|
||||
|
||||
context["can_add_family"] = PermissionBackend.check_perm(self.request, "family.family_create")
|
||||
context["can_add_challenge"] = PermissionBackend.check_perm(self.request, "family.challenge_create")
|
||||
context["can_add_family"] = PermissionBackend.has_model_perm(self.request, Family(), "add")
|
||||
context["can_add_challenge"] = PermissionBackend.has_model_perm(self.request, Challenge(), "add")
|
||||
context["can_add_achievement"] = PermissionBackend.has_model_perm(self.request, Achievement(), "add")
|
||||
|
||||
# Get the user's family if they have one
|
||||
try:
|
||||
@@ -308,6 +352,16 @@ class FamilyManageView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
||||
except FamilyMembership.DoesNotExist:
|
||||
context["user_family"] = None
|
||||
|
||||
phone_numbers = [
|
||||
u.profile.phone_number for u in User.objects.filter(
|
||||
memberships__roles__id=35,
|
||||
memberships__date_end__gte=date.today(),
|
||||
profile__phone_number__isnull=False
|
||||
).distinct()
|
||||
]
|
||||
formatted_phone_numbers = [phonenumbers.format_number(num, phonenumbers.PhoneNumberFormat.INTERNATIONAL) for num in phone_numbers if num]
|
||||
context["phone_numbers"] = formatted_phone_numbers
|
||||
|
||||
return context
|
||||
|
||||
def get_table(self, **kwargs):
|
||||
@@ -316,6 +370,13 @@ class FamilyManageView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
||||
table.orderable = False
|
||||
return table
|
||||
|
||||
def get_table_data(self, **kwargs):
|
||||
qs = super().get_queryset(**kwargs)
|
||||
|
||||
qs = qs.filter(PermissionBackend.filter_queryset(self.request, Achievement, "view"))
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
class AchievementListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, ListView):
|
||||
"""
|
||||
@@ -325,6 +386,14 @@ class AchievementListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMi
|
||||
tables = [AchievementTable, AchievementTable, ]
|
||||
extra_context = {'title': _('Achievement list')}
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
return self.handle_no_permission()
|
||||
|
||||
if not PermissionBackend.has_model_perm(self.request, Achievement(), "change"):
|
||||
raise PermissionDenied(_("You are not able to see the achievement validation interface."))
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_tables(self, **kwargs):
|
||||
tables = super().get_tables(**kwargs)
|
||||
|
||||
@@ -355,6 +424,19 @@ class AchievementValidateView(ProtectQuerysetMixin, LoginRequiredMixin, Template
|
||||
"""
|
||||
template_name = 'family/achievement_confirm_validate.html'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
return self.handle_no_permission()
|
||||
|
||||
fake_achievement = Achievement(
|
||||
family=Family.objects.first(),
|
||||
challenge=Challenge.objects.first(),
|
||||
valid=False,
|
||||
)
|
||||
if not PermissionBackend.check_perm(self.request, "family.change_achievement_valid", fake_achievement):
|
||||
raise PermissionDenied()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, pk):
|
||||
achievement = Achievement.objects.get(pk=pk)
|
||||
|
||||
@@ -370,5 +452,18 @@ class AchievementDeleteView(ProtectQuerysetMixin, LoginRequiredMixin, DeleteView
|
||||
"""
|
||||
model = Achievement
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
return self.handle_no_permission()
|
||||
|
||||
fake_achievement = Achievement(
|
||||
family=Family.objects.first(),
|
||||
challenge=Challenge.objects.first(),
|
||||
valid=False,
|
||||
)
|
||||
if not PermissionBackend.check_perm(self.request, "family.change_achievement_valid", fake_achievement):
|
||||
raise PermissionDenied()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('family:achievement_list')
|
||||
|
@@ -6,7 +6,7 @@ from django.conf import settings
|
||||
from django.db.models.signals import post_save
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .signals import save_user_profile
|
||||
from .signals import save_user_profile, update_wei_registration_fee_on_membership_creation, update_wei_registration_fee_on_club_change
|
||||
|
||||
|
||||
class MemberConfig(AppConfig):
|
||||
@@ -17,7 +17,16 @@ class MemberConfig(AppConfig):
|
||||
"""
|
||||
Define app internal signals to interact with other apps
|
||||
"""
|
||||
from .models import Membership, Club
|
||||
post_save.connect(
|
||||
save_user_profile,
|
||||
sender=settings.AUTH_USER_MODEL,
|
||||
)
|
||||
post_save.connect(
|
||||
update_wei_registration_fee_on_membership_creation,
|
||||
sender=Membership
|
||||
)
|
||||
post_save.connect(
|
||||
update_wei_registration_fee_on_club_change,
|
||||
sender=Club
|
||||
)
|
||||
|
18
apps/member/migrations/0015_alter_profile_promotion.py
Normal file
18
apps/member/migrations/0015_alter_profile_promotion.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-02 13:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('member', '0014_create_bda'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='promotion',
|
||||
field=models.PositiveSmallIntegerField(default=2025, help_text='Year of entry to the school (None if not ENS student)', null=True, verbose_name='promotion'),
|
||||
),
|
||||
]
|
@@ -1,6 +1,8 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def save_user_profile(instance, created, raw, **_kwargs):
|
||||
"""
|
||||
@@ -13,3 +15,27 @@ def save_user_profile(instance, created, raw, **_kwargs):
|
||||
instance.profile.email_confirmed = True
|
||||
instance.profile.registration_valid = True
|
||||
instance.profile.save()
|
||||
|
||||
|
||||
def update_wei_registration_fee_on_membership_creation(sender, instance, created, **kwargs):
|
||||
if not hasattr(instance, "_no_signal") and 'wei' in settings.INSTALLED_APPS and created:
|
||||
from wei.models import WEIRegistration
|
||||
if instance.club.id == 1 or instance.club.id == 2:
|
||||
registrations = WEIRegistration.objects.filter(
|
||||
user=instance.user,
|
||||
wei__year=instance.date_start.year,
|
||||
)
|
||||
for r in registrations:
|
||||
r._force_save = True
|
||||
r.save()
|
||||
|
||||
|
||||
def update_wei_registration_fee_on_club_change(sender, instance, **kwargs):
|
||||
if not hasattr(instance, "_no_signal") and 'wei' in settings.INSTALLED_APPS and (instance.id == 1 or instance.id == 2):
|
||||
from wei.models import WEIRegistration
|
||||
registrations = WEIRegistration.objects.filter(
|
||||
wei__year=instance.membership_start.year,
|
||||
)
|
||||
for r in registrations:
|
||||
r._force_save = True
|
||||
r.save()
|
||||
|
@@ -7,6 +7,7 @@
|
||||
<dt class="col-xl-6">{% trans 'username'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ user_object.username }}</dd>
|
||||
|
||||
{% if family_app_installed %}
|
||||
<dt class="col-xl-6">{% trans 'family'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">
|
||||
{% if families %}
|
||||
@@ -17,6 +18,7 @@
|
||||
<span class="text-muted">Aucune</span>
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if user_object.pk == user.pk %}
|
||||
<dt class="col-xl-6">{% trans 'password'|capfirst %}</dt>
|
||||
|
@@ -207,9 +207,10 @@ class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
modified_note.is_active = True
|
||||
context["can_unlock_note"] = not user.note.is_active and PermissionBackend\
|
||||
.check_perm(self.request, "note.change_noteuser_is_active", modified_note)
|
||||
|
||||
families = Family.objects.filter(memberships__user=user).distinct()
|
||||
context["families"] = families
|
||||
if 'family' in settings.INSTALLED_APPS:
|
||||
context["family_app_installed"] = True
|
||||
families = Family.objects.filter(memberships__user=user).distinct()
|
||||
context["families"] = families
|
||||
|
||||
return context
|
||||
|
||||
|
@@ -1391,12 +1391,12 @@
|
||||
"wei",
|
||||
"weiregistration"
|
||||
],
|
||||
"query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
|
||||
"query": "[\"AND\", {\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}, {\"deposit_type\": \"note\"}]",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "caution_check",
|
||||
"field": "deposit_given",
|
||||
"permanent": false,
|
||||
"description": "Dire si un chèque de caution est donné pour une inscription WEI"
|
||||
"description": "Autoriser une transaction de caution WEI"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -4347,7 +4347,343 @@
|
||||
"mask": 3,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Ajouter un membre au BDE ou à la Kfet"
|
||||
"description": "Faire adhérer BDE ou Kfet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 293,
|
||||
"fields": {
|
||||
"model": [
|
||||
"wei",
|
||||
"weimembership"
|
||||
],
|
||||
"query": "[\"AND\", {\"bus\": [\"membership\", \"weimembership\", \"bus\"]}, {\"club\": [\"club\"], \"club__weiclub__membership_end__gte\": [\"today\"]}]",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "team",
|
||||
"permanent": false,
|
||||
"description": "Modifier l'équipe d'une adhésion WEI à son bus"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 294,
|
||||
"fields": {
|
||||
"model": [
|
||||
"wei",
|
||||
"weiregistration"
|
||||
],
|
||||
"query": "[\"AND\", {\"wei__year\": [\"today\", \"year\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}, {\"deposit_type\": \"check\"}]",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "deposit_given",
|
||||
"permanent": false,
|
||||
"description": "Dire si un chèque de caution a été donné"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 295,
|
||||
"fields": {
|
||||
"model": [
|
||||
"wei",
|
||||
"weiregistration"
|
||||
],
|
||||
"query": "{\"wei__year\": [\"today\", \"year\"]}",
|
||||
"type": "view",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir toutes les inscriptions au WEI courant"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 296,
|
||||
"fields": {
|
||||
"model": [
|
||||
"wei",
|
||||
"weimembership"
|
||||
],
|
||||
"query": "{\"club__weiclub__year\": [\"today\", \"year\"]}",
|
||||
"type": "view",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir toutes les adhésions au WEI courant"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 297,
|
||||
"fields": {
|
||||
"model": [
|
||||
"wei",
|
||||
"weiregistration"
|
||||
],
|
||||
"query": "[\"AND\", {\"user\": [\"user\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}, [\"OR\", {\"wei\": [\"club\"]}, {\"wei__year\": [\"today\", \"year\"], \"membership\": null}]]",
|
||||
"type": "change",
|
||||
"mask": 1,
|
||||
"field": "deposit_type",
|
||||
"permanent": false,
|
||||
"description": "Modifier le type de caution de mon inscription WEI tant qu'elle n'est pas validée"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 311,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"family"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "view",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir toutes les familles"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 312,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"family"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "add",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Créer une famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 313,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"family"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Modifier n'importe quelle famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 314,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"family"
|
||||
],
|
||||
"query": "{\"pk\": [\"user\", \"family_memberships\", \"family\", \"pk\"]}",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Modifier ma famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 315,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"familymembership"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "view",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir les membres de n'importe quelle famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 316,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"familymembership"
|
||||
],
|
||||
"query": "{\"family\": [\"user\", \"family_memberships\", \"family\"]}",
|
||||
"type": "view",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir les membres de ma famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 317,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"familymembership"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "add",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Ajouter un membre à n'importe quelle famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 318,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"familymembership"
|
||||
],
|
||||
"query": "{\"family\": [\"user\", \"family_memberships\", \"family\"]}",
|
||||
"type": "add",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Ajouter un membre à ma famille"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 319,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"challenge"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "view",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir tous les défis"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 320,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"challenge"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "add",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Créer un défi"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 321,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"challenge"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "change",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Modifier un défi"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 322,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"challenge"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "delete",
|
||||
"mask": 2,
|
||||
"field": "{}",
|
||||
"permanent": false,
|
||||
"description": "Supprimer un défi"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 323,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"achievement"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "view",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Voir tous les succès"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 324,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"achievement"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "add",
|
||||
"mask": 2,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Créer un succès"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 325,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"achievement"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "change",
|
||||
"mask": 1,
|
||||
"field": "valid",
|
||||
"permanent": false,
|
||||
"description": "Valider un succès"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.permission",
|
||||
"pk": 326,
|
||||
"fields": {
|
||||
"model": [
|
||||
"family",
|
||||
"achievement"
|
||||
],
|
||||
"query": "{}",
|
||||
"type": "delete",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": false,
|
||||
"description": "Supprimer un succès"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -4402,9 +4738,13 @@
|
||||
206,
|
||||
248,
|
||||
249,
|
||||
255,
|
||||
256,
|
||||
257
|
||||
255,
|
||||
256,
|
||||
257,
|
||||
311,
|
||||
316,
|
||||
319,
|
||||
323
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -4444,7 +4784,8 @@
|
||||
159,
|
||||
160,
|
||||
212,
|
||||
222
|
||||
222,
|
||||
297
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -4631,7 +4972,10 @@
|
||||
176,
|
||||
177,
|
||||
178,
|
||||
183
|
||||
183,
|
||||
294,
|
||||
295,
|
||||
296
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -4764,7 +5108,6 @@
|
||||
"name": "Chef\u22c5fe de bus",
|
||||
"permissions": [
|
||||
22,
|
||||
84,
|
||||
115,
|
||||
117,
|
||||
118,
|
||||
@@ -4778,7 +5121,8 @@
|
||||
287,
|
||||
289,
|
||||
290,
|
||||
291
|
||||
291,
|
||||
293
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -4790,7 +5134,6 @@
|
||||
"name": "Chef\u22c5fe d'\u00e9quipe",
|
||||
"permissions": [
|
||||
22,
|
||||
84,
|
||||
116,
|
||||
123,
|
||||
124,
|
||||
@@ -4805,8 +5148,7 @@
|
||||
"for_club": null,
|
||||
"name": "\u00c9lectron libre",
|
||||
"permissions": [
|
||||
22,
|
||||
84
|
||||
22
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -4926,7 +5268,7 @@
|
||||
216
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 23,
|
||||
@@ -4939,7 +5281,7 @@
|
||||
32
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 24,
|
||||
@@ -4948,7 +5290,7 @@
|
||||
"name": "Staffeur⋅euse (S&L,Respo Tech,...)",
|
||||
"permissions": []
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 25,
|
||||
@@ -4957,7 +5299,6 @@
|
||||
"name": "Référent⋅e Bus",
|
||||
"permissions": [
|
||||
22,
|
||||
84,
|
||||
115,
|
||||
117,
|
||||
118,
|
||||
@@ -4971,10 +5312,11 @@
|
||||
287,
|
||||
289,
|
||||
290,
|
||||
291
|
||||
291,
|
||||
293
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 28,
|
||||
@@ -5004,7 +5346,7 @@
|
||||
269
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 30,
|
||||
@@ -5012,15 +5354,15 @@
|
||||
"for_club": 10,
|
||||
"name": "Respo sorties",
|
||||
"permissions": [
|
||||
49,
|
||||
62,
|
||||
141,
|
||||
241,
|
||||
242,
|
||||
49,
|
||||
62,
|
||||
141,
|
||||
241,
|
||||
242,
|
||||
243
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 31,
|
||||
@@ -5032,7 +5374,7 @@
|
||||
244
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 32,
|
||||
@@ -5044,7 +5386,7 @@
|
||||
245
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 33,
|
||||
@@ -5052,15 +5394,48 @@
|
||||
"for_club": 10,
|
||||
"name": "Respo Jam",
|
||||
"permissions": [
|
||||
247,
|
||||
250,
|
||||
251,
|
||||
252,
|
||||
253,
|
||||
247,
|
||||
250,
|
||||
251,
|
||||
252,
|
||||
253,
|
||||
254
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 34,
|
||||
"fields": {
|
||||
"for_club": 1,
|
||||
"name": "Chef·fe de famille",
|
||||
"permissions": [
|
||||
314,
|
||||
318,
|
||||
324
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "permission.role",
|
||||
"pk": 35,
|
||||
"fields": {
|
||||
"for_club": 1,
|
||||
"name": "Respo familles",
|
||||
"permissions": [
|
||||
312,
|
||||
313,
|
||||
315,
|
||||
317,
|
||||
320,
|
||||
321,
|
||||
322,
|
||||
324,
|
||||
325,
|
||||
326
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "wei.weirole",
|
||||
"pk": 12,
|
||||
|
@@ -353,13 +353,11 @@ class SogeCredit(models.Model):
|
||||
def amount(self):
|
||||
if self.valid:
|
||||
return self.credit_transaction.total
|
||||
amount = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all())
|
||||
if 'wei' in settings.INSTALLED_APPS:
|
||||
from wei.models import WEIMembership
|
||||
if not WEIMembership.objects\
|
||||
.filter(club__weiclub__year=self.credit_transaction.created_at.year, user=self.user).exists():
|
||||
# 80 € for people that don't go to WEI
|
||||
amount += 8000
|
||||
amount = 0
|
||||
transactions_wei = self.transactions.filter(membership__club__weiclub__isnull=False)
|
||||
amount += sum(max(transaction.total - transaction.membership.club.weiclub.fee_soge_credit, 0) for transaction in transactions_wei)
|
||||
transactions_not_wei = self.transactions.filter(membership__club__weiclub__isnull=True)
|
||||
amount += sum(transaction.total for transaction in transactions_not_wei)
|
||||
return amount
|
||||
|
||||
def update_transactions(self):
|
||||
@@ -441,7 +439,7 @@ class SogeCredit(models.Model):
|
||||
With Great Power Comes Great Responsibility...
|
||||
"""
|
||||
|
||||
total_fee = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all() if not transaction.valid)
|
||||
total_fee = self.amount
|
||||
if self.user.note.balance < total_fee:
|
||||
raise ValidationError(_("This user doesn't have enough money to pay the memberships with its note. "
|
||||
"Please ask her/him to credit the note before invalidating this credit."))
|
||||
|
@@ -77,7 +77,7 @@ class WEIRegistrationViewSet(ReadProtectedModelViewSet):
|
||||
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
||||
filterset_fields = ['user', 'user__username', 'user__first_name', 'user__last_name', 'user__email',
|
||||
'user__note__alias__name', 'user__note__alias__normalized_name', 'wei', 'wei__name',
|
||||
'wei__email', 'wei__year', 'soge_credit', 'deposit_check', 'birth_date', 'gender',
|
||||
'wei__email', 'wei__year', 'soge_credit', 'deposit_given', 'birth_date', 'gender',
|
||||
'clothing_cut', 'clothing_size', 'first_year', 'emergency_contact_name',
|
||||
'emergency_contact_phone', ]
|
||||
search_fields = ['$user__username', '$user__first_name', '$user__last_name', '$user__email',
|
||||
|
@@ -1,11 +1,11 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .registration import WEIForm, WEIRegistrationForm, WEIRegistration1AForm, WEIRegistration2AForm, WEIMembership1AForm, \
|
||||
from .registration import WEIForm, WEIRegistrationForm, WEIMembership1AForm, \
|
||||
WEIMembershipForm, BusForm, BusTeamForm
|
||||
from .surveys import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, CurrentSurvey
|
||||
|
||||
__all__ = [
|
||||
'WEIForm', 'WEIRegistrationForm', 'WEIRegistration1AForm', 'WEIRegistration2AForm', 'WEIMembership1AForm', 'WEIMembershipForm', 'BusForm', 'BusTeamForm',
|
||||
'WEIForm', 'WEIRegistrationForm', 'WEIMembership1AForm', 'WEIMembershipForm', 'BusForm', 'BusTeamForm',
|
||||
'WEISurvey', 'WEISurveyInformation', 'WEISurveyAlgorithm', 'CurrentSurvey',
|
||||
]
|
||||
|
@@ -44,7 +44,7 @@ class WEIRegistrationForm(forms.ModelForm):
|
||||
fields = [
|
||||
'user', 'soge_credit', 'birth_date', 'gender', 'clothing_size',
|
||||
'health_issues', 'emergency_contact_name', 'emergency_contact_phone',
|
||||
'first_year', 'information_json', 'deposit_check'
|
||||
'first_year', 'information_json', 'deposit_given', 'deposit_type'
|
||||
]
|
||||
widgets = {
|
||||
"user": Autocomplete(
|
||||
@@ -59,30 +59,17 @@ class WEIRegistrationForm(forms.ModelForm):
|
||||
'minDate': '1900-01-01',
|
||||
'maxDate': '2100-01-01'
|
||||
}),
|
||||
"deposit_check": forms.BooleanField(
|
||||
required=False,
|
||||
"deposit_given": forms.CheckboxInput(
|
||||
attrs={'class': 'form-check-input'},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class WEIRegistration2AForm(WEIRegistrationForm):
|
||||
class Meta(WEIRegistrationForm.Meta):
|
||||
fields = WEIRegistrationForm.Meta.fields + ['deposit_type']
|
||||
widgets = WEIRegistrationForm.Meta.widgets.copy()
|
||||
widgets.update({
|
||||
"deposit_type": forms.RadioSelect(),
|
||||
})
|
||||
|
||||
|
||||
class WEIRegistration1AForm(WEIRegistrationForm):
|
||||
class Meta(WEIRegistrationForm.Meta):
|
||||
fields = WEIRegistrationForm.Meta.fields
|
||||
}
|
||||
|
||||
|
||||
class WEIChooseBusForm(forms.Form):
|
||||
bus = forms.ModelMultipleChoiceField(
|
||||
queryset=Bus.objects,
|
||||
label=_("bus"),
|
||||
label=_("Bus"),
|
||||
help_text=_("This choice is not definitive. The WEI organizers are free to attribute for you a bus and a team,"
|
||||
+ " in particular if you are a free eletron."),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
@@ -174,7 +161,7 @@ class WEIMembership1AForm(WEIMembershipForm):
|
||||
"""
|
||||
Used to confirm registrations of first year members without choosing a bus now.
|
||||
"""
|
||||
deposit_check = None
|
||||
deposit_given = None
|
||||
roles = None
|
||||
|
||||
def clean(self):
|
||||
|
@@ -10,20 +10,197 @@ from django import forms
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, WEIBusInformation
|
||||
from ...models import WEIMembership, Bus
|
||||
|
||||
WORDS = [
|
||||
'13 organisé', '3ième mi temps', 'Années 2000', 'Apéro', 'BBQ', 'BP', 'Beauf', 'Binge drinking', 'Bon enfant',
|
||||
'Cartouche', 'Catacombes', 'Chansons paillardes', 'Chansons populaires', 'Chanteur', 'Chartreuse', 'Chill',
|
||||
'Core', 'DJ', 'Dancefloor', 'Danse', 'David Guetta', 'Disco', 'Eau de vie', 'Électro', 'Escalade', 'Familial',
|
||||
'Fanfare', 'Fracassage', 'Féria', 'Hard rock', 'Hoeggarden', 'House', 'Huit-six', 'IPA', 'Inclusif', 'Inferno',
|
||||
'Introverti', 'Jager bomb', 'Jazz', 'Jeux d\'alcool', 'Jeux de rôles', 'Jeux vidéo', 'Jul', 'Jus de fruit',
|
||||
'Karaoké', 'LGBTQI+', 'Lady Gaga', 'Loup garou', 'Morning beer', 'Métal', 'Nuit blanche', 'Ovalie', 'Psychedelic',
|
||||
'Pétanque', 'Rave', 'Reggae', 'Rhum', 'Ricard', 'Rock', 'Rosé', 'Rétro', 'Séducteur', 'Techno', 'Thérapie taxi',
|
||||
'Théâtre', 'Trap', 'Turn up', 'Underground', 'Volley', 'Wati B', 'Zinédine Zidane',
|
||||
]
|
||||
WORDS = {
|
||||
'list': [
|
||||
'Fiesta', 'Graillance', 'Move it move it', 'Calme', 'Nert et geek', 'Jeux de rôles et danse rock',
|
||||
'Strass et paillettes', 'Spectaculaire', 'Splendide', 'Flow inégalable', 'Rap', 'Battles légendaires',
|
||||
'Techno', 'Alcool', 'Kiffeur·euse', 'Rugby', 'Médiéval', 'Festif',
|
||||
'Stylé', 'Chipie', 'Rétro', 'Vache', 'Farfadet', 'Fanfare',
|
||||
],
|
||||
'questions': {
|
||||
"alcool": [
|
||||
"""Sur une échelle allant de 0 (= 0 alcool ou très peu) à 5 (= la fontaine de jouvence alcoolique),
|
||||
quel niveau de consommation d’alcool souhaiterais-tu ?""",
|
||||
{
|
||||
42: 4,
|
||||
47: 1,
|
||||
48: 3,
|
||||
45: 3.5,
|
||||
44: 4,
|
||||
46: 5,
|
||||
43: 3,
|
||||
49: 3
|
||||
}
|
||||
],
|
||||
"voie_post_bac": [
|
||||
"""Si la DA du bus de ton choix correspondait à une voie post-bac, laquelle serait-elle ?""",
|
||||
{
|
||||
42: "Double licence cuisine/arts du cirque option burger",
|
||||
47: "BTS Exploration de donjon",
|
||||
48: "Ecole des stars en herbe",
|
||||
45: "Déscolarisation précoce",
|
||||
44: "Rattrapage pour excès de kiff",
|
||||
46: "Double cursus STAPS / Licence d’histoire",
|
||||
43: "Recherche active d’un sugar daddy/d’un sugar mommy",
|
||||
49: "Licence de musicologie"
|
||||
}
|
||||
],
|
||||
"boite": [
|
||||
"""Tu es seul·e sur une île déserte et devant toi il y a une sombre boîte de taille raisonnable.
|
||||
Qu’y a-t-il à l’intérieur ?""",
|
||||
{
|
||||
42: "Un burgouzz de valouzz",
|
||||
47: "Un ocarina (pour me téléporter hors de ce bourbier)",
|
||||
48: "Des paillettes, un micro de karaoké et une enceinte bluetooth",
|
||||
45: "",
|
||||
44: "Une 86 et un caisson pour taper du pied",
|
||||
46: "Une épée, un ballon et une tireuse",
|
||||
43: "Des lunettes de soleil",
|
||||
49: "Mon instrument de musique"
|
||||
}
|
||||
],
|
||||
"tardif": [
|
||||
"""Il est 00h, tu as passé la journée à la plage avec tes copains et iels te proposent de prolonger parce
|
||||
qu’après tout, il n’y a plus personne sur la plage à cette heure-ci. Tu n’habites pas loin mais t’enchaînes
|
||||
demain avec une journée similaire avec un autre groupe d’amis parce que t’es trop #busy. Que fais-tu ?""",
|
||||
{
|
||||
42: "On veut se déchaîner toute la nuit !!",
|
||||
47: "Je prends une glace et chill un moment avant d’aller dormir",
|
||||
48: "J’enfile mes boogie shoes pour enflammer le dancefloor avec elleux et lancer un concours de slay, le perdant finit la bouteille de rhum",
|
||||
45: "La fête continuuuuue",
|
||||
44: "Soirée sangria plage → boîte → lever de soleil sur la plage",
|
||||
46: "Minuit ? C’est l’heure du genepi. On commence les alcools forts !!",
|
||||
43: "T’enchaînes direct (faut pas les priver de ta présence)",
|
||||
49: "On continue en mode chill (soirée potins)"
|
||||
}
|
||||
],
|
||||
"cohesion": [
|
||||
"""C’est la rentrée de Seconde et tu découvres ta classe, tes camarades et ta prof principale!!!
|
||||
qui vous propose une activité de cohésion. Laquelle est-elle ?""",
|
||||
{
|
||||
42: "Un relais cubi en ventriglisse",
|
||||
47: "Un jeu de rôle",
|
||||
48: "Organiser la soirée de l’année dans le lycée. Le thème : SLAY (Spotlight, Love, Amaze/All-night, Yeah), paillettes, disco",
|
||||
45: "La prof de français propose un slam parce qu'elle pense que c'est du rap littéraire qui fera plaisir aux élèves",
|
||||
44: "P’tit escape game + apéro",
|
||||
46: "Joute avec des boucliers Gilbert",
|
||||
43: "Tournage d’un clip de confessions nocturnes de Diam’s",
|
||||
49: "Je sais pas j’ai raté mon BAFA"
|
||||
}
|
||||
],
|
||||
"artiste": [
|
||||
"""C’est l’été et la saison des festivals a commencé. Tu regardes la programmation du festival
|
||||
pas loin de chez toi et tu découvres avec joie la présence d’un·e artiste. De qui s’agit-il ?""",
|
||||
{
|
||||
42: "Moto-Moto (il chantera son fameux tube “je les aime grosses, je les aime bombées”)",
|
||||
47: "Hatsune Miku",
|
||||
48: "Rihanna",
|
||||
45: "Vald",
|
||||
44: "Qui connaît vraiment les noms des artistes de tech ?",
|
||||
46: "Perceval",
|
||||
43: "Fatal bazooka",
|
||||
49: "Måneskin"
|
||||
}
|
||||
],
|
||||
"annonce_noel": [
|
||||
"""C’est Noël et tu revois toute ta famille, oncles, tantes, cousin·e·s, grands-parents, la totale.
|
||||
D’un coup, tu te lèves, tapotes de manière pompeuse sur ton verre avec un de tes couverts.
|
||||
Qu’annonces-tu ?""",
|
||||
{
|
||||
42: """« Chère famille. Je sais bien que nous avions dit : pas de politique à table.
|
||||
Je ne peux toutefois me retenir de vous annoncer une grande nouvelle…
|
||||
j’ai décidé de quitter la ville pour consacrer ma vie au culte du Roi Julian.
|
||||
A moi la jungle luxuriante, là où le soleil chaud caresse les palmiers,
|
||||
où les lémuriens dansent avec frénésie et où chaque repas est une ode au burger sauvage.
|
||||
Longue vie à Sa Majesté le Roi Julian ! »""",
|
||||
47: "« J’ai perdu »",
|
||||
48: "« Mes chers parents je pars, j’arrête l’ENS pour devenir DJ slay à Ibiza »",
|
||||
45: "J’interromps le repas pour rapper les 6min de bande organisée",
|
||||
44: "« Digestif ? Pétanque ? Les deux ? »",
|
||||
46: "« Montjoie St Denis à bas la Macronie »",
|
||||
43: "« Je suis enceinte » (c’est faux j’ai juste besoin d’attention)",
|
||||
49: """Discours de remerciement :
|
||||
je lance un powerpoint de 65 slides et sors une feuille A4 blanche (je fais semblant de lire mon discours dessus)"""
|
||||
}
|
||||
],
|
||||
"vacances": [
|
||||
"""Les vacances sont là et t’aimerais bien partir quelque part, mais où ?""",
|
||||
{
|
||||
42: "A Madagascar, à bord d’un bus conduit par des pingouins",
|
||||
47: "Dans ma chambre",
|
||||
48: "Rio de Janeiro",
|
||||
45: "N'importe où tant qu'on peut sortir tous les soirs",
|
||||
44: "Tu suis les plans du club ski ou de piratens",
|
||||
46: "Carcassonne",
|
||||
43: "Coachella",
|
||||
49: "Dans les montagnes de la république populaire d’Auvergne-Rhônes-Alpes pour profiter de la fraîcheur, de la nature et de mes ami·e·s"
|
||||
}
|
||||
],
|
||||
"loisir": [
|
||||
"""T’as fini ta journée de cours et tu t’apprêtes à profiter d’une activité/hobby/loisir de ton choix.
|
||||
Laquelle est-ce ?""",
|
||||
{
|
||||
42: "Cueillir des noix de coco",
|
||||
47: "Essayer de travailler puis chill avec des potes autour d’un jeu en buvant du thé",
|
||||
48: "Repet du nouveau spectacle de mon club, before (potins) puis sortie avec les potes jusqu’au bout de la night",
|
||||
45: "Zoner avec les copaings jusqu’à pas d’heure",
|
||||
44: "Go Kfet pour se faire traquenard jusqu’à 3h du mat",
|
||||
46: "Déterminer ce qui est le plus solide entre mon crâne et une ecocup",
|
||||
43: "Revoir pour la 6e fois gossip girl au fond de ton lit",
|
||||
49: "Jouer de mon instrument préféré avec les copains/copines pour préparer le prochain concert #solidays"
|
||||
}
|
||||
],
|
||||
"plan": [
|
||||
"""Tu reçois un message sur la conversation de groupe que tu partages avec tes potes :
|
||||
vous êtes chaud·e·s pour vous retrouver. Quel plan t’attire le plus ?""",
|
||||
{
|
||||
42: """Après-midi piscine, puis before arrosé de mojito,
|
||||
avant d’aller s’éclater en pot avec toute la savane et de finir sur un after spécial pina colada""",
|
||||
47: """(matin) : Ptit jeu de rôle
|
||||
(repas) : le traditionnel poké-tacos
|
||||
(juste après le repas) : combat avec des épées en mousse avec les copains!
|
||||
(16h00) : pause thé
|
||||
(fin d’après midi) : initiation à la danse rock
|
||||
(soirée) : découverte d’un jeu de société avec des règles obscures
|
||||
""",
|
||||
48: "Soirée champagne and chic : spectacle et dîner au moulin rouge puis soirée sur les champs",
|
||||
45: "Se regrouper pour une soirée, même si il n’est encore que 10h",
|
||||
44: "P’tit poké qui termine en koin koin avec after poker",
|
||||
46: "Une dégustation de bière, un rugby et toute autre activité joviale",
|
||||
43: "Un brunch de pour papoter puis friperies",
|
||||
49: "Soirée raclette !"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
IMAGES = {
|
||||
"vacances": {
|
||||
49: "/static/wei/img/logo_auvergne_rhone_alpes.jpg",
|
||||
}
|
||||
}
|
||||
|
||||
NB_WORDS = 5
|
||||
|
||||
|
||||
class OptionalImageRadioSelect(forms.RadioSelect):
|
||||
def __init__(self, images=None, *args, **kwargs):
|
||||
self.images = images or {}
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
|
||||
option = super().create_option(name, value, label, selected, index, subindex=subindex, attrs=attrs)
|
||||
img_url = self.images.get(value)
|
||||
if img_url:
|
||||
option['label'] = mark_safe(f'{label} <img src="{img_url}" style="height:32px;vertical-align:middle;">')
|
||||
else:
|
||||
option['label'] = label
|
||||
return option
|
||||
|
||||
|
||||
class WEISurveyForm2025(forms.Form):
|
||||
@@ -32,11 +209,6 @@ class WEISurveyForm2025(forms.Form):
|
||||
Members choose 20 words, from which we calculate the best associated bus.
|
||||
"""
|
||||
|
||||
word = forms.ChoiceField(
|
||||
label=_("Choose a word:"),
|
||||
widget=forms.RadioSelect(),
|
||||
)
|
||||
|
||||
def set_registration(self, registration):
|
||||
"""
|
||||
Filter the bus selector with the buses of the current WEI.
|
||||
@@ -48,34 +220,43 @@ class WEISurveyForm2025(forms.Form):
|
||||
registration._force_save = True
|
||||
registration.save()
|
||||
|
||||
if self.data:
|
||||
self.fields["word"].choices = [(w, w) for w in WORDS]
|
||||
rng = Random((information.step + 1) * information.seed)
|
||||
|
||||
if information.step == 0:
|
||||
self.fields["words"] = forms.MultipleChoiceField(
|
||||
label=_(f"Select {NB_WORDS} words that describe the WEI experience you want to have."),
|
||||
choices=[(w, w) for w in WORDS['list']],
|
||||
widget=forms.CheckboxSelectMultiple(),
|
||||
required=True,
|
||||
)
|
||||
if self.is_valid():
|
||||
return
|
||||
|
||||
rng = Random((information.step + 1) * information.seed)
|
||||
|
||||
buses = WEISurveyAlgorithm2025.get_buses()
|
||||
informations = {bus: WEIBusInformation2025(bus) for bus in buses}
|
||||
scores = sum((list(informations[bus].scores.values()) for bus in buses), [])
|
||||
if scores:
|
||||
average_score = sum(scores) / len(scores)
|
||||
all_preferred_words = WORDS['list']
|
||||
rng.shuffle(all_preferred_words)
|
||||
self.fields["words"].choices = [(w, w) for w in all_preferred_words]
|
||||
else:
|
||||
average_score = 0
|
||||
questions = list(WORDS['questions'].items())
|
||||
idx = information.step - 1
|
||||
if idx < len(questions):
|
||||
q, (desc, answers) = questions[idx]
|
||||
if q == 'alcool':
|
||||
choices = [(i / 2, str(i / 2)) for i in range(11)]
|
||||
else:
|
||||
choices = [(k, v) for k, v in answers.items()]
|
||||
rng.shuffle(choices)
|
||||
self.fields[q] = forms.ChoiceField(
|
||||
label=desc,
|
||||
choices=choices,
|
||||
widget=OptionalImageRadioSelect(images=IMAGES.get(q, {})),
|
||||
required=True,
|
||||
)
|
||||
|
||||
preferred_words = {bus: [word for word in WORDS
|
||||
if informations[bus].scores[word] >= average_score]
|
||||
for bus in buses}
|
||||
|
||||
# Correction : proposer plusieurs mots différents à chaque étape
|
||||
n_choices = 4 # Nombre de mots à proposer à chaque étape
|
||||
all_preferred_words = set()
|
||||
for bus_words in preferred_words.values():
|
||||
all_preferred_words.update(bus_words)
|
||||
all_preferred_words = list(all_preferred_words)
|
||||
rng.shuffle(all_preferred_words)
|
||||
words = all_preferred_words[:n_choices]
|
||||
self.fields["word"].choices = [(w, w) for w in words]
|
||||
def clean_words(self):
|
||||
data = self.cleaned_data['words']
|
||||
if len(data) != NB_WORDS:
|
||||
raise forms.ValidationError(_(f"Please choose exactly {NB_WORDS} words"))
|
||||
return data
|
||||
|
||||
|
||||
class WEIBusInformation2025(WEIBusInformation):
|
||||
@@ -86,8 +267,6 @@ class WEIBusInformation2025(WEIBusInformation):
|
||||
|
||||
def __init__(self, bus):
|
||||
self.scores = {}
|
||||
for word in WORDS:
|
||||
self.scores[word] = 0
|
||||
super().__init__(bus)
|
||||
|
||||
|
||||
@@ -95,7 +274,9 @@ class BusInformationForm2025(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Bus
|
||||
fields = ['information_json']
|
||||
widgets = {}
|
||||
widgets = {
|
||||
'information_json': forms.HiddenInput(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, words=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -108,7 +289,7 @@ class BusInformationForm2025(forms.ModelForm):
|
||||
except (json.JSONDecodeError, TypeError, AttributeError):
|
||||
initial_scores = {}
|
||||
if words is None:
|
||||
words = WORDS
|
||||
words = WORDS['list']
|
||||
self.words = words
|
||||
|
||||
choices = [(i, str(i)) for i in range(6)] # [(0, '0'), (1, '1'), ..., (5, '5')]
|
||||
@@ -117,7 +298,7 @@ class BusInformationForm2025(forms.ModelForm):
|
||||
label=word,
|
||||
choices=choices,
|
||||
coerce=int,
|
||||
initial=initial_scores.get(word, 0),
|
||||
initial=initial_scores.get(word, 0) if word in initial_scores else None,
|
||||
required=True,
|
||||
widget=forms.RadioSelect,
|
||||
help_text=_("Rate between 0 and 5."),
|
||||
@@ -145,10 +326,26 @@ class WEISurveyInformation2025(WEISurveyInformation):
|
||||
step = 0
|
||||
|
||||
def __init__(self, registration):
|
||||
for i in range(1, 21):
|
||||
for i in range(1, NB_WORDS + 1):
|
||||
setattr(self, "word" + str(i), None)
|
||||
for q in WORDS['questions']:
|
||||
setattr(self, q, None)
|
||||
super().__init__(registration)
|
||||
|
||||
def reset(self, registration):
|
||||
"""
|
||||
Réinitialise complètement le questionnaire : step, seed, mots choisis et réponses aux questions.
|
||||
"""
|
||||
self.step = 0
|
||||
self.seed = 0
|
||||
for i in range(1, NB_WORDS + 1):
|
||||
setattr(self, f"word{i}", None)
|
||||
for q in WORDS['questions']:
|
||||
setattr(self, q, None)
|
||||
self.save(registration)
|
||||
registration._force_save = True
|
||||
registration.save()
|
||||
|
||||
|
||||
class WEISurvey2025(WEISurvey):
|
||||
"""
|
||||
@@ -174,10 +371,20 @@ class WEISurvey2025(WEISurvey):
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
word = form.cleaned_data["word"]
|
||||
self.information.step += 1
|
||||
setattr(self.information, "word" + str(self.information.step), word)
|
||||
self.save()
|
||||
if self.information.step == 0:
|
||||
words = form.cleaned_data['words']
|
||||
for i, word in enumerate(words, 1):
|
||||
setattr(self.information, "word" + str(i), word)
|
||||
self.information.step += 1
|
||||
self.save()
|
||||
else:
|
||||
questions = list(WORDS['questions'].keys())
|
||||
idx = self.information.step - 1
|
||||
if idx < len(questions):
|
||||
q = questions[idx]
|
||||
setattr(self.information, q, form.cleaned_data[q])
|
||||
self.information.step += 1
|
||||
self.save()
|
||||
|
||||
@classmethod
|
||||
def get_algorithm_class(cls):
|
||||
@@ -187,7 +394,7 @@ class WEISurvey2025(WEISurvey):
|
||||
"""
|
||||
The survey is complete once the bus is chosen.
|
||||
"""
|
||||
return self.information.step == 20
|
||||
return self.information.step > len(WORDS['questions'])
|
||||
|
||||
@classmethod
|
||||
@lru_cache()
|
||||
@@ -199,24 +406,42 @@ class WEISurvey2025(WEISurvey):
|
||||
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
|
||||
|
||||
@lru_cache()
|
||||
def score(self, bus):
|
||||
def score_questions(self, bus):
|
||||
"""
|
||||
The score given by the answers to the questions
|
||||
"""
|
||||
if not self.is_complete():
|
||||
raise ValueError("Survey is not ended, can't calculate score")
|
||||
s = sum(1 for q in WORDS['questions'] if q != 'alcool' and getattr(self.information, q) == bus.pk)
|
||||
if 'alcool' in WORDS['questions'] and bus.pk in WORDS['questions']['alcool'][1] and hasattr(self.information, 'alcool'):
|
||||
s -= abs(float(self.information.alcool) - float(WORDS['questions']['alcool'][1][bus.pk]))
|
||||
return s
|
||||
|
||||
@lru_cache()
|
||||
def score_words(self, bus):
|
||||
"""
|
||||
The score given by the choice of words
|
||||
"""
|
||||
if not self.is_complete():
|
||||
raise ValueError("Survey is not ended, can't calculate score")
|
||||
|
||||
bus_info = self.get_algorithm_class().get_bus_information(bus)
|
||||
# Score is the given score by the bus subtracted to the mid-score of the buses.
|
||||
s = sum(bus_info.scores[getattr(self.information, 'word' + str(i))]
|
||||
- self.word_mean(getattr(self.information, 'word' + str(i))) for i in range(1, 21)) / 20
|
||||
- self.word_mean(getattr(self.information, 'word' + str(i))) for i in range(1, 1 + NB_WORDS)) / self.get_algorithm_class().get_buses().count()
|
||||
return s
|
||||
|
||||
@lru_cache()
|
||||
def scores_per_bus(self):
|
||||
return {bus: self.score(bus) for bus in self.get_algorithm_class().get_buses()}
|
||||
return {bus: (self.score_questions(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
|
||||
|
||||
@lru_cache()
|
||||
def ordered_buses(self):
|
||||
"""
|
||||
Order the buses by the score_questions of the survey.
|
||||
"""
|
||||
values = list(self.scores_per_bus().items())
|
||||
values.sort(key=lambda item: -item[1])
|
||||
values.sort(key=lambda item: -item[1][0])
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
@@ -243,10 +468,18 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
||||
def get_bus_information_form(cls):
|
||||
return BusInformationForm2025
|
||||
|
||||
@classmethod
|
||||
def get_buses(cls):
|
||||
|
||||
if not hasattr(cls, '_buses'):
|
||||
cls._buses = Bus.objects.filter(wei__year=cls.get_survey_class().get_year(), size__gt=0).all().exclude(name='Staff')
|
||||
return cls._buses
|
||||
|
||||
def run_algorithm(self, display_tqdm=False):
|
||||
"""
|
||||
Gale-Shapley algorithm implementation.
|
||||
We modify it to allow buses to have multiple "weddings".
|
||||
We use lexigographical order on both scores
|
||||
"""
|
||||
surveys = list(self.get_survey_class()(r) for r in self.get_registrations()) # All surveys
|
||||
surveys = [s for s in surveys if s.is_complete()] # Don't consider invalid surveys
|
||||
@@ -307,7 +540,7 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
||||
while free_surveys: # Some students are not affected
|
||||
survey = free_surveys[0]
|
||||
buses = survey.ordered_buses() # Preferences of the student
|
||||
for bus, current_score in buses:
|
||||
for bus, current_scores in buses:
|
||||
if self.get_bus_information(bus).has_free_seats(surveys, quotas):
|
||||
# Selected bus has free places. Put student in the bus
|
||||
survey.select_bus(bus)
|
||||
@@ -322,8 +555,8 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
||||
for survey2 in surveys:
|
||||
if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
|
||||
continue
|
||||
score2 = survey2.score(bus)
|
||||
if current_score <= score2: # Ignore better students
|
||||
score2 = survey2.score_words(bus)
|
||||
if current_scores[1] <= score2: # Ignore better students
|
||||
continue
|
||||
if least_preferred_survey is None or score2 < least_score:
|
||||
least_preferred_survey = survey2
|
||||
|
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.2.4 on 2025-07-19 12:17
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wei', '0015_remove_weiclub_caution_amount_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='weiregistration',
|
||||
name='fee',
|
||||
field=models.PositiveIntegerField(blank=True, default=0, verbose_name='fee'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='weiclub',
|
||||
name='fee_soge_credit',
|
||||
field=models.PositiveIntegerField(default=2000, verbose_name='membership fee (soge credit)'),
|
||||
),
|
||||
]
|
18
apps/wei/migrations/0017_alter_weiclub_fee_soge_credit.py
Normal file
18
apps/wei/migrations/0017_alter_weiclub_fee_soge_credit.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-02 13:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wei', '0016_weiregistration_fee_alter_weiclub_fee_soge_credit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='weiclub',
|
||||
name='fee_soge_credit',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='membership fee (soge credit)'),
|
||||
),
|
||||
]
|
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-02 17:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wei', '0017_alter_weiclub_fee_soge_credit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='weiregistration',
|
||||
name='deposit_check',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='weiregistration',
|
||||
name='deposit_given',
|
||||
field=models.BooleanField(default=False, verbose_name='Deposit given'),
|
||||
),
|
||||
]
|
@@ -40,7 +40,7 @@ class WEIClub(Club):
|
||||
|
||||
fee_soge_credit = models.PositiveIntegerField(
|
||||
verbose_name=_("membership fee (soge credit)"),
|
||||
default=2000,
|
||||
default=0,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -202,9 +202,9 @@ class WEIRegistration(models.Model):
|
||||
verbose_name=_("Credit from Société générale"),
|
||||
)
|
||||
|
||||
deposit_check = models.BooleanField(
|
||||
deposit_given = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name=_("Deposit check given")
|
||||
verbose_name=_("Deposit given")
|
||||
)
|
||||
|
||||
deposit_type = models.CharField(
|
||||
@@ -285,6 +285,12 @@ class WEIRegistration(models.Model):
|
||||
"encoded in JSON"),
|
||||
)
|
||||
|
||||
fee = models.PositiveIntegerField(
|
||||
default=0,
|
||||
verbose_name=_('fee'),
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('user', 'wei',)
|
||||
verbose_name = _("WEI User")
|
||||
@@ -309,7 +315,25 @@ class WEIRegistration(models.Model):
|
||||
self.information_json = json.dumps(information, indent=2)
|
||||
|
||||
@property
|
||||
def fee(self):
|
||||
def is_validated(self):
|
||||
try:
|
||||
return self.membership is not None
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
@property
|
||||
def validation_status(self):
|
||||
"""
|
||||
Define an order to have easier access to validatable registrations
|
||||
"""
|
||||
if self.fee + (self.wei.deposit_amount if self.deposit_type == 'note' else 0) > self.user.note.balance:
|
||||
return 2
|
||||
elif self.first_year:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def calculate_fee(self):
|
||||
bde = Club.objects.get(pk=1)
|
||||
kfet = Club.objects.get(pk=2)
|
||||
|
||||
@@ -336,12 +360,9 @@ class WEIRegistration(models.Model):
|
||||
|
||||
return fee
|
||||
|
||||
@property
|
||||
def is_validated(self):
|
||||
try:
|
||||
return self.membership is not None
|
||||
except AttributeError:
|
||||
return False
|
||||
def save(self, *args, **kwargs):
|
||||
self.fee = self.calculate_fee()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class WEIMembership(Membership):
|
||||
|
@@ -58,8 +58,8 @@ class WEIRegistrationTable(tables.Table):
|
||||
|
||||
validate = tables.Column(
|
||||
verbose_name=_("Validate"),
|
||||
orderable=False,
|
||||
accessor=A('pk'),
|
||||
orderable=True,
|
||||
accessor='validate_status',
|
||||
attrs={
|
||||
'th': {
|
||||
'id': 'validate-membership-header'
|
||||
@@ -71,7 +71,7 @@ class WEIRegistrationTable(tables.Table):
|
||||
'wei:wei_delete_registration',
|
||||
args=[A('pk')],
|
||||
orderable=False,
|
||||
verbose_name=_("delete"),
|
||||
verbose_name=_("Delete"),
|
||||
text=_("Delete"),
|
||||
attrs={
|
||||
'th': {
|
||||
@@ -84,6 +84,35 @@ class WEIRegistrationTable(tables.Table):
|
||||
},
|
||||
)
|
||||
|
||||
def render_deposit_type(self, record):
|
||||
if record.first_year:
|
||||
return format_html("∅")
|
||||
if record.deposit_type == 'check':
|
||||
# TODO Install Font Awesome 6 to acces more icons (and keep compaibility with current used v4)
|
||||
return format_html("""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="1.5em" height="1.5em"
|
||||
fill="currentColor" style="position: relative; left: -0.15em;">
|
||||
<path d="
|
||||
M128 128C92.7 128 64 156.7 64 192L64 448C64 483.3 92.7 512 128 512L512 512
|
||||
C547.3 512 576 483.3 576 448L576 192C576 156.7 547.3 128 512 128L128 128z
|
||||
M360 352L488 352C501.3 352 512 362.7 512 376C512 389.3 501.3 400 488 400L360 400
|
||||
C346.7 400 336 389.3 336 376C336 362.7 346.7 352 360 352z
|
||||
M336 264C336 250.7 346.7 240 360 240L488 240C501.3 240 512 250.7 512 264
|
||||
C512 277.3 501.3 288 488 288L360 288C346.7 288 336 277.3 336 264z
|
||||
M212 208C223 208 232 217 232 228L232 232L240 232C251 232 260 241 260 252
|
||||
C260 263 251 272 240 272L192.5 272C185.6 272 180 277.6 180 284.5
|
||||
C180 290.6 184.4 295.8 190.4 296.8L232.1 303.8C257.4 308 276 329.9 276 355.6
|
||||
C276 381.7 257 403.3 232 407.4L232 412.1C232 423.1 223 432.1 212 432.1
|
||||
C201 432.1 192 423.1 192 412.1L192 408.1L168 408.1C157 408.1 148 399.1 148 388.1
|
||||
C148 377.1 157 368.1 168 368.1L223.5 368.1C230.4 368.1 236 362.5 236 355.6
|
||||
C236 349.5 231.6 344.3 225.6 343.3L183.9 336.3C158.5 332 140 310.1 140 284.5
|
||||
C140 255.7 163.2 232.3 192 232L192 228C192 217 201 208 212 208z
|
||||
" />
|
||||
</svg>
|
||||
""")
|
||||
if record.deposit_type == 'note':
|
||||
return format_html("<i class=\"fa fa-exchange\"></i>")
|
||||
|
||||
def render_validate(self, record):
|
||||
hasperm = PermissionBackend.check_perm(
|
||||
get_current_request(), "wei.add_weimembership", WEIMembership(
|
||||
@@ -98,12 +127,13 @@ class WEIRegistrationTable(tables.Table):
|
||||
if not hasperm:
|
||||
return format_html("<span class='no-perm'></span>")
|
||||
|
||||
url = reverse_lazy('wei:wei_update_registration', args=(record.pk,)) + '?validate=true'
|
||||
url = reverse_lazy('wei:validate_registration', args=(record.pk,))
|
||||
text = _('Validate')
|
||||
if record.fee > record.user.note.balance and not record.soge_credit:
|
||||
status = record.validation_status
|
||||
if status == 2:
|
||||
btn_class = 'btn-secondary'
|
||||
tooltip = _("The user does not have enough money.")
|
||||
elif record.first_year:
|
||||
elif status == 1:
|
||||
btn_class = 'btn-info'
|
||||
tooltip = _("The user is in first year. You may validate the credit, the algorithm will run later.")
|
||||
else:
|
||||
@@ -121,10 +151,11 @@ class WEIRegistrationTable(tables.Table):
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped table-hover'
|
||||
}
|
||||
order_by = ('validate', 'user',)
|
||||
model = WEIRegistration
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'deposit_check',
|
||||
'edit', 'validate', 'delete',)
|
||||
fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'deposit_given',
|
||||
'deposit_type', 'edit', 'validate', 'delete',)
|
||||
row_attrs = {
|
||||
'class': 'table-row',
|
||||
'id': lambda record: "row-" + str(record.pk),
|
||||
@@ -134,8 +165,8 @@ class WEIRegistrationTable(tables.Table):
|
||||
|
||||
class WEIMembershipTable(tables.Table):
|
||||
user = tables.LinkColumn(
|
||||
'wei:wei_update_registration',
|
||||
args=[A('registration__pk')],
|
||||
'wei:wei_update_membership',
|
||||
args=[A('pk')],
|
||||
)
|
||||
|
||||
year = tables.Column(
|
||||
@@ -156,6 +187,35 @@ class WEIMembershipTable(tables.Table):
|
||||
def render_year(self, record):
|
||||
return str(record.user.profile.ens_year) + "A"
|
||||
|
||||
def render_registration__deposit_type(self, record):
|
||||
if record.registration.first_year:
|
||||
return format_html("∅")
|
||||
if record.registration.deposit_type == 'check':
|
||||
# TODO Install Font Awesome 6 to acces more icons (and keep compaibility with current used v4)
|
||||
return format_html("""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="1.5em" height="1.5em"
|
||||
fill="currentColor" style="position: relative; left: -0.15em;">
|
||||
<path d="
|
||||
M128 128C92.7 128 64 156.7 64 192L64 448C64 483.3 92.7 512 128 512L512 512
|
||||
C547.3 512 576 483.3 576 448L576 192C576 156.7 547.3 128 512 128L128 128z
|
||||
M360 352L488 352C501.3 352 512 362.7 512 376C512 389.3 501.3 400 488 400L360 400
|
||||
C346.7 400 336 389.3 336 376C336 362.7 346.7 352 360 352z
|
||||
M336 264C336 250.7 346.7 240 360 240L488 240C501.3 240 512 250.7 512 264
|
||||
C512 277.3 501.3 288 488 288L360 288C346.7 288 336 277.3 336 264z
|
||||
M212 208C223 208 232 217 232 228L232 232L240 232C251 232 260 241 260 252
|
||||
C260 263 251 272 240 272L192.5 272C185.6 272 180 277.6 180 284.5
|
||||
C180 290.6 184.4 295.8 190.4 296.8L232.1 303.8C257.4 308 276 329.9 276 355.6
|
||||
C276 381.7 257 403.3 232 407.4L232 412.1C232 423.1 223 432.1 212 432.1
|
||||
C201 432.1 192 423.1 192 412.1L192 408.1L168 408.1C157 408.1 148 399.1 148 388.1
|
||||
C148 377.1 157 368.1 168 368.1L223.5 368.1C230.4 368.1 236 362.5 236 355.6
|
||||
C236 349.5 231.6 344.3 225.6 343.3L183.9 336.3C158.5 332 140 310.1 140 284.5
|
||||
C140 255.7 163.2 232.3 192 232L192 228C192 217 201 208 212 208z
|
||||
" />
|
||||
</svg>
|
||||
""")
|
||||
if record.registration.deposit_type == 'note':
|
||||
return format_html("<i class=\"fa fa-exchange\"></i>")
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped table-hover'
|
||||
@@ -163,7 +223,7 @@ class WEIMembershipTable(tables.Table):
|
||||
model = WEIMembership
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('user', 'user__last_name', 'user__first_name', 'registration__gender', 'user__profile__department',
|
||||
'year', 'bus', 'team', 'registration__deposit_check', )
|
||||
'year', 'bus', 'team', 'registration__deposit_given', 'registration__deposit_type')
|
||||
row_attrs = {
|
||||
'class': 'table-row',
|
||||
'id': lambda record: "row-" + str(record.pk),
|
||||
|
@@ -50,7 +50,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endif %}
|
||||
|
||||
{% if club.deposit_amount > 0 %}
|
||||
<dt class="col-xl-6">{% trans 'Deposit amount'|capfirst %}</dt>
|
||||
<dt class="col-xl-6">{% trans 'deposit amount'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.deposit_amount|pretty_money }}</dd>
|
||||
{% endif %}
|
||||
|
||||
|
@@ -22,8 +22,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endif %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:update_bus' pk=object.pk %}"
|
||||
data-turbolinks="false">{% trans "Edit" %}</a>
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:update_bus_info' pk=object.pk %}"
|
||||
data-turbolinks="false">{% trans "Edit information" %}</a>
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:update_bus_info' pk=object.pk %}"
|
||||
data-turbolinks="false">{% trans "Edit information for survey" %}</a>
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:add_team' pk=object.pk %}"
|
||||
data-turbolinks="false">{% trans "Add team" %}</a>
|
||||
</div>
|
||||
|
@@ -31,15 +31,29 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<a class="btn btn-success" href="{% url "wei:wei_register_1A_myself" wei_pk=club.pk %}" data-turbolinks="false">
|
||||
{% trans "Register to the WEI! – 1A" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-success" href="{% url "wei:wei_register_2A_myself" wei_pk=club.pk %}" data-turbolinks="false">
|
||||
{% trans "Register to the WEI! – 2A+" %}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-success" href="{% url "wei:wei_register_2A_myself" wei_pk=club.pk %}" data-turbolinks="false">
|
||||
{% trans "Register to the WEI! – 2A+" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if registration.validated %}
|
||||
<a class="btn btn-warning" href="{% url "wei:wei_update_registration" pk=my_registration.pk %}"
|
||||
data-turbolinks="false">
|
||||
{% trans "Update my registration" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if my_registration.first_year %}
|
||||
{% if not survey_complete %}
|
||||
<a class="btn btn-warning" href="{% url "wei:wei_survey" pk=my_registration.pk %}" data-turbolinks="false">
|
||||
{% trans "Continue survey" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-warning" href="{% url "wei:wei_survey" pk=my_registration.pk %}?reset=true" data-turbolinks="false">
|
||||
{% trans "Restart survey" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -67,20 +81,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if history_list.data %}
|
||||
<div class="card bg-white mb-3">
|
||||
<div class="card-header position-relative" id="historyListHeading">
|
||||
<a class="stretched-link font-weight-bold text-decoration-none" {% if "note.view_note"|has_perm:club.note %}
|
||||
href="{% url 'note:transactions' pk=club.note.pk %}" {% endif %}>
|
||||
<i class="fa fa-euro"></i> {% trans "Transaction history" %}
|
||||
</a>
|
||||
</div>
|
||||
<div id="history_list">
|
||||
{% render_table history_list %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if pre_registrations.data %}
|
||||
<div class="card bg-white mb-3">
|
||||
<div class="card-header position-relative" id="historyListHeading">
|
||||
@@ -99,6 +99,19 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<a href="{% url 'wei:wei_1A_list' pk=object.pk %}" class="btn btn-block btn-info">{% trans "Attribute buses" %}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if history_list.data %}
|
||||
<div class="card bg-white mt-3">
|
||||
<div class="card-header position-relative" id="historyListHeading">
|
||||
<a class="stretched-link font-weight-bold text-decoration-none" {% if "note.view_note"|has_perm:club.note %}
|
||||
href="{% url 'note:transactions' pk=club.note.pk %}" {% endif %}>
|
||||
<i class="fa fa-euro"></i> {% trans "Transaction history" %}
|
||||
</a>
|
||||
</div>
|
||||
<div id="history_list">
|
||||
{% render_table history_list %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
@@ -96,7 +96,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<dt class="col-xl-6">{% trans 'Deposit check given'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ registration.deposit_check|yesno }}</dd>
|
||||
<dd class="col-xl-6">{{ registration.deposit_given|yesno }}</dd>
|
||||
|
||||
{% with information=registration.information %}
|
||||
<dt class="col-xl-6">{% trans 'preferred bus'|capfirst %}</dt>
|
||||
@@ -143,12 +143,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="alert {% if registration.user.note.balance < fee %}alert-danger{% else %}alert-success{% endif %}">
|
||||
<div class="alert {% if registration.validation_status == 2 %}alert-danger{% else %}alert-success{% endif %}">
|
||||
<h5>{% trans "Required payments:" %}</h5>
|
||||
<ul>
|
||||
<li>{% blocktrans trimmed with amount=fee|pretty_money %}
|
||||
Membership fees: {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% if not registration.first_year %}
|
||||
{% if registration.deposit_type == 'note' %}
|
||||
<li>{% blocktrans trimmed with amount=club.deposit_amount|pretty_money %}
|
||||
Deposit (by Note transaction): {{ amount }}
|
||||
@@ -158,6 +159,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Deposit (by check): {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<li><strong>{% blocktrans trimmed with total=total_needed|pretty_money %}
|
||||
Total needed: {{ total }}
|
||||
{% endblocktrans %}</strong></li>
|
||||
@@ -167,9 +169,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endblocktrans %}</p>
|
||||
</div>
|
||||
|
||||
{% if not registration.deposit_check and not registration.first_year and registration.caution_type == 'check' %}
|
||||
{% if not registration.deposit_given and not registration.first_year and registration.caution_type == 'check' %}
|
||||
<div class="alert alert-danger">
|
||||
{% trans "The user didn't give her/his caution check." %}
|
||||
{% trans "The user didn't give her/his caution." %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -213,7 +215,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
$("input[name='bus']:checked").each(function (ignored) {
|
||||
buses.push($(this).parent().text().trim());
|
||||
});
|
||||
console.log(buses);
|
||||
$("input[name='team']").each(function () {
|
||||
let label = $(this).parent();
|
||||
$(this).parent().addClass('d-none');
|
||||
|
46
apps/wei/templates/wei/weimembership_update.html
Normal file
46
apps/wei/templates/wei/weimembership_update.html
Normal file
@@ -0,0 +1,46 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
{% load i18n crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card bg-white mb-3">
|
||||
<h3 class="card-header text-center">
|
||||
{{ title }}
|
||||
</h3>
|
||||
<div class="card-body" id="form">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<button class="btn btn-primary" type="submit">{% trans "Submit"%}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
function refreshTeams() {
|
||||
let buses = [];
|
||||
$("input[name='bus']:checked").each(function (ignored) {
|
||||
buses.push($(this).parent().text().trim());
|
||||
});
|
||||
$("input[name='team']").each(function () {
|
||||
let label = $(this).parent();
|
||||
$(this).parent().addClass('d-none');
|
||||
buses.forEach(function (bus) {
|
||||
if (label.text().includes(bus))
|
||||
label.removeClass('d-none');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$("input[name='bus']").change(refreshTeams);
|
||||
|
||||
refreshTeams();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@@ -6,7 +6,7 @@ import random
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from ..forms.surveys.wei2025 import WEIBusInformation2025, WEISurvey2025, WORDS, WEISurveyInformation2025
|
||||
from ..forms.surveys.wei2025 import WEIBusInformation2025, WEISurvey2025, WORDS, NB_WORDS, WEISurveyInformation2025
|
||||
from ..models import Bus, WEIClub, WEIRegistration
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ class TestWEIAlgorithm(TestCase):
|
||||
)
|
||||
|
||||
self.buses = []
|
||||
for i in range(10):
|
||||
for i in range(8):
|
||||
bus = Bus.objects.create(wei=self.wei, name=f"Bus {i}", size=10)
|
||||
self.buses.append(bus)
|
||||
information = WEIBusInformation2025(bus)
|
||||
for word in WORDS:
|
||||
information.scores[word] = random.randint(0, 101)
|
||||
for word in WORDS['list']:
|
||||
information.scores[word] = random.randint(0, 6)
|
||||
information.save()
|
||||
bus.save()
|
||||
|
||||
@@ -54,7 +54,7 @@ class TestWEIAlgorithm(TestCase):
|
||||
)
|
||||
information = WEISurveyInformation2025(registration)
|
||||
for j in range(1, 21):
|
||||
setattr(information, f'word{j}', random.choice(WORDS))
|
||||
setattr(information, f'word{j}', random.choice(WORDS['list']))
|
||||
information.step = 20
|
||||
information.save(registration)
|
||||
registration.save()
|
||||
@@ -74,7 +74,7 @@ class TestWEIAlgorithm(TestCase):
|
||||
Buses are full of first year people, ensure that they are happy
|
||||
"""
|
||||
# Add a lot of users
|
||||
for i in range(95):
|
||||
for i in range(80):
|
||||
user = User.objects.create(username=f"user{i}")
|
||||
registration = WEIRegistration.objects.create(
|
||||
user=user,
|
||||
@@ -83,11 +83,14 @@ class TestWEIAlgorithm(TestCase):
|
||||
birth_date='2000-01-01',
|
||||
)
|
||||
information = WEISurveyInformation2025(registration)
|
||||
for j in range(1, 21):
|
||||
setattr(information, f'word{j}', random.choice(WORDS))
|
||||
information.step = 20
|
||||
for j in range(1, 1 + NB_WORDS):
|
||||
setattr(information, f'word{j}', random.choice(WORDS['list']))
|
||||
for q in WORDS['questions']:
|
||||
setattr(information, q, random.choice(list(WORDS['questions'][q][1].keys())))
|
||||
information.step = len(WORDS['questions']) + 1
|
||||
information.save(registration)
|
||||
registration.save()
|
||||
survey = WEISurvey2025(registration)
|
||||
|
||||
# Run algorithm
|
||||
WEISurvey2025.get_algorithm_class()().run_algorithm()
|
||||
@@ -102,10 +105,23 @@ class TestWEIAlgorithm(TestCase):
|
||||
survey = WEISurvey2025(r)
|
||||
chosen_bus = survey.information.get_selected_bus()
|
||||
buses = survey.ordered_buses()
|
||||
score = min(v for bus, v in buses if bus == chosen_bus)
|
||||
max_score = buses[0][1]
|
||||
penalty += (max_score - score) ** 2
|
||||
|
||||
self.assertLessEqual(max_score - score, 25) # Always less than 25 % of tolerance
|
||||
|
||||
self.assertIn(chosen_bus, [x[0] for x in buses])
|
||||
score_questions, score_words = next(scores for bus, scores in buses if bus == chosen_bus)
|
||||
max_score_questions = max(buses[i][1][0] for i in range(len(buses)))
|
||||
max_score_words = max(buses[i][1][1] for i in range(len(buses)))
|
||||
penalty += (max_score_words - score_words) ** 2
|
||||
penalty += (max_score_questions - score_questions) ** 2
|
||||
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %
|
||||
|
||||
# There shouldn't be users who would prefer to switch buses
|
||||
for r1 in WEIRegistration.objects.filter(wei=self.wei).all():
|
||||
survey1 = WEISurvey2025(r1)
|
||||
bus1 = survey1.information.get_selected_bus()
|
||||
for r2 in WEIRegistration.objects.filter(wei=self.wei, pk__gt=r1.pk):
|
||||
survey2 = WEISurvey2025(r2)
|
||||
bus2 = survey2.information.get_selected_bus()
|
||||
|
||||
prefer_switch_bus_words = survey1.score_words(bus2) > survey1.score_words(bus1) and survey2.score_words(bus1) > survey2.score_words(bus2)
|
||||
prefer_switch_bus_questions = survey1.score_questions(bus2) > survey1.score_questions(bus1) and\
|
||||
survey2.score_questions(bus1) > survey2.score_questions(bus2)
|
||||
self.assertFalse(prefer_switch_bus_words and prefer_switch_bus_questions)
|
||||
|
@@ -101,7 +101,7 @@ class TestWEIRegistration(TestCase):
|
||||
user_id=self.user.id,
|
||||
wei_id=self.wei.id,
|
||||
soge_credit=True,
|
||||
deposit_check=True,
|
||||
deposit_given=True,
|
||||
birth_date=date(2000, 1, 1),
|
||||
gender="nonbinary",
|
||||
clothing_cut="male",
|
||||
@@ -642,7 +642,7 @@ class TestWEIRegistration(TestCase):
|
||||
last_name="admin",
|
||||
first_name="admin",
|
||||
bank="Société générale",
|
||||
deposit_check=True,
|
||||
deposit_given=True,
|
||||
))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse(response.context["form"].is_valid())
|
||||
@@ -657,7 +657,7 @@ class TestWEIRegistration(TestCase):
|
||||
last_name="admin",
|
||||
first_name="admin",
|
||||
bank="Société générale",
|
||||
deposit_check=True,
|
||||
deposit_given=True,
|
||||
))
|
||||
self.assertRedirects(response, reverse("wei:wei_registrations", kwargs=dict(pk=self.registration.wei.pk)), 302, 200)
|
||||
|
||||
@@ -813,7 +813,7 @@ class TestWeiAPI(TestAPI):
|
||||
user_id=self.user.id,
|
||||
wei_id=self.wei.id,
|
||||
soge_credit=True,
|
||||
deposit_check=True,
|
||||
deposit_given=True,
|
||||
birth_date=date(2000, 1, 1),
|
||||
gender="nonbinary",
|
||||
clothing_cut="male",
|
||||
|
@@ -7,7 +7,7 @@ from .views import CurrentWEIDetailView, WEI1AListView, WEIListView, WEICreateVi
|
||||
WEIRegistrationsView, WEIMembershipsView, MemberListRenderView, BusInformationUpdateView, \
|
||||
BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView, \
|
||||
WEIAttributeBus1AView, WEIAttributeBus1ANextView, WEIRegister1AView, WEIRegister2AView, WEIUpdateRegistrationView, \
|
||||
WEIDeleteRegistrationView, WEIValidateRegistrationView, WEISurveyView, WEISurveyEndView, WEIClosedView
|
||||
WEIDeleteRegistrationView, WEIValidateRegistrationView, WEISurveyView, WEISurveyEndView, WEIClosedView, WEIUpdateMembershipView
|
||||
|
||||
app_name = 'wei'
|
||||
urlpatterns = [
|
||||
@@ -43,4 +43,6 @@ urlpatterns = [
|
||||
path('bus-1A/<int:pk>/', WEIAttributeBus1AView.as_view(), name="wei_bus_1A"),
|
||||
path('bus-1A/next/<int:pk>/', WEIAttributeBus1ANextView.as_view(), name="wei_bus_1A_next"),
|
||||
path('update-bus-info/<int:pk>/', BusInformationUpdateView.as_view(), name="update_bus_info"),
|
||||
|
||||
path('edit_membership/<int:pk>/', WEIUpdateMembershipView.as_view(), name="wei_update_membership"),
|
||||
]
|
||||
|
@@ -13,7 +13,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.db.models import Q, Count
|
||||
from django.db.models import Q, Count, Case, When, Value, IntegerField, F
|
||||
from django.db.models.functions.text import Lower
|
||||
from django import forms
|
||||
from django.http import HttpResponse, Http404
|
||||
@@ -35,7 +35,7 @@ from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
||||
|
||||
from .forms.registration import WEIChooseBusForm
|
||||
from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam, WEIRole
|
||||
from .forms import WEIForm, WEIRegistrationForm, WEIRegistration1AForm, WEIRegistration2AForm, BusForm, BusTeamForm, WEIMembership1AForm, \
|
||||
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembership1AForm, \
|
||||
WEIMembershipForm, CurrentSurvey
|
||||
from .tables import BusRepartitionTable, BusTable, BusTeamTable, WEITable, WEIRegistrationTable, \
|
||||
WEIRegistration1ATable, WEIMembershipTable
|
||||
@@ -133,6 +133,23 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, D
|
||||
membership=None,
|
||||
wei=club
|
||||
)
|
||||
# Annotate the query to be able to sort registrations on validate status
|
||||
pre_registrations = pre_registrations.annotate(
|
||||
deposit=Case(
|
||||
When(deposit_type='note', then=F('wei__deposit_amount')),
|
||||
default=Value(0),
|
||||
output_field=IntegerField()
|
||||
)
|
||||
).annotate(
|
||||
total_fee=F('fee') + F('deposit')
|
||||
).annotate(
|
||||
validate_status=Case(
|
||||
When(total_fee__gt=F('user__note__balance'), then=Value(2)),
|
||||
When(first_year=True, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
buses = Bus.objects.filter(PermissionBackend.filter_queryset(self.request, Bus, "view")) \
|
||||
.filter(wei=self.object).annotate(count=Count("memberships")).order_by("name")
|
||||
return [club_transactions, club_member, pre_registrations, buses, ]
|
||||
@@ -149,6 +166,7 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, D
|
||||
my_registration = WEIRegistration.objects.filter(wei=club, user=self.request.user)
|
||||
if my_registration.exists():
|
||||
my_registration = my_registration.get()
|
||||
context["survey_complete"] = CurrentSurvey(my_registration).is_complete()
|
||||
else:
|
||||
my_registration = None
|
||||
context["my_registration"] = my_registration
|
||||
@@ -196,6 +214,8 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, D
|
||||
|
||||
context["not_first_year"] = WEIMembership.objects.filter(user=self.request.user).exists()
|
||||
|
||||
context["registration_validated"] = WEIMembership.objects.filter(registration=my_registration).exists() if my_registration else False
|
||||
|
||||
qs = WEIMembership.objects.filter(club=club, registration__first_year=True, bus__isnull=True)
|
||||
context["can_validate_1a"] = PermissionBackend.check_perm(
|
||||
self.request, "wei.change_weimembership_bus", qs.first()) if qs.exists() else False
|
||||
@@ -260,6 +280,23 @@ class WEIRegistrationsView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTable
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
qs = super().get_queryset(**kwargs).filter(wei=self.club, membership=None).distinct()
|
||||
# Annotate the query to be able to sort registrations on validate status
|
||||
qs = qs.annotate(
|
||||
deposit=Case(
|
||||
When(deposit_type='note', then=F('wei__deposit_amount')),
|
||||
default=Value(0),
|
||||
output_field=IntegerField()
|
||||
)
|
||||
).annotate(
|
||||
total_fee=F('fee') + F('deposit')
|
||||
).annotate(
|
||||
validate_status=Case(
|
||||
When(total_fee__gt=F('user__note__balance'), then=Value(2)),
|
||||
When(first_year=True, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
|
||||
pattern = self.request.GET.get("search", "")
|
||||
|
||||
@@ -510,7 +547,7 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
Register a new user to the WEI
|
||||
"""
|
||||
model = WEIRegistration
|
||||
form_class = WEIRegistration1AForm
|
||||
form_class = WEIRegistrationForm
|
||||
extra_context = {"title": _("Register first year student to the WEI")}
|
||||
|
||||
def get_sample_object(self):
|
||||
@@ -560,8 +597,8 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
# Cacher les champs pendant l'inscription initiale
|
||||
if "first_year" in form.fields:
|
||||
del form.fields["first_year"]
|
||||
if "deposit_check" in form.fields:
|
||||
del form.fields["deposit_check"]
|
||||
if "deposit_given" in form.fields:
|
||||
del form.fields["deposit_given"]
|
||||
if "information_json" in form.fields:
|
||||
del form.fields["information_json"]
|
||||
if "deposit_type" in form.fields:
|
||||
@@ -606,7 +643,7 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
Register an old user to the WEI
|
||||
"""
|
||||
model = WEIRegistration
|
||||
form_class = WEIRegistration2AForm
|
||||
form_class = WEIRegistrationForm
|
||||
extra_context = {"title": _("Register old student to the WEI")}
|
||||
|
||||
def get_sample_object(self):
|
||||
@@ -670,8 +707,8 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
# Cacher les champs pendant l'inscription initiale
|
||||
if "first_year" in form.fields:
|
||||
del form.fields["first_year"]
|
||||
if "deposit_check" in form.fields:
|
||||
del form.fields["deposit_check"]
|
||||
if "deposit_given" in form.fields:
|
||||
del form.fields["deposit_given"]
|
||||
if "information_json" in form.fields:
|
||||
del form.fields["information_json"]
|
||||
|
||||
@@ -739,14 +776,11 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
if today >= wei.date_start or today < wei.membership_start:
|
||||
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
|
||||
# Store the validate parameter in the view's state
|
||||
self.should_validate = request.GET.get('validate', False)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["club"] = self.object.wei
|
||||
# Pass the validate parameter to the template
|
||||
context["should_validate"] = self.should_validate
|
||||
|
||||
if self.object.is_validated:
|
||||
membership_form = self.get_membership_form(instance=self.object.membership,
|
||||
@@ -767,11 +801,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])
|
||||
context["membership_form"] = choose_bus_form
|
||||
|
||||
if not self.object.soge_credit and self.object.user.profile.soge:
|
||||
form = context["form"]
|
||||
form.fields["soge_credit"].disabled = True
|
||||
form.fields["soge_credit"].help_text = _("You already opened an account in the Société générale.")
|
||||
|
||||
return context
|
||||
|
||||
def get_form(self, form_class=None):
|
||||
@@ -780,15 +809,23 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
# The auto-json-format may cause issues with the default field remove
|
||||
if "information_json" in form.fields:
|
||||
del form.fields["information_json"]
|
||||
# Masquer le champ deposit_check pour tout le monde dans le formulaire de modification
|
||||
if "deposit_check" in form.fields:
|
||||
del form.fields["deposit_check"]
|
||||
# Masquer le champ deposit_given pour tout le monde dans le formulaire de modification
|
||||
if "deposit_given" in form.fields:
|
||||
form.fields["deposit_given"].help_text = _("Tick if the deposit check has been given")
|
||||
if self.object.first_year or self.object.deposit_type == 'note':
|
||||
del form.fields["deposit_given"]
|
||||
|
||||
# S'assurer que le champ deposit_type est obligatoire pour les 2A+
|
||||
if not self.object.first_year and "deposit_type" in form.fields:
|
||||
form.fields["deposit_type"].required = True
|
||||
form.fields["deposit_type"].help_text = _("Choose how you want to pay the deposit")
|
||||
form.fields["deposit_type"].widget = forms.RadioSelect(choices=form.fields["deposit_type"].choices)
|
||||
if "deposit_type" in form.fields:
|
||||
if self.object.first_year:
|
||||
del form.fields["deposit_type"]
|
||||
else:
|
||||
form.fields["deposit_type"].required = True
|
||||
form.fields["deposit_type"].help_text = _("Choose how you want to pay the deposit")
|
||||
|
||||
if self.object.user.profile.soge:
|
||||
form.fields["soge_credit"].disabled = True
|
||||
form.fields["soge_credit"].help_text = _("You already opened an account in the Société générale.")
|
||||
|
||||
return form
|
||||
|
||||
@@ -849,7 +886,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
information["preferred_roles_name"] = [role.name for role in choose_bus_form.cleaned_data["roles"]]
|
||||
form.instance.information = information
|
||||
|
||||
# Sauvegarder le type de caution pour les 2A+
|
||||
if "deposit_type" in form.cleaned_data:
|
||||
form.instance.deposit_type = form.cleaned_data["deposit_type"]
|
||||
form.instance.save()
|
||||
@@ -862,9 +898,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
survey = CurrentSurvey(self.object)
|
||||
if not survey.is_complete():
|
||||
return reverse_lazy("wei:wei_survey", kwargs={"pk": self.object.pk})
|
||||
# On redirige vers la validation uniquement si c'est explicitement demandé (et stocké dans la vue)
|
||||
if self.should_validate and self.request.user.has_perm("wei.add_weimembership"):
|
||||
return reverse_lazy("wei:validate_registration", kwargs={"pk": self.object.pk})
|
||||
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk})
|
||||
|
||||
|
||||
@@ -963,9 +996,9 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
|
||||
form = context["form"]
|
||||
if registration.soge_credit:
|
||||
form.fields["credit_amount"].initial = registration.fee
|
||||
form.fields["credit_amount"].initial = fee
|
||||
else:
|
||||
form.fields["credit_amount"].initial = max(0, registration.fee - registration.user.note.balance)
|
||||
form.fields["credit_amount"].initial = max(0, fee - registration.user.note.balance)
|
||||
|
||||
return context
|
||||
|
||||
@@ -988,17 +1021,18 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
form.fields["last_name"].initial = registration.user.last_name
|
||||
form.fields["first_name"].initial = registration.user.first_name
|
||||
|
||||
# Ajouter le champ deposit_check uniquement pour les non-première année et le rendre obligatoire
|
||||
# Ajouter le champ deposit_given uniquement pour les non-première année et le rendre obligatoire
|
||||
if not registration.first_year:
|
||||
if registration.deposit_type == 'check':
|
||||
form.fields["deposit_check"] = forms.BooleanField(
|
||||
form.fields["deposit_given"] = forms.BooleanField(
|
||||
required=True,
|
||||
initial=registration.deposit_check,
|
||||
disabled=True,
|
||||
initial=registration.deposit_given,
|
||||
label=_("Deposit check given"),
|
||||
help_text=_("Please make sure the check is given before validating the registration")
|
||||
help_text=_("Only treasurers can validate this field")
|
||||
)
|
||||
else:
|
||||
form.fields["deposit_check"] = forms.BooleanField(
|
||||
form.fields["deposit_given"] = forms.BooleanField(
|
||||
required=True,
|
||||
initial=False,
|
||||
label=_("Create deposit transaction"),
|
||||
@@ -1039,8 +1073,8 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
club = registration.wei
|
||||
user = registration.user
|
||||
|
||||
if "deposit_check" in form.data:
|
||||
registration.deposit_check = form.data["deposit_check"] == "on"
|
||||
if "deposit_given" in form.data:
|
||||
registration.deposit_given = form.data["deposit_given"] == "on"
|
||||
registration.save()
|
||||
membership = form.instance
|
||||
membership.user = user
|
||||
@@ -1052,7 +1086,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
|
||||
fee = club.membership_fee_paid if user.profile.paid else club.membership_fee_unpaid
|
||||
if registration.soge_credit:
|
||||
fee = 2000
|
||||
fee = registration.wei.fee_soge_credit
|
||||
|
||||
kfet = club.parent_club
|
||||
bde = kfet.parent_club
|
||||
@@ -1096,16 +1130,16 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
'credit': credit_amount,
|
||||
'needed': total_needed}
|
||||
)
|
||||
return super().form_invalid(form)
|
||||
return self.form_invalid(form)
|
||||
|
||||
if credit_amount:
|
||||
if not last_name:
|
||||
form.add_error('last_name', _("This field is required."))
|
||||
return super().form_invalid(form)
|
||||
return self.form_invalid(form)
|
||||
|
||||
if not first_name:
|
||||
form.add_error('first_name', _("This field is required."))
|
||||
return super().form_invalid(form)
|
||||
return self.form_invalid(form)
|
||||
|
||||
# Credit note before adding the membership
|
||||
SpecialTransaction.objects.create(
|
||||
@@ -1149,11 +1183,60 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
def form_invalid(self, form):
|
||||
registration = getattr(form.instance, "registration", None)
|
||||
if registration is not None:
|
||||
registration.deposit_given = False
|
||||
registration.save()
|
||||
return super().form_invalid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
self.object.refresh_from_db()
|
||||
return reverse_lazy("wei:wei_registrations", kwargs={"pk": self.object.club.pk})
|
||||
|
||||
|
||||
class WEIUpdateMembershipView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||
"""
|
||||
Update a membership for the WEI
|
||||
"""
|
||||
model = WEIMembership
|
||||
context_object_name = "membership"
|
||||
template_name = "wei/weimembership_update.html"
|
||||
extra_context = {"title": _("Update WEI Membership")}
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
wei = self.get_object().registration.wei
|
||||
today = date.today()
|
||||
# We can't update a registration once the WEI is started and before the membership start date
|
||||
if today >= wei.date_start or today < wei.membership_start:
|
||||
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
|
||||
# Store the validate parameter in the view's state
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form(self):
|
||||
form = WEIMembershipForm(
|
||||
self.request.POST or None,
|
||||
self.request.FILES or None,
|
||||
instance=self.object,
|
||||
wei=self.object.registration.wei,
|
||||
)
|
||||
|
||||
form.fields["roles"].initial = self.object.roles.all()
|
||||
form.fields["bus"].initial = self.object.bus
|
||||
form.fields["team"].initial = self.object.team
|
||||
|
||||
del form.fields["credit_type"]
|
||||
del form.fields["credit_amount"]
|
||||
del form.fields["first_name"]
|
||||
del form.fields["last_name"]
|
||||
del form.fields["bank"]
|
||||
|
||||
return form
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.registration.wei.pk})
|
||||
|
||||
|
||||
class WEISurveyView(LoginRequiredMixin, BaseFormView, DetailView):
|
||||
"""
|
||||
Display the survey for the WEI for first year members.
|
||||
@@ -1176,6 +1259,10 @@ class WEISurveyView(LoginRequiredMixin, BaseFormView, DetailView):
|
||||
|
||||
if not self.survey:
|
||||
self.survey = CurrentSurvey(obj)
|
||||
|
||||
if request.GET.get("reset") == "true":
|
||||
info = self.survey.information
|
||||
info.reset(obj)
|
||||
# If the survey is complete, then display the end page.
|
||||
if self.survey.is_complete():
|
||||
return redirect(reverse_lazy('wei:wei_survey_end', args=(self.survey.registration.pk,)))
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -82,7 +82,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
{% url 'family:family_list' as url %}
|
||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-users"></i> {% trans 'Families' %}</a>
|
||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-home"></i> {% trans 'Families' %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
|
Reference in New Issue
Block a user