Create select widget based on tomselect on django backend

Replace make_ajax in elections by the new widget
This commit is contained in:
2024-10-19 21:32:58 +02:00
parent 0a0092e189
commit 8be8328830
5 changed files with 103 additions and 60 deletions

View File

@ -1,6 +1,5 @@
from typing import TYPE_CHECKING
from ajax_select import make_ajax_field
from ajax_select.fields import AutoCompleteSelectField
from django import forms
from django.core.exceptions import PermissionDenied
@ -13,7 +12,11 @@ from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
from core.views import CanCreateMixin, CanEditMixin, CanViewMixin
from core.views.forms import MarkdownInput, SelectDateTime
from core.views.forms import (
AutoCompleteSelectMultiple,
MarkdownInput,
SelectDateTime,
)
from election.models import Candidature, Election, ElectionList, Role, Vote
if TYPE_CHECKING:
@ -146,23 +149,12 @@ class ElectionForm(forms.ModelForm):
"vote_groups",
"candidature_groups",
]
edit_groups = make_ajax_field(
Election, "edit_groups", "groups", help_text="", label=_("edit groups")
)
view_groups = make_ajax_field(
Election, "view_groups", "groups", help_text="", label=_("view groups")
)
vote_groups = make_ajax_field(
Election, "vote_groups", "groups", help_text="", label=_("vote groups")
)
candidature_groups = make_ajax_field(
Election,
"candidature_groups",
"groups",
help_text="",
label=_("candidature groups"),
)
widgets = {
"edit_groups": AutoCompleteSelectMultiple,
"view_groups": AutoCompleteSelectMultiple,
"vote_groups": AutoCompleteSelectMultiple,
"candidature_groups": AutoCompleteSelectMultiple,
}
start_date = forms.DateTimeField(
label=_("Start date"), widget=SelectDateTime, required=True