forked from DGNum/gestioCOF
Compatibilité python 3
Rend GestioCOF compatible avec python 3. En particulier, il s'agit de : - Utiliser la version "fonction" de `print` dans `sync_clipper` et `tirage_bda`, avec le `from __future__ import print_function` pour garder la compatibilité avec python 2 - Utiliser de l'unicode par défaut, même en python 2, avec `from __future__ import unicode_literals` et le décorateur de compatibilité `python_2_unicode_compatible` de Django pour les modèles, comme décrit à https://docs.djangoproject.com/en/1.9/topics/python3/#str-and-unicode-methods - Utiliser `six.text_type` à la place de `unicode` Fixes #2.
This commit is contained in:
parent
7f61870236
commit
21b8b6042f
18 changed files with 174 additions and 81 deletions
|
@ -1,5 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import calendar
|
||||
|
||||
from django.db import models
|
||||
|
@ -8,6 +10,7 @@ from django.template import loader, Context
|
|||
from django.core import mail
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
def render_template(template_name, data):
|
||||
|
@ -16,6 +19,7 @@ def render_template(template_name, data):
|
|||
return tmpl.render(ctxt)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Tirage(models.Model):
|
||||
title = models.CharField("Titre", max_length=300)
|
||||
ouverture = models.DateTimeField("Date et heure d'ouverture du tirage")
|
||||
|
@ -26,18 +30,20 @@ class Tirage(models.Model):
|
|||
def date_no_seconds(self):
|
||||
return self.fermeture.strftime('%d %b %Y %H:%M')
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s - %s" % (self.title, self.date_no_seconds())
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.title, self.date_no_seconds())
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Salle(models.Model):
|
||||
name = models.CharField("Nom", max_length=300)
|
||||
address = models.TextField("Adresse")
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Spectacle(models.Model):
|
||||
title = models.CharField("Titre", max_length=300)
|
||||
date = models.DateTimeField("Date & heure")
|
||||
|
@ -57,7 +63,7 @@ class Spectacle(models.Model):
|
|||
ordering = ("priority", "date", "title",)
|
||||
|
||||
def __repr__(self):
|
||||
return u"[%s]" % self.__unicode__()
|
||||
return "[%s]" % self
|
||||
|
||||
def timestamp(self):
|
||||
return "%d" % calendar.timegm(self.date.utctimetuple())
|
||||
|
@ -65,9 +71,9 @@ class Spectacle(models.Model):
|
|||
def date_no_seconds(self):
|
||||
return self.date.strftime('%d %b %Y %H:%M')
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s - %s, %s, %.02f€" % (self.title, self.date_no_seconds(),
|
||||
self.location, self.price)
|
||||
def __str__(self):
|
||||
return "%s - %s, %s, %.02f€" % (self.title, self.date_no_seconds(),
|
||||
self.location, self.price)
|
||||
|
||||
def send_rappel(self):
|
||||
# On récupère la liste des participants
|
||||
|
@ -156,10 +162,11 @@ class ChoixSpectacle(models.Model):
|
|||
verbose_name_plural = "voeux"
|
||||
|
||||
|
||||
@python2_unicode_compatible
|
||||
class Attribution(models.Model):
|
||||
participant = models.ForeignKey(Participant)
|
||||
spectacle = models.ForeignKey(Spectacle, related_name="attribues")
|
||||
given = models.BooleanField(u"Donnée", default=False)
|
||||
given = models.BooleanField("Donnée", default=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s -- %s" % (self.participant, self.spectacle)
|
||||
def __str__(self):
|
||||
return "%s -- %s" % (self.participant, self.spectacle)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue