diff --git a/apache/wsgi.py b/apache/wsgi.py index b7a1eb92..177542a8 100644 --- a/apache/wsgi.py +++ b/apache/wsgi.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + """ WSGI config for myproject project. It exposes the WSGI callable as a module-level variable named ``application``. @@ -5,6 +7,10 @@ For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + import os from django.core.wsgi import get_wsgi_application diff --git a/bda/admin.py b/bda/admin.py index cc4746ca..8f5915d5 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.core.mail import send_mail @@ -87,7 +89,7 @@ Le Bureau des Arts name = member.user.get_full_name() mail = mail % name else: - mail = u"""Cher-e %s, + mail = """Cher-e %s, Tu t'es inscrit-e pour le tirage au sort du BdA. Tu as été sélectionné-e pour les spectacles suivants : @@ -149,8 +151,8 @@ class AttributionAdminForm(forms.ModelForm): if participant and spectacle: if participant.tirage != spectacle.tirage: raise forms.ValidationError( - u"Erreur : le participant et le spectacle n'appartiennent" - u"pas au même tirage") + "Erreur : le participant et le spectacle n'appartiennent" + "pas au même tirage") return cleaned_data diff --git a/bda/algorithm.py b/bda/algorithm.py index 4a2dbdcc..bf9b690f 100644 --- a/bda/algorithm.py +++ b/bda/algorithm.py @@ -1,6 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.db.models import Max diff --git a/bda/autocomplete_light_registry.py b/bda/autocomplete_light_registry.py index aa6d4d57..6c2f3ea6 100644 --- a/bda/autocomplete_light_registry.py +++ b/bda/autocomplete_light_registry.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import autocomplete_light diff --git a/bda/forms.py b/bda/forms.py index 60efa029..9f5e3890 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django import forms diff --git a/bda/models.py b/bda/models.py index 7d92897e..46b90b99 100644 --- a/bda/models.py +++ b/bda/models.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import calendar @@ -140,6 +142,7 @@ DOUBLE_CHOICES = ( ) +@python_2_unicode_compatible class ChoixSpectacle(models.Model): participant = models.ForeignKey(Participant) spectacle = models.ForeignKey(Spectacle, related_name="participants") diff --git a/bda/tests.py b/bda/tests.py index 501deb77..22efc5a2 100644 --- a/bda/tests.py +++ b/bda/tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ This file demonstrates writing tests using the unittest module. These will pass when you run "manage.py test". @@ -5,6 +6,11 @@ when you run "manage.py test". Replace this with more appropriate tests for your application. """ +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + + from django.test import TestCase diff --git a/bda/urls.py b/bda/urls.py index 268bb352..4e5811a1 100644 --- a/bda/urls.py +++ b/bda/urls.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + from django.conf.urls import url, patterns from bda.views import SpectacleListView diff --git a/bda/views.py b/bda/views.py index d9b63615..fbf75359 100644 --- a/bda/views.py +++ b/bda/views.py @@ -1,6 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.shortcuts import render, get_object_or_404 @@ -195,7 +196,7 @@ def do_tirage(request, tirage_id): tirage_elt = get_object_or_404(Tirage, id=tirage_id) form = TokenForm(request.POST) if not form.is_valid(): - return tirage(request) + return tirage(request, tirage_id) tirage_elt.token = form.cleaned_data['token'] tirage_elt.save() start = time.time() diff --git a/cof/settings_dev.py b/cof/settings_dev.py index 1ef05f8c..502cb0ee 100644 --- a/cof/settings_dev.py +++ b/cof/settings_dev.py @@ -1,5 +1,4 @@ -# -*-coding:utf-8 -* - +# -*- coding: utf-8 -*- """ Django settings for cof project. @@ -10,6 +9,10 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os diff --git a/cof/urls.py b/cof/urls.py index 16c6a5f6..ee9d8457 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -1,17 +1,17 @@ -# -*-coding:utf-8 -* +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.conf import settings from django.conf.urls import patterns, include, url from django.conf.urls.static import static +from django.contrib import admin +from django.views.generic.base import TemplateView import autocomplete_light -from django.contrib import admin - -from django.views.generic.base import TemplateView - from gestioncof.urls import export_patterns, petitcours_patterns, \ surveys_patterns, events_patterns @@ -77,7 +77,7 @@ urlpatterns = patterns( url(r'^utile_bda/bda_revente$', 'gestioncof.views.liste_bdarevente'), ) + \ (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - if settings.DEBUG - else []) + if settings.DEBUG + else []) # Si on est en production, MEDIA_ROOT est servi par Apache. # Il faut dire à Django de servir MEDIA_ROOT lui-même en développement. diff --git a/gestioncof/admin.py b/gestioncof/admin.py index fb188f4b..86935f64 100644 --- a/gestioncof/admin.py +++ b/gestioncof/admin.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.contrib import admin @@ -15,8 +17,8 @@ import django.utils.six as six import autocomplete_light -def add_link_field(target_model='', field='', link_text=unicode, - desc_text=unicode): +def add_link_field(target_model='', field='', link_text=six.text_type, + desc_text=six.text_type): def add_link(cls): reverse_name = target_model or cls.model.__name__.lower() diff --git a/gestioncof/autocomplete.py b/gestioncof/autocomplete.py index 248a6ae7..5b4616be 100644 --- a/gestioncof/autocomplete.py +++ b/gestioncof/autocomplete.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django import shortcuts diff --git a/gestioncof/autocomplete_light_registry.py b/gestioncof/autocomplete_light_registry.py index 1b211691..f2a2ca6e 100644 --- a/gestioncof/autocomplete_light_registry.py +++ b/gestioncof/autocomplete_light_registry.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import autocomplete_light diff --git a/gestioncof/csv_views.py b/gestioncof/csv_views.py index f8037413..c1d82aca 100644 --- a/gestioncof/csv_views.py +++ b/gestioncof/csv_views.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import csv diff --git a/gestioncof/decorators.py b/gestioncof/decorators.py index e5416e32..d7e70608 100644 --- a/gestioncof/decorators.py +++ b/gestioncof/decorators.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django_cas_ng.decorators import user_passes_test diff --git a/gestioncof/forms.py b/gestioncof/forms.py index 7479586e..ce3a1b9e 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django import forms diff --git a/gestioncof/models.py b/gestioncof/models.py index 0c967a5b..8d660a53 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.db import models @@ -34,24 +36,21 @@ TYPE_COMMENT_FIELD = ( ) -def choices_length(choices): - return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0) - - +@python_2_unicode_compatible class CofProfile(models.Model): user = models.OneToOneField(User, related_name="profile") login_clipper = models.CharField("Login clipper", max_length=8, blank=True) is_cof = models.BooleanField("Membre du COF", default=False) num = models.IntegerField("Numéro d'adhérent", blank=True, default=0) phone = models.CharField("Téléphone", max_length=20, blank=True) - occupation = models.CharField(_(u"Occupation"), + occupation = models.CharField(_("Occupation"), default="1A", choices=OCCUPATION_CHOICES, max_length=choices_length( OCCUPATION_CHOICES)) - departement = models.CharField(_(u"Département"), max_length=50, + departement = models.CharField(_("Département"), max_length=50, blank=True) - type_cotiz = models.CharField(_(u"Type de cotisation"), + type_cotiz = models.CharField(_("Type de cotisation"), default="normalien", choices=TYPE_COTIZ_CHOICES, max_length=choices_length( @@ -83,6 +82,7 @@ def create_user_profile(sender, instance, created, **kwargs): post_save.connect(create_user_profile, sender=User) +@python_2_unicode_compatible class Club(models.Model): name = models.CharField("Nom", max_length=200) description = models.TextField("Description") @@ -141,6 +141,7 @@ class EventCommentField(models.Model): return six.text_type(self.name) +@python_2_unicode_compatible class EventCommentValue(models.Model): commentfield = models.ForeignKey(EventCommentField, related_name="values") registration = models.ForeignKey("EventRegistration", @@ -187,9 +188,9 @@ class EventRegistration(models.Model): verbose_name = "Inscription" unique_together = ("user", "event") - def __unicode__(self): - return u"Inscription de %s à %s" % (unicode(self.user), - unicode(self.event.title)) + def __str__(self): + return "Inscription de %s à %s" % (six.text_type(self.user), + six.text_type(self.event.title)) @python_2_unicode_compatible @@ -231,6 +232,7 @@ class SurveyQuestionAnswer(models.Model): return six.text_type(self.answer) +@python_2_unicode_compatible class SurveyAnswer(models.Model): user = models.ForeignKey(User) survey = models.ForeignKey(Survey) @@ -242,6 +244,7 @@ class SurveyAnswer(models.Model): unique_together = ("user", "survey") +@python_2_unicode_compatible class Clipper(models.Model): username = models.CharField("Identifiant", max_length=20) fullname = models.CharField("Nom complet", max_length=200) diff --git a/gestioncof/petits_cours_models.py b/gestioncof/petits_cours_models.py index b8487478..e9c2943d 100644 --- a/gestioncof/petits_cours_models.py +++ b/gestioncof/petits_cours_models.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.db import models @@ -39,11 +41,11 @@ class PetitCoursSubject(models.Model): @python_2_unicode_compatible class PetitCoursAbility(models.Model): user = models.ForeignKey(User) - matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière")) - niveau = models.CharField(_(u"Niveau"), + matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière")) + niveau = models.CharField(_("Niveau"), choices=LEVELS_CHOICES, max_length=choices_length(LEVELS_CHOICES)) - agrege = models.BooleanField(_(u"Agrégé"), default=False) + agrege = models.BooleanField(_("Agrégé"), default=False) class Meta: verbose_name = "Compétence petits cours" @@ -56,41 +58,41 @@ class PetitCoursAbility(models.Model): @python_2_unicode_compatible class PetitCoursDemande(models.Model): - name = models.CharField(_(u"Nom/prénom"), max_length=200) - email = models.CharField(_(u"Adresse email"), max_length=300) - phone = models.CharField(_(u"Téléphone (facultatif)"), + name = models.CharField(_("Nom/prénom"), max_length=200) + email = models.CharField(_("Adresse email"), max_length=300) + phone = models.CharField(_("Téléphone (facultatif)"), max_length=20, blank=True) quand = models.CharField( - _(u"Quand ?"), - help_text=_(u"Indiquez ici la période désirée pour les petits" + _("Quand ?"), + help_text=_("Indiquez ici la période désirée pour les petits" " cours (vacances scolaires, semaine, week-end)."), max_length=300, blank=True) freq = models.CharField( - _(u"Fréquence"), - help_text=_(u"Indiquez ici la fréquence envisagée " + _("Fréquence"), + help_text=_("Indiquez ici la fréquence envisagée " + "(hebdomadaire, 2 fois par semaine, ...)"), max_length=300, blank=True) lieu = models.CharField( - _(u"Lieu (si préférence)"), - help_text=_(u"Si vous avez avez une préférence sur le lieu."), + _("Lieu (si préférence)"), + help_text=_("Si vous avez avez une préférence sur le lieu."), max_length=300, blank=True) matieres = models.ManyToManyField( - PetitCoursSubject, verbose_name=_(u"Matières"), + PetitCoursSubject, verbose_name=_("Matières"), related_name="demandes") - agrege_requis = models.BooleanField(_(u"Agrégé requis"), default=False) - niveau = models.CharField(_(u"Niveau"), + agrege_requis = models.BooleanField(_("Agrégé requis"), default=False) + niveau = models.CharField(_("Niveau"), default="", choices=LEVELS_CHOICES, max_length=choices_length(LEVELS_CHOICES)) - remarques = models.TextField(_(u"Remarques et précisions"), blank=True) + remarques = models.TextField(_("Remarques et précisions"), blank=True) - traitee = models.BooleanField(_(u"Traitée"), default=False) + traitee = models.BooleanField(_("Traitée"), default=False) traitee_par = models.ForeignKey(User, blank=True, null=True) - processed = models.DateTimeField(_(u"Date de traitement"), + processed = models.DateTimeField(_("Date de traitement"), blank=True, null=True) - created = models.DateTimeField(_(u"Date de création"), auto_now_add=True) + created = models.DateTimeField(_("Date de création"), auto_now_add=True) class Meta: verbose_name = "Demande de petits cours" @@ -105,10 +107,10 @@ class PetitCoursDemande(models.Model): class PetitCoursAttribution(models.Model): user = models.ForeignKey(User) demande = models.ForeignKey(PetitCoursDemande, verbose_name=_("Demande")) - matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière")) - date = models.DateTimeField(_(u"Date d'attribution"), auto_now_add=True) + matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière")) + date = models.DateTimeField(_("Date d'attribution"), auto_now_add=True) rank = models.IntegerField("Rang dans l'email") - selected = models.BooleanField(_(u"Sélectionné par le demandeur"), + selected = models.BooleanField(_("Sélectionné par le demandeur"), default=False) class Meta: @@ -116,7 +118,7 @@ class PetitCoursAttribution(models.Model): verbose_name_plural = "Attributions de petits cours" def __str__(self): - return u"Attribution de la demande %d à %s pour %s" \ + return "Attribution de la demande %d à %s pour %s" \ % (self.demande.id, self.user.username, self.matiere) @@ -130,6 +132,6 @@ class PetitCoursAttributionCounter(models.Model): verbose_name = "Compteur d'attribution de petits cours" verbose_name_plural = "Compteurs d'attributions de petits cours" - def __unicode__(self): + def __str__(self): return "%d demandes envoyées à %s pour %s" \ % (self.count, self.user.username, self.matiere) diff --git a/gestioncof/petits_cours_views.py b/gestioncof/petits_cours_views.py index 7cba7ae1..b0f64d37 100644 --- a/gestioncof/petits_cours_views.py +++ b/gestioncof/petits_cours_views.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.shortcuts import render, get_object_or_404, redirect @@ -183,12 +185,12 @@ def _traitement_other_preparing(request, demande): if choice == -1: continue if choice not in candidates: - errors.append(u"Choix invalide pour la proposition %d" + errors.append("Choix invalide pour la proposition %d" "en %s" % (choice_id + 1, matiere)) continue user = candidates[choice] if user in proposals[matiere]: - errors.append(u"La proposition %d en %s est un doublon" + errors.append("La proposition %d en %s est un doublon" % (choice_id + 1, matiere)) continue proposals[matiere].append(user) diff --git a/gestioncof/shared.py b/gestioncof/shared.py index 4fb2e4bc..fc901d50 100644 --- a/gestioncof/shared.py +++ b/gestioncof/shared.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + from django.contrib.sites.models import Site from django.conf import settings from django_cas_ng.backends import CASBackend diff --git a/gestioncof/templatetags/utils.py b/gestioncof/templatetags/utils.py index 4785c822..223f208b 100644 --- a/gestioncof/templatetags/utils.py +++ b/gestioncof/templatetags/utils.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django import template diff --git a/gestioncof/tests.py b/gestioncof/tests.py index 501deb77..a83ebffc 100644 --- a/gestioncof/tests.py +++ b/gestioncof/tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ This file demonstrates writing tests using the unittest module. These will pass when you run "manage.py test". @@ -5,6 +6,10 @@ when you run "manage.py test". Replace this with more appropriate tests for your application. """ +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + from django.test import TestCase diff --git a/gestioncof/urls.py b/gestioncof/urls.py index 787dd80f..5cea2f8e 100644 --- a/gestioncof/urls.py +++ b/gestioncof/urls.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + from django.conf.urls import url from gestioncof.petits_cours_views import DemandeListView diff --git a/gestioncof/views.py b/gestioncof/views.py index dc05d816..9dc1615e 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -1,5 +1,7 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import unicodecsv @@ -280,35 +282,6 @@ def survey_status(request, survey_id): "form": form}) -class UserProfileForm(forms.ModelForm): - first_name = forms.CharField(label=_('Prénom'), max_length=30) - last_name = forms.CharField(label=_('Nom'), max_length=30) - - def __init__(self, *args, **kw): - super(UserProfileForm, self).__init__(*args, **kw) - self.fields['first_name'].initial = self.instance.user.first_name - self.fields['last_name'].initial = self.instance.user.last_name - - self.fields.keyOrder = [ - 'first_name', - 'last_name', - 'phone', - 'mailing_cof', - 'mailing_bda', - 'mailing_bda_revente', - ] - - def save(self, *args, **kw): - super(UserProfileForm, self).save(*args, **kw) - self.instance.user.first_name = self.cleaned_data.get('first_name') - self.instance.user.last_name = self.cleaned_data.get('last_name') - self.instance.user.save() - - class Meta: - model = CofProfile - fields = ("phone", "mailing_cof", "mailing_bda", "mailing_bda_revente",) ->>>>>>> Compatibilité python 3 - @login_required def profile(request): success = False @@ -523,7 +496,7 @@ def export_members(request): bits = [profile.num, user.username, user.first_name, user.last_name, user.email, profile.phone, profile.occupation, profile.departement, profile.type_cotiz] - writer.writerow([unicode(bit) for bit in bits]) + writer.writerow([six.text_type(bit) for bit in bits]) return response @@ -543,7 +516,7 @@ def csv_export_mega(filename, qs): profile.phone, profile.num, profile.comments if profile.comments else "", comments] - writer.writerow([unicode(bit) for bit in bits]) + writer.writerow([six.text_type(bit) for bit in bits]) return response @@ -563,7 +536,7 @@ def export_mega_remarksonly(request): profile = user.profile bits = [user.username, user.first_name, user.last_name, user.email, profile.phone, profile.num, profile.comments, val.content] - writer.writerow([unicode(bit) for bit in bits]) + writer.writerow([six.text_type(bit) for bit in bits]) return response diff --git a/gestioncof/widgets.py b/gestioncof/widgets.py index d819f5a2..758fc4ad 100644 --- a/gestioncof/widgets.py +++ b/gestioncof/widgets.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- + +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals from django.forms.widgets import Widget diff --git a/sync_clipper.py b/sync_clipper.py index 78a88e76..d9620b2d 100644 --- a/sync_clipper.py +++ b/sync_clipper.py @@ -1,6 +1,9 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- -from __future__ import print_function, unicode_literals +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals import os import sys