Update Py3 compat

This commit is contained in:
Basile Clement 2016-07-15 00:02:56 +02:00
parent aa6e5e5479
commit 210c6d7712
27 changed files with 155 additions and 95 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import autocomplete_light

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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.

View file

@ -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()

View file

@ -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

View file

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import autocomplete_light

View file

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import csv

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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