diff --git a/bda/management/commands/loadbdadevdata.py b/bda/management/commands/loadbdadevdata.py index a8851e3d..f348b310 100644 --- a/bda/management/commands/loadbdadevdata.py +++ b/bda/management/commands/loadbdadevdata.py @@ -77,7 +77,7 @@ class Command(MyBaseCommand): self.stdout.write("Inscription des utilisateurs aux tirages") ChoixSpectacle.objects.all().delete() choices = [] - for user in User.objects.filter(profile__is_cof=True): + for user in User.objects.filter(profile__cof__is_cof=True): for tirage in tirages: part, _ = Participant.objects.get_or_create( user=user, diff --git a/cof/autocomplete.py b/cof/autocomplete.py index 38dea4a2..2c05c701 100644 --- a/cof/autocomplete.py +++ b/cof/autocomplete.py @@ -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')) diff --git a/cof/decorators.py b/cof/decorators.py index d7e70608..a7ced8f7 100644 --- a/cof/decorators.py +++ b/cof/decorators.py @@ -9,8 +9,8 @@ from django_cas_ng.decorators import user_passes_test def is_cof(user): try: - profile = user.profile - return profile.is_cof + cofprofile = user.profile.cof + return cofprofile.is_cof except: return False @@ -21,8 +21,8 @@ cof_required_customdenied = user_passes_test(lambda u: is_cof(u), def is_buro(user): try: - profile = user.profile - return profile.is_buro + cofprofile = user.profile.cof + return cofprofile.is_buro except: return False diff --git a/cof/forms.py b/cof/forms.py index cf6652c7..a1ae7e1f 100644 --- a/cof/forms.py +++ b/cof/forms.py @@ -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): diff --git a/cof/management/commands/loaddevdata.py b/cof/management/commands/loaddevdata.py index 4627c2d0..1525152c 100644 --- a/cof/management/commands/loaddevdata.py +++ b/cof/management/commands/loaddevdata.py @@ -19,6 +19,8 @@ from cof.petits_cours_models import ( PetitCoursAttributionCounter ) +from cof.models import CofProfile + # Où sont stockés les fichiers json DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data') @@ -47,8 +49,10 @@ class Command(MyBaseCommand): # Gaulois gaulois = self.from_json('gaulois.json', DATA_DIR, User) for user in gaulois: - user.profile.is_cof = True - user.profile.save() + CofProfile.objects.create( + profile=user.profile, + is_cof=True + ) # Romains self.from_json('romains.json', DATA_DIR, User) @@ -65,10 +69,12 @@ class Command(MyBaseCommand): root.set_password('root') root.is_staff = True root.is_superuser = True - root.profile.is_cof = True - root.profile.is_buro = True - root.profile.save() root.save() + CofProfile.objects.create( + profile=root.profile, + is_cof=True, + is_buro=True + ) # --- # Petits cours diff --git a/cof/templates/autocomplete_user.html b/cof/templates/autocomplete_user.html index 26411eee..f5802c5d 100644 --- a/cof/templates/autocomplete_user.html +++ b/cof/templates/autocomplete_user.html @@ -3,7 +3,7 @@ {% if members %}
  • Membres du COF
  • {% for member in members %}{% if forloop.counter < 5 %} -
  • {{ member.user|highlight_user:q }}
  • +
  • {{ member.profile.user|highlight_user:q }}
  • {% elif forloop.counter == 5 %}
  • ...{% endif %}{% endfor %} {% endif %} {% if users %} diff --git a/cof/templates/home.html b/cof/templates/home.html index 5e9732c7..0d0edf63 100644 --- a/cof/templates/home.html +++ b/cof/templates/home.html @@ -7,7 +7,7 @@
    -
    +
    - {% if not user.profile.is_buro %} + {% if not user.profile.cof.is_buro %}
    diff --git a/cof/templates/registration.html b/cof/templates/registration.html index e3bf7e31..eb9bfd99 100644 --- a/cof/templates/registration.html +++ b/cof/templates/registration.html @@ -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", diff --git a/cof/views.py b/cof/views.py index 8c5398c2..06ecfe11 100644 --- a/cof/views.py +++ b/cof/views.py @@ -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() diff --git a/gestioCOF/urls.py b/gestioCOF/urls.py index c76337a2..d4a01618 100644 --- a/gestioCOF/urls.py +++ b/gestioCOF/urls.py @@ -31,7 +31,7 @@ urlpatterns = [ # Page d'accueil url(r'^$', cof_views.home, name='home'), # The common views - url(r"^$", include("gestion.urls")), + url(r"^", include("gestion.urls", namespace='gestion')), # Le BdA url(r'^bda/', include('bda.urls')), # Les exports diff --git a/gestion/templates/gestion/profile.html b/gestion/templates/gestion/profile.html index 54bdb9b6..183b36e4 100644 --- a/gestion/templates/gestion/profile.html +++ b/gestion/templates/gestion/profile.html @@ -8,11 +8,16 @@ {% if success %}

    Votre profil a été mis à jour avec succès !

    {% endif %} -
    +
    {% csrf_token %} - {% for field in form %} + {% for field in user_form %} + {{ field | bootstrap }} + {% endfor %} + + + {% for field in profile_form %} {{ field | bootstrap }} {% endfor %} diff --git a/gestion/urls.py b/gestion/urls.py index a5075985..037101dc 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -3,8 +3,6 @@ from django.conf.urls import url from . import views -app_name = "gestion" - urlpatterns = [ - url(r"^profile$", views.profile, name="profile"), + url(r"^profile/?$", views.profile, name="profile"), ] diff --git a/gestion/views.py b/gestion/views.py index 698d7886..a4e1d71c 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -11,7 +11,7 @@ def profile(request): if request.method == "POST": user_form = UserForm(request.POST, instance=user) profile_form = ProfileForm(request.POST, instance=user.profile) - if all(user_form.is_valid(), profile_form.is_valid()): + if all((user_form.is_valid(), profile_form.is_valid())): user_form.save() profile_form.save() success = True