forked from DGNum/gestioCOF
Merge branch 'Elarnon/py3' into 'master'
Rend GestioCOF compatible avec Python3 See merge request !58
This commit is contained in:
commit
bcbf9d9521
27 changed files with 337 additions and 160 deletions
28
bda/admin.py
28
bda/admin.py
|
@ -1,4 +1,8 @@
|
|||
# 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
|
||||
|
||||
|
@ -52,9 +56,9 @@ class ParticipantAdmin(admin.ModelAdmin):
|
|||
def total(self, obj):
|
||||
tot = obj.total
|
||||
if tot:
|
||||
return u"%.02f €" % tot
|
||||
return "%.02f €" % tot
|
||||
else:
|
||||
return u"0 €"
|
||||
return "0 €"
|
||||
total.admin_order_field = "total"
|
||||
total.short_description = "Total à payer"
|
||||
list_display = ("user", "nb_places", "total", "paid", "paymenttype",
|
||||
|
@ -70,7 +74,7 @@ class ParticipantAdmin(admin.ModelAdmin):
|
|||
for member in queryset.all():
|
||||
attribs = member.attributions.all()
|
||||
if len(attribs) == 0:
|
||||
mail = u"""Cher-e %s,
|
||||
mail = """Cher-e %s,
|
||||
|
||||
Tu t'es inscrit-e pour le tirage au sort du BdA. Malheureusement, tu n'as
|
||||
obtenu aucune place.
|
||||
|
@ -85,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 :
|
||||
|
@ -120,7 +124,7 @@ Le Bureau des Arts
|
|||
attribs_text = ""
|
||||
name = member.user.get_full_name()
|
||||
for attrib in attribs:
|
||||
attribs_text += u"- 1 place pour %s\n" % attrib
|
||||
attribs_text += "- 1 place pour %s\n" % attrib
|
||||
deadline = member.tirage.fermeture + timedelta(days=7)
|
||||
mail = mail % (name, attribs_text,
|
||||
deadline.strftime('%d %b %Y'))
|
||||
|
@ -129,14 +133,14 @@ Le Bureau des Arts
|
|||
fail_silently=True)
|
||||
count = len(queryset.all())
|
||||
if count == 1:
|
||||
message_bit = u"1 membre a"
|
||||
message_bit = "1 membre a"
|
||||
plural = ""
|
||||
else:
|
||||
message_bit = u"%d membres ont" % count
|
||||
message_bit = "%d membres ont" % count
|
||||
plural = "s"
|
||||
self.message_user(request, u"%s été informé%s avec succès."
|
||||
self.message_user(request, "%s été informé%s avec succès."
|
||||
% (message_bit, plural))
|
||||
send_attribs.short_description = u"Envoyer les résultats par mail"
|
||||
send_attribs.short_description = "Envoyer les résultats par mail"
|
||||
|
||||
|
||||
class AttributionAdminForm(forms.ModelForm):
|
||||
|
@ -147,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
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# 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
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import autocomplete_light
|
||||
|
||||
from bda.models import Participant, Spectacle
|
||||
|
|
10
bda/forms.py
10
bda/forms.py
|
@ -1,4 +1,8 @@
|
|||
# coding: utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.forms.models import BaseInlineFormSet
|
||||
|
@ -33,8 +37,8 @@ class TokenForm(forms.Form):
|
|||
|
||||
class SpectacleModelChoiceField(forms.ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
return u"%s le %s (%s) à %.02f€" % (obj.title, obj.date_no_seconds(),
|
||||
obj.location, obj.price)
|
||||
return "%s le %s (%s) à %.02f€" % (obj.title, obj.date_no_seconds(),
|
||||
obj.location, obj.price)
|
||||
|
||||
|
||||
class ResellForm(forms.Form):
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
# coding: utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import calendar
|
||||
|
||||
|
@ -8,6 +12,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 +21,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 +32,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 +65,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 +73,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
|
||||
|
@ -102,13 +110,14 @@ class Spectacle(models.Model):
|
|||
return members.values()
|
||||
|
||||
PAYMENT_TYPES = (
|
||||
("cash", u"Cash"),
|
||||
("cash", "Cash"),
|
||||
("cb", "CB"),
|
||||
("cheque", u"Chèque"),
|
||||
("autre", u"Autre"),
|
||||
("cheque", "Chèque"),
|
||||
("autre", "Autre"),
|
||||
)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Participant(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
choices = models.ManyToManyField(Spectacle,
|
||||
|
@ -117,14 +126,14 @@ class Participant(models.Model):
|
|||
attributions = models.ManyToManyField(Spectacle,
|
||||
through="Attribution",
|
||||
related_name="attributed_to")
|
||||
paid = models.BooleanField(u"A payé", default=False)
|
||||
paymenttype = models.CharField(u"Moyen de paiement",
|
||||
paid = models.BooleanField("A payé", default=False)
|
||||
paymenttype = models.CharField("Moyen de paiement",
|
||||
max_length=6, choices=PAYMENT_TYPES,
|
||||
blank=True)
|
||||
tirage = models.ForeignKey(Tirage)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s" % (self.user)
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.user, self.tirage.title)
|
||||
|
||||
DOUBLE_CHOICES = (
|
||||
("1", "1 place"),
|
||||
|
@ -133,6 +142,7 @@ DOUBLE_CHOICES = (
|
|||
)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ChoixSpectacle(models.Model):
|
||||
participant = models.ForeignKey(Participant)
|
||||
spectacle = models.ForeignKey(Spectacle, related_name="participants")
|
||||
|
@ -149,6 +159,11 @@ class ChoixSpectacle(models.Model):
|
|||
return self.double_choice == "autoquit"
|
||||
autoquit = property(get_autoquit)
|
||||
|
||||
def __str__(self):
|
||||
return "Vœux de %s pour %s" % (
|
||||
self.participant.user.get_full_name,
|
||||
self.spectacle.title)
|
||||
|
||||
class Meta:
|
||||
ordering = ("priority",)
|
||||
unique_together = (("participant", "spectacle",),)
|
||||
|
@ -156,10 +171,11 @@ class ChoixSpectacle(models.Model):
|
|||
verbose_name_plural = "voeux"
|
||||
|
||||
|
||||
@python_2_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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
14
bda/views.py
14
bda/views.py
|
@ -1,6 +1,8 @@
|
|||
# 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
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
@ -64,7 +66,7 @@ def etat_places(request, tirage_id):
|
|||
|
||||
|
||||
def _hash_queryset(queryset):
|
||||
data = serializers.serialize("json", queryset)
|
||||
data = serializers.serialize("json", queryset).encode()
|
||||
hasher = hashlib.sha256()
|
||||
hasher.update(data)
|
||||
return hasher.hexdigest()
|
||||
|
@ -145,7 +147,7 @@ def inscription(request, tirage_id):
|
|||
return render(request, "resume_inscription.html",
|
||||
{"error_title": "C'est fini !",
|
||||
"error_description":
|
||||
u"Tirage au sort dans la journée !",
|
||||
"Tirage au sort dans la journée !",
|
||||
"choices": choices})
|
||||
|
||||
def formfield_callback(f, **kwargs):
|
||||
|
@ -194,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()
|
||||
|
@ -223,7 +225,7 @@ def do_tirage(request, tirage_id):
|
|||
deficit = (show.slots - len(members)) * show.price
|
||||
total_sold += show.slots * show.price
|
||||
if deficit >= 0:
|
||||
if u"Opéra" in show.location.name:
|
||||
if "Opéra" in show.location.name:
|
||||
opera_deficit += deficit
|
||||
total_deficit += deficit
|
||||
data["total_sold"] = total_sold - total_deficit
|
||||
|
@ -277,7 +279,7 @@ def do_resell(request, form):
|
|||
spectacle = form.cleaned_data["spectacle"]
|
||||
count = form.cleaned_data["count"]
|
||||
places = "2 places" if count == "2" else "une place"
|
||||
mail = u"""Bonjour,
|
||||
mail = """Bonjour,
|
||||
|
||||
Je souhaite revendre %s pour %s le %s (%s) à %.02f€.
|
||||
Contactez moi par email si vous êtes intéressé·e·s !
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue