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

View file

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

View file

@ -3,7 +3,7 @@
{% if members %} {% if members %}
<li class="autocomplete-header">Membres du COF</li> <li class="autocomplete-header">Membres du COF</li>
{% for member in members %}{% if forloop.counter < 5 %} {% 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 %} {% elif forloop.counter == 5 %}<li class="autocomplete-more">...</a>{% endif %}{% endfor %}
{% endif %} {% endif %}
{% if users %} {% if users %}

View file

@ -57,7 +57,7 @@
<li><a href="{% url "cof.views.calendar" %}">Calendrier dynamique</a></li> <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 %} {% 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 %} {% 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> </ul>
</div> </div>

View file

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

View file

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