From 4c20b17b4e70df9e336a765d232051f4dd55bf34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 16 Jul 2016 18:48:43 +0200 Subject: [PATCH 1/3] Nettoyage Simplement une suppression des `from foo import *` --- gestioncof/admin.py | 8 ++++++-- gestioncof/models.py | 2 +- gestioncof/petits_cours_views.py | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gestioncof/admin.py b/gestioncof/admin.py index 86935f64..702a3089 100644 --- a/gestioncof/admin.py +++ b/gestioncof/admin.py @@ -5,8 +5,12 @@ from __future__ import print_function from __future__ import unicode_literals from django.contrib import admin -from gestioncof.models import * -from gestioncof.petits_cours_models import * +from gestioncof.models import SurveyQuestionAnswer, SurveyQuestion, \ + CofProfile, EventOption, EventOptionChoice, Event, Club, CustomMail, \ + Survey, EventCommentField, EventRegistration +from gestioncof.petits_cours_models import PetitCoursDemande, \ + PetitCoursSubject, PetitCoursAbility, PetitCoursAttribution, \ + PetitCoursAttributionCounter from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from django.core.urlresolvers import reverse diff --git a/gestioncof/models.py b/gestioncof/models.py index cf3742f1..7df0fb00 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -11,7 +11,7 @@ from django.utils.encoding import python_2_unicode_compatible import django.utils.six as six from django.db.models.signals import post_save -from gestioncof.petits_cours_models import * +from gestioncof.petits_cours_models import choices_length OCCUPATION_CHOICES = ( ('exterieur', _("Extérieur")), diff --git a/gestioncof/petits_cours_views.py b/gestioncof/petits_cours_views.py index b0f64d37..b87d4ea2 100644 --- a/gestioncof/petits_cours_views.py +++ b/gestioncof/petits_cours_views.py @@ -20,7 +20,9 @@ from django.contrib.auth.decorators import login_required from django.db.models import Min from gestioncof.models import CofProfile -from gestioncof.petits_cours_models import * +from gestioncof.petits_cours_models import PetitCoursDemande, \ + PetitCoursAttribution, PetitCoursAttributionCounter, PetitCoursAbility, \ + PetitCoursSubject from gestioncof.decorators import buro_required from gestioncof.shared import lock_table, unlock_tables From d4e7cd698e97e5d8de5c79dae1fb6016f2d627cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 16 Jul 2016 20:54:52 +0200 Subject: [PATCH 2/3] Nettoyage Modifications dans le sens de PEP8 dans les fichiers qu'on utilise --- gestioncof/admin.py | 4 ++-- gestioncof/petits_cours_models.py | 2 +- gestioncof/petits_cours_views.py | 2 +- gestioncof/templatetags/utils.py | 12 +++++++++--- gestioncof/views.py | 3 ++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gestioncof/admin.py b/gestioncof/admin.py index 702a3089..342317f3 100644 --- a/gestioncof/admin.py +++ b/gestioncof/admin.py @@ -15,7 +15,6 @@ from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from django.core.urlresolvers import reverse from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ import django.utils.six as six import autocomplete_light @@ -191,7 +190,8 @@ else: class EventRegistrationAdmin(admin.ModelAdmin): form = autocomplete_light.modelform_factory(EventRegistration, exclude=[]) - list_display = ('__unicode__' if six.PY2 else '__str__', 'event', 'user', 'paid') + list_display = ('__unicode__' if six.PY2 else '__str__', 'event', 'user', + 'paid') list_filter = ('paid',) search_fields = ('user__username', 'user__first_name', 'user__last_name', 'user__email', 'event__title') diff --git a/gestioncof/petits_cours_models.py b/gestioncof/petits_cours_models.py index e9c2943d..4428b78c 100644 --- a/gestioncof/petits_cours_models.py +++ b/gestioncof/petits_cours_models.py @@ -53,7 +53,7 @@ class PetitCoursAbility(models.Model): def __str__(self): return "%s - %s - %s" % (self.user.username, - self.matiere, self.niveau) + self.matiere, self.niveau) @python_2_unicode_compatible diff --git a/gestioncof/petits_cours_views.py b/gestioncof/petits_cours_views.py index b87d4ea2..7d54766e 100644 --- a/gestioncof/petits_cours_views.py +++ b/gestioncof/petits_cours_views.py @@ -361,7 +361,7 @@ def inscription(request): abilities = PetitCoursAbility.objects \ .filter(user=request.user).all() for ability in abilities: - counter = _get_attrib_counter(ability.user, ability.matiere) + _get_attrib_counter(ability.user, ability.matiere) unlock_tables() success = True formset = MatieresFormSet(instance=request.user) diff --git a/gestioncof/templatetags/utils.py b/gestioncof/templatetags/utils.py index 223f208b..16a1f4e3 100644 --- a/gestioncof/templatetags/utils.py +++ b/gestioncof/templatetags/utils.py @@ -11,6 +11,7 @@ import re register = template.Library() + @register.filter def key(d, key_name): try: @@ -20,19 +21,25 @@ def key(d, key_name): value = settings.TEMPLATE_STRING_IF_INVALID return value + def highlight_text(text, q): q2 = "|".join(q.split()) pattern = re.compile(r"(?P%s)" % q2, re.IGNORECASE) - return mark_safe(re.sub(pattern, r"\g", text)) + return mark_safe(re.sub(pattern, + r"\g", + text)) + @register.filter def highlight_user(user, q): if user.first_name and user.last_name: - text = "%s %s (%s)" % (user.first_name, user.last_name, user.username) + text = "%s %s (%s)" % (user.first_name, user.last_name, + user.username) else: text = user.username return highlight_text(text, q) + @register.filter def highlight_clipper(clipper, q): if clipper.fullname: @@ -40,4 +47,3 @@ def highlight_clipper(clipper, q): else: text = clipper.username return highlight_text(text, q) - diff --git a/gestioncof/views.py b/gestioncof/views.py index 39eba050..e2f59d44 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -458,7 +458,8 @@ def registration(request): (current_registration, created_reg) = \ EventRegistration.objects.get_or_create(user=member, event=form.event) - update_event_form_comments(form.event, form, current_registration) + update_event_form_comments(form.event, form, + current_registration) current_registration.options = all_choices current_registration.paid = \ (form.cleaned_data['status'] == 'paid') From 87c7c98cefeb3476d77fe9396e6b40866dd71a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Thu, 28 Jul 2016 01:31:50 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Ajoute=20une=20redirection=20apr=C3=A8s=20l?= =?UTF-8?q?ogin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si un utilisateur est redirigé vers la page de login en demandant une page, il est redirigé vers la page demandée initialement après authentification. --- gestioncof/templates/login.html | 3 ++- gestioncof/templates/login_switch.html | 6 ++++-- gestioncof/views.py | 13 +++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gestioncof/templates/login.html b/gestioncof/templates/login.html index 7e6a6e66..89b68380 100644 --- a/gestioncof/templates/login.html +++ b/gestioncof/templates/login.html @@ -10,7 +10,8 @@

Identifiants incorrects.

{% endif %} -
+ {% csrf_token %} diff --git a/gestioncof/templates/login_switch.html b/gestioncof/templates/login_switch.html index fe816a78..aafbf54f 100644 --- a/gestioncof/templates/login_switch.html +++ b/gestioncof/templates/login_switch.html @@ -3,10 +3,12 @@ {% block content %}
- + Compte clipper - + Extérieur
diff --git a/gestioncof/views.py b/gestioncof/views.py index e2f59d44..2d5f0487 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -43,7 +43,10 @@ def home(request): def login(request): if request.user.is_authenticated(): return redirect("gestioncof.views.home") - return render(request, "login_switch.html", {}) + context = {} + if request.method == "GET" and 'next' in request.GET: + context['next'] = request.GET['next'] + return render(request, "login_switch.html", context) def login_ext(request): @@ -60,7 +63,13 @@ def login_ext(request): {"error_type": "no_password"}) except User.DoesNotExist: pass - return django_login_view(request, template_name='login.html') + context = {} + if request.method == "GET" and 'next' in request.GET: + context['next'] = request.GET['next'] + if request.method == "POST" and 'next' in request.POST: + context['next'] = request.POST['next'] + return django_login_view(request, template_name='login.html', + extra_context=context) @login_required