mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-15 02:33:22 +00:00
Remove ajax_select from clubs
This commit is contained in:
parent
a950585a02
commit
84ee6dd2f5
@ -22,7 +22,6 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from ajax_select.fields import AutoCompleteSelectMultipleField
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -30,6 +29,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from club.models import Club, Mailing, MailingSubscription, Membership
|
from club.models import Club, Mailing, MailingSubscription, Membership
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from core.views.forms import SelectDate, SelectDateTime
|
from core.views.forms import SelectDate, SelectDateTime
|
||||||
|
from core.views.widgets.select import AutoCompleteSelectMultipleUser
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
|
|
||||||
|
|
||||||
@ -50,11 +50,12 @@ class MailingForm(forms.Form):
|
|||||||
ACTION_NEW_SUBSCRIPTION = 2
|
ACTION_NEW_SUBSCRIPTION = 2
|
||||||
ACTION_REMOVE_SUBSCRIPTION = 3
|
ACTION_REMOVE_SUBSCRIPTION = 3
|
||||||
|
|
||||||
subscription_users = AutoCompleteSelectMultipleField(
|
subscription_users = forms.ModelMultipleChoiceField(
|
||||||
"users",
|
|
||||||
label=_("Users to add"),
|
label=_("Users to add"),
|
||||||
help_text=_("Search users to add (one or more)."),
|
help_text=_("Search users to add (one or more)."),
|
||||||
required=False,
|
required=False,
|
||||||
|
widget=AutoCompleteSelectMultipleUser,
|
||||||
|
queryset=User.objects.all(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, club_id, user_id, mailings, *args, **kwargs):
|
def __init__(self, club_id, user_id, mailings, *args, **kwargs):
|
||||||
@ -111,12 +112,7 @@ class MailingForm(forms.Form):
|
|||||||
"""Convert given users into real users and check their validity."""
|
"""Convert given users into real users and check their validity."""
|
||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
users = []
|
users = []
|
||||||
for user_id in cleaned_data["subscription_users"]:
|
for user in cleaned_data["subscription_users"]:
|
||||||
user = User.objects.filter(id=user_id).first()
|
|
||||||
if not user:
|
|
||||||
raise forms.ValidationError(
|
|
||||||
_("One of the selected users doesn't exist"), code="invalid"
|
|
||||||
)
|
|
||||||
if not user.email:
|
if not user.email:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
_("One of the selected users doesn't have an email address"),
|
_("One of the selected users doesn't have an email address"),
|
||||||
@ -180,11 +176,12 @@ class ClubMemberForm(forms.Form):
|
|||||||
error_css_class = "error"
|
error_css_class = "error"
|
||||||
required_css_class = "required"
|
required_css_class = "required"
|
||||||
|
|
||||||
users = AutoCompleteSelectMultipleField(
|
users = forms.ModelMultipleChoiceField(
|
||||||
"users",
|
|
||||||
label=_("Users to add"),
|
label=_("Users to add"),
|
||||||
help_text=_("Search users to add (one or more)."),
|
help_text=_("Search users to add (one or more)."),
|
||||||
required=False,
|
required=False,
|
||||||
|
widget=AutoCompleteSelectMultipleUser,
|
||||||
|
queryset=User.objects.all(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -238,12 +235,7 @@ class ClubMemberForm(forms.Form):
|
|||||||
"""
|
"""
|
||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
users = []
|
users = []
|
||||||
for user_id in cleaned_data["users"]:
|
for user in cleaned_data["users"]:
|
||||||
user = User.objects.filter(id=user_id).first()
|
|
||||||
if not user:
|
|
||||||
raise forms.ValidationError(
|
|
||||||
_("One of the selected users doesn't exist"), code="invalid"
|
|
||||||
)
|
|
||||||
if not user.is_subscribed:
|
if not user.is_subscribed:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
_("User must be subscriber to take part to a club"), code="invalid"
|
_("User must be subscriber to take part to a club"), code="invalid"
|
||||||
|
@ -254,7 +254,7 @@ class TestClubModel(TestClub):
|
|||||||
self.client.force_login(self.root)
|
self.client.force_login(self.root)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.members_url,
|
self.members_url,
|
||||||
{"users": self.subscriber.id, "role": 3},
|
{"users": [self.subscriber.id], "role": 3},
|
||||||
)
|
)
|
||||||
self.assertRedirects(response, self.members_url)
|
self.assertRedirects(response, self.members_url)
|
||||||
self.subscriber.refresh_from_db()
|
self.subscriber.refresh_from_db()
|
||||||
@ -266,7 +266,7 @@ class TestClubModel(TestClub):
|
|||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.members_url,
|
self.members_url,
|
||||||
{
|
{
|
||||||
"users": f"|{self.subscriber.id}|{self.krophil.id}|",
|
"users": (self.subscriber.id, self.krophil.id),
|
||||||
"role": 3,
|
"role": 3,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -330,7 +330,7 @@ class TestClubModel(TestClub):
|
|||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.members_url,
|
self.members_url,
|
||||||
{
|
{
|
||||||
"users": f"|{self.subscriber.id}|{9999}|",
|
"users": (self.subscriber.id, 9999),
|
||||||
"start_date": "12/06/2016",
|
"start_date": "12/06/2016",
|
||||||
"role": 3,
|
"role": 3,
|
||||||
},
|
},
|
||||||
@ -629,7 +629,7 @@ class TestMailingForm(TestCase):
|
|||||||
self.mail_url,
|
self.mail_url,
|
||||||
{
|
{
|
||||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||||
"subscription_users": "|%s|%s|" % (self.comunity.id, self.rbatsbak.id),
|
"subscription_users": (self.comunity.id, self.rbatsbak.id),
|
||||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -715,16 +715,17 @@ class TestMailingForm(TestCase):
|
|||||||
self.mail_url,
|
self.mail_url,
|
||||||
{
|
{
|
||||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||||
"subscription_users": "|789|",
|
"subscription_users": [789],
|
||||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
self.assertInHTML(
|
self.assertInHTML(
|
||||||
_("One of the selected users doesn't exist"), response.content.decode()
|
_("You must specify at least an user or an email address"),
|
||||||
|
response.content.decode(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# An user has no email adress
|
# An user has no email address
|
||||||
self.krophil.email = ""
|
self.krophil.email = ""
|
||||||
self.krophil.save()
|
self.krophil.save()
|
||||||
|
|
||||||
@ -782,8 +783,11 @@ class TestMailingForm(TestCase):
|
|||||||
self.mail_url,
|
self.mail_url,
|
||||||
{
|
{
|
||||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||||
"subscription_users": "|%s|%s|%s|"
|
"subscription_users": (
|
||||||
% (self.comunity.id, self.rbatsbak.id, self.krophil.id),
|
self.comunity.id,
|
||||||
|
self.rbatsbak.id,
|
||||||
|
self.krophil.id,
|
||||||
|
),
|
||||||
"subscription_mailing": mde.id,
|
"subscription_mailing": mde.id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user