mirror of https://gitlab.crans.org/bde/nk20
🐛 Better entry page
This commit is contained in:
parent
fbf3a0bcf6
commit
0a2c9d9c87
|
@ -114,28 +114,31 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||
context = super().get_context_data(**kwargs)
|
||||
|
||||
activity = Activity.objects.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view"))\
|
||||
.get(pk=self.kwargs["pk"])
|
||||
.distinct().get(pk=self.kwargs["pk"])
|
||||
context["activity"] = activity
|
||||
|
||||
matched = []
|
||||
|
||||
pattern = "^$"
|
||||
if "search" in self.request.GET:
|
||||
pattern = self.request.GET["search"]
|
||||
|
||||
if not pattern:
|
||||
pattern = "^$"
|
||||
|
||||
if pattern[0] != "^":
|
||||
pattern = "^" + pattern
|
||||
|
||||
guest_qs = Guest.objects\
|
||||
.annotate(balance=F("inviter__balance"), note_name=F("inviter__user__username"))\
|
||||
.filter(Q(first_name__regex=pattern) | Q(last_name__regex=pattern)
|
||||
| Q(inviter__alias__name__regex=pattern)
|
||||
| Q(inviter__alias__normalized_name__regex=Alias.normalize(pattern))) \
|
||||
.filter(activity=activity)\
|
||||
.filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view"))\
|
||||
.distinct()[:20]
|
||||
.order_by('last_name', 'first_name').distinct()
|
||||
|
||||
if "search" in self.request.GET:
|
||||
pattern = self.request.GET["search"]
|
||||
if pattern[0] != "^":
|
||||
pattern = "^" + pattern
|
||||
guest_qs = guest_qs.filter(
|
||||
Q(first_name__regex=pattern)
|
||||
| Q(last_name__regex=pattern)
|
||||
| Q(inviter__alias__name__regex=pattern)
|
||||
| Q(inviter__alias__normalized_name__regex=Alias.normalize(pattern))
|
||||
)
|
||||
else:
|
||||
pattern = None
|
||||
guest_qs = guest_qs.none()
|
||||
|
||||
for guest in guest_qs:
|
||||
guest.type = "Invité"
|
||||
matched.append(guest)
|
||||
|
@ -145,12 +148,18 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||
username=F("note__noteuser__user__username"),
|
||||
note_name=F("name"),
|
||||
balance=F("note__balance"))\
|
||||
.filter(Q(note__polymorphic_ctype__model="noteuser")
|
||||
& (Q(note__noteuser__user__first_name__regex=pattern)
|
||||
| Q(note__noteuser__user__last_name__regex=pattern)
|
||||
| Q(name__regex=pattern)
|
||||
| Q(normalized_name__regex=Alias.normalize(pattern)))) \
|
||||
.filter(note__polymorphic_ctype__model="noteuser")\
|
||||
.filter(PermissionBackend.filter_queryset(self.request.user, Alias, "view"))
|
||||
if pattern:
|
||||
note_qs = note_qs.filter(
|
||||
Q(note__noteuser__user__first_name__regex=pattern)
|
||||
| Q(note__noteuser__user__last_name__regex=pattern)
|
||||
| Q(name__regex=pattern)
|
||||
| Q(normalized_name__regex=Alias.normalize(pattern))
|
||||
)
|
||||
else:
|
||||
note_qs = note_qs.none()
|
||||
|
||||
if settings.DATABASES[note_qs.db]["ENGINE"] == 'django.db.backends.postgresql_psycopg2':
|
||||
note_qs = note_qs.distinct('note__pk')[:20]
|
||||
else:
|
||||
|
@ -158,6 +167,7 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||
# have distinct aliases rather than distinct notes with a SQLite DB, but it can fill the result page.
|
||||
# In production mode, please use PostgreSQL.
|
||||
note_qs = note_qs.distinct()[:20]
|
||||
|
||||
for note in note_qs:
|
||||
note.type = "Adhérent"
|
||||
note.activity = activity
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note.models import NoteSpecial, Alias
|
||||
from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput
|
||||
|
@ -151,6 +152,7 @@ class MembershipRolesForm(forms.ModelForm):
|
|||
roles = forms.ModelMultipleChoiceField(
|
||||
queryset=Role.objects.filter(weirole=None).all(),
|
||||
label=_("Roles"),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete, ColorWidget
|
||||
|
||||
|
@ -47,6 +48,7 @@ class WEIChooseBusForm(forms.Form):
|
|||
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(),
|
||||
)
|
||||
|
||||
team = forms.ModelMultipleChoiceField(
|
||||
|
@ -54,17 +56,24 @@ class WEIChooseBusForm(forms.Form):
|
|||
label=_("Team"),
|
||||
required=False,
|
||||
help_text=_("Leave this field empty if you won't be in a team (staff, bus chief, free electron)"),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
)
|
||||
|
||||
roles = forms.ModelMultipleChoiceField(
|
||||
queryset=WEIRole.objects.filter(~Q(name="1A")),
|
||||
label=_("WEI Roles"),
|
||||
help_text=_("Select the roles that you are interested in."),
|
||||
initial=WEIRole.objects.filter(name="Adhérent WEI").all(),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
)
|
||||
|
||||
|
||||
class WEIMembershipForm(forms.ModelForm):
|
||||
roles = forms.ModelMultipleChoiceField(queryset=WEIRole.objects, label=_("WEI Roles"))
|
||||
roles = forms.ModelMultipleChoiceField(
|
||||
queryset=WEIRole.objects,
|
||||
label=_("WEI Roles"),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
|
|
@ -527,8 +527,9 @@ class WEIRegister2AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
|
|||
context["form"].fields["user"].disabled = True
|
||||
|
||||
choose_bus_form = WEIChooseBusForm()
|
||||
choose_bus_form.fields["bus"].queryset = Bus.objects.filter(wei=context["club"])
|
||||
choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])
|
||||
choose_bus_form.fields["bus"].queryset = Bus.objects.filter(wei=context["club"]).order_by('name')
|
||||
choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])\
|
||||
.order_by('bus__name', 'name')
|
||||
context['membership_form'] = choose_bus_form
|
||||
|
||||
return context
|
||||
|
|
|
@ -14,3 +14,29 @@
|
|||
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
function refreshTeams() {
|
||||
let buses = [];
|
||||
$("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');
|
||||
buses.forEach(function(bus) {
|
||||
if (label.text().includes(bus))
|
||||
label.removeClass('d-none');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$("input[name='bus']").change(refreshTeams);
|
||||
|
||||
refreshTeams();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue