WIP: Aureplop/kpsul js refactor #501

Draft
delobell wants to merge 215 commits from aureplop/kpsul_js_refactor into master
91 changed files with 4929 additions and 1062 deletions
Showing only changes of commit f03ce35126 - Show all commits

View file

@ -7,6 +7,7 @@ variables:
DJANGO_SETTINGS_MODULE: "cof.settings.prod" DJANGO_SETTINGS_MODULE: "cof.settings.prod"
DBHOST: "postgres" DBHOST: "postgres"
REDIS_HOST: "redis" REDIS_HOST: "redis"
REDIS_PASSWD: "dummy"
# Cached packages # Cached packages
PYTHONPATH: "$CI_PROJECT_DIR/vendor/python" PYTHONPATH: "$CI_PROJECT_DIR/vendor/python"
@ -16,6 +17,8 @@ variables:
POSTGRES_USER: "cof_gestion" POSTGRES_USER: "cof_gestion"
POSTGRES_DB: "cof_gestion" POSTGRES_DB: "cof_gestion"
# psql password authentication
PGPASSWORD: $POSTGRES_PASSWORD
cache: cache:
paths: paths:
@ -27,10 +30,10 @@ before_script:
- mkdir -p vendor/{python,pip,apt} - mkdir -p vendor/{python,pip,apt}
- apt-get update -q && apt-get -o dir::cache::archives="vendor/apt" install -yqq postgresql-client - apt-get update -q && apt-get -o dir::cache::archives="vendor/apt" install -yqq postgresql-client
- sed -E 's/^REDIS_HOST.*/REDIS_HOST = "redis"/' cof/settings/secret_example.py > cof/settings/secret.py - sed -E 's/^REDIS_HOST.*/REDIS_HOST = "redis"/' cof/settings/secret_example.py > cof/settings/secret.py
- sed -i.bak -E 's;^REDIS_PASSWD = .*$;REDIS_PASSWD = "";' cof/settings/secret.py
# Remove the old test database if it has not been done yet # Remove the old test database if it has not been done yet
- psql --username=cof_gestion --password="4KZt3nGPLVeWSvtBZPSM3fSzXpzEU4" --host="$DBHOST" - psql --username=$POSTGRES_USER --host=$DBHOST -c "DROP DATABASE IF EXISTS test_$POSTGRES_DB"
-e "DROP DATABASE test_$DBNAME" || true - pip install --upgrade --cache-dir vendor/pip -t vendor/python -r requirements.txt
- pip install --cache-dir vendor/pip -t vendor/python -r requirements.txt
test: test:
stage: test stage: test

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import autocomplete_light
from datetime import timedelta from datetime import timedelta
from custommail.shortcuts import send_mass_custom_mail from custommail.shortcuts import send_mass_custom_mail
@ -9,6 +8,9 @@ from django.db.models import Sum, Count
from django.template.defaultfilters import pluralize from django.template.defaultfilters import pluralize
from django.utils import timezone from django.utils import timezone
from django import forms from django import forms
from dal.autocomplete import ModelSelect2
from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\ from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\
Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente
@ -24,8 +26,17 @@ class ReadOnlyMixin(object):
return readonly_fields + self.readonly_fields_update return readonly_fields + self.readonly_fields_update
class ChoixSpectacleAdminForm(forms.ModelForm):
class Meta:
widgets = {
'participant': ModelSelect2(url='bda-participant-autocomplete'),
'spectacle': ModelSelect2(url='bda-spectacle-autocomplete'),
}
class ChoixSpectacleInline(admin.TabularInline): class ChoixSpectacleInline(admin.TabularInline):
model = ChoixSpectacle model = ChoixSpectacle
form = ChoixSpectacleAdminForm
sortable_field_name = "priority" sortable_field_name = "priority"
@ -56,17 +67,17 @@ class AttributionInline(admin.TabularInline):
def get_queryset(self, request): def get_queryset(self, request):
qs = super().get_queryset(request) qs = super().get_queryset(request)
if self.listing is not None: if self.listing is not None:
qs.filter(spectacle__listing=self.listing) qs = qs.filter(spectacle__listing=self.listing)
return qs return qs
class WithListingAttributionInline(AttributionInline): class WithListingAttributionInline(AttributionInline):
exclude = ('given', )
form = WithListingAttributionTabularAdminForm form = WithListingAttributionTabularAdminForm
listing = True listing = True
class WithoutListingAttributionInline(AttributionInline): class WithoutListingAttributionInline(AttributionInline):
exclude = ('given', )
form = WithoutListingAttributionTabularAdminForm form = WithoutListingAttributionTabularAdminForm
listing = False listing = False
@ -180,7 +191,7 @@ class AttributionAdmin(ReadOnlyMixin, admin.ModelAdmin):
class ChoixSpectacleAdmin(admin.ModelAdmin): class ChoixSpectacleAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(ChoixSpectacle, exclude=[]) form = ChoixSpectacleAdminForm
def tirage(self, obj): def tirage(self, obj):
return obj.participant.tirage return obj.participant.tirage

View file

@ -1,18 +0,0 @@
# -*- 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
autocomplete_light.register(
Participant, search_fields=('user__username', 'user__first_name',
'user__last_name'),
autocomplete_js_attributes={'placeholder': 'participant...'})
autocomplete_light.register(
Spectacle, search_fields=('title', ),
autocomplete_js_attributes={'placeholder': 'spectacle...'})

View file

@ -59,7 +59,7 @@ class Migration(migrations.Migration):
('price', models.FloatField(verbose_name=b"Prix d'une place", blank=True)), ('price', models.FloatField(verbose_name=b"Prix d'une place", blank=True)),
('slots', models.IntegerField(verbose_name=b'Places')), ('slots', models.IntegerField(verbose_name=b'Places')),
('priority', models.IntegerField(default=1000, verbose_name=b'Priorit\xc3\xa9')), ('priority', models.IntegerField(default=1000, verbose_name=b'Priorit\xc3\xa9')),
('location', models.ForeignKey(to='bda.Salle')), ('location', models.ForeignKey(to='bda.Salle', on_delete=models.CASCADE)),
], ],
options={ options={
'ordering': ('priority', 'date', 'title'), 'ordering': ('priority', 'date', 'title'),
@ -79,27 +79,27 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='participant', model_name='participant',
name='user', name='user',
field=models.OneToOneField(to=settings.AUTH_USER_MODEL), field=models.OneToOneField(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='choixspectacle', model_name='choixspectacle',
name='participant', name='participant',
field=models.ForeignKey(to='bda.Participant'), field=models.ForeignKey(to='bda.Participant', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='choixspectacle', model_name='choixspectacle',
name='spectacle', name='spectacle',
field=models.ForeignKey(related_name='participants', to='bda.Spectacle'), field=models.ForeignKey(related_name='participants', to='bda.Spectacle', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='attribution', model_name='attribution',
name='participant', name='participant',
field=models.ForeignKey(to='bda.Participant'), field=models.ForeignKey(to='bda.Participant', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='attribution', model_name='attribution',
name='spectacle', name='spectacle',
field=models.ForeignKey(related_name='attribues', to='bda.Spectacle'), field=models.ForeignKey(related_name='attribues', to='bda.Spectacle', on_delete=models.CASCADE),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='choixspectacle', name='choixspectacle',

View file

@ -5,17 +5,34 @@ from django.db import migrations, models
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
def forwards_func(apps, schema_editor):
def fill_tirage_fields(apps, schema_editor):
"""
Create a `Tirage` to fill new field `tirage` of `Participant`
and `Spectacle` already existing.
"""
Participant = apps.get_model("bda", "Participant")
Spectacle = apps.get_model("bda", "Spectacle")
Tirage = apps.get_model("bda", "Tirage") Tirage = apps.get_model("bda", "Tirage")
db_alias = schema_editor.connection.alias
Tirage.objects.using(db_alias).bulk_create([ # These querysets only contains instances not linked to any `Tirage`.
Tirage( participants = Participant.objects.filter(tirage=None)
id=1, spectacles = Spectacle.objects.filter(tirage=None)
if not participants.count() and not spectacles.count():
# No need to create a "trash" tirage.
return
tirage = Tirage.objects.create(
title="Tirage de test (migration)", title="Tirage de test (migration)",
active=False, active=False,
ouverture=timezone.now(), ouverture=timezone.now(),
fermeture=timezone.now()), fermeture=timezone.now(),
]) )
participants.update(tirage=tirage)
spectacles.update(tirage=tirage)
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -35,22 +52,33 @@ class Migration(migrations.Migration):
('active', models.BooleanField(default=True, verbose_name=b'Tirage actif')), ('active', models.BooleanField(default=True, verbose_name=b'Tirage actif')),
], ],
), ),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
migrations.AlterField( migrations.AlterField(
model_name='participant', model_name='participant',
name='user', name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL), field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
# Create fields `spectacle` for `Participant` and `Spectacle` models.
# These fields are not nullable, but we first create them as nullable
# to give a default value for existing instances of these models.
migrations.AddField( migrations.AddField(
model_name='participant', model_name='participant',
name='tirage', name='tirage',
field=models.ForeignKey(default=1, to='bda.Tirage'), field=models.ForeignKey(to='bda.Tirage', null=True, on_delete=models.CASCADE),
preserve_default=False,
), ),
migrations.AddField( migrations.AddField(
model_name='spectacle', model_name='spectacle',
name='tirage', name='tirage',
field=models.ForeignKey(default=1, to='bda.Tirage'), field=models.ForeignKey(to='bda.Tirage', null=True, on_delete=models.CASCADE),
preserve_default=False, ),
migrations.RunPython(fill_tirage_fields, migrations.RunPython.noop),
migrations.AlterField(
model_name='participant',
name='tirage',
field=models.ForeignKey(to='bda.Tirage', on_delete=models.CASCADE),
),
migrations.AlterField(
model_name='spectacle',
name='tirage',
field=models.ForeignKey(to='bda.Tirage', on_delete=models.CASCADE),
), ),
] ]

View file

@ -73,6 +73,7 @@ class Migration(migrations.Migration):
model_name='spectacle', model_name='spectacle',
name='category', name='category',
field=models.ForeignKey(blank=True, to='bda.CategorieSpectacle', field=models.ForeignKey(blank=True, to='bda.CategorieSpectacle',
on_delete=models.CASCADE,
null=True), null=True),
), ),
migrations.AddField( migrations.AddField(
@ -84,6 +85,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='quote', model_name='quote',
name='spectacle', name='spectacle',
field=models.ForeignKey(to='bda.Spectacle'), field=models.ForeignKey(to='bda.Spectacle',
on_delete=models.CASCADE),
), ),
] ]

View file

@ -47,12 +47,14 @@ class Migration(migrations.Migration):
model_name='spectaclerevente', model_name='spectaclerevente',
name='attribution', name='attribution',
field=models.OneToOneField(to='bda.Attribution', field=models.OneToOneField(to='bda.Attribution',
on_delete=models.CASCADE,
related_name='revente'), related_name='revente'),
), ),
migrations.AddField( migrations.AddField(
model_name='spectaclerevente', model_name='spectaclerevente',
name='seller', name='seller',
field=models.ForeignKey(to='bda.Participant', field=models.ForeignKey(to='bda.Participant',
on_delete=models.CASCADE,
verbose_name='Vendeur', verbose_name='Vendeur',
related_name='original_shows'), related_name='original_shows'),
), ),
@ -60,6 +62,7 @@ class Migration(migrations.Migration):
model_name='spectaclerevente', model_name='spectaclerevente',
name='soldTo', name='soldTo',
field=models.ForeignKey(to='bda.Participant', field=models.ForeignKey(to='bda.Participant',
on_delete=models.CASCADE,
verbose_name='Vendue à', null=True, verbose_name='Vendue à', null=True,
blank=True), blank=True),
), ),

View file

@ -6,12 +6,15 @@ from datetime import timedelta
from custommail.shortcuts import send_mass_custom_mail from custommail.shortcuts import send_mass_custom_mail
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core import mail
from django.db import models from django.db import models
from django.db.models import Count from django.db.models import Count
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.utils import timezone, formats from django.utils import timezone, formats
from custommail.models import CustomMail
def get_generic_user(): def get_generic_user():
generic, _ = User.objects.get_or_create( generic, _ = User.objects.get_or_create(
@ -59,9 +62,12 @@ class CategorieSpectacle(models.Model):
class Spectacle(models.Model): class Spectacle(models.Model):
title = models.CharField("Titre", max_length=300) title = models.CharField("Titre", max_length=300)
category = models.ForeignKey(CategorieSpectacle, blank=True, null=True) category = models.ForeignKey(
CategorieSpectacle, on_delete=models.CASCADE,
blank=True, null=True,
)
date = models.DateTimeField("Date & heure") date = models.DateTimeField("Date & heure")
location = models.ForeignKey(Salle) location = models.ForeignKey(Salle, on_delete=models.CASCADE)
vips = models.TextField('Personnalités', blank=True) vips = models.TextField('Personnalités', blank=True)
description = models.TextField("Description", blank=True) description = models.TextField("Description", blank=True)
slots_description = models.TextField("Description des places", blank=True) slots_description = models.TextField("Description des places", blank=True)
@ -71,7 +77,7 @@ class Spectacle(models.Model):
max_length=500) max_length=500)
price = models.FloatField("Prix d'une place") price = models.FloatField("Prix d'une place")
slots = models.IntegerField("Places") slots = models.IntegerField("Places")
tirage = models.ForeignKey(Tirage) tirage = models.ForeignKey(Tirage, on_delete=models.CASCADE)
listing = models.BooleanField("Les places sont sur listing") listing = models.BooleanField("Les places sont sur listing")
rappel_sent = models.DateTimeField("Mail de rappel envoyé", blank=True, rappel_sent = models.DateTimeField("Mail de rappel envoyé", blank=True,
null=True) null=True)
@ -135,7 +141,7 @@ class Spectacle(models.Model):
class Quote(models.Model): class Quote(models.Model):
spectacle = models.ForeignKey(Spectacle) spectacle = models.ForeignKey(Spectacle, on_delete=models.CASCADE)
text = models.TextField('Citation') text = models.TextField('Citation')
author = models.CharField('Auteur', max_length=200) author = models.CharField('Auteur', max_length=200)
@ -149,7 +155,7 @@ PAYMENT_TYPES = (
class Participant(models.Model): class Participant(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
choices = models.ManyToManyField(Spectacle, choices = models.ManyToManyField(Spectacle,
through="ChoixSpectacle", through="ChoixSpectacle",
related_name="chosen_by") related_name="chosen_by")
@ -160,7 +166,7 @@ class Participant(models.Model):
paymenttype = models.CharField("Moyen de paiement", paymenttype = models.CharField("Moyen de paiement",
max_length=6, choices=PAYMENT_TYPES, max_length=6, choices=PAYMENT_TYPES,
blank=True) blank=True)
tirage = models.ForeignKey(Tirage) tirage = models.ForeignKey(Tirage, on_delete=models.CASCADE)
choicesrevente = models.ManyToManyField(Spectacle, choicesrevente = models.ManyToManyField(Spectacle,
related_name="subscribed", related_name="subscribed",
blank=True) blank=True)
@ -176,8 +182,11 @@ DOUBLE_CHOICES = (
class ChoixSpectacle(models.Model): class ChoixSpectacle(models.Model):
participant = models.ForeignKey(Participant) participant = models.ForeignKey(Participant, on_delete=models.CASCADE)
spectacle = models.ForeignKey(Spectacle, related_name="participants") spectacle = models.ForeignKey(
Spectacle, on_delete=models.CASCADE,
related_name="participants",
)
priority = models.PositiveIntegerField("Priorité") priority = models.PositiveIntegerField("Priorité")
double_choice = models.CharField("Nombre de places", double_choice = models.CharField("Nombre de places",
default="1", choices=DOUBLE_CHOICES, default="1", choices=DOUBLE_CHOICES,
@ -204,8 +213,11 @@ class ChoixSpectacle(models.Model):
class Attribution(models.Model): class Attribution(models.Model):
participant = models.ForeignKey(Participant) participant = models.ForeignKey(Participant, on_delete=models.CASCADE)
spectacle = models.ForeignKey(Spectacle, related_name="attribues") spectacle = models.ForeignKey(
Spectacle, on_delete=models.CASCADE,
related_name="attribues",
)
given = models.BooleanField("Donnée", default=False) given = models.BooleanField("Donnée", default=False)
def __str__(self): def __str__(self):
@ -214,18 +226,25 @@ class Attribution(models.Model):
class SpectacleRevente(models.Model): class SpectacleRevente(models.Model):
attribution = models.OneToOneField(Attribution, attribution = models.OneToOneField(
related_name="revente") Attribution, on_delete=models.CASCADE,
related_name="revente",
)
date = models.DateTimeField("Date de mise en vente", date = models.DateTimeField("Date de mise en vente",
default=timezone.now) default=timezone.now)
answered_mail = models.ManyToManyField(Participant, answered_mail = models.ManyToManyField(Participant,
related_name="wanted", related_name="wanted",
blank=True) blank=True)
seller = models.ForeignKey(Participant, seller = models.ForeignKey(
Participant, on_delete=models.CASCADE,
verbose_name="Vendeur",
related_name="original_shows", related_name="original_shows",
verbose_name="Vendeur") )
soldTo = models.ForeignKey(Participant, blank=True, null=True, soldTo = models.ForeignKey(
verbose_name="Vendue à") Participant, on_delete=models.CASCADE,
verbose_name="Vendue à",
blank=True, null=True,
)
notif_sent = models.BooleanField("Notification envoyée", notif_sent = models.BooleanField("Notification envoyée",
default=False) default=False)
@ -312,37 +331,55 @@ class SpectacleRevente(models.Model):
# Envoie un mail au gagnant et au vendeur # Envoie un mail au gagnant et au vendeur
winner = random.choice(inscrits) winner = random.choice(inscrits)
self.soldTo = winner self.soldTo = winner
datatuple = []
mails = []
context = { context = {
'acheteur': winner.user, 'acheteur': winner.user,
'vendeur': seller.user, 'vendeur': seller.user,
'show': spectacle, 'show': spectacle,
} }
datatuple.append((
'bda-revente-winner', c_mails_qs = CustomMail.objects.filter(shortname__in=[
context, 'bda-revente-winner', 'bda-revente-loser',
settings.MAIL_DATA['revente']['FROM'],
[winner.user.email],
))
datatuple.append((
'bda-revente-seller', 'bda-revente-seller',
])
c_mails = {cm.shortname: cm for cm in c_mails_qs}
mails.append(
c_mails['bda-revente-winner'].get_message(
context, context,
settings.MAIL_DATA['revente']['FROM'], from_email=settings.MAIL_DATA['revente']['FROM'],
[seller.user.email] to=[winner.user.email],
)) )
)
mails.append(
c_mails['bda-revente-seller'].get_message(
context,
from_email=settings.MAIL_DATA['revente']['FROM'],
to=[seller.user.email],
reply_to=[winner.user.email],
)
)
# Envoie un mail aux perdants # Envoie un mail aux perdants
for inscrit in inscrits: for inscrit in inscrits:
if inscrit != winner: if inscrit != winner:
new_context = dict(context) new_context = dict(context)
new_context['acheteur'] = inscrit.user new_context['acheteur'] = inscrit.user
datatuple.append((
'bda-revente-loser', mails.append(
c_mails['bda-revente-loser'].get_message(
new_context, new_context,
settings.MAIL_DATA['revente']['FROM'], from_email=settings.MAIL_DATA['revente']['FROM'],
[inscrit.user.email] to=[inscrit.user.email],
)) )
send_mass_custom_mail(datatuple) )
mail_conn = mail.get_connection()
mail_conn.send_messages(mails)
# Si personne ne veut de la place, elle part au shotgun # Si personne ne veut de la place, elle part au shotgun
else: else:
self.shotgun = True self.shotgun = True

View file

@ -47,7 +47,7 @@
<div> <div>
<button class="btn btn-default" type="button" onclick="toggle('export-salle')">Afficher/Cacher liste noms</button> <button class="btn btn-default" type="button" onclick="toggle('export-salle')">Afficher/Cacher liste noms</button>
<pre id="export-salle" style="display:none">{% spaceless %} <pre id="export-salle" style="display:none">{% spaceless %}
{% for participant in participants %}{{participant.name}} : {{participant.nb_places}} places {% for participant in participants %}{{ participant.name }} : {{ participant.nb_places }} place{{ participant.nb_places|pluralize }}
{% endfor %} {% endfor %}
{% endspaceless %}</pre> {% endspaceless %}</pre>
</div> </div>

0
bda/tests/__init__.py Normal file
View file

100
bda/tests/test_models.py Normal file
View file

@ -0,0 +1,100 @@
from datetime import timedelta
from unittest import mock
from django.contrib.auth import get_user_model
from django.core import mail
from django.test import TestCase
from django.utils import timezone
from bda.models import (
Attribution, Participant, Salle, Spectacle, SpectacleRevente, Tirage,
)
User = get_user_model()
class SpectacleReventeTests(TestCase):
fixtures = ['gestioncof/management/data/custommail.json']
def setUp(self):
now = timezone.now()
self.t = Tirage.objects.create(
title='Tirage',
ouverture=now - timedelta(days=7),
fermeture=now - timedelta(days=3),
active=True,
)
self.s = Spectacle.objects.create(
title='Spectacle',
date=now + timedelta(days=20),
location=Salle.objects.create(name='Salle', address='Address'),
price=10.5,
slots=5,
tirage=self.t,
listing=False,
)
self.seller = Participant.objects.create(
user=User.objects.create(
username='seller', email='seller@mail.net'),
tirage=self.t,
)
self.p1 = Participant.objects.create(
user=User.objects.create(username='part1', email='part1@mail.net'),
tirage=self.t,
)
self.p2 = Participant.objects.create(
user=User.objects.create(username='part2', email='part2@mail.net'),
tirage=self.t,
)
self.p3 = Participant.objects.create(
user=User.objects.create(username='part3', email='part3@mail.net'),
tirage=self.t,
)
self.attr = Attribution.objects.create(
participant=self.seller,
spectacle=self.s,
)
self.rev = SpectacleRevente.objects.create(
attribution=self.attr,
seller=self.seller,
)
def test_tirage(self):
revente = self.rev
wanted_by = [self.p1, self.p2, self.p3]
revente.answered_mail = wanted_by
with mock.patch('bda.models.random.choice') as mc:
# Set winner to self.p1.
mc.return_value = self.p1
revente.tirage()
# Call to random.choice used participants in wanted_by.
mc_args, _ = mc.call_args
self.assertEqual(set(mc_args[0]), set(wanted_by))
self.assertEqual(revente.soldTo, self.p1)
self.assertTrue(revente.tirage_done)
mails = {m.to[0]: m for m in mail.outbox}
self.assertEqual(len(mails), 4)
m_seller = mails['seller@mail.net']
self.assertListEqual(m_seller.to, ['seller@mail.net'])
self.assertListEqual(m_seller.reply_to, ['part1@mail.net'])
m_winner = mails['part1@mail.net']
self.assertListEqual(m_winner.to, ['part1@mail.net'])
self.assertCountEqual(
[mails['part2@mail.net'].to, mails['part3@mail.net'].to],
[['part2@mail.net'], ['part3@mail.net']],
)

View file

@ -4,7 +4,7 @@ from django.contrib.auth.models import User
from django.test import TestCase, Client from django.test import TestCase, Client
from django.utils import timezone from django.utils import timezone
from .models import Tirage, Spectacle, Salle, CategorieSpectacle from bda.models import Tirage, Spectacle, Salle, CategorieSpectacle
class TestBdAViews(TestCase): class TestBdAViews(TestCase):

View file

@ -32,6 +32,12 @@ urlpatterns = [
url(r'^spectacles/unpaid/(?P<tirage_id>\d+)$', url(r'^spectacles/unpaid/(?P<tirage_id>\d+)$',
views.unpaid, views.unpaid,
name="bda-unpaid"), name="bda-unpaid"),
url(r'^spectacles/autocomplete$',
views.spectacle_autocomplete,
name="bda-spectacle-autocomplete"),
url(r'^participants/autocomplete$',
views.participant_autocomplete,
name="bda-participant-autocomplete"),
url(r'^liste-revente/(?P<tirage_id>\d+)$', url(r'^liste-revente/(?P<tirage_id>\d+)$',
views.list_revente, views.list_revente,
name="bda-liste-revente"), name="bda-liste-revente"),

View file

@ -33,6 +33,8 @@ from bda.forms import (
InscriptionInlineFormSet, InscriptionInlineFormSet,
) )
from utils.views.autocomplete import Select2QuerySetView
@cof_required @cof_required
def etat_places(request, tirage_id): def etat_places(request, tirage_id):
@ -782,9 +784,9 @@ def catalogue(request, request_type):
.select_related('location') .select_related('location')
.prefetch_related('quote_set') .prefetch_related('quote_set')
) )
if categories_id: if categories_id and 0 not in categories_id:
shows_qs = shows_qs.filter(category__id__in=categories_id) shows_qs = shows_qs.filter(category__id__in=categories_id)
if locations_id: if locations_id and 0 not in locations_id:
shows_qs = shows_qs.filter(location__id__in=locations_id) shows_qs = shows_qs.filter(location__id__in=locations_id)
# On convertit les descriptions à envoyer en une liste facilement # On convertit les descriptions à envoyer en une liste facilement
@ -813,3 +815,26 @@ def catalogue(request, request_type):
return JsonResponse(data_return, safe=False) return JsonResponse(data_return, safe=False)
# Si la requête n'est pas de la forme attendue, on quitte avec une erreur # Si la requête n'est pas de la forme attendue, on quitte avec une erreur
return HttpResponseBadRequest() return HttpResponseBadRequest()
##
# Autocomplete views
#
# https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#create-an-autocomplete-view
##
class ParticipantAutocomplete(Select2QuerySetView):
model = Participant
search_fields = ('user__username', 'user__first_name', 'user__last_name')
participant_autocomplete = buro_required(ParticipantAutocomplete.as_view())
class SpectacleAutocomplete(Select2QuerySetView):
model = Spectacle
search_fields = ('title',)
spectacle_autocomplete = buro_required(SpectacleAutocomplete.as_view())

0
cof/settings/__init__.py Normal file
View file

View file

@ -31,6 +31,7 @@ def import_secret(name):
SECRET_KEY = import_secret("SECRET_KEY") SECRET_KEY = import_secret("SECRET_KEY")
ADMINS = import_secret("ADMINS") ADMINS = import_secret("ADMINS")
SERVER_EMAIL = import_secret("SERVER_EMAIL") SERVER_EMAIL = import_secret("SERVER_EMAIL")
EMAIL_HOST = import_secret("EMAIL_HOST")
DBNAME = import_secret("DBNAME") DBNAME = import_secret("DBNAME")
DBUSER = import_secret("DBUSER") DBUSER = import_secret("DBUSER")
@ -45,6 +46,7 @@ RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY")
RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY") RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY")
KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN") KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN")
LDAP_SERVER_URL = import_secret("LDAP_SERVER_URL")
BASE_DIR = os.path.dirname( BASE_DIR = os.path.dirname(
@ -55,17 +57,22 @@ BASE_DIR = os.path.dirname(
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'gestioncof', 'gestioncof',
# Must be before 'django.contrib.admin'.
# https://django-autocomplete-light.readthedocs.io/en/master/install.html
'dal',
'dal_select2',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'grappelli',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.admindocs', 'django.contrib.admindocs',
'bda', 'bda',
'autocomplete_light',
'captcha', 'captcha',
'django_cas_ng', 'django_cas_ng',
'bootstrapform', 'bootstrapform',
@ -91,16 +98,17 @@ INSTALLED_APPS = [
'wagtailmenus', 'wagtailmenus',
'modelcluster', 'modelcluster',
'taggit', 'taggit',
'kfet.auth',
'kfet.cms', 'kfet.cms',
] ]
MIDDLEWARE_CLASSES = [ MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'kfet.middleware.KFetAuthenticationMiddleware', 'kfet.auth.middleware.TemporaryAuthMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
@ -122,13 +130,13 @@ TEMPLATES = [
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n', 'django.template.context_processors.i18n',
'django.core.context_processors.media', 'django.template.context_processors.media',
'django.core.context_processors.static', 'django.template.context_processors.static',
'wagtailmenus.context_processors.wagtailmenus', 'wagtailmenus.context_processors.wagtailmenus',
'djconfig.context_processors.config', 'djconfig.context_processors.config',
'gestioncof.shared.context_processor', 'gestioncof.shared.context_processor',
'kfet.context_processors.auth', 'kfet.auth.context_processors.temporary_auth',
'kfet.context_processors.config', 'kfet.context_processors.config',
], ],
}, },
@ -191,7 +199,7 @@ CAS_EMAIL_FORMAT = "%s@clipper.ens.fr"
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
'gestioncof.shared.COFCASBackend', 'gestioncof.shared.COFCASBackend',
'kfet.backends.GenericTeamBackend', 'kfet.auth.backends.GenericBackend',
) )
RECAPTCHA_USE_SSL = True RECAPTCHA_USE_SSL = True

View file

@ -4,7 +4,7 @@ The settings that are not listed here are imported from .common
""" """
from .common import * # NOQA from .common import * # NOQA
from .common import INSTALLED_APPS, MIDDLEWARE_CLASSES from .common import INSTALLED_APPS, MIDDLEWARE
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
@ -37,10 +37,11 @@ def show_toolbar(request):
return DEBUG return DEBUG
INSTALLED_APPS += ["debug_toolbar", "debug_panel"] INSTALLED_APPS += ["debug_toolbar", "debug_panel"]
MIDDLEWARE_CLASSES = (
["debug_panel.middleware.DebugPanelMiddleware"] MIDDLEWARE = [
+ MIDDLEWARE_CLASSES "debug_panel.middleware.DebugPanelMiddleware"
) ] + MIDDLEWARE
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar, 'SHOW_TOOLBAR_CALLBACK': show_toolbar,
} }

View file

@ -1,6 +1,7 @@
SECRET_KEY = 'q()(zn4m63i%5cp4)f+ww4-28_w+ly3q9=6imw2ciu&_(5_4ah' SECRET_KEY = 'q()(zn4m63i%5cp4)f+ww4-28_w+ly3q9=6imw2ciu&_(5_4ah'
ADMINS = None ADMINS = None
SERVER_EMAIL = "root@vagrant" SERVER_EMAIL = "root@vagrant"
EMAIL_HOST = "localhost"
DBUSER = "cof_gestion" DBUSER = "cof_gestion"
DBNAME = "cof_gestion" DBNAME = "cof_gestion"

View file

@ -4,8 +4,6 @@
Fichier principal de configuration des urls du projet GestioCOF Fichier principal de configuration des urls du projet GestioCOF
""" """
import autocomplete_light
from django.conf import settings from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from django.conf.urls.static import static from django.conf.urls.static import static
@ -26,7 +24,6 @@ from gestioncof.urls import export_patterns, petitcours_patterns, \
clubs_patterns clubs_patterns
from gestioncof.autocomplete import autocomplete from gestioncof.autocomplete import autocomplete
autocomplete_light.autodiscover()
admin.autodiscover() admin.autodiscover()
urlpatterns = [ urlpatterns = [
@ -51,18 +48,22 @@ urlpatterns = [
name="cof-denied"), name="cof-denied"),
url(r'^cas/login$', django_cas_views.login, name="cas_login_view"), url(r'^cas/login$', django_cas_views.login, name="cas_login_view"),
url(r'^cas/logout$', django_cas_views.logout), url(r'^cas/logout$', django_cas_views.logout),
url(r'^outsider/login$', gestioncof_views.login_ext), url(r'^outsider/login$', gestioncof_views.login_ext,
name="ext_login_view"),
url(r'^outsider/logout$', django_views.logout, {'next_page': 'home'}), url(r'^outsider/logout$', django_views.logout, {'next_page': 'home'}),
url(r'^login$', gestioncof_views.login, name="cof-login"), url(r'^login$', gestioncof_views.login, name="cof-login"),
url(r'^logout$', gestioncof_views.logout, name="cof-logout"), url(r'^logout$', gestioncof_views.logout, name="cof-logout"),
# Infos persos # Infos persos
url(r'^profile$', gestioncof_views.profile), url(r'^profile$', gestioncof_views.profile,
url(r'^outsider/password-change$', django_views.password_change), name='profile'),
url(r'^outsider/password-change$', django_views.password_change,
name='password_change'),
url(r'^outsider/password-change-done$', url(r'^outsider/password-change-done$',
django_views.password_change_done, django_views.password_change_done,
name='password_change_done'), name='password_change_done'),
# Inscription d'un nouveau membre # Inscription d'un nouveau membre
url(r'^registration$', gestioncof_views.registration), url(r'^registration$', gestioncof_views.registration,
name='registration'),
url(r'^registration/clipper/(?P<login_clipper>[\w-]+)/' url(r'^registration/clipper/(?P<login_clipper>[\w-]+)/'
r'(?P<fullname>.*)$', r'(?P<fullname>.*)$',
gestioncof_views.registration_form2, name="clipper-registration"), gestioncof_views.registration_form2, name="clipper-registration"),
@ -72,7 +73,8 @@ urlpatterns = [
name="empty-registration"), name="empty-registration"),
# Autocompletion # Autocompletion
url(r'^autocomplete/registration$', autocomplete), url(r'^autocomplete/registration$', autocomplete),
url(r'^autocomplete/', include('autocomplete_light.urls')), url(r'^user/autocomplete$', gestioncof_views.user_autocomplete,
name='cof-user-autocomplete'),
# Interface admin # Interface admin
url(r'^admin/logout/', gestioncof_views.logout), url(r'^admin/logout/', gestioncof_views.logout),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
@ -80,10 +82,11 @@ urlpatterns = [
csv_views.admin_list_export, csv_views.admin_list_export,
{'fields': ['username', ]}), {'fields': ['username', ]}),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
url(r'^grappelli/', include('grappelli.urls')),
# Liens utiles du COF et du BdA # Liens utiles du COF et du BdA
url(r'^utile_cof$', gestioncof_views.utile_cof), url(r'^utile_cof$', gestioncof_views.utile_cof,
url(r'^utile_bda$', gestioncof_views.utile_bda), name='utile_cof'),
url(r'^utile_bda$', gestioncof_views.utile_bda,
name='utile_bda'),
url(r'^utile_bda/bda_diff$', gestioncof_views.liste_bdadiff), url(r'^utile_bda/bda_diff$', gestioncof_views.liste_bdadiff),
url(r'^utile_cof/diff_cof$', gestioncof_views.liste_diffcof), url(r'^utile_cof/diff_cof$', gestioncof_views.liste_diffcof),
url(r'^utile_bda/bda_revente$', gestioncof_views.liste_bdarevente), url(r'^utile_bda/bda_revente$', gestioncof_views.liste_bdarevente),

View file

@ -13,7 +13,7 @@ from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.db.models import Q from django.db.models import Q
import autocomplete_light from dal.autocomplete import ModelSelect2
def add_link_field(target_model='', field='', link_text=str, def add_link_field(target_model='', field='', link_text=str,
@ -217,8 +217,16 @@ def user_str(self):
User.__str__ = user_str User.__str__ = user_str
class EventRegistrationAdminForm(forms.ModelForm):
class Meta:
widgets = {
'user': ModelSelect2(url='cof-user-autocomplete'),
}
class EventRegistrationAdmin(admin.ModelAdmin): class EventRegistrationAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(EventRegistration, exclude=[]) form = EventRegistrationAdminForm
list_display = ('__str__', 'event', 'user', 'paid') list_display = ('__str__', 'event', 'user', 'paid')
list_filter = ('paid',) list_filter = ('paid',)
search_fields = ('user__username', 'user__first_name', 'user__last_name', search_fields = ('user__username', 'user__first_name', 'user__last_name',

View file

@ -58,7 +58,7 @@ def autocomplete(request):
) )
# Fetching data from the SPI # Fetching data from the SPI
if hasattr(settings, 'LDAP_SERVER_URL'): if getattr(settings, 'LDAP_SERVER_URL', None):
# Fetching # Fetching
ldap_query = '(&{:s})'.format(''.join( ldap_query = '(&{:s})'.format(''.join(
'(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=bit) '(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=bit)

View file

@ -1,10 +0,0 @@
# -*- coding: utf-8 -*-
import autocomplete_light
from django.contrib.auth.models import User
autocomplete_light.register(
User, search_fields=('username', 'first_name', 'last_name'),
attrs={'placeholder': 'membre...'}
)

View file

@ -1,587 +1,600 @@
[ [
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 1,
"fields": { "fields": {
"kind": "model",
"content_type": [ "content_type": [
"auth", "auth",
"user" "user"
], ],
"inner1": null, "inner1": null,
"kind": "model",
"inner2": null "inner2": null
} },
"pk": 1
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 2,
"fields": { "fields": {
"kind": "int",
"content_type": null, "content_type": null,
"inner1": null, "inner1": null,
"kind": "int",
"inner2": null "inner2": null
} },
"pk": 2
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 3,
"fields": { "fields": {
"kind": "model",
"content_type": [ "content_type": [
"bda", "bda",
"spectacle" "spectacle"
], ],
"inner1": null, "inner1": null,
"kind": "model",
"inner2": null "inner2": null
} },
"pk": 3
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 4,
"fields": { "fields": {
"kind": "model",
"content_type": [ "content_type": [
"bda", "bda",
"spectaclerevente" "spectaclerevente"
], ],
"inner1": null, "inner1": null,
"kind": "model",
"inner2": null "inner2": null
} },
"pk": 4
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 5,
"fields": { "fields": {
"kind": "model",
"content_type": [ "content_type": [
"sites", "sites",
"site" "site"
], ],
"inner1": null, "inner1": null,
"kind": "model",
"inner2": null "inner2": null
} },
"pk": 5
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 6,
"fields": { "fields": {
"kind": "model",
"content_type": [ "content_type": [
"gestioncof", "gestioncof",
"petitcoursdemande" "petitcoursdemande"
], ],
"inner1": null, "inner1": null,
"kind": "model",
"inner2": null "inner2": null
} },
"pk": 6
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 7,
"fields": { "fields": {
"content_type": null,
"inner1": null,
"kind": "list", "kind": "list",
"content_type": null,
"inner1": 12,
"inner2": null "inner2": null
} },
"pk": 7
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 8,
"fields": { "fields": {
"kind": "list",
"content_type": null, "content_type": null,
"inner1": 1, "inner1": 1,
"kind": "list",
"inner2": null "inner2": null
} },
"pk": 8
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 9,
"fields": { "fields": {
"content_type": null,
"inner1": null,
"kind": "pair", "kind": "pair",
"content_type": null,
"inner1": 12,
"inner2": 8 "inner2": 8
} },
"pk": 9
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 10,
"fields": { "fields": {
"kind": "list",
"content_type": null, "content_type": null,
"inner1": 9, "inner1": 9,
"kind": "list",
"inner2": null "inner2": null
} },
"pk": 10
}, },
{ {
"model": "custommail.variabletype", "model": "custommail.type",
"pk": 11,
"fields": { "fields": {
"kind": "list",
"content_type": null, "content_type": null,
"inner1": 3, "inner1": 3,
"kind": "list",
"inner2": null "inner2": null
} },
"pk": 11
},
{
"model": "custommail.type",
"fields": {
"kind": "model",
"content_type": [
"gestioncof",
"petitcourssubject"
],
"inner1": null,
"inner2": null
},
"pk": 12
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 1,
"fields": { "fields": {
"shortname": "welcome", "shortname": "welcome",
"subject": "Bienvenue au COF", "subject": "Bienvenue au COF",
"description": "Mail de bienvenue au COF envoy\u00e9 automatiquement \u00e0 l'inscription d'un nouveau membre", "body": "Bonjour {{ member.first_name }} et bienvenue au COF !\r\n\r\nTu trouveras plein de trucs cool sur le site du COF : https://www.cof.ens.fr/ et notre page Facebook : https://www.facebook.com/cof.ulm\r\nEt n'oublie pas d'aller d\u00e9couvrir GestioCOF, la plateforme de gestion du COF !\r\nSi tu as des questions, tu peux nous envoyer un mail \u00e0 cof@ens.fr (on aime le spam), ou passer nous voir au Bur\u00f4 pr\u00e8s de la Cour\u00f4 du lundi au vendredi de 12h \u00e0 14h et de 18h \u00e0 20h.\r\n\r\nRetrouvez les \u00e9v\u00e8nements de rentr\u00e9e pour les conscrit.e.s et les vieux/vieilles organis\u00e9s par le COF et ses clubs ici : http://www.cof.ens.fr/depot/Rentree.pdf \r\n\r\nAmicalement,\r\n\r\nTon COF qui t'aime.",
"body": "Bonjour {{ member.first_name }} et bienvenue au COF !\r\n\r\nTu trouveras plein de trucs cool sur le site du COF : https://www.cof.ens.fr/ et notre page Facebook : https://www.facebook.com/cof.ulm\r\nEt n'oublie pas d'aller d\u00e9couvrir GestioCOF, la plateforme de gestion du COF !\r\nSi tu as des questions, tu peux nous envoyer un mail \u00e0 cof@ens.fr (on aime le spam), ou passer nous voir au Bur\u00f4 pr\u00e8s de la Cour\u00f4 du lundi au vendredi de 12h \u00e0 14h et de 18h \u00e0 20h.\r\n\r\nRetrouvez les \u00e9v\u00e8nements de rentr\u00e9e pour les conscrit.e.s et les vieux/vieilles organis\u00e9s par le COF et ses clubs ici : http://www.cof.ens.fr/depot/Rentree.pdf \r\n\r\nAmicalement,\r\n\r\nTon COF qui t'aime." "description": "Mail de bienvenue au COF envoy\u00e9 automatiquement \u00e0 l'inscription d'un nouveau membre"
} },
"pk": 1
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 2,
"fields": { "fields": {
"shortname": "bda-rappel", "shortname": "bda-rappel",
"subject": "{{ show }}", "subject": "{{ show }}",
"description": "Mail de rappel pour les spectacles BdA", "body": "Bonjour {{ member.first_name }},\r\n\r\nNous te rappellons que tu as eu la chance d'obtenir {{ nb_attr|pluralize:\"une place,deux places\" }}\r\npour {{ show.title }}, le {{ show.date }} au {{ show.location }}. N'oublie pas de t'y rendre !\r\n{% if nb_attr == 2 %}\r\nTu as obtenu deux places pour ce spectacle. Nous te rappelons que\r\nces places sont strictement r\u00e9serv\u00e9es aux personnes de moins de 28 ans.\r\n{% endif %}\r\n{% if show.listing %}Pour ce spectacle, tu as re\u00e7u des places sur\r\nlisting. Il te faudra donc te rendre 15 minutes en avance sur les lieux de la repr\u00e9sentation\r\npour retirer {{ nb_attr|pluralize:\"ta place,tes places\" }}.\r\n{% else %}Pour assister \u00e0 ce spectacle, tu dois pr\u00e9senter les billets qui ont\r\n\u00e9t\u00e9 distribu\u00e9s au bur\u00f4.\r\n{% endif %}\r\n\r\nSi tu ne peux plus assister \u00e0 cette repr\u00e9sentation, tu peux\r\nrevendre ta place via BdA-revente, accessible directement sur\r\nGestioCOF (lien \"revendre une place du premier tirage\" sur la page\r\nd'accueil https://www.cof.ens.fr/gestion/).\r\n\r\nEn te souhaitant un excellent spectacle,\r\n\r\nLe Bureau des Arts",
"body": "Bonjour {{ member.first_name }},\r\n\r\nNous te rappellons que tu as eu la chance d'obtenir {{ nb_attr|pluralize:\"une place,deux places\" }}\r\npour {{ show.title }}, le {{ show.date }} au {{ show.location }}. N'oublie pas de t'y rendre !\r\n{% if nb_attr == 2 %}\r\nTu as obtenu deux places pour ce spectacle. Nous te rappelons que\r\nces places sont strictement r\u00e9serv\u00e9es aux personnes de moins de 28 ans.\r\n{% endif %}\r\n{% if show.listing %}Pour ce spectacle, tu as re\u00e7u des places sur\r\nlisting. Il te faudra donc te rendre 15 minutes en avance sur les lieux de la repr\u00e9sentation\r\npour retirer {{ nb_attr|pluralize:\"ta place,tes places\" }}.\r\n{% else %}Pour assister \u00e0 ce spectacle, tu dois pr\u00e9senter les billets qui ont\r\n\u00e9t\u00e9 distribu\u00e9s au bur\u00f4.\r\n{% endif %}\r\n\r\nSi tu ne peux plus assister \u00e0 cette repr\u00e9sentation, tu peux\r\nrevendre ta place via BdA-revente, accessible directement sur\r\nGestioCOF (lien \"revendre une place du premier tirage\" sur la page\r\nd'accueil https://www.cof.ens.fr/gestion/).\r\n\r\nEn te souhaitant un excellent spectacle,\r\n\r\nLe Bureau des Arts" "description": "Mail de rappel pour les spectacles BdA"
} },
"pk": 2
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 3,
"fields": { "fields": {
"shortname": "bda-revente", "shortname": "bda-revente",
"subject": "{{ show }}", "subject": "{{ show }}",
"description": "Notification envoy\u00e9e \u00e0 toutes les personnes int\u00e9ress\u00e9es par un spectacle pour le signaler qu'une place vient d'\u00eatre mise en vente.", "body": "Bonjour {{ member.first_name }}\r\n\r\nUne place pour le spectacle {{ show.title }} ({{ show.date }})\r\na \u00e9t\u00e9 post\u00e9e sur BdA-Revente.\r\n\r\nSi ce spectacle t'int\u00e9resse toujours, merci de nous le signaler en cliquant\r\nsur ce lien : http://{{ site }}{% url \"bda-revente-interested\" revente.id %}.\r\nDans le cas o\u00f9 plusieurs personnes seraient int\u00e9ress\u00e9es, nous proc\u00e8derons \u00e0\r\nun tirage au sort le {{ revente.date_tirage|date:\"DATE_FORMAT\" }}.\r\n\r\nChaleureusement,\r\nLe BdA",
"body": "Bonjour {{ member.first_name }}\r\n\r\nUne place pour le spectacle {{ show.title }} ({{ show.date }})\r\na \u00e9t\u00e9 post\u00e9e sur BdA-Revente.\r\n\r\nSi ce spectacle t'int\u00e9resse toujours, merci de nous le signaler en cliquant\r\nsur ce lien : http://{{ site }}{% url \"bda-revente-interested\" revente.id %}.\r\nDans le cas o\u00f9 plusieurs personnes seraient int\u00e9ress\u00e9es, nous proc\u00e8derons \u00e0\r\nun tirage au sort le {{ revente.date_tirage|date:\"DATE_FORMAT\" }}.\r\n\r\nChaleureusement,\r\nLe BdA" "description": "Notification envoy\u00e9e \u00e0 toutes les personnes int\u00e9ress\u00e9es par un spectacle pour le signaler qu'une place vient d'\u00eatre mise en vente."
} },
"pk": 3
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 4,
"fields": { "fields": {
"shortname": "bda-shotgun", "shortname": "bda-shotgun",
"subject": "{{ show }}", "subject": "{{ show }}",
"description": "Notification signalant qu'une place est au shotgun aux personnes int\u00e9ress\u00e9es.", "body": "Bonjour {{ member.first_name }}\r\n\r\nUne place pour le spectacle {{ show.title }} ({{ show.date }})\r\na \u00e9t\u00e9 post\u00e9e sur BdA-Revente.\r\n\r\nPuisque ce spectacle a lieu dans moins de 24h, il n'y a pas de tirage au sort pour\r\ncette place : elle est disponible imm\u00e9diatement \u00e0 l'adresse\r\nhttp://{{ site }}{% url \"bda-buy-revente\" show.id %}, \u00e0 la disposition de tous.\r\n\r\nChaleureusement,\r\nLe BdA",
"body": "Bonjour {{ member.first_name }}\r\n\r\nUne place pour le spectacle {{ show.title }} ({{ show.date }})\r\na \u00e9t\u00e9 post\u00e9e sur BdA-Revente.\r\n\r\nPuisque ce spectacle a lieu dans moins de 24h, il n'y a pas de tirage au sort pour\r\ncette place : elle est disponible imm\u00e9diatement \u00e0 l'adresse\r\nhttp://{{ site }}{% url \"bda-buy-revente\" show.id %}, \u00e0 la disposition de tous.\r\n\r\nChaleureusement,\r\nLe BdA" "description": "Notification signalant qu'une place est au shotgun aux personnes int\u00e9ress\u00e9es."
} },
"pk": 4
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 5,
"fields": { "fields": {
"shortname": "bda-revente-winner", "shortname": "bda-revente-winner",
"subject": "BdA-Revente : {{ show.title }}", "subject": "BdA-Revente : {{ show.title }}",
"description": "Mail envoy\u00e9 au gagnant d'un tirage BdA-Revente", "body": "Bonjour {{ acheteur.first_name }},\r\n\r\nTu as \u00e9t\u00e9 tir\u00e9-e au sort pour racheter une place pour {{ show.title }} le {{ show.date }} ({{ show.location }}) \u00e0 {{ show.price|floatformat:2 }}\u20ac.\r\nTu peux contacter le/la vendeur-se \u00e0 l'adresse {{ vendeur.email }}.\r\n\r\nChaleureusement,\r\nLe BdA",
"body": "Bonjour {{ acheteur.first_name }},\r\n\r\nTu as \u00e9t\u00e9 tir\u00e9-e au sort pour racheter une place pour {{ show.title }} le {{ show.date }} ({{ show.location }}) \u00e0 {{ show.price|floatformat:2 }}\u20ac.\r\nTu peux contacter le/la vendeur-se \u00e0 l'adresse {{ vendeur.email }}.\r\n\r\nChaleureusement,\r\nLe BdA" "description": "Mail envoy\u00e9 au gagnant d'un tirage BdA-Revente"
} },
"pk": 5
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 6,
"fields": { "fields": {
"shortname": "bda-revente-loser", "shortname": "bda-revente-loser",
"subject": "BdA-Revente : {{ show.title }}", "subject": "BdA-Revente : {{ show.title }}",
"description": "Notification envoy\u00e9e aux perdants d'un tirage de revente.", "body": "Bonjour {{ acheteur.first_name }},\r\n\r\nTu t'\u00e9tais inscrit-e pour la revente de la place de {{ vendeur.get_full_name }}\r\npour {{ show.title }}.\r\nMalheureusement, une autre personne a \u00e9t\u00e9 tir\u00e9e au sort pour racheter la place.\r\nTu pourras certainement retenter ta chance pour une autre revente !\r\n\r\n\u00c0 tr\u00e8s bient\u00f4t,\r\nLe Bureau des Arts",
"body": "Bonjour {{ acheteur.first_name }},\r\n\r\nTu t'\u00e9tais inscrit-e pour la revente de la place de {{ vendeur.get_full_name }}\r\npour {{ show.title }}.\r\nMalheureusement, une autre personne a \u00e9t\u00e9 tir\u00e9e au sort pour racheter la place.\r\nTu pourras certainement retenter ta chance pour une autre revente !\r\n\r\n\u00c0 tr\u00e8s bient\u00f4t,\r\nLe Bureau des Arts" "description": "Notification envoy\u00e9e aux perdants d'un tirage de revente."
} },
"pk": 6
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 7,
"fields": { "fields": {
"shortname": "bda-revente-seller", "shortname": "bda-revente-seller",
"subject": "BdA-Revente : {{ show.title }}", "subject": "BdA-Revente : {{ show.title }}",
"description": "Notification envoy\u00e9e au vendeur d'une place pour lui indiquer qu'elle vient d'\u00eatre attribu\u00e9e", "body": "Bonjour {{ vendeur.first_name }},\r\n\r\nLa personne tir\u00e9e au sort pour racheter ta place pour {{ show.title }} est {{ acheteur.get_full_name }}.\r\nTu peux le/la contacter \u00e0 l'adresse {{ acheteur.email }}, ou en r\u00e9pondant \u00e0 ce mail.\r\n\r\nChaleureusement,\r\nLe BdA",
"body": "Bonjour {{ vendeur.first_name }},\r\n\r\nLa personne tir\u00e9e au sort pour racheter ta place pour {{ show.title }} est {{ acheteur.get_full_name }}.\r\nTu peux le/la contacter \u00e0 l'adresse {{ acheteur.email }}, ou en r\u00e9pondant \u00e0 ce mail.\r\n\r\nChaleureusement,\r\nLe BdA" "description": "Notification envoy\u00e9e au vendeur d'une place pour lui indiquer qu'elle vient d'\u00eatre attribu\u00e9e"
} },
"pk": 7
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 8,
"fields": { "fields": {
"shortname": "bda-revente-new", "shortname": "bda-revente-new",
"subject": "BdA-Revente : {{ show.title }}", "subject": "BdA-Revente : {{ show.title }}",
"description": "Notification signalant au vendeur d'une place que sa mise en vente a bien eu lieu et lui donnant quelques informations compl\u00e9mentaires.", "body": "Bonjour {{ vendeur.first_name }},\r\n\r\nTu t\u2019es bien inscrit-e pour la revente de {{ show.title }}.\r\n\r\n{% with revente.date_tirage as time %}\r\nLe tirage au sort entre tout-e-s les racheteuse-eur-s potentiel-le-s aura lieu\r\nle {{ time|date:\"DATE_FORMAT\" }} \u00e0 {{ time|time:\"TIME_FORMAT\" }} (dans {{time|timeuntil }}).\r\nSi personne ne s\u2019est inscrit pour racheter la place, celle-ci apparaitra parmi\r\nles \u00ab Places disponibles imm\u00e9diatement \u00e0 la revente \u00bb sur GestioCOF.\r\n{% endwith %}\r\n\r\nBonne revente !\r\nLe Bureau des Arts",
"body": "Bonjour {{ vendeur.first_name }},\r\n\r\nTu t\u2019es bien inscrit-e pour la revente de {{ show.title }}.\r\n\r\n{% with revente.date_tirage as time %}\r\nLe tirage au sort entre tout-e-s les racheteuse-eur-s potentiel-le-s aura lieu\r\nle {{ time|date:\"DATE_FORMAT\" }} \u00e0 {{ time|time:\"TIME_FORMAT\" }} (dans {{time|timeuntil }}).\r\nSi personne ne s\u2019est inscrit pour racheter la place, celle-ci apparaitra parmi\r\nles \u00ab Places disponibles imm\u00e9diatement \u00e0 la revente \u00bb sur GestioCOF.\r\n{% endwith %}\r\n\r\nBonne revente !\r\nLe Bureau des Arts" "description": "Notification signalant au vendeur d'une place que sa mise en vente a bien eu lieu et lui donnant quelques informations compl\u00e9mentaires."
} },
"pk": 8
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 9,
"fields": { "fields": {
"shortname": "bda-buy-shotgun", "shortname": "bda-buy-shotgun",
"subject": "BdA-Revente : {{ show.title }}", "subject": "BdA-Revente : {{ show.title }}",
"description": "Mail envoy\u00e9 au revendeur lors d'un achat au shotgun.", "body": "Bonjour {{ vendeur.first_name }} !\r\n\r\nJe souhaiterais racheter ta place pour {{ show.title }} le {{ show.date }} ({{ show.location }}) \u00e0 {{ show.price|floatformat:2 }}\u20ac.\r\nContacte-moi si tu es toujours int\u00e9ress\u00e9\u00b7e !\r\n\r\n{{ acheteur.get_full_name }} ({{ acheteur.email }})",
"body": "Bonjour {{ vendeur.first_name }} !\r\n\r\nJe souhaiterais racheter ta place pour {{ show.title }} le {{ show.date }} ({{ show.location }}) \u00e0 {{ show.price|floatformat:2 }}\u20ac.\r\nContacte-moi si tu es toujours int\u00e9ress\u00e9\u00b7e !\r\n\r\n{{ acheteur.get_full_name }} ({{ acheteur.email }})" "description": "Mail envoy\u00e9 au revendeur lors d'un achat au shotgun."
} },
"pk": 9
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 10,
"fields": { "fields": {
"shortname": "petit-cours-mail-eleve", "shortname": "petit-cours-mail-eleve",
"subject": "Petits cours ENS par le COF", "subject": "Petits cours ENS par le COF",
"description": "Mail envoy\u00e9 aux personnes dont ont a donn\u00e9 les contacts \u00e0 des demandeurs de petits cours", "body": "Salut,\r\n\r\nLe COF a re\u00e7u une demande de petit cours qui te correspond. Tu es en haut de la liste d'attente donc on a transmis tes coordonn\u00e9es, ainsi que celles de 2 autres qui correspondaient aussi (c'est la vie, on donne les num\u00e9ros 3 par 3 pour que ce soit plus souple). Voici quelques infos sur l'annonce en question :\r\n\r\n\u00a4 Nom : {{ demande.name }}\r\n\r\n\u00a4 P\u00e9riode : {{ demande.quand }}\r\n\r\n\u00a4 Fr\u00e9quence : {{ demande.freq }}\r\n\r\n\u00a4 Lieu (si pr\u00e9f\u00e9r\u00e9) : {{ demande.lieu }}\r\n\r\n\u00a4 Niveau : {{ demande.get_niveau_display }}\r\n\r\n\u00a4 Remarques diverses (d\u00e9sol\u00e9 pour les balises HTML) : {{ demande.remarques }}\r\n\r\n{% if matieres|length > 1 %}\u00a4 Mati\u00e8res :\r\n{% for matiere in matieres %} \u00a4 {{ matiere }}\r\n{% endfor %}{% else %}\u00a4 Mati\u00e8re : {% for matiere in matieres %}{{ matiere }}\r\n{% endfor %}{% endif %}\r\nVoil\u00e0, cette personne te contactera peut-\u00eatre sous peu, tu pourras voir les d\u00e9tails directement avec elle (prix, modalit\u00e9s, ...). Pour indication, 30 Euro/h semble \u00eatre la moyenne.\r\n\r\nSi tu te rends compte qu'en fait tu ne peux pas/plus donner de cours en ce moment, \u00e7a serait cool que tu d\u00e9coches la case \"Recevoir des propositions de petits cours\" sur GestioCOF. Ensuite d\u00e8s que tu voudras r\u00e9appara\u00eetre tu pourras recocher la case et tu seras \u00e0 nouveau sur la liste.\r\n\r\n\u00c0 bient\u00f4t,\r\n\r\n--\r\nLe COF, pour les petits cours",
"body": "Salut,\r\n\r\nLe COF a re\u00e7u une demande de petit cours qui te correspond. Tu es en haut de la liste d'attente donc on a transmis tes coordonn\u00e9es, ainsi que celles de 2 autres qui correspondaient aussi (c'est la vie, on donne les num\u00e9ros 3 par 3 pour que ce soit plus souple). Voici quelques infos sur l'annonce en question :\r\n\r\n\u00a4 Nom : {{ demande.name }}\r\n\r\n\u00a4 P\u00e9riode : {{ demande.quand }}\r\n\r\n\u00a4 Fr\u00e9quence : {{ demande.freq }}\r\n\r\n\u00a4 Lieu (si pr\u00e9f\u00e9r\u00e9) : {{ demande.lieu }}\r\n\r\n\u00a4 Niveau : {{ demande.get_niveau_display }}\r\n\r\n\u00a4 Remarques diverses (d\u00e9sol\u00e9 pour les balises HTML) : {{ demande.remarques }}\r\n\r\n{% if matieres|length > 1 %}\u00a4 Mati\u00e8res :\r\n{% for matiere in matieres %} \u00a4 {{ matiere }}\r\n{% endfor %}{% else %}\u00a4 Mati\u00e8re : {% for matiere in matieres %}{{ matiere }}\r\n{% endfor %}{% endif %}\r\nVoil\u00e0, cette personne te contactera peut-\u00eatre sous peu, tu pourras voir les d\u00e9tails directement avec elle (prix, modalit\u00e9s, ...). Pour indication, 30 Euro/h semble \u00eatre la moyenne.\r\n\r\nSi tu te rends compte qu'en fait tu ne peux pas/plus donner de cours en ce moment, \u00e7a serait cool que tu d\u00e9coches la case \"Recevoir des propositions de petits cours\" sur GestioCOF. Ensuite d\u00e8s que tu voudras r\u00e9appara\u00eetre tu pourras recocher la case et tu seras \u00e0 nouveau sur la liste.\r\n\r\n\u00c0 bient\u00f4t,\r\n\r\n--\r\nLe COF, pour les petits cours" "description": "Mail envoy\u00e9 aux personnes dont ont a donn\u00e9 les contacts \u00e0 des demandeurs de petits cours"
} },
"pk": 10
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 11,
"fields": { "fields": {
"shortname": "petits-cours-mail-demandeur", "shortname": "petits-cours-mail-demandeur",
"subject": "Cours particuliers ENS", "subject": "Cours particuliers ENS",
"description": "Mail envoy\u00e9 aux personnent qui demandent des petits cours lorsque leur demande est trait\u00e9e.\r\n\r\n(Ne pas toucher \u00e0 {{ extra|safe }})", "body": "Bonjour,\r\n\r\nJe vous contacte au sujet de votre annonce pass\u00e9e sur le site du COF pour rentrer en contact avec un \u00e9l\u00e8ve normalien pour des cours particuliers. Voici les coordonn\u00e9es d'\u00e9l\u00e8ves qui sont motiv\u00e9s par de tels cours et correspondent aux crit\u00e8res que vous nous aviez transmis :\r\n\r\n{% for matiere, proposed in proposals %}\u00a4 {{ matiere }} :{% for user in proposed %}\r\n \u00a4 {{ user.get_full_name }}{% if user.profile.phone %}, {{ user.profile.phone }}{% endif %}{% if user.email %}, {{ user.email }}{% endif %}{% endfor %}\r\n\r\n{% endfor %}{% if unsatisfied %}Nous n'avons cependant pas pu trouver d'\u00e9l\u00e8ve disponible pour des cours de {% for matiere in unsatisfied %}{% if forloop.counter0 > 0 %}, {% endif %}{{ matiere }}{% endfor %}.\r\n\r\n{% endif %}Si pour une raison ou une autre ces num\u00e9ros ne suffisaient pas, n'h\u00e9sitez pas \u00e0 r\u00e9pondre \u00e0 cet e-mail et je vous en ferai parvenir d'autres sans probl\u00e8me.\r\n{% if extra|length > 0 %}\r\n{{ extra|safe }}\r\n{% endif %}\r\nCordialement,\r\n\r\n--\r\nLe COF, BdE de l'ENS",
"body": "Bonjour,\r\n\r\nJe vous contacte au sujet de votre annonce pass\u00e9e sur le site du COF pour rentrer en contact avec un \u00e9l\u00e8ve normalien pour des cours particuliers. Voici les coordonn\u00e9es d'\u00e9l\u00e8ves qui sont motiv\u00e9s par de tels cours et correspondent aux crit\u00e8res que vous nous aviez transmis :\r\n\r\n{% for matiere, proposed in proposals %}\u00a4 {{ matiere }} :{% for user in proposed %}\r\n \u00a4 {{ user.get_full_name }}{% if user.profile.phone %}, {{ user.profile.phone }}{% endif %}{% if user.email %}, {{ user.email }}{% endif %}{% endfor %}\r\n\r\n{% endfor %}{% if unsatisfied %}Nous n'avons cependant pas pu trouver d'\u00e9l\u00e8ve disponible pour des cours de {% for matiere in unsatisfied %}{% if forloop.counter0 > 0 %}, {% endif %}{{ matiere }}{% endfor %}.\r\n\r\n{% endif %}Si pour une raison ou une autre ces num\u00e9ros ne suffisaient pas, n'h\u00e9sitez pas \u00e0 r\u00e9pondre \u00e0 cet e-mail et je vous en ferai parvenir d'autres sans probl\u00e8me.\r\n{% if extra|length > 0 %}\r\n{{ extra|safe }}\r\n{% endif %}\r\nCordialement,\r\n\r\n--\r\nLe COF, BdE de l'ENS" "description": "Mail envoy\u00e9 aux personnes qui demandent des petits cours lorsque leur demande est trait\u00e9e.\r\n\r\n(Ne pas toucher \u00e0 {{ extra|safe }})"
} },
"pk": 11
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 12,
"fields": { "fields": {
"shortname": "bda-attributions", "shortname": "bda-attributions",
"subject": "R\u00e9sultats du tirage au sort", "subject": "R\u00e9sultats du tirage au sort",
"description": "Mail annon\u00e7ant les r\u00e9sultats du tirage au sort du BdA aux gagnants d'une ou plusieurs places", "body": "Cher-e {{ member.first_name }},\r\n\r\nTu t'es inscrit-e pour le tirage au sort du BdA. Tu as \u00e9t\u00e9 s\u00e9lectionn\u00e9-e\r\npour les spectacles suivants :\r\n{% for place in places %}\r\n- 1 place pour {{ place }}{% endfor %}\r\n\r\n*Paiement*\r\nL'int\u00e9gralit\u00e9 de ces places de spectacles est \u00e0 r\u00e9gler d\u00e8s maintenant et AVANT\r\nvendredi prochain, au bureau du COF pendant les heures de permanences (du lundi au vendredi\r\nentre 12h et 14h, et entre 18h et 20h). Des facilit\u00e9s de paiement sont bien\r\n\u00e9videmment possibles : nous pouvons ne pas encaisser le ch\u00e8que imm\u00e9diatement,\r\nou bien d\u00e9couper votre paiement en deux fois. Pour ceux qui ne pourraient pas\r\nvenir payer au bureau, merci de nous contacter par mail.\r\n\r\n*Mode de retrait des places*\r\nAu moment du paiement, certaines places vous seront remises directement,\r\nd'autres seront \u00e0 r\u00e9cup\u00e9rer au cours de l'ann\u00e9e, d'autres encore seront\r\nnominatives et \u00e0 retirer le soir m\u00eame dans les the\u00e2tres correspondants.\r\nPour chaque spectacle, vous recevrez un mail quelques jours avant la\r\nrepr\u00e9sentation vous indiquant le mode de retrait.\r\n\r\nNous vous rappelons que l'obtention de places du BdA vous engage \u00e0\r\nrespecter les r\u00e8gles de fonctionnement :\r\nhttp://www.cof.ens.fr/bda/?page_id=1370\r\nUn syst\u00e8me de revente des places via les mails BdA-revente disponible\r\ndirectement sur votre compte GestioCOF.\r\n\r\nEn vous souhaitant de tr\u00e8s beaux spectacles tout au long de l'ann\u00e9e,\r\n--\r\nLe Bureau des Arts",
"body": "Cher-e {{ member.first_name }},\r\n\r\nTu t'es inscrit-e pour le tirage au sort du BdA. Tu as \u00e9t\u00e9 s\u00e9lectionn\u00e9-e\r\npour les spectacles suivants :\r\n{% for place in places %}\r\n- 1 place pour {{ place }}{% endfor %}\r\n\r\n*Paiement*\r\nL'int\u00e9gralit\u00e9 de ces places de spectacles est \u00e0 r\u00e9gler d\u00e8s maintenant et AVANT\r\nvendredi prochain, au bureau du COF pendant les heures de permanences (du lundi au vendredi\r\nentre 12h et 14h, et entre 18h et 20h). Des facilit\u00e9s de paiement sont bien\r\n\u00e9videmment possibles : nous pouvons ne pas encaisser le ch\u00e8que imm\u00e9diatement,\r\nou bien d\u00e9couper votre paiement en deux fois. Pour ceux qui ne pourraient pas\r\nvenir payer au bureau, merci de nous contacter par mail.\r\n\r\n*Mode de retrait des places*\r\nAu moment du paiement, certaines places vous seront remises directement,\r\nd'autres seront \u00e0 r\u00e9cup\u00e9rer au cours de l'ann\u00e9e, d'autres encore seront\r\nnominatives et \u00e0 retirer le soir m\u00eame dans les the\u00e2tres correspondants.\r\nPour chaque spectacle, vous recevrez un mail quelques jours avant la\r\nrepr\u00e9sentation vous indiquant le mode de retrait.\r\n\r\nNous vous rappelons que l'obtention de places du BdA vous engage \u00e0\r\nrespecter les r\u00e8gles de fonctionnement :\r\nhttp://www.cof.ens.fr/bda/?page_id=1370\r\nUn syst\u00e8me de revente des places via les mails BdA-revente disponible\r\ndirectement sur votre compte GestioCOF.\r\n\r\nEn vous souhaitant de tr\u00e8s beaux spectacles tout au long de l'ann\u00e9e,\r\n--\r\nLe Bureau des Arts" "description": "Mail annon\u00e7ant les r\u00e9sultats du tirage au sort du BdA aux gagnants d'une ou plusieurs places"
} },
"pk": 12
}, },
{ {
"model": "custommail.custommail", "model": "custommail.custommail",
"pk": 13,
"fields": { "fields": {
"shortname": "bda-attributions-decus", "shortname": "bda-attributions-decus",
"subject": "R\u00e9sultats du tirage au sort", "subject": "R\u00e9sultats du tirage au sort",
"description": "Mail annon\u00e7ant les r\u00e9sultats du tirage au sort du BdA aux personnes n'ayant pas obtenu de place", "body": "Cher-e {{ member.first_name }},\r\n\r\nTu t'es inscrit-e pour le tirage au sort du BdA. Malheureusement, tu n'as\r\nobtenu aucune place.\r\n\r\nNous proposons cependant de nombreuses offres hors-tirage tout au long de\r\nl'ann\u00e9e, et nous t'invitons \u00e0 nous contacter si l'une d'entre elles\r\nt'int\u00e9resse !\r\n--\r\nLe Bureau des Arts",
"body": "Cher-e {{ member.first_name }},\r\n\r\nTu t'es inscrit-e pour le tirage au sort du BdA. Malheureusement, tu n'as\r\nobtenu aucune place.\r\n\r\nNous proposons cependant de nombreuses offres hors-tirage tout au long de\r\nl'ann\u00e9e, et nous t'invitons \u00e0 nous contacter si l'une d'entre elles\r\nt'int\u00e9resse !\r\n--\r\nLe Bureau des Arts" "description": "Mail annon\u00e7ant les r\u00e9sultats du tirage au sort du BdA aux personnes n'ayant pas obtenu de place"
} },
"pk": 13
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 1,
"fields": { "fields": {
"name": "member",
"description": "Utilisateur de GestioCOF",
"custommail": 1, "custommail": 1,
"type": 1 "type": 1,
}
},
{
"model": "custommail.custommailvariable",
"pk": 2,
"fields": {
"name": "member", "name": "member",
"description": "Utilisateur ayant eu une place pour ce spectacle", "description": "Utilisateur de GestioCOF"
"custommail": 2, },
"type": 1 "pk": 1
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 3,
"fields": { "fields": {
"custommail": 2,
"type": 1,
"name": "member",
"description": "Utilisateur ayant eu une place pour ce spectacle"
},
"pk": 2
},
{
"model": "custommail.variable",
"fields": {
"custommail": 2,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
"custommail": 2, },
"type": 3 "pk": 3
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 4,
"fields": { "fields": {
"custommail": 2,
"type": 2,
"name": "nb_attr", "name": "nb_attr",
"description": "Nombre de places obtenues", "description": "Nombre de places obtenues"
"custommail": 2, },
"type": 2 "pk": 4
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 5,
"fields": { "fields": {
"custommail": 3,
"type": 4,
"name": "revente", "name": "revente",
"description": "Revente mentionn\u00e9e dans le mail", "description": "Revente mentionn\u00e9e dans le mail"
"custommail": 3, },
"type": 4 "pk": 5
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 6,
"fields": { "fields": {
"custommail": 3,
"type": 1,
"name": "member", "name": "member",
"description": "Personne int\u00e9ress\u00e9e par la place", "description": "Personne int\u00e9ress\u00e9e par la place"
"custommail": 3, },
"type": 1 "pk": 6
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 7,
"fields": { "fields": {
"custommail": 3,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
"custommail": 3, },
"type": 3 "pk": 7
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 8,
"fields": { "fields": {
"name": "site",
"description": "Site web (gestioCOF)",
"custommail": 3, "custommail": 3,
"type": 5 "type": 5,
} "name": "site",
"description": "Site web (gestioCOF)"
},
"pk": 8
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 9,
"fields": { "fields": {
"name": "site",
"description": "Site web (gestioCOF)",
"custommail": 4, "custommail": 4,
"type": 5 "type": 5,
} "name": "site",
"description": "Site web (gestioCOF)"
},
"pk": 9
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 10,
"fields": { "fields": {
"custommail": 4,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
"custommail": 4, },
"type": 3 "pk": 10
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 11,
"fields": { "fields": {
"custommail": 4,
"type": 1,
"name": "member", "name": "member",
"description": "Personne int\u00e9ress\u00e9e par la place", "description": "Personne int\u00e9ress\u00e9e par la place"
"custommail": 4, },
"type": 1 "pk": 11
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 12,
"fields": { "fields": {
"name": "acheteur",
"description": "Gagnant-e du tirage",
"custommail": 5, "custommail": 5,
"type": 1 "type": 1,
}
},
{
"model": "custommail.custommailvariable",
"pk": 13,
"fields": {
"name": "vendeur",
"description": "Personne qui vend une place",
"custommail": 5,
"type": 1
}
},
{
"model": "custommail.custommailvariable",
"pk": 14,
"fields": {
"name": "show",
"description": "Spectacle",
"custommail": 5,
"type": 3
}
},
{
"model": "custommail.custommailvariable",
"pk": 15,
"fields": {
"name": "show",
"description": "Spectacle",
"custommail": 6,
"type": 3
}
},
{
"model": "custommail.custommailvariable",
"pk": 16,
"fields": {
"name": "vendeur",
"description": "Personne qui vend une place",
"custommail": 6,
"type": 1
}
},
{
"model": "custommail.custommailvariable",
"pk": 17,
"fields": {
"name": "acheteur", "name": "acheteur",
"description": "Personne inscrite au tirage qui n'a pas eu la place", "description": "Gagnant-e du tirage"
"custommail": 6, },
"type": 1 "pk": 12
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 18,
"fields": {
"name": "acheteur",
"description": "Gagnant-e du tirage",
"custommail": 7,
"type": 1
}
},
{
"model": "custommail.custommailvariable",
"pk": 19,
"fields": { "fields": {
"custommail": 5,
"type": 1,
"name": "vendeur", "name": "vendeur",
"description": "Personne qui vend une place", "description": "Personne qui vend une place"
"custommail": 7, },
"type": 1 "pk": 13
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 20,
"fields": { "fields": {
"custommail": 5,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
"custommail": 7, },
"type": 3 "pk": 14
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 21,
"fields": { "fields": {
"custommail": 6,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
},
"pk": 15
},
{
"model": "custommail.variable",
"fields": {
"custommail": 6,
"type": 1,
"name": "vendeur",
"description": "Personne qui vend une place"
},
"pk": 16
},
{
"model": "custommail.variable",
"fields": {
"custommail": 6,
"type": 1,
"name": "acheteur",
"description": "Personne inscrite au tirage qui n'a pas eu la place"
},
"pk": 17
},
{
"model": "custommail.variable",
"fields": {
"custommail": 7,
"type": 1,
"name": "acheteur",
"description": "Gagnant-e du tirage"
},
"pk": 18
},
{
"model": "custommail.variable",
"fields": {
"custommail": 7,
"type": 1,
"name": "vendeur",
"description": "Personne qui vend une place"
},
"pk": 19
},
{
"model": "custommail.variable",
"fields": {
"custommail": 7,
"type": 3,
"name": "show",
"description": "Spectacle"
},
"pk": 20
},
{
"model": "custommail.variable",
"fields": {
"custommail": 8, "custommail": 8,
"type": 3 "type": 3,
} "name": "show",
"description": "Spectacle"
},
"pk": 21
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 22,
"fields": { "fields": {
"name": "vendeur",
"description": "Personne qui vend la place",
"custommail": 8, "custommail": 8,
"type": 1 "type": 1,
} "name": "vendeur",
"description": "Personne qui vend la place"
},
"pk": 22
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 23,
"fields": { "fields": {
"custommail": 8,
"type": 4,
"name": "revente", "name": "revente",
"description": "Revente mentionn\u00e9e dans le mail", "description": "Revente mentionn\u00e9e dans le mail"
"custommail": 8, },
"type": 4 "pk": 23
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 24,
"fields": { "fields": {
"custommail": 9,
"type": 1,
"name": "vendeur", "name": "vendeur",
"description": "Personne qui vend la place", "description": "Personne qui vend la place"
"custommail": 9, },
"type": 1 "pk": 24
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 25,
"fields": { "fields": {
"custommail": 9,
"type": 3,
"name": "show", "name": "show",
"description": "Spectacle", "description": "Spectacle"
"custommail": 9, },
"type": 3 "pk": 25
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 26,
"fields": { "fields": {
"custommail": 9,
"type": 1,
"name": "acheteur", "name": "acheteur",
"description": "Personne qui prend la place au shotgun", "description": "Personne qui prend la place au shotgun"
"custommail": 9, },
"type": 1 "pk": 26
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 27,
"fields": { "fields": {
"custommail": 10,
"type": 6,
"name": "demande", "name": "demande",
"description": "Demande de petit cours", "description": "Demande de petit cours"
"custommail": 10, },
"type": 6 "pk": 27
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 28,
"fields": { "fields": {
"custommail": 10,
"type": 7,
"name": "matieres", "name": "matieres",
"description": "Liste des mati\u00e8res concern\u00e9es par la demande", "description": "Liste des mati\u00e8res concern\u00e9es par la demande"
"custommail": 10, },
"type": 7 "pk": 28
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 29,
"fields": { "fields": {
"custommail": 11,
"type": 10,
"name": "proposals", "name": "proposals",
"description": "Liste associant une liste d'enseignants \u00e0 chaque mati\u00e8re", "description": "Liste associant une liste d'enseignants \u00e0 chaque mati\u00e8re"
"custommail": 11, },
"type": 10 "pk": 29
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 30,
"fields": { "fields": {
"custommail": 11,
"type": 7,
"name": "unsatisfied", "name": "unsatisfied",
"description": "Liste des mati\u00e8res pour lesquelles on n'a pas d'enseigant \u00e0 proposer", "description": "Liste des mati\u00e8res pour lesquelles on n'a pas d'enseigant \u00e0 proposer"
"custommail": 11, },
"type": 7 "pk": 30
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 31,
"fields": { "fields": {
"custommail": 12,
"type": 11,
"name": "places", "name": "places",
"description": "Places de spectacle du participant", "description": "Places de spectacle du participant"
"custommail": 12, },
"type": 11 "pk": 31
}
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 32,
"fields": { "fields": {
"name": "member",
"description": "Participant du tirage au sort",
"custommail": 12, "custommail": 12,
"type": 1 "type": 1,
} "name": "member",
"description": "Participant du tirage au sort"
},
"pk": 32
}, },
{ {
"model": "custommail.custommailvariable", "model": "custommail.variable",
"pk": 33,
"fields": { "fields": {
"name": "member",
"description": "Participant du tirage au sort",
"custommail": 13, "custommail": 13,
"type": 1 "type": 1,
} "name": "member",
"description": "Participant du tirage au sort"
},
"pk": 33
} }
] ]

View file

@ -48,7 +48,7 @@ class Migration(migrations.Migration):
('is_buro', models.BooleanField(default=False, verbose_name=b'Membre du Bur\xc3\xb4')), ('is_buro', models.BooleanField(default=False, verbose_name=b'Membre du Bur\xc3\xb4')),
('petits_cours_accept', models.BooleanField(default=False, verbose_name=b'Recevoir des petits cours')), ('petits_cours_accept', models.BooleanField(default=False, verbose_name=b'Recevoir des petits cours')),
('petits_cours_remarques', models.TextField(default=b'', verbose_name='Remarques et pr\xe9cisions pour les petits cours', blank=True)), ('petits_cours_remarques', models.TextField(default=b'', verbose_name='Remarques et pr\xe9cisions pour les petits cours', blank=True)),
('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL)), ('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Profil COF', 'verbose_name': 'Profil COF',
@ -91,7 +91,7 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=200, verbose_name=b'Champ')), ('name', models.CharField(max_length=200, verbose_name=b'Champ')),
('fieldtype', models.CharField(default=b'text', max_length=10, verbose_name=b'Type', choices=[(b'text', 'Texte long'), (b'char', 'Texte court')])), ('fieldtype', models.CharField(default=b'text', max_length=10, verbose_name=b'Type', choices=[(b'text', 'Texte long'), (b'char', 'Texte court')])),
('default', models.TextField(verbose_name=b'Valeur par d\xc3\xa9faut', blank=True)), ('default', models.TextField(verbose_name=b'Valeur par d\xc3\xa9faut', blank=True)),
('event', models.ForeignKey(related_name='commentfields', to='gestioncof.Event')), ('event', models.ForeignKey(related_name='commentfields', to='gestioncof.Event', on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Champ', 'verbose_name': 'Champ',
@ -102,7 +102,7 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('content', models.TextField(null=True, verbose_name=b'Contenu', blank=True)), ('content', models.TextField(null=True, verbose_name=b'Contenu', blank=True)),
('commentfield', models.ForeignKey(related_name='values', to='gestioncof.EventCommentField')), ('commentfield', models.ForeignKey(related_name='values', to='gestioncof.EventCommentField', on_delete=models.CASCADE)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
@ -111,7 +111,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=200, verbose_name=b'Option')), ('name', models.CharField(max_length=200, verbose_name=b'Option')),
('multi_choices', models.BooleanField(default=False, verbose_name=b'Choix multiples')), ('multi_choices', models.BooleanField(default=False, verbose_name=b'Choix multiples')),
('event', models.ForeignKey(related_name='options', to='gestioncof.Event')), ('event', models.ForeignKey(related_name='options', to='gestioncof.Event', on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Option', 'verbose_name': 'Option',
@ -122,7 +122,7 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.CharField(max_length=200, verbose_name=b'Valeur')), ('value', models.CharField(max_length=200, verbose_name=b'Valeur')),
('event_option', models.ForeignKey(related_name='choices', to='gestioncof.EventOption')), ('event_option', models.ForeignKey(related_name='choices', to='gestioncof.EventOption', on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Choix', 'verbose_name': 'Choix',
@ -133,10 +133,10 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('paid', models.BooleanField(default=False, verbose_name=b'A pay\xc3\xa9')), ('paid', models.BooleanField(default=False, verbose_name=b'A pay\xc3\xa9')),
('event', models.ForeignKey(to='gestioncof.Event')), ('event', models.ForeignKey(to='gestioncof.Event', on_delete=models.CASCADE)),
('filledcomments', models.ManyToManyField(to='gestioncof.EventCommentField', through='gestioncof.EventCommentValue')), ('filledcomments', models.ManyToManyField(to='gestioncof.EventCommentField', through='gestioncof.EventCommentValue')),
('options', models.ManyToManyField(to='gestioncof.EventOptionChoice')), ('options', models.ManyToManyField(to='gestioncof.EventOptionChoice')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Inscription', 'verbose_name': 'Inscription',
@ -240,7 +240,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('question', models.CharField(max_length=200, verbose_name=b'Question')), ('question', models.CharField(max_length=200, verbose_name=b'Question')),
('multi_answers', models.BooleanField(default=False, verbose_name=b'Choix multiples')), ('multi_answers', models.BooleanField(default=False, verbose_name=b'Choix multiples')),
('survey', models.ForeignKey(related_name='questions', to='gestioncof.Survey')), ('survey', models.ForeignKey(related_name='questions', to='gestioncof.Survey', on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'Question', 'verbose_name': 'Question',
@ -251,7 +251,7 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('answer', models.CharField(max_length=200, verbose_name=b'R\xc3\xa9ponse')), ('answer', models.CharField(max_length=200, verbose_name=b'R\xc3\xa9ponse')),
('survey_question', models.ForeignKey(related_name='answers', to='gestioncof.SurveyQuestion')), ('survey_question', models.ForeignKey(related_name='answers', to='gestioncof.SurveyQuestion', on_delete=models.CASCADE)),
], ],
options={ options={
'verbose_name': 'R\xe9ponse', 'verbose_name': 'R\xe9ponse',
@ -265,12 +265,12 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='surveyanswer', model_name='surveyanswer',
name='survey', name='survey',
field=models.ForeignKey(to='gestioncof.Survey'), field=models.ForeignKey(to='gestioncof.Survey', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='surveyanswer', model_name='surveyanswer',
name='user', name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL), field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursdemande', model_name='petitcoursdemande',
@ -280,47 +280,47 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='petitcoursdemande', model_name='petitcoursdemande',
name='traitee_par', name='traitee_par',
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True), field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursattributioncounter', model_name='petitcoursattributioncounter',
name='matiere', name='matiere',
field=models.ForeignKey(verbose_name='Matiere', to='gestioncof.PetitCoursSubject'), field=models.ForeignKey(verbose_name='Matiere', to='gestioncof.PetitCoursSubject', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursattributioncounter', model_name='petitcoursattributioncounter',
name='user', name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL), field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursattribution', model_name='petitcoursattribution',
name='demande', name='demande',
field=models.ForeignKey(verbose_name='Demande', to='gestioncof.PetitCoursDemande'), field=models.ForeignKey(verbose_name='Demande', to='gestioncof.PetitCoursDemande', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursattribution', model_name='petitcoursattribution',
name='matiere', name='matiere',
field=models.ForeignKey(verbose_name='Mati\xe8re', to='gestioncof.PetitCoursSubject'), field=models.ForeignKey(verbose_name='Mati\xe8re', to='gestioncof.PetitCoursSubject', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursattribution', model_name='petitcoursattribution',
name='user', name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL), field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursability', model_name='petitcoursability',
name='matiere', name='matiere',
field=models.ForeignKey(verbose_name='Mati\xe8re', to='gestioncof.PetitCoursSubject'), field=models.ForeignKey(verbose_name='Mati\xe8re', to='gestioncof.PetitCoursSubject', on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='petitcoursability', model_name='petitcoursability',
name='user', name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL), field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
), ),
migrations.AddField( migrations.AddField(
model_name='eventcommentvalue', model_name='eventcommentvalue',
name='registration', name='registration',
field=models.ForeignKey(related_name='comments', to='gestioncof.EventRegistration'), field=models.ForeignKey(related_name='comments', to='gestioncof.EventRegistration', on_delete=models.CASCADE),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='surveyanswer', name='surveyanswer',

View file

@ -23,7 +23,8 @@ class Migration(migrations.Migration):
('subscribe_to_events', models.BooleanField(default=True)), ('subscribe_to_events', models.BooleanField(default=True)),
('subscribe_to_my_shows', models.BooleanField(default=True)), ('subscribe_to_my_shows', models.BooleanField(default=True)),
('other_shows', models.ManyToManyField(to='bda.Spectacle')), ('other_shows', models.ManyToManyField(to='bda.Spectacle')),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)),
], ],
), ),
migrations.AlterModelOptions( migrations.AlterModelOptions(

View file

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('gestioncof', '0012_merge'),
]
operations = [
migrations.AlterField(
model_name='cofprofile',
name='occupation',
field=models.CharField(
verbose_name='Occupation',
max_length=9,
default='1A',
choices=[
('exterieur', 'Extérieur'),
('1A', '1A'),
('2A', '2A'),
('3A', '3A'),
('4A', '4A'),
('archicube', 'Archicube'),
('doctorant', 'Doctorant'),
('CST', 'CST'),
('PEI', 'PEI')
]),
),
migrations.AlterField(
model_name='cofprofile',
name='type_cotiz',
field=models.CharField(
verbose_name='Type de cotisation',
max_length=9,
default='normalien',
choices=[
('etudiant', 'Normalien étudiant'),
('normalien', 'Normalien élève'),
('exterieur', 'Extérieur'),
('gratis', 'Gratuit')
]),
),
]

View file

@ -8,23 +8,6 @@ from gestioncof.petits_cours_models import choices_length
from bda.models import Spectacle from bda.models import Spectacle
OCCUPATION_CHOICES = (
('exterieur', _("Extérieur")),
('1A', _("1A")),
('2A', _("2A")),
('3A', _("3A")),
('4A', _("4A")),
('archicube', _("Archicube")),
('doctorant', _("Doctorant")),
('CST', _("CST")),
)
TYPE_COTIZ_CHOICES = (
('etudiant', _("Normalien étudiant")),
('normalien', _("Normalien élève")),
('exterieur', _("Extérieur")),
)
TYPE_COMMENT_FIELD = ( TYPE_COMMENT_FIELD = (
('text', _("Texte long")), ('text', _("Texte long")),
('char', _("Texte court")), ('char', _("Texte court")),
@ -32,7 +15,44 @@ TYPE_COMMENT_FIELD = (
class CofProfile(models.Model): class CofProfile(models.Model):
user = models.OneToOneField(User, related_name="profile") STATUS_EXTE = "exterieur"
STATUS_1A = "1A"
STATUS_2A = "2A"
STATUS_3A = "3A"
STATUS_4A = "4A"
STATUS_ARCHI = "archicube"
STATUS_DOCTORANT = "doctorant"
STATUS_CST = "CST"
STATUS_PEI = "PEI"
OCCUPATION_CHOICES = (
(STATUS_EXTE, _("Extérieur")),
(STATUS_1A, _("1A")),
(STATUS_2A, _("2A")),
(STATUS_3A, _("3A")),
(STATUS_4A, _("4A")),
(STATUS_ARCHI, _("Archicube")),
(STATUS_DOCTORANT, _("Doctorant")),
(STATUS_CST, _("CST")),
(STATUS_PEI, _("PEI")),
)
COTIZ_ETUDIANT = "etudiant"
COTIZ_NORMALIEN = "normalien"
COTIZ_EXTE = "exterieur"
COTIZ_GRATIS = "gratis"
TYPE_COTIZ_CHOICES = (
(COTIZ_ETUDIANT, _("Normalien étudiant")),
(COTIZ_NORMALIEN, _("Normalien élève")),
(COTIZ_EXTE, _("Extérieur")),
(COTIZ_GRATIS, _("Gratuit")),
)
user = models.OneToOneField(
User, on_delete=models.CASCADE,
related_name="profile",
)
login_clipper = models.CharField( login_clipper = models.CharField(
"Login clipper", max_length=32, blank=True "Login clipper", max_length=32, blank=True
) )
@ -113,7 +133,10 @@ class Event(models.Model):
class EventCommentField(models.Model): class EventCommentField(models.Model):
event = models.ForeignKey(Event, related_name="commentfields") event = models.ForeignKey(
Event, on_delete=models.CASCADE,
related_name="commentfields",
)
name = models.CharField("Champ", max_length=200) name = models.CharField("Champ", max_length=200)
fieldtype = models.CharField("Type", max_length=10, fieldtype = models.CharField("Type", max_length=10,
choices=TYPE_COMMENT_FIELD, default="text") choices=TYPE_COMMENT_FIELD, default="text")
@ -127,9 +150,14 @@ class EventCommentField(models.Model):
class EventCommentValue(models.Model): class EventCommentValue(models.Model):
commentfield = models.ForeignKey(EventCommentField, related_name="values") commentfield = models.ForeignKey(
registration = models.ForeignKey("EventRegistration", EventCommentField, on_delete=models.CASCADE,
related_name="comments") related_name="values",
)
registration = models.ForeignKey(
"EventRegistration", on_delete=models.CASCADE,
related_name="comments",
)
content = models.TextField("Contenu", blank=True, null=True) content = models.TextField("Contenu", blank=True, null=True)
def __str__(self): def __str__(self):
@ -137,7 +165,10 @@ class EventCommentValue(models.Model):
class EventOption(models.Model): class EventOption(models.Model):
event = models.ForeignKey(Event, related_name="options") event = models.ForeignKey(
Event, on_delete=models.CASCADE,
related_name="options",
)
name = models.CharField("Option", max_length=200) name = models.CharField("Option", max_length=200)
multi_choices = models.BooleanField("Choix multiples", default=False) multi_choices = models.BooleanField("Choix multiples", default=False)
@ -149,7 +180,10 @@ class EventOption(models.Model):
class EventOptionChoice(models.Model): class EventOptionChoice(models.Model):
event_option = models.ForeignKey(EventOption, related_name="choices") event_option = models.ForeignKey(
EventOption, on_delete=models.CASCADE,
related_name="choices",
)
value = models.CharField("Valeur", max_length=200) value = models.CharField("Valeur", max_length=200)
class Meta: class Meta:
@ -161,8 +195,8 @@ class EventOptionChoice(models.Model):
class EventRegistration(models.Model): class EventRegistration(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
event = models.ForeignKey(Event) event = models.ForeignKey(Event, on_delete=models.CASCADE)
options = models.ManyToManyField(EventOptionChoice) options = models.ManyToManyField(EventOptionChoice)
filledcomments = models.ManyToManyField(EventCommentField, filledcomments = models.ManyToManyField(EventCommentField,
through=EventCommentValue) through=EventCommentValue)
@ -190,7 +224,10 @@ class Survey(models.Model):
class SurveyQuestion(models.Model): class SurveyQuestion(models.Model):
survey = models.ForeignKey(Survey, related_name="questions") survey = models.ForeignKey(
Survey, on_delete=models.CASCADE,
related_name="questions",
)
question = models.CharField("Question", max_length=200) question = models.CharField("Question", max_length=200)
multi_answers = models.BooleanField("Choix multiples", default=False) multi_answers = models.BooleanField("Choix multiples", default=False)
@ -202,7 +239,10 @@ class SurveyQuestion(models.Model):
class SurveyQuestionAnswer(models.Model): class SurveyQuestionAnswer(models.Model):
survey_question = models.ForeignKey(SurveyQuestion, related_name="answers") survey_question = models.ForeignKey(
SurveyQuestion, on_delete=models.CASCADE,
related_name="answers",
)
answer = models.CharField("Réponse", max_length=200) answer = models.CharField("Réponse", max_length=200)
class Meta: class Meta:
@ -213,8 +253,8 @@ class SurveyQuestionAnswer(models.Model):
class SurveyAnswer(models.Model): class SurveyAnswer(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
survey = models.ForeignKey(Survey) survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
answers = models.ManyToManyField(SurveyQuestionAnswer, answers = models.ManyToManyField(SurveyQuestionAnswer,
related_name="selected_by") related_name="selected_by")
@ -230,7 +270,7 @@ class SurveyAnswer(models.Model):
class CalendarSubscription(models.Model): class CalendarSubscription(models.Model):
token = models.UUIDField() token = models.UUIDField()
user = models.OneToOneField(User) user = models.OneToOneField(User, on_delete=models.CASCADE)
other_shows = models.ManyToManyField(Spectacle) other_shows = models.ManyToManyField(Spectacle)
subscribe_to_events = models.BooleanField(default=True) subscribe_to_events = models.BooleanField(default=True)
subscribe_to_my_shows = models.BooleanField(default=True) subscribe_to_my_shows = models.BooleanField(default=True)

View file

@ -35,8 +35,11 @@ class PetitCoursSubject(models.Model):
class PetitCoursAbility(models.Model): class PetitCoursAbility(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière")) matiere = models.ForeignKey(
PetitCoursSubject, on_delete=models.CASCADE,
verbose_name=_("Matière"),
)
niveau = models.CharField(_("Niveau"), niveau = models.CharField(_("Niveau"),
choices=LEVELS_CHOICES, choices=LEVELS_CHOICES,
max_length=choices_length(LEVELS_CHOICES)) max_length=choices_length(LEVELS_CHOICES))
@ -84,7 +87,10 @@ class PetitCoursDemande(models.Model):
remarques = models.TextField(_("Remarques et précisions"), blank=True) remarques = models.TextField(_("Remarques et précisions"), blank=True)
traitee = models.BooleanField(_("Traitée"), default=False) traitee = models.BooleanField(_("Traitée"), default=False)
traitee_par = models.ForeignKey(User, blank=True, null=True) traitee_par = models.ForeignKey(
User, on_delete=models.CASCADE,
blank=True, null=True,
)
processed = models.DateTimeField(_("Date de traitement"), processed = models.DateTimeField(_("Date de traitement"),
blank=True, null=True) blank=True, null=True)
created = models.DateTimeField(_("Date de création"), auto_now_add=True) created = models.DateTimeField(_("Date de création"), auto_now_add=True)
@ -126,9 +132,15 @@ class PetitCoursDemande(models.Model):
class PetitCoursAttribution(models.Model): class PetitCoursAttribution(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
demande = models.ForeignKey(PetitCoursDemande, verbose_name=_("Demande")) demande = models.ForeignKey(
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière")) PetitCoursDemande, on_delete=models.CASCADE,
verbose_name=_("Demande"),
)
matiere = models.ForeignKey(
PetitCoursSubject, on_delete=models.CASCADE,
verbose_name=_("Matière"),
)
date = models.DateTimeField(_("Date d'attribution"), auto_now_add=True) date = models.DateTimeField(_("Date d'attribution"), auto_now_add=True)
rank = models.IntegerField("Rang dans l'email") rank = models.IntegerField("Rang dans l'email")
selected = models.BooleanField(_("Sélectionné par le demandeur"), selected = models.BooleanField(_("Sélectionné par le demandeur"),
@ -145,8 +157,11 @@ class PetitCoursAttribution(models.Model):
class PetitCoursAttributionCounter(models.Model): class PetitCoursAttributionCounter(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User, on_delete=models.CASCADE)
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matiere")) matiere = models.ForeignKey(
PetitCoursSubject, on_delete=models.CASCADE,
verbose_name=_("Matiere"),
)
count = models.IntegerField("Nombre d'envois", default=0) count = models.IntegerField("Nombre d'envois", default=0)
@classmethod @classmethod
@ -157,14 +172,16 @@ class PetitCoursAttributionCounter(models.Model):
compteurs de tout le monde. compteurs de tout le monde.
""" """
counter, created = cls.objects.get_or_create( counter, created = cls.objects.get_or_create(
user=user, matiere=matiere) user=user,
matiere=matiere,
)
if created: if created:
mincount = ( mincount = (
cls.objects.filter(matiere=matiere).exclude(user=user) cls.objects.filter(matiere=matiere).exclude(user=user)
.aggregate(Min('count')) .aggregate(Min('count'))
['count__min'] ['count__min']
) )
counter.count = mincount counter.count = mincount or 0
counter.save() counter.save()
return counter return counter

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json import json
from datetime import datetime
from custommail.shortcuts import render_custom_mail from custommail.shortcuts import render_custom_mail
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
@ -13,6 +12,7 @@ from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.utils import timezone
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from gestioncof.petits_cours_models import ( from gestioncof.petits_cours_models import (
@ -287,7 +287,7 @@ def _traitement_post(request, demande):
attrib.save() attrib.save()
demande.traitee = True demande.traitee = True
demande.traitee_par = request.user demande.traitee_par = request.user
demande.processed = datetime.now() demande.processed = timezone.now()
demande.save() demande.save()
return render(request, return render(request,
"gestioncof/traitement_demande_petit_cours_success.html", "gestioncof/traitement_demande_petit_cours_success.html",

View file

@ -1,6 +0,0 @@
{% extends "admin/base.html" %}
{% block extrahead %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}

View file

@ -1,78 +0,0 @@
{% extends "admin/base_site.html" %}
<!-- LOADING -->
{% load i18n grp_tags log %}
<!-- JAVASCRIPTS -->
{% block javascripts %}
{{ block.super }}
{% endblock %}
<!-- COLTYPE/BODYCLASS-- >
{% block bodyclass %}dashboard{% endblock %}
{% block content-class %}content-grid{% endblock %}
<!-- BREADCRUMBS -->
{% block breadcrumbs %}
<ul class="grp-horizontal-list">
<li>{% trans "Home" %}</li>
</ul>
{% endblock %}
{% block content_title %}
{% if title %}
<header><h1>{{ title }}</h1></header>
{% endif %}
{% endblock %}
<!-- CONTENT -->
{% block content %}
<div class="g-d-c">
<div class="g-d-12 g-d-f">
{% for app in app_list %}
<div class="grp-module" id="app_{{ app.name|lower }}">
<h2><a href="{{ app.app_url }}" class="grp-section">{% trans app.name %}</a></h2>
{% for model in app.models %}
<div class="grp-row">
{% if model.perms.change %}<a href="{{ model.admin_url }}"><strong>{{ model.name }}</strong></a>{% else %}<span><strong>{{ model.name }}</strong></span>{% endif %}
{% if model.perms.add or model.perms.change %}
<ul class="grp-actions">
{% if model.perms.add %}<li class="grp-add-link"><a href="{{ model.admin_url }}add/">{% trans 'Add' %}</a></li>{% endif %}
{% if model.perms.change %}<li class="grp-change-link"><a href="{{ model.admin_url }}">{% trans 'Change' %}</a></li>{% endif %}
</ul>
{% endif %}
</div>
{% endfor %}
</div>
{% empty %}
<p>{% trans "You don´t have permission to edit anything." %}</p>
{% endfor %}
</div>
<div class="g-d-6 g-d-l">
<div class="grp-module" id="grp-recent-actions-module">
<h2>{% trans 'Recent Actions' %}</h2>
<div class="grp-module">
<h3>{% trans 'My Actions' %}</h3>
{% get_admin_log 20 as admin_log for_user user %}
{% if not admin_log %}
<p>{% trans 'None available' %}</p>
{% else %}
<ul class="grp-listing-small">
{% for entry in admin_log %}
<li class="grp-row{% if entry.is_addition %} grp-add-link{% endif %}{% if entry.is_change %} grp-change-link{% endif %}{% if entry.is_deletion %} grp-delete-link{% endif %}">
{% if entry.is_deletion %}
<span>{{ entry.object_repr }}</span>
{% else %}
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %}
<span class="grp-font-color-quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -3,7 +3,7 @@
{% block content %} {% block content %}
<header> <header>
<div class="container banner"> <div class="container banner">
<a href="{% url "gestioncof.views.home" %}"> <a href="{% url "home" %}">
<h1>GestioCOF</h1> <h1>GestioCOF</h1>
{% block homelink %} {% block homelink %}
<span class="glyphicon glyphicon-home" aria-hidden=true></span> <span class="glyphicon glyphicon-home" aria-hidden=true></span>
@ -11,7 +11,7 @@
</a> </a>
<div class="secondary"> <div class="secondary">
<span class="hidden-xxs">&nbsp;&nbsp;|&nbsp; </span> <span class="hidden-xxs">&nbsp;&nbsp;|&nbsp; </span>
<span><a href="{% url "gestioncof.views.logout" %}">Se déconnecter&nbsp;<span class="glyphicon glyphicon-log-out"></span></a></span> <span><a href="{% url "cof-logout" %}">Se déconnecter&nbsp;<span class="glyphicon glyphicon-log-out"></span></a></span>
</div> </div>
<h2 class="member-status">{% if user.first_name %}{{ user.first_name }}{% else %}<tt>{{ user.username }}</tt>{% endif %}, {% if user.profile.is_cof %}<tt class="user-is-cof">au COF{% else %}<tt class="user-is-not-cof">non-COF{% endif %}</tt></h2> <h2 class="member-status">{% if user.first_name %}{{ user.first_name }}{% else %}<tt>{{ user.username }}</tt>{% endif %}, {% if user.profile.is_cof %}<tt class="user-is-cof">au COF{% else %}<tt class="user-is-not-cof">non-COF{% endif %}</tt></h2>
</div><!-- /.container --> </div><!-- /.container -->

View file

@ -5,7 +5,7 @@
{% if event.details %} {% if event.details %}
<p>{{ event.details }}</p> <p>{{ event.details }}</p>
{% endif %} {% endif %}
<form method="post" action="{% url 'gestioncof.views.event' event.id %}"> <form method="post" action="{% url 'event.details' event.id %}">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" class="btn-submit" value="Enregistrer" /> <input type="submit" class="btn-submit" value="Enregistrer" />

View file

@ -14,7 +14,7 @@
<div class="hm-block"> <div class="hm-block">
<ul> <ul>
{% for event in open_events %} {% for event in open_events %}
<li><a href="{% url "gestioncof.views.event" event.id %}">{{ event.title }}</a></li> <li><a href="{% url "event.details" event.id %}">{{ event.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
@ -24,7 +24,7 @@
<div class="hm-block"> <div class="hm-block">
<ul> <ul>
{% for survey in open_surveys %} {% for survey in open_surveys %}
<li><a href="{% url "gestioncof.views.survey" survey.id %}">{{ survey.title }}</a></li> <li><a href="{% url "survey.details" survey.id %}">{{ survey.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
@ -69,11 +69,11 @@
<h3 class="block-title">Divers<span class="pull-right glyphicon glyphicon-question-sign"></span></h3> <h3 class="block-title">Divers<span class="pull-right glyphicon glyphicon-question-sign"></span></h3>
<div class="hm-block"> <div class="hm-block">
<ul> <ul>
<li><a href="{% url "gestioncof.views.calendar" %}">Calendrier dynamique</a></li> <li><a href="{% url "calendar" %}">Calendrier dynamique</a></li>
{% if user.profile.is_cof %}<li><a href="{% url "petits-cours-inscription" %}">Inscription pour donner des petits cours</a></li>{% endif %} {% if user.profile.is_cof %}<li><a href="{% url "petits-cours-inscription" %}">Inscription pour donner des petits cours</a></li>{% endif %}
<li><a href="{% url "gestioncof.views.profile" %}">Éditer mon profil</a></li> <li><a href="{% url "profile" %}">Éditer mon profil</a></li>
{% if not user.profile.login_clipper %}<li><a href="{% url "django.contrib.auth.views.password_change" %}">Changer mon mot de passe</a></li>{% endif %} {% if not user.profile.login_clipper %}<li><a href="{% url "password_change" %}">Changer mon mot de passe</a></li>{% endif %}
</ul> </ul>
</div> </div>
{% endif %} {% endif %}
@ -86,16 +86,16 @@
<h4>Général</h4> <h4>Général</h4>
<li><a href="{% url "admin:index" %}">Administration générale</a></li> <li><a href="{% url "admin:index" %}">Administration générale</a></li>
<li><a href="{% url "petits-cours-demandes-list" %}">Demandes de petits cours</a></li> <li><a href="{% url "petits-cours-demandes-list" %}">Demandes de petits cours</a></li>
<li><a href="{% url "gestioncof.views.registration" %}">Inscription d'un nouveau membre</a></li> <li><a href="{% url "registration" %}">Inscription d'un nouveau membre</a></li>
<li><a href="{% url "liste-clubs" %}">Gestion des clubs</a></li> <li><a href="{% url "liste-clubs" %}">Gestion des clubs</a></li>
</ul> </ul>
<ul> <ul>
<h4>Évènements & Sondages</h4> <h4>Évènements & Sondages</h4>
{% for event in events %} {% for event in events %}
<li><a href="{% url "gestioncof.views.event_status" event.id %}">Événement : {{ event.title }}</a></li> <li><a href="{% url "event.details.status" event.id %}">Événement : {{ event.title }}</a></li>
{% endfor %} {% endfor %}
{% for survey in surveys %} {% for survey in surveys %}
<li><a href="{% url "gestioncof.views.survey_status" survey.id %}">Sondage : {{ survey.title }}</a></li> <li><a href="{% url "survey.details.status" survey.id %}">Sondage : {{ survey.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
@ -120,8 +120,8 @@
<h3 class="block-title">Liens utiles<span class="pull-right glyphicon glyphicon-link"></span></h3> <h3 class="block-title">Liens utiles<span class="pull-right glyphicon glyphicon-link"></span></h3>
<div class="hm-block"> <div class="hm-block">
<ul> <ul>
<li><a href="{% url "gestioncof.views.utile_cof" %}">Liens utiles du COF</a></li> <li><a href="{% url "utile_cof" %}">Liens utiles du COF</a></li>
<li><a href="{% url "gestioncof.views.utile_bda" %}">Liens utiles BdA</a></li> <li><a href="{% url "utile_bda" %}">Liens utiles BdA</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -15,7 +15,7 @@
<p class="error">Identifiants incorrects.</p> <p class="error">Identifiants incorrects.</p>
{% endif %} {% endif %}
<form class="form-horizontal" method="post" <form class="form-horizontal" method="post"
action="{% url 'gestioncof.views.login_ext' %}?next={{ next|urlencode }}"> action="{% url 'ext_login_view' %}?next={{ next|urlencode }}">
{% csrf_token %} {% csrf_token %}
<div class="form-group"> <div class="form-group">
<input class="form-control" id="id_username" maxlength="254" name="username" type="text" placeholder="Nom d'utilisateur"> <input class="form-control" id="id_username" maxlength="254" name="username" type="text" placeholder="Nom d'utilisateur">

View file

@ -12,13 +12,13 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row" style="margin:0;"> <div class="row" style="margin:0;">
<a aria-label="Compte clipper" <a aria-label="Compte clipper"
href="{% url 'django_cas_ng.views.login' %}?next={{ next|urlencode }}"> href="{% url 'cas_login_view' %}?next={{ next|urlencode }}">
<div class="col-xs-12 col-sm-6" id="login_clipper"> <div class="col-xs-12 col-sm-6" id="login_clipper">
Compte clipper Compte clipper
</div> </div>
</a> </a>
<a aria-label="Extérieur" <a aria-label="Extérieur"
href="{% url 'gestioncof.views.login_ext' %}?next={{ next|urlencode }}"> href="{% url 'ext_login_view' %}?next={{ next|urlencode }}">
<div class="col-xs-12 col-sm-6" id="login_outsider"> <div class="col-xs-12 col-sm-6" id="login_outsider">
Extérieur Extérieur
</div> </div>

View file

@ -5,5 +5,5 @@
{% block realcontent %} {% block realcontent %}
<h2>Mot de passe modifié avec succès !</h2> <h2>Mot de passe modifié avec succès !</h2>
<h3><a href="{% url "gestioncof.views.home" %}">Retour au menu principal</a></h3> <h3><a href="{% url "home" %}">Retour au menu principal</a></h3>
{% endblock %} {% endblock %}

View file

@ -5,7 +5,7 @@
{% block realcontent %} {% block realcontent %}
<h2>Changement de mot de passe</h2> <h2>Changement de mot de passe</h2>
<form class="form-horizontal" method="post" action="{% url 'django.contrib.auth.views.password_change' %}"> <form class="form-horizontal" method="post" action="{% url 'password_change' %}">
{% csrf_token %} {% csrf_token %}
{{ form | bootstrap }} {{ form | bootstrap }}
<input type="submit" class="btn btn-primary pull-right" value="Changer" /> <input type="submit" class="btn btn-primary pull-right" value="Changer" />

View file

@ -36,19 +36,23 @@ petitcours_patterns = [
] ]
surveys_patterns = [ surveys_patterns = [
url(r'^(?P<survey_id>\d+)/status$', views.survey_status), url(r'^(?P<survey_id>\d+)/status$', views.survey_status,
url(r'^(?P<survey_id>\d+)$', views.survey), name='survey.details.status'),
url(r'^(?P<survey_id>\d+)$', views.survey,
name='survey.details'),
] ]
events_patterns = [ events_patterns = [
url(r'^(?P<event_id>\d+)$', views.event), url(r'^(?P<event_id>\d+)$', views.event,
url(r'^(?P<event_id>\d+)/status$', views.event_status), name='event.details'),
url(r'^(?P<event_id>\d+)/status$', views.event_status,
name='event.details.status'),
] ]
calendar_patterns = [ calendar_patterns = [
url(r'^subscription$', 'gestioncof.views.calendar'), url(r'^subscription$', views.calendar,
url(r'^(?P<token>[a-z0-9-]+)/calendar.ics$', name='calendar'),
'gestioncof.views.calendar_ics') url(r'^(?P<token>[a-z0-9-]+)/calendar.ics$', views.calendar_ics)
] ]
clubs_patterns = [ clubs_patterns = [

View file

@ -20,6 +20,8 @@ from django.contrib import messages
from django_cas_ng.views import logout as cas_logout_view from django_cas_ng.views import logout as cas_logout_view
from utils.views.autocomplete import Select2QuerySetView
from gestioncof.models import Survey, SurveyAnswer, SurveyQuestion, \ from gestioncof.models import Survey, SurveyAnswer, SurveyQuestion, \
SurveyQuestionAnswer SurveyQuestionAnswer
from gestioncof.models import Event, EventRegistration, EventOption, \ from gestioncof.models import Event, EventRegistration, EventOption, \
@ -54,8 +56,8 @@ def home(request):
def login(request): def login(request):
if request.user.is_authenticated(): if request.user.is_authenticated:
return redirect("gestioncof.views.home") return redirect("home")
context = {} context = {}
if request.method == "GET" and 'next' in request.GET: if request.method == "GET" and 'next' in request.GET:
context['next'] = request.GET['next'] context['next'] = request.GET['next']
@ -577,7 +579,7 @@ def export_members(request):
writer = unicodecsv.writer(response) writer = unicodecsv.writer(response)
for profile in CofProfile.objects.filter(is_cof=True).all(): for profile in CofProfile.objects.filter(is_cof=True).all():
user = profile.user user = profile.user
bits = [profile.id, user.username, user.first_name, user.last_name, bits = [user.id, user.username, user.first_name, user.last_name,
user.email, profile.phone, profile.occupation, user.email, profile.phone, profile.occupation,
profile.departement, profile.type_cotiz] profile.departement, profile.type_cotiz]
writer.writerow([str(bit) for bit in bits]) writer.writerow([str(bit) for bit in bits])
@ -596,7 +598,7 @@ def csv_export_mega(filename, qs):
comments = "---".join( comments = "---".join(
[comment.content for comment in reg.comments.all()]) [comment.content for comment in reg.comments.all()])
bits = [user.username, user.first_name, user.last_name, user.email, bits = [user.username, user.first_name, user.last_name, user.email,
profile.phone, profile.id, profile.phone, user.id,
profile.comments if profile.comments else "", comments] profile.comments if profile.comments else "", comments]
writer.writerow([str(bit) for bit in bits]) writer.writerow([str(bit) for bit in bits])
@ -786,3 +788,18 @@ class ConfigUpdate(FormView):
def form_valid(self, form): def form_valid(self, form):
form.save() form.save()
return super().form_valid(form) return super().form_valid(form)
##
# Autocomplete views
#
# https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#create-an-autocomplete-view
##
class UserAutocomplete(Select2QuerySetView):
model = User
search_fields = ('username', 'first_name', 'last_name')
user_autocomplete = buro_required(UserAutocomplete.as_view())

View file

@ -11,7 +11,6 @@ class KFetConfig(AppConfig):
verbose_name = "Application K-Fêt" verbose_name = "Application K-Fêt"
def ready(self): def ready(self):
import kfet.signals
self.register_config() self.register_config()
def register_config(self): def register_config(self):

4
kfet/auth/__init__.py Normal file
View file

@ -0,0 +1,4 @@
default_app_config = 'kfet.auth.apps.KFetAuthConfig'
KFET_GENERIC_USERNAME = 'kfet_genericteam'
KFET_GENERIC_TRIGRAMME = 'GNR'

14
kfet/auth/apps.py Normal file
View file

@ -0,0 +1,14 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.utils.translation import ugettext_lazy as _
class KFetAuthConfig(AppConfig):
name = 'kfet.auth'
label = 'kfetauth'
verbose_name = _("K-Fêt - Authentification et Autorisation")
def ready(self):
from . import signals # noqa
from .utils import setup_kfet_generic_user
post_migrate.connect(setup_kfet_generic_user, sender=self)

43
kfet/auth/backends.py Normal file
View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from django.contrib.auth import get_user_model
from kfet.models import Account, GenericTeamToken
from .utils import get_kfet_generic_user
User = get_user_model()
class BaseKFetBackend:
def get_user(self, user_id):
"""
Add extra select related up to Account.
"""
try:
return (
User.objects
.select_related('profile__account_kfet')
.get(pk=user_id)
)
except User.DoesNotExist:
return None
class AccountBackend(BaseKFetBackend):
def authenticate(self, request, kfet_password=None):
try:
return Account.objects.get_by_password(kfet_password).user
except Account.DoesNotExist:
return None
class GenericBackend(BaseKFetBackend):
def authenticate(self, request, kfet_token=None):
try:
team_token = GenericTeamToken.objects.get(token=kfet_token)
except GenericTeamToken.DoesNotExist:
return
# No need to keep the token.
team_token.delete()
return get_kfet_generic_user()

View file

@ -0,0 +1,10 @@
from django.contrib.auth.context_processors import PermWrapper
def temporary_auth(request):
if hasattr(request, 'real_user'):
return {
'user': request.real_user,
'perms': PermWrapper(request.real_user),
}
return {}

20
kfet/auth/fields.py Normal file
View file

@ -0,0 +1,20 @@
from django import forms
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.forms import widgets
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
queryset = Permission.objects.filter(
content_type__in=ContentType.objects.filter(app_label="kfet"),
)
super().__init__(
queryset=queryset,
widget=widgets.CheckboxSelectMultiple,
*args, **kwargs
)
def label_from_instance(self, obj):
return obj.name

48
kfet/auth/forms.py Normal file
View file

@ -0,0 +1,48 @@
from django import forms
from django.contrib.auth.models import Group, User
from .fields import KFetPermissionsField
class GroupForm(forms.ModelForm):
permissions = KFetPermissionsField()
def clean_name(self):
name = self.cleaned_data['name']
return 'K-Fêt %s' % name
def clean_permissions(self):
kfet_perms = self.cleaned_data['permissions']
# TODO: With Django >=1.11, the QuerySet method 'difference' can be
# used.
# other_groups = self.instance.permissions.difference(
# self.fields['permissions'].queryset
# )
if self.instance.pk is None:
return kfet_perms
other_perms = self.instance.permissions.exclude(
pk__in=[p.pk for p in self.fields['permissions'].queryset],
)
return list(kfet_perms) + list(other_perms)
class Meta:
model = Group
fields = ['name', 'permissions']
class UserGroupForm(forms.ModelForm):
groups = forms.ModelMultipleChoiceField(
Group.objects.filter(name__icontains='K-Fêt'),
label='Statut équipe',
required=False)
def clean_groups(self):
kfet_groups = self.cleaned_data.get('groups')
if self.instance.pk is None:
return kfet_groups
other_groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return list(kfet_groups) + list(other_groups)
class Meta:
model = User
fields = ['groups']

43
kfet/auth/middleware.py Normal file
View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from django.contrib.auth import get_user_model
from .backends import AccountBackend
User = get_user_model()
class TemporaryAuthMiddleware:
"""Authenticate another user for this request if AccountBackend succeeds.
By the way, if a user is authenticated, we refresh its from db to add
values from CofProfile and Account of this user.
"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.user.is_authenticated:
# avoid multiple db accesses in views and templates
request.user = (
User.objects
.select_related('profile__account_kfet')
.get(pk=request.user.pk)
)
temp_request_user = AccountBackend().authenticate(
request,
kfet_password=self.get_kfet_password(request),
)
if temp_request_user:
request.real_user = request.user
request.user = temp_request_user
return self.get_response(request)
def get_kfet_password(self, request):
return (
request.META.get('HTTP_KFETPASSWORD') or
request.POST.get('KFETPASSWORD')
)

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth', '0006_require_contenttypes_0002'),
# Following dependency allows using Account model to set up the kfet
# generic user in post_migrate receiver.
('kfet', '0058_delete_genericteamtoken'),
]
operations = [
migrations.CreateModel(
name='GenericTeamToken',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('token', models.CharField(unique=True, max_length=50)),
],
),
]

View file

17
kfet/auth/models.py Normal file
View file

@ -0,0 +1,17 @@
from django.db import models
from django.utils.crypto import get_random_string
class GenericTeamTokenManager(models.Manager):
def create_token(self):
token = get_random_string(50)
while self.filter(token=token).exists():
token = get_random_string(50)
return self.create(token=token)
class GenericTeamToken(models.Model):
token = models.CharField(max_length=50, unique=True)
objects = GenericTeamTokenManager()

40
kfet/auth/signals.py Normal file
View file

@ -0,0 +1,40 @@
from django.contrib import messages
from django.contrib.auth.signals import user_logged_in
from django.core.urlresolvers import reverse
from django.dispatch import receiver
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from .utils import get_kfet_generic_user
@receiver(user_logged_in)
def suggest_auth_generic(sender, request, user, **kwargs):
"""
Suggest logged in user to continue as the kfet generic user.
Message is only added if the following conditions are met:
- the next page (where user is going to be redirected due to successful
authentication) is related to kfet, i.e. 'k-fet' is in its url.
- logged in user is a kfet staff member (except the generic user).
"""
# Filter against the next page.
if not(hasattr(request, 'GET') and 'next' in request.GET):
return
next_page = request.GET['next']
generic_url = reverse('kfet.login.generic')
if not('k-fet' in next_page and not next_page.startswith(generic_url)):
return
# Filter against the logged in user.
if not(user.has_perm('kfet.is_team') and user != get_kfet_generic_user()):
return
# Seems legit to add message.
text = _("K-Fêt — Ouvrir une session partagée ?")
messages.info(request, mark_safe(
'<a href="#" data-url="{}" onclick="submit_url(this)">{}</a>'
.format(generic_url, text)
))

369
kfet/auth/tests.py Normal file
View file

@ -0,0 +1,369 @@
# -*- coding: utf-8 -*-
from unittest import mock
from django.core import signing
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser, Group, Permission, User
from django.test import RequestFactory, TestCase
from kfet.forms import UserGroupForm
from kfet.models import Account
from . import KFET_GENERIC_TRIGRAMME, KFET_GENERIC_USERNAME
from .backends import AccountBackend, GenericBackend
from .middleware import TemporaryAuthMiddleware
from .models import GenericTeamToken
from .utils import get_kfet_generic_user
from .views import GenericLoginView
##
# Forms
##
class UserGroupFormTests(TestCase):
"""Test suite for UserGroupForm."""
def setUp(self):
# create user
self.user = User.objects.create(username="foo", password="foo")
# create some K-Fêt groups
prefix_name = "K-Fêt "
names = ["Group 1", "Group 2", "Group 3"]
self.kfet_groups = [
Group.objects.create(name=prefix_name+name)
for name in names
]
# create a non-K-Fêt group
self.other_group = Group.objects.create(name="Other group")
def test_choices(self):
"""Only K-Fêt groups are selectable."""
form = UserGroupForm(instance=self.user)
groups_field = form.fields['groups']
self.assertQuerysetEqual(
groups_field.queryset,
[repr(g) for g in self.kfet_groups],
ordered=False,
)
def test_keep_others(self):
"""User stays in its non-K-Fêt groups."""
user = self.user
# add user to a non-K-Fêt group
user.groups.add(self.other_group)
# add user to some K-Fêt groups through UserGroupForm
data = {
'groups': [group.pk for group in self.kfet_groups],
}
form = UserGroupForm(data, instance=user)
form.is_valid()
form.save()
self.assertQuerysetEqual(
user.groups.all(),
[repr(g) for g in [self.other_group] + self.kfet_groups],
ordered=False,
)
class KFetGenericUserTests(TestCase):
def test_exists(self):
"""
The account is set up when app is ready, so it should exist.
"""
generic = Account.objects.get_generic()
self.assertEqual(generic.trigramme, KFET_GENERIC_TRIGRAMME)
self.assertEqual(generic.user.username, KFET_GENERIC_USERNAME)
self.assertEqual(get_kfet_generic_user(), generic.user)
##
# Backends
##
class AccountBackendTests(TestCase):
def setUp(self):
self.request = RequestFactory().get('/')
def test_valid(self):
acc = Account(trigramme='000')
acc.change_pwd('valid')
acc.save({'username': 'user'})
auth = AccountBackend().authenticate(
self.request, kfet_password='valid')
self.assertEqual(auth, acc.user)
def test_invalid(self):
auth = AccountBackend().authenticate(
self.request, kfet_password='invalid')
self.assertIsNone(auth)
class GenericBackendTests(TestCase):
def setUp(self):
self.request = RequestFactory().get('/')
def test_valid(self):
token = GenericTeamToken.objects.create_token()
auth = GenericBackend().authenticate(
self.request, kfet_token=token.token)
self.assertEqual(auth, get_kfet_generic_user())
self.assertEqual(GenericTeamToken.objects.all().count(), 0)
def test_invalid(self):
auth = GenericBackend().authenticate(
self.request, kfet_token='invalid')
self.assertIsNone(auth)
##
# Views
##
class GenericLoginViewTests(TestCase):
def setUp(self):
patcher_messages = mock.patch('gestioncof.signals.messages')
patcher_messages.start()
self.addCleanup(patcher_messages.stop)
user_acc = Account(trigramme='000')
user_acc.save({'username': 'user'})
self.user = user_acc.user
self.user.set_password('user')
self.user.save()
team_acc = Account(trigramme='100')
team_acc.save({'username': 'team'})
self.team = team_acc.user
self.team.set_password('team')
self.team.save()
self.team.user_permissions.add(
Permission.objects.get(
content_type__app_label='kfet', codename='is_team'),
)
self.url = reverse('kfet.login.generic')
self.generic_user = get_kfet_generic_user()
def test_url(self):
self.assertEqual(self.url, '/k-fet/login/generic')
def test_notoken_get(self):
"""
Send confirmation for user to emit POST request, instead of GET.
"""
self.client.login(username='team', password='team')
r = self.client.get(self.url)
self.assertEqual(r.status_code, 200)
self.assertTemplateUsed(r, 'kfet/confirm_form.html')
def test_notoken_post(self):
"""
POST request without token in COOKIES sets a token and redirects to
logout url.
"""
self.client.login(username='team', password='team')
r = self.client.post(self.url)
self.assertRedirects(
r, '/logout?next={}'.format(self.url),
fetch_redirect_response=False,
)
def test_notoken_not_team(self):
"""
Logged in user must be a team user to initiate login as generic user.
"""
self.client.login(username='user', password='user')
# With GET.
r = self.client.get(self.url)
self.assertRedirects(
r, '/login?next={}'.format(self.url),
fetch_redirect_response=False,
)
# Also with POST.
r = self.client.post(self.url)
self.assertRedirects(
r, '/login?next={}'.format(self.url),
fetch_redirect_response=False,
)
def _set_signed_cookie(self, client, key, value):
signed_value = signing.get_cookie_signer(salt=key).sign(value)
client.cookies.load({key: signed_value})
def _is_cookie_deleted(self, client, key):
try:
self.assertNotIn(key, client.cookies)
except AssertionError:
try:
cookie = client.cookies[key]
# It also can be emptied.
self.assertEqual(cookie.value, '')
self.assertEqual(
cookie['expires'], 'Thu, 01-Jan-1970 00:00:00 GMT')
self.assertEqual(cookie['max-age'], 0)
except AssertionError:
raise AssertionError("The cookie '%s' still exists." % key)
def test_withtoken_valid(self):
"""
The kfet generic user is logged in.
"""
token = GenericTeamToken.objects.create(token='valid')
self._set_signed_cookie(
self.client, GenericLoginView.TOKEN_COOKIE_NAME, 'valid')
r = self.client.get(self.url)
self.assertRedirects(r, reverse('kfet.kpsul'))
self.assertEqual(r.wsgi_request.user, self.generic_user)
self._is_cookie_deleted(
self.client, GenericLoginView.TOKEN_COOKIE_NAME)
with self.assertRaises(GenericTeamToken.DoesNotExist):
token.refresh_from_db()
def test_withtoken_invalid(self):
"""
If token is invalid, delete it and try again.
"""
self._set_signed_cookie(
self.client, GenericLoginView.TOKEN_COOKIE_NAME, 'invalid')
r = self.client.get(self.url)
self.assertRedirects(r, self.url, fetch_redirect_response=False)
self.assertEqual(r.wsgi_request.user, AnonymousUser())
self._is_cookie_deleted(
self.client, GenericLoginView.TOKEN_COOKIE_NAME)
def test_flow_ok(self):
"""
A team user is logged in as the kfet generic user.
"""
self.client.login(username='team', password='team')
next_url = '/k-fet/'
r = self.client.post(
'{}?next={}'.format(self.url, next_url), follow=True)
self.assertEqual(r.wsgi_request.user, self.generic_user)
self.assertEqual(r.wsgi_request.path, '/k-fet/')
##
# Temporary authentication
#
# Includes:
# - TemporaryAuthMiddleware
# - temporary_auth context processor
##
class TemporaryAuthTests(TestCase):
def setUp(self):
patcher_messages = mock.patch('gestioncof.signals.messages')
patcher_messages.start()
self.addCleanup(patcher_messages.stop)
self.factory = RequestFactory()
self.middleware = TemporaryAuthMiddleware(mock.Mock())
user1_acc = Account(trigramme='000')
user1_acc.change_pwd('kfet_user1')
user1_acc.save({'username': 'user1'})
self.user1 = user1_acc.user
self.user1.set_password('user1')
self.user1.save()
user2_acc = Account(trigramme='100')
user2_acc.change_pwd('kfet_user2')
user2_acc.save({'username': 'user2'})
self.user2 = user2_acc.user
self.user2.set_password('user2')
self.user2.save()
self.perm = Permission.objects.get(
content_type__app_label='kfet', codename='is_team')
self.user2.user_permissions.add(self.perm)
def test_middleware_header(self):
"""
A user can be authenticated if ``HTTP_KFETPASSWORD`` header of a
request contains a valid kfet password.
"""
request = self.factory.get('/', HTTP_KFETPASSWORD='kfet_user2')
request.user = self.user1
self.middleware(request)
self.assertEqual(request.user, self.user2)
self.assertEqual(request.real_user, self.user1)
def test_middleware_post(self):
"""
A user can be authenticated if ``KFETPASSWORD`` of POST data contains
a valid kfet password.
"""
request = self.factory.post('/', {'KFETPASSWORD': 'kfet_user2'})
request.user = self.user1
self.middleware(request)
self.assertEqual(request.user, self.user2)
self.assertEqual(request.real_user, self.user1)
def test_middleware_invalid(self):
"""
The given password must be a password of an Account.
"""
request = self.factory.post('/', {'KFETPASSWORD': 'invalid'})
request.user = self.user1
self.middleware(request)
self.assertEqual(request.user, self.user1)
self.assertFalse(hasattr(request, 'real_user'))
def test_context_processor(self):
"""
Context variables give the real authenticated user and his permissions.
"""
self.client.login(username='user1', password='user1')
r = self.client.get('/k-fet/accounts/', HTTP_KFETPASSWORD='kfet_user2')
self.assertEqual(r.context['user'], self.user1)
self.assertNotIn('kfet.is_team', r.context['perms'])
def test_auth_not_persistent(self):
"""
The authentication is temporary, i.e. for one request.
"""
self.client.login(username='user1', password='user1')
r1 = self.client.get(
'/k-fet/accounts/', HTTP_KFETPASSWORD='kfet_user2')
self.assertEqual(r1.wsgi_request.user, self.user2)
r2 = self.client.get('/k-fet/accounts/')
self.assertEqual(r2.wsgi_request.user, self.user1)

34
kfet/auth/utils.py Normal file
View file

@ -0,0 +1,34 @@
import hashlib
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from kfet.models import Account
User = get_user_model()
def get_kfet_generic_user():
"""
Return the user related to the kfet generic account.
"""
return Account.objects.get_generic().user
def setup_kfet_generic_user(**kwargs):
"""
First steps of setup of the kfet generic user are done in a migration, as
it is more robust against database schema changes.
Following steps cannot be done from migration.
"""
generic = get_kfet_generic_user()
generic.user_permissions.add(
Permission.objects.get(
content_type__app_label='kfet',
codename='is_team',
)
)
def hash_password(password):
return hashlib.sha256(password.encode('utf-8')).hexdigest()

136
kfet/auth/views.py Normal file
View file

@ -0,0 +1,136 @@
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import Group, User
from django.contrib.auth.views import redirect_to_login
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Prefetch
from django.http import QueryDict
from django.shortcuts import redirect, render
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View
from django.views.decorators.http import require_http_methods
from django.views.generic.edit import CreateView, UpdateView
from .forms import GroupForm
from .models import GenericTeamToken
class GenericLoginView(View):
"""
View to authenticate as kfet generic user.
It is a 2-step view. First, issue a token if user is a team member and send
him to the logout view (for proper disconnect) with callback url to here.
Then authenticate the token to log in as the kfet generic user.
Token is stored in COOKIES to avoid share it with the authentication
provider, which can be external. Session is unusable as it will be cleared
on logout.
"""
TOKEN_COOKIE_NAME = 'kfettoken'
@method_decorator(require_http_methods(['GET', 'POST']))
def dispatch(self, request, *args, **kwargs):
token = request.get_signed_cookie(self.TOKEN_COOKIE_NAME, None)
if not token:
if not request.user.has_perm('kfet.is_team'):
return redirect_to_login(request.get_full_path())
if request.method == 'POST':
# Step 1: set token and logout user.
return self.prepare_auth()
else:
# GET request should not change server/client states. Send a
# confirmation template to emit a POST request.
return render(request, 'kfet/confirm_form.html', {
'title': _("Ouvrir une session partagée"),
'text': _(
"Êtes-vous sûr·e de vouloir ouvrir une session "
"partagée ?"
),
})
else:
# Step 2: validate token.
return self.validate_auth(token)
def prepare_auth(self):
# Issue token.
token = GenericTeamToken.objects.create_token()
# Prepare callback of logout.
here_url = reverse(login_generic)
if 'next' in self.request.GET:
# Keep given next page.
here_qd = QueryDict(mutable=True)
here_qd['next'] = self.request.GET['next']
here_url += '?{}'.format(here_qd.urlencode())
logout_url = reverse('cof-logout')
logout_qd = QueryDict(mutable=True)
logout_qd['next'] = here_url
logout_url += '?{}'.format(logout_qd.urlencode(safe='/'))
resp = redirect(logout_url)
resp.set_signed_cookie(
self.TOKEN_COOKIE_NAME, token.token, httponly=True)
return resp
def validate_auth(self, token):
# Authenticate with GenericBackend.
user = authenticate(request=self.request, kfet_token=token)
if user:
# Log in generic user.
login(self.request, user)
messages.success(self.request, _(
"K-Fêt — Ouverture d'une session partagée."
))
resp = redirect(self.get_next_url())
else:
# Try again.
resp = redirect(self.request.get_full_path())
# Prevents blocking due to an invalid COOKIE.
resp.delete_cookie(self.TOKEN_COOKIE_NAME)
return resp
def get_next_url(self):
return self.request.GET.get('next', reverse('kfet.kpsul'))
login_generic = GenericLoginView.as_view()
@permission_required('kfet.manage_perms')
def account_group(request):
user_pre = Prefetch(
'user_set',
queryset=User.objects.select_related('profile__account_kfet'),
)
groups = (
Group.objects
.filter(name__icontains='K-Fêt')
.prefetch_related('permissions', user_pre)
)
return render(request, 'kfet/account_group.html', {
'groups': groups,
})
class AccountGroupCreate(SuccessMessageMixin, CreateView):
model = Group
template_name = 'kfet/account_group_form.html'
form_class = GroupForm
success_message = 'Nouveau groupe : %(name)s'
success_url = reverse_lazy('kfet.account.group')
class AccountGroupUpdate(SuccessMessageMixin, UpdateView):
queryset = Group.objects.filter(name__icontains='K-Fêt')
template_name = 'kfet/account_group_form.html'
form_class = GroupForm
success_message = 'Groupe modifié : %(name)s'
success_url = reverse_lazy('kfet.account.group')

View file

@ -76,7 +76,7 @@ def account_create(request):
queries['users_notcof'].values_list('username', flat=True)) queries['users_notcof'].values_list('username', flat=True))
# Fetching data from the SPI # Fetching data from the SPI
if hasattr(settings, 'LDAP_SERVER_URL'): if getattr(settings, 'LDAP_SERVER_URL', None):
# Fetching # Fetching
ldap_query = '(&{:s})'.format(''.join( ldap_query = '(&{:s})'.format(''.join(
'(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=word) '(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=word)
@ -106,6 +106,7 @@ def account_create(request):
return render(request, "kfet/account_create_autocomplete.html", data) return render(request, "kfet/account_create_autocomplete.html", data)
@teamkfet_required
def account_search(request): def account_search(request):
if "q" not in request.GET: if "q" not in request.GET:
raise Http404 raise Http404

View file

@ -1,54 +0,0 @@
# -*- coding: utf-8 -*-
import hashlib
from django.contrib.auth.models import User, Permission
from gestioncof.models import CofProfile
from kfet.models import Account, GenericTeamToken
class KFetBackend(object):
def authenticate(self, request):
password = request.POST.get('KFETPASSWORD', '')
password = request.META.get('HTTP_KFETPASSWORD', password)
if not password:
return None
try:
password_sha256 = (
hashlib.sha256(password.encode('utf-8'))
.hexdigest()
)
account = Account.objects.get(password=password_sha256)
return account.cofprofile.user
except Account.DoesNotExist:
return None
class GenericTeamBackend(object):
def authenticate(self, username=None, token=None):
valid_token = GenericTeamToken.objects.get(token=token)
if username == 'kfet_genericteam' and valid_token:
# Création du user s'il n'existe pas déjà
user, _ = User.objects.get_or_create(username='kfet_genericteam')
profile, _ = CofProfile.objects.get_or_create(user=user)
account, _ = Account.objects.get_or_create(
cofprofile=profile,
trigramme='GNR')
# Ajoute la permission kfet.is_team à ce user
perm_is_team = Permission.objects.get(codename='is_team')
user.user_permissions.add(perm_is_team)
return user
return None
def get_user(self, user_id):
try:
return (
User.objects
.select_related('profile__account_kfet')
.get(pk=user_id)
)
except User.DoesNotExist:
return None

View file

@ -53,7 +53,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -83,7 +83,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -113,7 +113,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -143,7 +143,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -173,7 +173,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -203,7 +203,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -233,7 +233,7 @@
"page" "page"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -263,7 +263,7 @@
"kfetpage" "kfetpage"
], ],
"owner": [ "owner": [
"root" "kfet_genericteam"
], ],
"expired": false, "expired": false,
"first_published_at": "2017-05-28T04:20:00.000Z", "first_published_at": "2017-05-28T04:20:00.000Z",
@ -681,7 +681,7 @@
"fields": { "fields": {
"created_at": "2017-05-30T04:20:00.000Z", "created_at": "2017-05-30T04:20:00.000Z",
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"collection": 2, "collection": 2,
"title": "K-F\u00eat - Plan d'acc\u00e8s", "title": "K-F\u00eat - Plan d'acc\u00e8s",
@ -694,7 +694,7 @@
"fields": { "fields": {
"created_at": "2017-05-30T04:20:00.000Z", "created_at": "2017-05-30T04:20:00.000Z",
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"collection": 2, "collection": 2,
"title": "K-F\u00eat - Demande d'autorisation", "title": "K-F\u00eat - Demande d'autorisation",
@ -707,7 +707,7 @@
"fields": { "fields": {
"created_at": "2017-05-30T04:20:00.000Z", "created_at": "2017-05-30T04:20:00.000Z",
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"collection": 2, "collection": 2,
"title": "K-F\u00eat - Trait\u00e9 de Flipper Th\u00e9orique", "title": "K-F\u00eat - Trait\u00e9 de Flipper Th\u00e9orique",
@ -730,7 +730,7 @@
"title": "K-F\u00eat - Amazon Hunt", "title": "K-F\u00eat - Amazon Hunt",
"width": 200, "width": 200,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
] ]
} }
}, },
@ -750,7 +750,7 @@
"title": "K-F\u00eat - Fun Machine", "title": "K-F\u00eat - Fun Machine",
"width": 200, "width": 200,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
] ]
} }
}, },
@ -767,7 +767,7 @@
"title": "Hugo Manet", "title": "Hugo Manet",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -787,7 +787,7 @@
"title": "Lisa Gourdon", "title": "Lisa Gourdon",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -807,7 +807,7 @@
"title": "Pierre Quesselaire", "title": "Pierre Quesselaire",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -827,7 +827,7 @@
"title": "Thibault Scoquard", "title": "Thibault Scoquard",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -847,7 +847,7 @@
"title": "Arnaud Fanthomme", "title": "Arnaud Fanthomme",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -867,7 +867,7 @@
"title": "Vincent Balerdi", "title": "Vincent Balerdi",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -887,7 +887,7 @@
"title": "Nathana\u00ebl Willaime", "title": "Nathana\u00ebl Willaime",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -907,7 +907,7 @@
"title": "\u00c9lisabeth Miller", "title": "\u00c9lisabeth Miller",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -927,7 +927,7 @@
"title": "Arthur Lesage", "title": "Arthur Lesage",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -947,7 +947,7 @@
"title": "Sarah Asset", "title": "Sarah Asset",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -967,7 +967,7 @@
"title": "Alexandre Legrand", "title": "Alexandre Legrand",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -987,7 +987,7 @@
"title": "\u00c9tienne Baudel", "title": "\u00c9tienne Baudel",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1007,7 +1007,7 @@
"title": "Marine Snape", "title": "Marine Snape",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1027,7 +1027,7 @@
"title": "Anatole Gosset", "title": "Anatole Gosset",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1047,7 +1047,7 @@
"title": "Jacko Rastikian", "title": "Jacko Rastikian",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1067,7 +1067,7 @@
"title": "Alexandre Jannaud", "title": "Alexandre Jannaud",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1087,7 +1087,7 @@
"title": "Aur\u00e9lien Delobelle", "title": "Aur\u00e9lien Delobelle",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1107,7 +1107,7 @@
"title": "Sylvain Douteau", "title": "Sylvain Douteau",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1127,7 +1127,7 @@
"title": "Rapha\u00ebl Lescanne", "title": "Rapha\u00ebl Lescanne",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1147,7 +1147,7 @@
"title": "Romain Gourvil", "title": "Romain Gourvil",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1167,7 +1167,7 @@
"title": "Marie Labeye", "title": "Marie Labeye",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1187,7 +1187,7 @@
"title": "Oscar Blumberg", "title": "Oscar Blumberg",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1207,7 +1207,7 @@
"title": "Za\u00efd Allybokus", "title": "Za\u00efd Allybokus",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1227,7 +1227,7 @@
"title": "Damien Garreau", "title": "Damien Garreau",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1247,7 +1247,7 @@
"title": "Andr\u00e9a Londono-Lopez", "title": "Andr\u00e9a Londono-Lopez",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1267,7 +1267,7 @@
"title": "Tristan Roussel", "title": "Tristan Roussel",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1287,7 +1287,7 @@
"title": "Guillaume Vernade", "title": "Guillaume Vernade",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1307,7 +1307,7 @@
"title": "Lucas Mercier", "title": "Lucas Mercier",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1327,7 +1327,7 @@
"title": "Fran\u00e7ois Maillot", "title": "Fran\u00e7ois Maillot",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },
@ -1347,7 +1347,7 @@
"title": "Fabrice Catoire", "title": "Fabrice Catoire",
"collection": 2, "collection": 2,
"uploaded_by_user": [ "uploaded_by_user": [
"root" "kfet_genericteam"
], ],
"created_at": "2017-05-30T04:20:00.000Z" "created_at": "2017-05-30T04:20:00.000Z"
}, },

View file

@ -20,7 +20,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='KFetPage', name='KFetPage',
fields=[ fields=[
('page_ptr', models.OneToOneField(serialize=False, primary_key=True, parent_link=True, auto_created=True, to='wagtailcore.Page')), ('page_ptr', models.OneToOneField(serialize=False, primary_key=True, parent_link=True, auto_created=True, to='wagtailcore.Page', on_delete=models.CASCADE)),
('no_header', models.BooleanField(verbose_name='Sans en-tête', help_text="Coché, l'en-tête (avec le titre) de la page n'est pas affiché.", default=False)), ('no_header', models.BooleanField(verbose_name='Sans en-tête', help_text="Coché, l'en-tête (avec le titre) de la page n'est pas affiché.", default=False)),
('content', wagtail.wagtailcore.fields.StreamField((('rich', wagtail.wagtailcore.blocks.RichTextBlock(label='Éditeur')), ('carte', kfet.cms.models.MenuBlock()), ('group_team', wagtail.wagtailcore.blocks.StructBlock((('show_only', wagtail.wagtailcore.blocks.IntegerBlock(help_text='Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.', required=False, label='Montrer seulement')), ('members', wagtail.wagtailcore.blocks.ListBlock(wagtail.wagtailsnippets.blocks.SnippetChooserBlock(kfet.cms.models.MemberTeam), classname='team-group', label='K-Fêt-eux-ses'))))), ('group', wagtail.wagtailcore.blocks.StreamBlock((('rich', wagtail.wagtailcore.blocks.RichTextBlock(label='Éditeur')), ('carte', kfet.cms.models.MenuBlock()), ('group_team', wagtail.wagtailcore.blocks.StructBlock((('show_only', wagtail.wagtailcore.blocks.IntegerBlock(help_text='Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.', required=False, label='Montrer seulement')), ('members', wagtail.wagtailcore.blocks.ListBlock(wagtail.wagtailsnippets.blocks.SnippetChooserBlock(kfet.cms.models.MemberTeam), classname='team-group', label='K-Fêt-eux-ses')))))), label='Contenu groupé'))), verbose_name='Contenu')), ('content', wagtail.wagtailcore.fields.StreamField((('rich', wagtail.wagtailcore.blocks.RichTextBlock(label='Éditeur')), ('carte', kfet.cms.models.MenuBlock()), ('group_team', wagtail.wagtailcore.blocks.StructBlock((('show_only', wagtail.wagtailcore.blocks.IntegerBlock(help_text='Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.', required=False, label='Montrer seulement')), ('members', wagtail.wagtailcore.blocks.ListBlock(wagtail.wagtailsnippets.blocks.SnippetChooserBlock(kfet.cms.models.MemberTeam), classname='team-group', label='K-Fêt-eux-ses'))))), ('group', wagtail.wagtailcore.blocks.StreamBlock((('rich', wagtail.wagtailcore.blocks.RichTextBlock(label='Éditeur')), ('carte', kfet.cms.models.MenuBlock()), ('group_team', wagtail.wagtailcore.blocks.StructBlock((('show_only', wagtail.wagtailcore.blocks.IntegerBlock(help_text='Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.', required=False, label='Montrer seulement')), ('members', wagtail.wagtailcore.blocks.ListBlock(wagtail.wagtailsnippets.blocks.SnippetChooserBlock(kfet.cms.models.MemberTeam), classname='team-group', label='K-Fêt-eux-ses')))))), label='Contenu groupé'))), verbose_name='Contenu')),
('layout', models.CharField(max_length=255, choices=[('kfet/base_col_1.html', 'Une colonne : centrée sur la page'), ('kfet/base_col_2.html', 'Deux colonnes : fixe à gauche, contenu à droite'), ('kfet/base_col_mult.html', 'Contenu scindé sur plusieurs colonnes')], help_text='Comment cette page devrait être affichée ?', verbose_name='Template', default='kfet/base_col_mult.html')), ('layout', models.CharField(max_length=255, choices=[('kfet/base_col_1.html', 'Une colonne : centrée sur la page'), ('kfet/base_col_2.html', 'Deux colonnes : fixe à gauche, contenu à droite'), ('kfet/base_col_mult.html', 'Contenu scindé sur plusieurs colonnes')], help_text='Comment cette page devrait être affichée ?', verbose_name='Template', default='kfet/base_col_mult.html')),

View file

@ -1,18 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.contrib.auth.context_processors import PermWrapper
from kfet.config import kfet_config from kfet.config import kfet_config
def auth(request):
if hasattr(request, 'real_user'):
return {
'user': request.real_user,
'perms': PermWrapper(request.real_user),
}
return {}
def config(request): def config(request):
return {'kfet_config': kfet_config} return {'kfet_config': kfet_config}

View file

@ -5,9 +5,8 @@ from decimal import Decimal
from django import forms from django import forms
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.contrib.auth.models import User, Group, Permission from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType from django.forms import modelformset_factory
from django.forms import modelformset_factory, widgets
from django.utils import timezone from django.utils import timezone
from djconfig.forms import ConfigForm from djconfig.forms import ConfigForm
@ -18,6 +17,8 @@ from kfet.models import (
TransferGroup, Supplier) TransferGroup, Supplier)
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from .auth.forms import UserGroupForm # noqa
# ----- # -----
# Widgets # Widgets
@ -128,61 +129,6 @@ class UserRestrictTeamForm(UserForm):
fields = ['first_name', 'last_name', 'email'] fields = ['first_name', 'last_name', 'email']
class UserGroupForm(forms.ModelForm):
groups = forms.ModelMultipleChoiceField(
Group.objects.filter(name__icontains='K-Fêt'),
label='Statut équipe',
required=False)
def clean_groups(self):
kfet_groups = self.cleaned_data.get('groups')
other_groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return list(kfet_groups) + list(other_groups)
class Meta:
model = User
fields = ['groups']
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
queryset = Permission.objects.filter(
content_type__in=ContentType.objects.filter(app_label="kfet"),
)
super().__init__(
queryset=queryset,
widget=widgets.CheckboxSelectMultiple,
*args, **kwargs
)
def label_from_instance(self, obj):
return obj.name
class GroupForm(forms.ModelForm):
permissions = KFetPermissionsField()
def clean_name(self):
name = self.cleaned_data['name']
return 'K-Fêt %s' % name
def clean_permissions(self):
kfet_perms = self.cleaned_data['permissions']
# TODO: With Django >=1.11, the QuerySet method 'difference' can be used.
# other_groups = self.instance.permissions.difference(
# self.fields['permissions'].queryset
# )
other_perms = self.instance.permissions.exclude(
pk__in=[p.pk for p in self.fields['permissions'].queryset],
)
return list(kfet_perms) + list(other_perms)
class Meta:
model = Group
fields = ['name', 'permissions']
class AccountNegativeForm(forms.ModelForm): class AccountNegativeForm(forms.ModelForm):
class Meta: class Meta:
model = AccountNegative model = AccountNegative

View file

@ -1,29 +0,0 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from kfet.backends import KFetBackend
class KFetAuthenticationMiddleware(object):
"""Authenticate another user for this request if KFetBackend succeeds.
By the way, if a user is authenticated, we refresh its from db to add
values from CofProfile and Account of this user.
"""
def process_request(self, request):
if request.user.is_authenticated():
# avoid multiple db accesses in views and templates
user_pk = request.user.pk
request.user = (
User.objects
.select_related('profile__account_kfet')
.get(pk=user_pk)
)
kfet_backend = KFetBackend()
temp_request_user = kfet_backend.authenticate(request)
if temp_request_user:
request.real_user = request.user
request.user = temp_request_user

View file

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('kfet', '0057_merge'),
]
operations = [
migrations.DeleteModel(
name='GenericTeamToken',
),
]

View file

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from kfet.auth import KFET_GENERIC_TRIGRAMME, KFET_GENERIC_USERNAME
def setup_kfet_generic_user(apps, schema_editor):
"""
Setup models instances for the kfet generic account.
Username and trigramme are retrieved from kfet.auth.__init__ module.
Other data are registered here.
See also setup_kfet_generic_user from kfet.auth.utils module.
"""
User = apps.get_model('auth', 'User')
CofProfile = apps.get_model('gestioncof', 'CofProfile')
Account = apps.get_model('kfet', 'Account')
user, _ = User.objects.update_or_create(
username=KFET_GENERIC_USERNAME,
defaults={
'first_name': 'Compte générique K-Fêt',
},
)
profile, _ = CofProfile.objects.update_or_create(user=user)
account, _ = Account.objects.update_or_create(
cofprofile=profile,
defaults={
'trigramme': KFET_GENERIC_TRIGRAMME,
},
)
class Migration(migrations.Migration):
dependencies = [
('kfet', '0058_delete_genericteamtoken'),
]
operations = [
migrations.RunPython(setup_kfet_generic_user),
]

View file

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('kfet', '0059_create_generic'),
]
operations = [
migrations.AlterField(
model_name='supplier',
name='address',
field=models.TextField(verbose_name='adresse', blank=True),
),
migrations.AlterField(
model_name='supplier',
name='articles',
field=models.ManyToManyField(verbose_name='articles vendus', through='kfet.SupplierArticle', related_name='suppliers', to='kfet.Article'),
),
migrations.AlterField(
model_name='supplier',
name='comment',
field=models.TextField(verbose_name='commentaire', blank=True),
),
migrations.AlterField(
model_name='supplier',
name='email',
field=models.EmailField(max_length=254, verbose_name='adresse mail', blank=True),
),
migrations.AlterField(
model_name='supplier',
name='phone',
field=models.CharField(max_length=20, verbose_name='téléphone', blank=True),
),
]

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('kfet', '0060_amend_supplier'),
]
operations = [
migrations.AlterModelOptions(
name='account',
options={'permissions': (('is_team', 'Is part of the team'), ('manage_perms', 'Gérer les permissions K-Fêt'), ('manage_addcosts', 'Gérer les majorations'), ('edit_balance_account', "Modifier la balance d'un compte"), ('change_account_password', "Modifier le mot de passe d'une personne de l'équipe"), ('special_add_account', 'Créer un compte avec une balance initiale'), ('can_force_close', 'Fermer manuellement la K-Fêt'), ('see_config', 'Voir la configuration K-Fêt'), ('change_config', 'Modifier la configuration K-Fêt'))},
),
]

View file

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('kfet', '0061_add_perms_config'),
]
operations = [
migrations.DeleteModel(
name='GlobalPermissions',
),
]

View file

@ -1,18 +1,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.db import models from django.db import models
from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
from django.contrib.auth.models import User from django.contrib.auth.models import User
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from django.urls import reverse
from django.utils.six.moves import reduce from django.utils.six.moves import reduce
from django.utils import timezone from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.db import transaction from django.db import transaction
from django.db.models import F from django.db.models import F
from datetime import date from datetime import date
import re import re
import hashlib
from .auth import KFET_GENERIC_TRIGRAMME
from .auth.models import GenericTeamToken # noqa
from .config import kfet_config from .config import kfet_config
from .utils import to_ukf from .utils import to_ukf
@ -33,6 +36,23 @@ class AccountManager(models.Manager):
return super().get_queryset().select_related('cofprofile__user', return super().get_queryset().select_related('cofprofile__user',
'negative') 'negative')
def get_generic(self):
"""
Get the kfet generic account instance.
"""
return self.get(trigramme=KFET_GENERIC_TRIGRAMME)
def get_by_password(self, password):
"""
Get a kfet generic account by clear password.
Raises Account.DoesNotExist if no Account has this password.
"""
from .auth.utils import hash_password
if password is None:
raise self.model.DoesNotExist
return self.get(password=hash_password(password))
class Account(models.Model): class Account(models.Model):
objects = AccountManager() objects = AccountManager()
@ -75,6 +95,8 @@ class Account(models.Model):
('special_add_account', ('special_add_account',
"Créer un compte avec une balance initiale"), "Créer un compte avec une balance initiale"),
('can_force_close', "Fermer manuellement la K-Fêt"), ('can_force_close', "Fermer manuellement la K-Fêt"),
('see_config', "Voir la configuration K-Fêt"),
('change_config', "Modifier la configuration K-Fêt"),
) )
def __str__(self): def __str__(self):
@ -236,10 +258,9 @@ class Account(models.Model):
self.cofprofile = cof self.cofprofile = cof
super(Account, self).save(*args, **kwargs) super(Account, self).save(*args, **kwargs)
def change_pwd(self, pwd): def change_pwd(self, clear_password):
pwd_sha256 = hashlib.sha256(pwd.encode('utf-8'))\ from .auth.utils import hash_password
.hexdigest() self.password = hash_password(clear_password)
self.password = pwd_sha256
# Surcharge de delete # Surcharge de delete
# Pas de suppression possible # Pas de suppression possible
@ -522,21 +543,24 @@ class InventoryArticle(models.Model):
self.stock_error = self.stock_new - self.stock_old self.stock_error = self.stock_new - self.stock_old
super(InventoryArticle, self).save(*args, **kwargs) super(InventoryArticle, self).save(*args, **kwargs)
@python_2_unicode_compatible
class Supplier(models.Model): class Supplier(models.Model):
articles = models.ManyToManyField( articles = models.ManyToManyField(
Article, Article,
through = 'SupplierArticle', verbose_name=_("articles vendus"),
related_name = "suppliers") through='SupplierArticle',
name = models.CharField("nom", max_length = 45) related_name='suppliers',
address = models.TextField("adresse") )
email = models.EmailField("adresse mail") name = models.CharField(_("nom"), max_length=45)
phone = models.CharField("téléphone", max_length = 10) address = models.TextField(_("adresse"), blank=True)
comment = models.TextField("commentaire") email = models.EmailField(_("adresse mail"), blank=True)
phone = models.CharField(_("téléphone"), max_length=20, blank=True)
comment = models.TextField(_("commentaire"), blank=True)
def __str__(self): def __str__(self):
return self.name return self.name
class SupplierArticle(models.Model): class SupplierArticle(models.Model):
supplier = models.ForeignKey( supplier = models.ForeignKey(
Supplier, on_delete = models.PROTECT) Supplier, on_delete = models.PROTECT)
@ -710,7 +734,3 @@ class Operation(models.Model):
return templates[self.type].format(nb=self.article_nb, return templates[self.type].format(nb=self.article_nb,
article=self.article, article=self.article,
amount=self.amount) amount=self.amount)
class GenericTeamToken(models.Model):
token = models.CharField(max_length = 50, unique = True)

View file

@ -85,7 +85,7 @@ class OpenKfet(CachedMixin, object):
'admin_status': self.admin_status(status), 'admin_status': self.admin_status(status),
'force_close': self.force_close, 'force_close': self.force_close,
} }
return base, {**base, **restrict} return base, dict(base, **restrict)
def export(self, user): def export(self, user):
"""Export internal state for a given user. """Export internal state for a given user.

View file

@ -1,5 +1,6 @@
import json import json
from datetime import timedelta from datetime import timedelta
from unittest import mock
from django.contrib.auth.models import AnonymousUser, Permission, User from django.contrib.auth.models import AnonymousUser, Permission, User
from django.test import Client from django.test import Client
@ -118,6 +119,11 @@ class OpenKfetViewsTest(ChannelTestCase):
"""OpenKfet views unit-tests suite.""" """OpenKfet views unit-tests suite."""
def setUp(self): def setUp(self):
# Need this (and here) because of '<client>.login' in setUp
patcher_messages = mock.patch('gestioncof.signals.messages')
patcher_messages.start()
self.addCleanup(patcher_messages.stop)
# get some permissions # get some permissions
perms = { perms = {
'kfet.is_team': Permission.objects.get(codename='is_team'), 'kfet.is_team': Permission.objects.get(codename='is_team'),
@ -194,7 +200,8 @@ class OpenKfetConsumerTest(ChannelTestCase):
OpenKfetConsumer.group_send('kfet.open.team', {'test': 'plop'}) OpenKfetConsumer.group_send('kfet.open.team', {'test': 'plop'})
self.assertIsNone(c.receive()) self.assertIsNone(c.receive())
def test_team_user(self): @mock.patch('gestioncof.signals.messages')
def test_team_user(self, mock_messages):
"""Team user is added to kfet.open.team group.""" """Team user is added to kfet.open.team group."""
# setup team user and its client # setup team user and its client
t = User.objects.create_user('team', '', 'team') t = User.objects.create_user('team', '', 'team')
@ -224,6 +231,11 @@ class OpenKfetScenarioTest(ChannelTestCase):
"""OpenKfet functionnal tests suite.""" """OpenKfet functionnal tests suite."""
def setUp(self): def setUp(self):
# Need this (and here) because of '<client>.login' in setUp
patcher_messages = mock.patch('gestioncof.signals.messages')
patcher_messages.start()
self.addCleanup(patcher_messages.stop)
# anonymous client (for views) # anonymous client (for views)
self.c = Client() self.c = Client()
# anonymous client (for websockets) # anonymous client (for websockets)

View file

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
from django.contrib import messages
from django.contrib.auth.signals import user_logged_in
from django.core.urlresolvers import reverse
from django.dispatch import receiver
from django.utils.safestring import mark_safe
@receiver(user_logged_in)
def messages_on_login(sender, request, user, **kwargs):
if (not user.username == 'kfet_genericteam' and
user.has_perm('kfet.is_team') and
hasattr(request, 'GET') and
'k-fet' in request.GET.get('next', '')):
messages.info(request, mark_safe(
'<a href="{}" class="genericteam" target="_blank">'
' Connexion en utilisateur partagé ?'
'</a>'
.format(reverse('kfet.login.genericteam'))
))

View file

@ -133,27 +133,37 @@ class Config {
} }
/*
* CSRF Token
*/
$(document).ready(function() { var csrftoken = '';
if (typeof Cookies !== 'undefined') { if (typeof Cookies !== 'undefined')
// Retrieving csrf token
csrftoken = Cookies.get('csrftoken'); csrftoken = Cookies.get('csrftoken');
// Appending csrf token to ajax post requests
function csrfSafeMethod(method) { // Add CSRF token in header of AJAX requests.
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection // these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
} }
$.ajaxSetup({
$.ajaxSetup({
beforeSend: function(xhr, settings) { beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) { if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken); xhr.setRequestHeader("X-CSRFToken", csrftoken);
} }
} }
});
}
}); });
function add_csrf_form($form) {
$form.append(
$('<input>', {'name': 'csrfmiddlewaretoken', 'value': csrftoken})
);
}
/* /*
* Capslock management * Capslock management
*/ */
@ -429,3 +439,28 @@ jconfirm.defaults = {
confirmButton: '<span class="glyphicon glyphicon-ok"></span>', confirmButton: '<span class="glyphicon glyphicon-ok"></span>',
cancelButton: '<span class="glyphicon glyphicon-remove"></span>' cancelButton: '<span class="glyphicon glyphicon-remove"></span>'
}; };
/**
* Create form node, given an url used as 'action', with csrftoken set.
*/
function create_form(url) {
let $form = $('<form>', {
'action': url,
'method': 'post',
});
add_csrf_form($form);
return $form;
}
/**
* Emit a POST request from <a> tag.
*
* Usage:
* <a href="#" data-url="{target url}" onclick="submit_url(this)">{}</a>
*/
function submit_url(el) {
let url = $(el).data('url');
create_form(url).appendTo($('body')).submit();
}

View file

@ -1,10 +1,12 @@
{% load static %} {% load i18n static %}
{% load wagtailcore_tags %} {% load wagtailcore_tags %}
{% slugurl "kfet" as kfet_home_url %}
<nav class="navbar navbar-fixed-top"> <nav class="navbar navbar-fixed-top">
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="{% slugurl "k-fet" %}"> <a class="navbar-brand" href="{{ kfet_home_url }}">
<img src="{% static 'kfet/img/logo3.png' %}"> <img src="{% static 'kfet/img/logo3.png' %}">
</a> </a>
</div> </div>
@ -62,7 +64,8 @@
</ul> </ul>
<ul class="nav navbar-nav navbar-right nav-app"> <ul class="nav navbar-nav navbar-right nav-app">
{% if user.username == 'kfet_genericteam' %} {% if user.username == 'kfet_genericteam' %}
{% include "kfet/nav_item.html" with text="Équipe standard" %} {% trans "Session partagée" as shared_str %}
{% include "kfet/nav_item.html" with text=shared_str glyphicon="sunglasses" %}
{% elif user.is_authenticated and not user.profile.account_kfet %} {% elif user.is_authenticated and not user.profile.account_kfet %}
{% include "kfet/nav_item.html" with class="disabled" href="#" glyphicon="user" text="Mon compte" %} {% include "kfet/nav_item.html" with class="disabled" href="#" glyphicon="user" text="Mon compte" %}
{% elif user.profile.account_kfet.readable %} {% elif user.profile.account_kfet.readable %}
@ -87,14 +90,18 @@
<li><a href="{% url 'kfet.order' %}">Commandes</a></li> <li><a href="{% url 'kfet.order' %}">Commandes</a></li>
{% if user.username != 'kfet_genericteam' %} {% if user.username != 'kfet_genericteam' %}
<li class="divider"></li> <li class="divider"></li>
<li><a href="{% url 'kfet.login.genericteam' %}" target="_blank" class="genericteam">Connexion standard</a></li> <li>
<a href="#" data-url="{% url "kfet.login.generic" %}" onclick="submit_url(this)">
{% trans "Ouvrir une session partagée" %}
</a>
</li>
{% endif %} {% endif %}
{% if perms.kfet.change_settings %} {% if perms.kfet.change_settings %}
<li><a href="{% url 'kfet.settings' %}">Paramètres</a></li> <li><a href="{% url 'kfet.settings' %}">Paramètres</a></li>
{% endif %} {% endif %}
<li class="divider"></li> <li class="divider"></li>
<li> <li>
<a href="{% url "cof-logout" %}?next={% slugurl "k-fet" %}"> <a href="{% url "cof-logout" %}?next={{ kfet_home_url|urlencode }}">
<span class="glyphicon glyphicon-log-out"></span><span>Déconnexion</span> <span class="glyphicon glyphicon-log-out"></span><span>Déconnexion</span>
</a> </a>
</li> </li>
@ -103,13 +110,13 @@
{% endif %} {% endif %}
{% if user.is_authenticated and not perms.kfet.is_team %} {% if user.is_authenticated and not perms.kfet.is_team %}
<li> <li>
<a href="{% url "cof-logout" %}?next={% slugurl "k-fet" %}" title="Déconnexion"> <a href="{% url "cof-logout" %}?next={{ kfet_home_url|urlencode }}" title="Déconnexion">
<span class="glyphicon glyphicon-log-out"></span> <span class="glyphicon glyphicon-log-out"></span>
</a> </a>
</li> </li>
{% elif not user.is_authenticated %} {% elif not user.is_authenticated %}
<li> <li>
<a href="{% url "cof-login" %}?next={{ request.path }}" title="Connexion"> <a href="{% url "cof-login" %}?next={{ request.path|urlencode }}" title="Connexion">
<span>Connexion</span><!-- <span>Connexion</span><!--
--><span class="glyphicon glyphicon-log-in"></span> --><span class="glyphicon glyphicon-log-in"></span>
</a> </a>
@ -118,13 +125,3 @@
</ul> </ul>
</div> </div>
</nav> </nav>
<script type="text/javascript">
$(document).ready(function () {
$('.genericteam').on('click', function () {
setTimeout(function () { location.reload() }, 1000);
});
});
</script>

View file

@ -0,0 +1,20 @@
{% extends "kfet/base_form.html" %}
{% load i18n %}
{% block title %}{{ title }}{% endblock %}
{% block header %}{% endblock %}
{% block main-class %}main-bg main-padding text-center{% endblock %}
{% block main-size %}col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3{% endblock %}
{% block main %}
<form action="{{ confirm_url }}" method="post">
<p>
{{ text }}
</p>
<button type="submit" class="btn btn-primary">{% trans "Confirmer" %}</button>
{% csrf_token %}
</form>
{% endblock %}

View file

@ -1,7 +0,0 @@
{% extends 'kfet/base.html' %}
{% block extra_head %}
<script type="text/javascript">
close();
</script>
{% endblock %}

View file

@ -4,6 +4,8 @@
<li class="{% if not href %}navbar-text{% endif %} {% if request.path == href %}active{% endif %} {{ class }}"> <li class="{% if not href %}navbar-text{% endif %} {% if request.path == href %}active{% endif %} {{ class }}">
{% if href %} {% if href %}
<a href="{{ href }}" title="{{ text }}"> <a href="{{ href }}" title="{{ text }}">
{% else %}
<span title="{{ text }}">
{% endif %}<!-- {% endif %}<!--
{% if glyphicon %} {% if glyphicon %}
--><span class="glyphicon glyphicon-{{ glyphicon }}"></span><!-- --><span class="glyphicon glyphicon-{{ glyphicon }}"></span><!--
@ -14,5 +16,7 @@
--> -->
{% if href %} {% if href %}
</a> </a>
{% else %}
</span>
{% endif %} {% endif %}
</li> </li>

View file

@ -11,7 +11,7 @@
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover table-condensed table-condensed-input text-center"> <table class="table table-hover table-condensed table-condensed-input text-center table-striped">
<thead> <thead>
<tr> <tr>
<td rowspan="2">Article</td> <td rowspan="2">Article</td>

View file

@ -1,56 +0,0 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.contrib.auth.models import User, Group
from kfet.forms import UserGroupForm
class UserGroupFormTests(TestCase):
"""Test suite for UserGroupForm."""
def setUp(self):
# create user
self.user = User.objects.create(username="foo", password="foo")
# create some K-Fêt groups
prefix_name = "K-Fêt "
names = ["Group 1", "Group 2", "Group 3"]
self.kfet_groups = [
Group.objects.create(name=prefix_name+name)
for name in names
]
# create a non-K-Fêt group
self.other_group = Group.objects.create(name="Other group")
def test_choices(self):
"""Only K-Fêt groups are selectable."""
form = UserGroupForm(instance=self.user)
groups_field = form.fields['groups']
self.assertQuerysetEqual(
groups_field.queryset,
[repr(g) for g in self.kfet_groups],
ordered=False,
)
def test_keep_others(self):
"""User stays in its non-K-Fêt groups."""
user = self.user
# add user to a non-K-Fêt group
user.groups.add(self.other_group)
# add user to some K-Fêt groups through UserGroupForm
data = {
'groups': [group.pk for group in self.kfet_groups],
}
form = UserGroupForm(data, instance=user)
form.is_valid()
form.save()
self.assertQuerysetEqual(
user.groups.all(),
[repr(g) for g in [self.other_group] + self.kfet_groups],
ordered=False,
)

25
kfet/tests/test_models.py Normal file
View file

@ -0,0 +1,25 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from kfet.models import Account
User = get_user_model()
class AccountTests(TestCase):
def setUp(self):
self.account = Account(trigramme='000')
self.account.save({'username': 'user'})
def test_password(self):
self.account.change_pwd('anna')
self.account.save()
self.assertEqual(Account.objects.get_by_password('anna'), self.account)
with self.assertRaises(Account.DoesNotExist):
Account.objects.get_by_password(None)
with self.assertRaises(Account.DoesNotExist):
Account.objects.get_by_password('bernard')

View file

@ -0,0 +1,95 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from gestioncof.models import CofProfile
from ..models import Account
from .testcases import TestCaseMixin
from .utils import (
create_user, create_team, create_root, get_perms, user_add_perms,
)
User = get_user_model()
class UserHelpersTests(TestCaseMixin, TestCase):
def test_create_user(self):
"""create_user creates a basic user and its account."""
u = create_user()
a = u.profile.account_kfet
self.assertInstanceExpected(u, {
'get_full_name': 'first last',
'username': 'user',
})
self.assertFalse(u.user_permissions.exists())
self.assertEqual('000', a.trigramme)
def test_create_team(self):
u = create_team()
a = u.profile.account_kfet
self.assertInstanceExpected(u, {
'get_full_name': 'team member',
'username': 'team',
})
self.assertTrue(u.has_perm('kfet.is_team'))
self.assertEqual('100', a.trigramme)
def test_create_root(self):
u = create_root()
a = u.profile.account_kfet
self.assertInstanceExpected(u, {
'get_full_name': 'super user',
'username': 'root',
'is_superuser': True,
'is_staff': True,
})
self.assertEqual('200', a.trigramme)
class PermHelpersTest(TestCaseMixin, TestCase):
def setUp(self):
cts = ContentType.objects.get_for_models(Account, CofProfile)
self.perm1 = Permission.objects.create(
content_type=cts[Account],
codename='test_perm',
name='Perm for test',
)
self.perm2 = Permission.objects.create(
content_type=cts[CofProfile],
codename='another_test_perm',
name='Another one',
)
self.perm_team = Permission.objects.get(
content_type__app_label='kfet',
codename='is_team',
)
def test_get_perms(self):
perms = get_perms('kfet.test_perm', 'gestioncof.another_test_perm')
self.assertDictEqual(perms, {
'kfet.test_perm': self.perm1,
'gestioncof.another_test_perm': self.perm2,
})
def test_user_add_perms(self):
user = User.objects.create_user(username='user', password='user')
user.user_permissions.add(self.perm1)
user_add_perms(user, ['kfet.is_team', 'gestioncof.another_test_perm'])
self.assertQuerysetEqual(
user.user_permissions.all(),
map(repr, [self.perm1, self.perm2, self.perm_team]),
ordered=False,
)

File diff suppressed because it is too large Load diff

353
kfet/tests/testcases.py Normal file
View file

@ -0,0 +1,353 @@
from unittest import mock
from urllib.parse import parse_qs, urlparse
from django.core.urlresolvers import reverse
from django.http import QueryDict
from django.test import Client
from django.utils import timezone
from django.utils.functional import cached_property
from .utils import create_root, create_team, create_user
class TestCaseMixin:
"""Extends TestCase for kfet application tests."""
def assertForbidden(self, response):
"""
Test that the response (retrieved with a Client) is a denial of access.
The response should verify one of the following:
- its HTTP response code is 403,
- it redirects to the login page with a GET parameter named 'next'
whose value is the url of the requested page.
"""
request = response.wsgi_request
try:
try:
# Is this an HTTP Forbidden response ?
self.assertEqual(response.status_code, 403)
except AssertionError:
# A redirection to the login view is fine too.
# Let's build the login url with the 'next' param on current
# page.
full_path = request.get_full_path()
querystring = QueryDict(mutable=True)
querystring['next'] = full_path
login_url = '/login?' + querystring.urlencode(safe='/')
# We don't focus on what the login view does.
# So don't fetch the redirect.
self.assertRedirects(
response, login_url,
fetch_redirect_response=False,
)
except AssertionError:
raise AssertionError(
"%(http_method)s request at %(path)s should be forbidden for "
"%(username)s user.\n"
"Response isn't 403, nor a redirect to login view. Instead, "
"response code is %(code)d." % {
'http_method': request.method,
'path': request.get_full_path(),
'username': (
"'{}'".format(request.user)
if request.user.is_authenticated
else 'anonymous'
),
'code': response.status_code,
}
)
def assertForbiddenKfet(self, response, form_ctx='form'):
"""
Test that a response (retrieved with a Client) contains error due to
lack of kfet permissions.
It checks that 'Permission refusée' is present in the non-field errors
of the form of response context at key 'form_ctx', or present in
messages.
This should be used for pages which can be accessed by the kfet team
members, but require additionnal permission(s) to make an operation.
"""
try:
self.assertEqual(response.status_code, 200)
try:
form = response.context[form_ctx]
self.assertIn("Permission refusée", form.non_field_errors())
except (AssertionError, AttributeError, KeyError):
messages = [str(msg) for msg in response.context['messages']]
self.assertIn("Permission refusée", messages)
except AssertionError:
request = response.wsgi_request
raise AssertionError(
"%(http_method)s request at %(path)s should raise an error "
"for %(username)s user.\n"
"Cannot find any errors in non-field errors of form "
"'%(form_ctx)s', nor in messages." % {
'http_method': request.method,
'path': request.get_full_path(),
'username': (
"'%s'" % request.user
if request.user.is_authenticated
else 'anonymous'
),
'form_ctx': form_ctx,
}
)
def assertInstanceExpected(self, instance, expected):
"""
Test that the values of the attributes and without-argument methods of
'instance' are equal to 'expected' pairs.
"""
for attr, expected_value in expected.items():
value = getattr(instance, attr)
if callable(value):
value = value()
self.assertEqual(value, expected_value)
def assertUrlsEqual(self, actual, expected):
"""
Test that the url 'actual' is as 'expected'.
Arguments:
actual (str): Url to verify.
expected: Two forms are accepted.
* (str): Expected url. Strings equality is checked.
* (dict): Its keys must be attributes of 'urlparse(actual)'.
Equality is checked for each present key, except for
'query' which must be a dict of the expected query string
parameters.
"""
if type(expected) == dict:
parsed = urlparse(actual)
for part, expected_part in expected.items():
if part == 'query':
self.assertDictEqual(
parse_qs(parsed.query),
expected.get('query', {}),
)
else:
self.assertEqual(getattr(parsed, part), expected_part)
else:
self.assertEqual(actual, expected)
class ViewTestCaseMixin(TestCaseMixin):
"""
TestCase extension to ease tests of kfet views.
Urls concerns
-------------
# Basic usage
Attributes:
url_name (str): Name of view under test, as given to 'reverse'
function.
url_args (list, optional): Will be given to 'reverse' call.
url_kwargs (dict, optional): Same.
url_expcted (str): What 'reverse' should return given previous
attributes.
View url can then be accessed at the 'url' attribute.
# Advanced usage
If multiple combinations of url name, args, kwargs can be used for a view,
it is possible to define 'urls_conf' attribute. It must be a list whose
each item is a dict defining arguments for 'reverse' call ('name', 'args',
'kwargs' keys) and its expected result ('expected' key).
The reversed urls can be accessed at the 't_urls' attribute.
Users concerns
--------------
During setup, three users are created with their kfet account:
- 'user': a basic user without any permission, account trigramme: 000,
- 'team': a user with kfet.is_team permission, account trigramme: 100,
- 'root': a superuser, account trigramme: 200.
Their password is their username.
One can create additionnal users with 'get_users_extra' method, or prevent
these 3 users to be created with 'get_users_base' method. See these two
methods for further informations.
By using 'register_user' method, these users can then be accessed at
'users' attribute by their label. Similarly, their kfet account is
registered on 'accounts' attribute.
A user label can be given to 'auth_user' attribute. The related user is
then authenticated on self.client during test setup. Its value defaults to
'None', meaning no user is authenticated.
Automated tests
---------------
# Url reverse
Based on url-related attributes/properties, the test 'test_urls' checks
that expected url is returned by 'reverse' (once with basic url usage and
each for advanced usage).
# Forbidden responses
The 'test_forbidden' test verifies that each user, from labels of
'auth_forbidden' attribute, can't access the url(s), i.e. response should
be a 403, or a redirect to login view.
Tested HTTP requests are given by 'http_methods' attribute. Additional data
can be given by defining an attribute '<method(lowercase)>_data'.
"""
url_name = None
url_expected = None
http_methods = ['GET']
auth_user = None
auth_forbidden = []
def setUp(self):
"""
Warning: Do not forget to call super().setUp() in subclasses.
"""
# Signals handlers on login/logout send messages.
# Due to the way the Django' test Client performs login, this raise an
# error. As workaround, we mock the Django' messages module.
patcher_messages = mock.patch('gestioncof.signals.messages')
patcher_messages.start()
self.addCleanup(patcher_messages.stop)
# A test can mock 'django.utils.timezone.now' and give this as return
# value. E.g. it is useful if the test checks values of 'auto_now' or
# 'auto_now_add' fields.
self.now = timezone.now()
# These attributes register users and accounts instances.
self.users = {}
self.accounts = {}
for label, user in dict(self.users_base, **self.users_extra).items():
self.register_user(label, user)
if self.auth_user:
# The wrapper is a sanity check.
self.assertTrue(
self.client.login(
username=self.auth_user,
password=self.auth_user,
)
)
def tearDown(self):
del self.users_base
del self.users_extra
def get_users_base(self):
"""
Dict of <label: user instance>.
Note: Don't access yourself this property. Use 'users_base' attribute
which cache the returned value from here.
It allows to give functions calls, which creates users instances, as
values here.
"""
# Format desc: username, password, trigramme
return {
# user, user, 000
'user': create_user(),
# team, team, 100
'team': create_team(),
# root, root, 200
'root': create_root(),
}
@cached_property
def users_base(self):
return self.get_users_base()
def get_users_extra(self):
"""
Dict of <label: user instance>.
Note: Don't access yourself this property. Use 'users_base' attribute
which cache the returned value from here.
It allows to give functions calls, which create users instances, as
values here.
"""
return {}
@cached_property
def users_extra(self):
return self.get_users_extra()
def register_user(self, label, user):
self.users[label] = user
if hasattr(user.profile, 'account_kfet'):
self.accounts[label] = user.profile.account_kfet
def get_user(self, label):
if self.auth_user is not None:
return self.auth_user
return self.auth_user_mapping.get(label)
@property
def urls_conf(self):
return [{
'name': self.url_name,
'args': getattr(self, 'url_args', []),
'kwargs': getattr(self, 'url_kwargs', {}),
'expected': self.url_expected,
}]
@property
def t_urls(self):
return [
reverse(
url_conf['name'],
args=url_conf.get('args', []),
kwargs=url_conf.get('kwargs', {}),
)
for url_conf in self.urls_conf]
@property
def url(self):
return self.t_urls[0]
def test_urls(self):
for url, conf in zip(self.t_urls, self.urls_conf):
self.assertEqual(url, conf['expected'])
def test_forbidden(self):
for method in self.http_methods:
for user in self.auth_forbidden:
for url in self.t_urls:
self.check_forbidden(method, url, user)
def check_forbidden(self, method, url, user=None):
method = method.lower()
client = Client()
if user is not None:
client.login(username=user, password=user)
send_request = getattr(client, method)
data = getattr(self, '{}_data'.format(method), {})
r = send_request(url, data)
self.assertForbidden(r)

188
kfet/tests/utils.py Normal file
View file

@ -0,0 +1,188 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from ..models import Account
User = get_user_model()
def _create_user_and_account(user_attrs, account_attrs, perms=None):
"""
Create a user and its account, and assign permissions to this user.
Arguments
user_attrs (dict): User data (first name, last name, password...).
account_attrs (dict): Account data (department, kfet password...).
perms (list of str: 'app.perm'): These permissions will be assigned to
the created user. No permission are assigned by default.
If 'password' is not given in 'user_attrs', username is used as password.
If 'kfet.is_team' is in 'perms' and 'password' is not in 'account_attrs',
the account password is 'kfetpwd_<user pwd>'.
"""
user_pwd = user_attrs.pop('password', user_attrs['username'])
user = User.objects.create(**user_attrs)
user.set_password(user_pwd)
user.save()
account_attrs['cofprofile'] = user.profile
kfet_pwd = account_attrs.pop('password', 'kfetpwd_{}'.format(user_pwd))
account = Account.objects.create(**account_attrs)
if perms is not None:
user = user_add_perms(user, perms)
if 'kfet.is_team' in perms:
account.change_pwd(kfet_pwd)
account.save()
return user
def create_user(username='user', trigramme='000', **kwargs):
"""
Create a user without any permission and its kfet account.
username and trigramme are accepted as arguments (defaults to 'user' and
'000').
user_attrs, account_attrs and perms can be given as keyword arguments to
customize the user and its kfet account.
# Default values
User
* username: user
* password: user
* first_name: first
* last_name: last
* email: mail@user.net
Account
* trigramme: 000
"""
user_attrs = kwargs.setdefault('user_attrs', {})
user_attrs.setdefault('username', username)
user_attrs.setdefault('first_name', 'first')
user_attrs.setdefault('last_name', 'last')
user_attrs.setdefault('email', 'mail@user.net')
account_attrs = kwargs.setdefault('account_attrs', {})
account_attrs.setdefault('trigramme', trigramme)
return _create_user_and_account(**kwargs)
def create_team(username='team', trigramme='100', **kwargs):
"""
Create a user, member of the kfet team, and its kfet account.
username and trigramme are accepted as arguments (defaults to 'team' and
'100').
user_attrs, account_attrs and perms can be given as keyword arguments to
customize the user and its kfet account.
# Default values
User
* username: team
* password: team
* first_name: team
* last_name: member
* email: mail@team.net
Account
* trigramme: 100
* kfet password: kfetpwd_team
"""
user_attrs = kwargs.setdefault('user_attrs', {})
user_attrs.setdefault('username', username)
user_attrs.setdefault('first_name', 'team')
user_attrs.setdefault('last_name', 'member')
user_attrs.setdefault('email', 'mail@team.net')
account_attrs = kwargs.setdefault('account_attrs', {})
account_attrs.setdefault('trigramme', trigramme)
perms = kwargs.setdefault('perms', [])
perms.append('kfet.is_team')
return _create_user_and_account(**kwargs)
def create_root(username='root', trigramme='200', **kwargs):
"""
Create a superuser and its kfet account.
username and trigramme are accepted as arguments (defaults to 'root' and
'200').
user_attrs, account_attrs and perms can be given as keyword arguments to
customize the user and its kfet account.
# Default values
User
* username: root
* password: root
* first_name: super
* last_name: user
* email: mail@root.net
* is_staff, is_superuser: True
Account
* trigramme: 200
* kfet password: kfetpwd_root
"""
user_attrs = kwargs.setdefault('user_attrs', {})
user_attrs.setdefault('username', username)
user_attrs.setdefault('first_name', 'super')
user_attrs.setdefault('last_name', 'user')
user_attrs.setdefault('email', 'mail@root.net')
user_attrs['is_superuser'] = user_attrs['is_staff'] = True
account_attrs = kwargs.setdefault('account_attrs', {})
account_attrs.setdefault('trigramme', trigramme)
return _create_user_and_account(**kwargs)
def get_perms(*labels):
"""Return Permission instances from a list of '<app>.<perm_codename>'."""
perms = {}
for label in set(labels):
app_label, codename = label.split('.', 1)
perms[label] = Permission.objects.get(
content_type__app_label=app_label,
codename=codename,
)
return perms
def user_add_perms(user, perms_labels):
"""
Add perms to a user.
Args:
user (User instance)
perms (list of str 'app.perm_name')
Returns:
The same user (refetched from DB to avoid missing perms)
"""
perms = get_perms(*perms_labels)
user.user_permissions.add(*perms.values())
# If permissions have already been fetched for this user, we need to reload
# it to avoid using of the previous permissions cache.
# https://docs.djangoproject.com/en/dev/topics/auth/default/#permission-caching
return User.objects.get(pk=user.pk)

View file

@ -8,8 +8,8 @@ from kfet.decorators import teamkfet_required
urlpatterns = [ urlpatterns = [
url(r'^login/genericteam$', views.login_genericteam, url(r'^login/generic$', views.login_generic,
name='kfet.login.genericteam'), name='kfet.login.generic'),
url(r'^history$', views.history, url(r'^history$', views.history,
name='kfet.history'), name='kfet.history'),
@ -183,13 +183,9 @@ urlpatterns = [
# Settings urls # Settings urls
# ----- # -----
url(r'^settings/$', url(r'^settings/$', views.config_list,
permission_required('kfet.change_settings')
(views.SettingsList.as_view()),
name='kfet.settings'), name='kfet.settings'),
url(r'^settings/edit$', url(r'^settings/edit$', views.config_update,
permission_required('kfet.change_settings')
(views.SettingsUpdate.as_view()),
name='kfet.settings.update'), name='kfet.settings.update'),

View file

@ -12,34 +12,30 @@ from django.views.generic.edit import CreateView, UpdateView
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib import messages from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.models import User, Permission, Group from django.contrib.auth.models import User, Permission
from django.http import JsonResponse, Http404 from django.http import JsonResponse, Http404
from django.forms import formset_factory from django.forms import formset_factory
from django.db import transaction from django.db import transaction
from django.db.models import Q, F, Sum, Prefetch, Count from django.db.models import Q, F, Sum, Prefetch, Count
from django.db.models.functions import Coalesce from django.db.models.functions import Coalesce
from django.utils import timezone from django.utils import timezone
from django.utils.crypto import get_random_string
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django_cas_ng.views import logout as cas_logout_view
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from kfet.config import kfet_config from kfet.config import kfet_config
from kfet.decorators import teamkfet_required from kfet.decorators import teamkfet_required
from kfet.models import ( from kfet.models import (
Account, Checkout, Article, AccountNegative, Account, Checkout, Article, AccountNegative,
CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle, Inventory, CheckoutStatement, Supplier, SupplierArticle, Inventory,
InventoryArticle, Order, OrderArticle, Operation, OperationGroup, InventoryArticle, Order, OrderArticle, Operation, OperationGroup,
TransferGroup, Transfer, ArticleCategory) TransferGroup, Transfer, ArticleCategory)
from kfet.forms import ( from kfet.forms import (
AccountTriForm, AccountBalanceForm, AccountNoTriForm, UserForm, CofForm, AccountTriForm, AccountBalanceForm, AccountNoTriForm, UserForm, CofForm,
UserRestrictTeamForm, UserGroupForm, AccountForm, CofRestrictForm, UserRestrictTeamForm, UserGroupForm, AccountForm, CofRestrictForm,
AccountPwdForm, AccountNegativeForm, UserRestrictForm, AccountRestrictForm, AccountPwdForm, AccountNegativeForm, UserRestrictForm, AccountRestrictForm,
GroupForm, CheckoutForm, CheckoutRestrictForm, CheckoutStatementCreateForm, CheckoutForm, CheckoutRestrictForm, CheckoutStatementCreateForm,
CheckoutStatementUpdateForm, ArticleForm, ArticleRestrictForm, CheckoutStatementUpdateForm, ArticleForm, ArticleRestrictForm,
KPsulOperationGroupForm, KPsulAccountForm, KPsulCheckoutForm, KPsulOperationGroupForm, KPsulAccountForm, KPsulCheckoutForm,
KPsulOperationFormSet, AddcostForm, FilterHistoryForm, KPsulOperationFormSet, AddcostForm, FilterHistoryForm,
@ -53,6 +49,9 @@ from decimal import Decimal
import heapq import heapq
import statistics import statistics
from kfet.statistic import ScaleMixin, last_stats_manifest, tot_ventes, WeekScale from kfet.statistic import ScaleMixin, last_stats_manifest, tot_ventes, WeekScale
from .auth.views import ( # noqa
account_group, login_generic, AccountGroupCreate, AccountGroupUpdate,
)
# source : docs.djangoproject.com/fr/1.10/topics/class-based-views/mixins/ # source : docs.djangoproject.com/fr/1.10/topics/class-based-views/mixins/
@ -79,25 +78,6 @@ class JSONResponseMixin(object):
# -- can be serialized as JSON. # -- can be serialized as JSON.
return context return context
@teamkfet_required
def login_genericteam(request):
# Check si besoin de déconnecter l'utilisateur de CAS
cas_logout = None
if request.user.profile.login_clipper:
# Récupèration de la vue de déconnexion de CAS
# Ici, car request sera modifié après
next_page = request.META.get('HTTP_REFERER', None)
cas_logout = cas_logout_view(request, next_page=next_page)
# Authentification du compte générique
token = GenericTeamToken.objects.create(token=get_random_string(50))
user = authenticate(username="kfet_genericteam", token=token.token)
login(request, user)
messages.success(request, "Connecté en utilisateur partagé")
return cas_logout or render(request, "kfet/login_genericteam.html")
def put_cleaned_data_in_dict(dict, form): def put_cleaned_data_in_dict(dict, form):
for field in form.cleaned_data: for field in form.cleaned_data:
@ -537,37 +517,6 @@ def account_update(request, trigramme):
}) })
@permission_required('kfet.manage_perms')
def account_group(request):
user_pre = Prefetch(
'user_set',
queryset=User.objects.select_related('profile__account_kfet'),
)
groups = (
Group.objects
.filter(name__icontains='K-Fêt')
.prefetch_related('permissions', user_pre)
)
return render(request, 'kfet/account_group.html', {
'groups': groups,
})
class AccountGroupCreate(SuccessMessageMixin, CreateView):
model = Group
template_name = 'kfet/account_group_form.html'
form_class = GroupForm
success_message = 'Nouveau groupe : %(name)s'
success_url = reverse_lazy('kfet.account.group')
class AccountGroupUpdate(SuccessMessageMixin, UpdateView):
queryset = Group.objects.filter(name__icontains='K-Fêt')
template_name = 'kfet/account_group_form.html'
form_class = GroupForm
success_message = 'Groupe modifié : %(name)s'
success_url = reverse_lazy('kfet.account.group')
class AccountNegativeList(ListView): class AccountNegativeList(ListView):
queryset = ( queryset = (
AccountNegative.objects AccountNegative.objects
@ -1477,8 +1426,7 @@ def history_json(request):
# Construction de la requête (sur les opérations) pour le prefetch # Construction de la requête (sur les opérations) pour le prefetch
ope_queryset_prefetch = Operation.objects.select_related( ope_queryset_prefetch = Operation.objects.select_related(
'canceled_by', 'addcost_for', 'canceled_by', 'addcost_for', 'article')
'article')
ope_prefetch = Prefetch('opes', ope_prefetch = Prefetch('opes',
queryset=ope_queryset_prefetch) queryset=ope_queryset_prefetch)
@ -1503,15 +1451,15 @@ def history_json(request):
opegroups = ( opegroups = (
OperationGroup.objects OperationGroup.objects
.prefetch_related(ope_prefetch) .prefetch_related(ope_prefetch)
.select_related('on_acc__trigramme', .select_related('on_acc',
'valid_by__trigramme') 'valid_by')
.order_by('at') .order_by('at')
) )
transfergroups = ( transfergroups = (
TransferGroup.objects TransferGroup.objects
.prefetch_related(transfer_prefetch) .prefetch_related(transfer_prefetch)
.select_related('valid_by__trigramme') .select_related('valid_by')
.order_by('at') .order_by('at')
) )
@ -1672,6 +1620,9 @@ class SettingsList(TemplateView):
template_name = 'kfet/settings.html' template_name = 'kfet/settings.html'
config_list = permission_required('kfet.see_config')(SettingsList.as_view())
class SettingsUpdate(SuccessMessageMixin, FormView): class SettingsUpdate(SuccessMessageMixin, FormView):
form_class = KFetConfigForm form_class = KFetConfigForm
template_name = 'kfet/settings_update.html' template_name = 'kfet/settings_update.html'
@ -1680,13 +1631,17 @@ class SettingsUpdate(SuccessMessageMixin, FormView):
def form_valid(self, form): def form_valid(self, form):
# Checking permission # Checking permission
if not self.request.user.has_perm('kfet.change_settings'): if not self.request.user.has_perm('kfet.change_config'):
form.add_error(None, 'Permission refusée') form.add_error(None, 'Permission refusée')
return self.form_invalid(form) return self.form_invalid(form)
form.save() form.save()
return super().form_valid(form) return super().form_valid(form)
config_update = (
permission_required('kfet.change_config')(SettingsUpdate.as_view())
)
# ----- # -----
# Transfer views # Transfer views

0
manage.py Normal file → Executable file
View file

View file

@ -1,4 +1,4 @@
-r requirements.txt -r requirements.txt
-e git://github.com/jazzband/django-debug-toolbar.git@88ddc7bdf39c7ff660eac054eab225ac22926754#egg=django-debug-toolbar django-debug-toolbar
django-debug-panel django-debug-panel
ipython ipython

View file

@ -1,17 +1,16 @@
configparser==3.5.0 configparser==3.5.0
Django==1.8.* Django==1.11.*
django-autocomplete-light==2.3.3 django-autocomplete-light==3.1.3
django-autoslug==1.9.3 django-autoslug==1.9.3
django-cas-ng==3.5.7 django-cas-ng==3.5.7
django-djconfig==0.5.3 django-djconfig==0.5.3
django-grappelli==2.8.1 django-recaptcha==1.2.1
django-recaptcha==1.0.5
django-redis-cache==1.7.1 django-redis-cache==1.7.1
icalendar
psycopg2 psycopg2
Pillow==3.3.0 Pillow
six==1.10.0 six
unicodecsv==0.14.1 unicodecsv
icalendar==3.10
django-bootstrap-form==3.2.1 django-bootstrap-form==3.2.1
asgiref==1.1.1 asgiref==1.1.1
daphne==1.3.0 daphne==1.3.0

0
utils/__init__.py Normal file
View file

0
utils/views/__init__.py Normal file
View file

View file

@ -0,0 +1,26 @@
from django.db.models import Q
from dal import autocomplete
class Select2QuerySetView(autocomplete.Select2QuerySetView):
model = None
search_fields = []
def get_queryset_filter(self):
q = self.q
filter_q = Q()
if not q:
return filter_q
words = q.split()
for word in words:
for field in self.search_fields:
filter_q |= Q(**{'{}__icontains'.format(field): word})
return filter_q
def get_queryset(self):
return self.model.objects.filter(self.get_queryset_filter())