Fix user registration

This commit is contained in:
Qwann 2017-02-11 18:41:47 +01:00
parent fcf392f40d
commit b9ed7320ec
6 changed files with 18 additions and 17 deletions

View file

@ -26,14 +26,14 @@ def autocomplete(request):
bits = q.split()
queries['members'] = CofProfile.objects.filter(Q(is_cof=True))
queries['users'] = User.objects.filter(Q(profile__is_cof=False))
queries['users'] = User.objects.filter(Q(profile__cof__is_cof=False))
queries['clippers'] = Clipper.objects
for bit in bits:
queries['members'] = queries['members'].filter(
Q(user__first_name__icontains=bit)
| Q(user__last_name__icontains=bit)
| Q(user__username__icontains=bit)
| Q(login_clipper__icontains=bit))
Q(profile__user__first_name__icontains=bit)
| Q(profile__user__last_name__icontains=bit)
| Q(profile__user__username__icontains=bit)
| Q(profile__login_clipper__icontains=bit))
queries['users'] = queries['users'].filter(
Q(first_name__icontains=bit)
| Q(last_name__icontains=bit)
@ -43,7 +43,7 @@ def autocomplete(request):
| Q(username__icontains=bit))
queries['members'] = queries['members'].distinct()
queries['users'] = queries['users'].distinct()
usernames = list(queries['members'].values_list('login_clipper',
usernames = list(queries['members'].values_list('profile__login_clipper',
flat='True')) \
+ list(queries['users'].values_list('profile__login_clipper',
flat='True'))

View file

@ -180,10 +180,6 @@ class EventStatusFilterForm(forms.Form):
class RegistrationUserForm(forms.ModelForm):
def __init__(self, *args, **kw):
super(RegistrationUserForm, self).__init__(*args, **kw)
self.fields['username'].help_text = ""
def force_long_username(self):
self.fields['username'].validators = [MinLengthValidator(9)]
@ -228,7 +224,6 @@ class RegistrationCofProfileForm(forms.ModelForm):
fields = [
"num", "type_cotiz", "is_cof", "is_buro",
"mailing", "mailing_bda", "mailing_bda_revente",
"petits_cours_accept", "petits_cours_remarques"
]
def save(self, *args, **kw):

View file

@ -3,7 +3,7 @@
{% if members %}
<li class="autocomplete-header">Membres du COF</li>
{% for member in members %}{% if forloop.counter < 5 %}
<li class="autocomplete-value"><a href="{% url 'user-registration' member.user.username %}">{{ member.user|highlight_user:q }}</a></li>
<li class="autocomplete-value"><a href="{% url 'user-registration' member.profile.user.username %}">{{ member.profile.user|highlight_user:q }}</a></li>
{% elif forloop.counter == 5 %}<li class="autocomplete-more">...</a>{% endif %}{% endfor %}
{% endif %}
{% if users %}

View file

@ -57,7 +57,7 @@
<li><a href="{% url "cof.views.calendar" %}">Calendrier dynamique</a></li>
{% if user.profile.cof.is_cof %}<li><a href="{% url "petits-cours-inscription" %}">Inscription pour donner des petits cours</a></li>{% endif %}
<li><a href="{% url "profile" %}">Éditer mon profil</a></li>
<li><a href="{% url "gestion:profile" %}">Éditer mon profil</a></li>
{% if not user.profile.login_clipper %}<li><a href="{% url "django.contrib.auth.views.password_change" %}">Changer mon mot de passe</a></li>{% endif %}
</ul>
</div>

View file

@ -18,7 +18,7 @@
$(document).ready(function() {
$('input#search_autocomplete').yourlabsAutocomplete({
url: '{% url 'cof.autocomplete.autocomplete' %}',
minimumCharacters: 1,
minimumCharacters: 3,
id: 'search_autocomplete',
choiceSelector: 'li:has(a)',
placeholder: "Chercher un utilisateur par nom, prénom ou identifiant clipper",

View file

@ -399,6 +399,7 @@ def registration(request):
else:
user_form = RegistrationUserForm(request_dict)
profile_form = RegistrationProfileForm(request_dict)
cofprofile_form = RegistrationCofProfileForm(request_dict)
clubs_form = ClubsForm(request_dict)
events = Event.objects.filter(old=False).all()
event_formset = EventFormset(events=events, data=request_dict,
@ -423,7 +424,8 @@ def registration(request):
if user_form.is_valid():
member = user_form.save()
cofprofile, _ = CofProfile.objects.get_or_create(user=member)
cofprofile, _ = (CofProfile.objects
.get_or_create(profile=member.profile))
was_cof = cofprofile.is_cof
request_dict["num"] = cofprofile.num
# Maintenant on remplit le formulaire de profil
@ -431,12 +433,16 @@ def registration(request):
request_dict,
instance=cofprofile
)
forms_are_valid = all(
profile_form = RegistrationProfileForm(
request_dict,
instance=member.profile
)
forms_are_valid = all((
profile_form.is_valid(),
cofprofile_form.is_valid(),
event_formset.is_valid(),
clubs_form.is_valid()
)
))
if forms_are_valid:
# Enregistrement du profil
profile_form.save()