Compare commits
5 commits
master
...
Production
Author | SHA1 | Date | |
---|---|---|---|
|
7460ca591f | ||
|
a4494c3648 | ||
|
1fbf27a9f7 | ||
|
3178657e33 | ||
|
a4ebeb266a |
93 changed files with 411 additions and 813 deletions
|
@ -43,21 +43,13 @@ variables:
|
|||
# Keep this disabled for now, as it may kill GitLab...
|
||||
# coverage: '/TOTAL.*\s(\d+\.\d+)\%$/'
|
||||
|
||||
kfettest:
|
||||
stage: test
|
||||
extends: .test_template
|
||||
variables:
|
||||
DJANGO_SETTINGS_MODULE: "gestioasso.settings.cof_prod"
|
||||
script:
|
||||
- coverage run manage.py test kfet
|
||||
|
||||
coftest:
|
||||
stage: test
|
||||
extends: .test_template
|
||||
variables:
|
||||
DJANGO_SETTINGS_MODULE: "gestioasso.settings.cof_prod"
|
||||
script:
|
||||
- coverage run manage.py test gestioncof bda petitscours shared --parallel
|
||||
- coverage run manage.py test gestioncof bda kfet petitscours shared --parallel
|
||||
|
||||
bdstest:
|
||||
stage: test
|
||||
|
|
|
@ -23,9 +23,6 @@ adhérents ni des cotisations.
|
|||
|
||||
## TODO Prod
|
||||
|
||||
- Lancer `python manage.py update_translation_fields` après la migration
|
||||
- Mettre à jour les units systemd `daphne.service` et `worker.service`
|
||||
|
||||
- Créer un compte hCaptcha (https://www.hcaptcha.com/), au COF, et remplacer les secrets associés
|
||||
|
||||
## Version ??? - ??/??/????
|
||||
|
@ -68,8 +65,6 @@ adhérents ni des cotisations.
|
|||
|
||||
- Fixe un problème de rendu causé par l'agrandissement du menu
|
||||
|
||||
- Mise à jour vers Channels 3.x et Django 3.2
|
||||
|
||||
## Version 0.12 - 17/06/2022
|
||||
|
||||
### K-Fêt
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 3.2.13 on 2022-06-30 10:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bda", "0018_auto_20201021_1818"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name="choixspectacle",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="choixspectacle",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("participant", "spectacle"), name="unique_participation"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -253,11 +253,7 @@ class ChoixSpectacle(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ("priority",)
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["participant", "spectacle"], name="unique_participation"
|
||||
)
|
||||
]
|
||||
unique_together = (("participant", "spectacle"),)
|
||||
verbose_name = "voeu"
|
||||
verbose_name_plural = "voeux"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link type="text/css" rel="stylesheet" href="{% static "bda/css/bda.css" %}" />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>État des inscriptions BdA</h2>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script type="text/javascript" src="{% static 'vendor/jquery/jquery-ui.min.js' %}" ></script>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>{{ spectacle }}</h2>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
|
||||
{%block realcontent %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>Inscription à une revente</h2>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles%}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>Inscriptions pour BdA-Revente</h2>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link type="text/css" rel="stylesheet" href="{% static "bda/css/bda.css" %}" />
|
||||
|
|
42
bda/urls.py
42
bda/urls.py
|
@ -1,80 +1,74 @@
|
|||
from django.urls import re_path
|
||||
from django.conf.urls import url
|
||||
|
||||
from bda import views
|
||||
from bda.views import SpectacleListView
|
||||
from gestioncof.decorators import buro_required
|
||||
|
||||
urlpatterns = [
|
||||
re_path(
|
||||
url(
|
||||
r"^inscription/(?P<tirage_id>\d+)$",
|
||||
views.inscription,
|
||||
name="bda-tirage-inscription",
|
||||
),
|
||||
re_path(r"^places/(?P<tirage_id>\d+)$", views.places, name="bda-places-attribuees"),
|
||||
re_path(
|
||||
r"^etat-places/(?P<tirage_id>\d+)$", views.etat_places, name="bda-etat-places"
|
||||
),
|
||||
re_path(r"^tirage/(?P<tirage_id>\d+)$", views.tirage, name="bda-tirage"),
|
||||
re_path(
|
||||
url(r"^places/(?P<tirage_id>\d+)$", views.places, name="bda-places-attribuees"),
|
||||
url(r"^etat-places/(?P<tirage_id>\d+)$", views.etat_places, name="bda-etat-places"),
|
||||
url(r"^tirage/(?P<tirage_id>\d+)$", views.tirage, name="bda-tirage"),
|
||||
url(
|
||||
r"^spectacles/(?P<tirage_id>\d+)$",
|
||||
buro_required(SpectacleListView.as_view()),
|
||||
name="bda-liste-spectacles",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^spectacles/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$",
|
||||
views.spectacle,
|
||||
name="bda-spectacle",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^spectacles/unpaid/(?P<tirage_id>\d+)$",
|
||||
views.UnpaidParticipants.as_view(),
|
||||
name="bda-unpaid",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^spectacles/autocomplete$",
|
||||
views.spectacle_autocomplete,
|
||||
name="bda-spectacle-autocomplete",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^participants/autocomplete$",
|
||||
views.participant_autocomplete,
|
||||
name="bda-participant-autocomplete",
|
||||
),
|
||||
# Urls BdA-Revente
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<tirage_id>\d+)/manage$",
|
||||
views.revente_manage,
|
||||
name="bda-revente-manage",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<tirage_id>\d+)/subscribe$",
|
||||
views.revente_subscribe,
|
||||
name="bda-revente-subscribe",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<tirage_id>\d+)/tirages$",
|
||||
views.revente_tirages,
|
||||
name="bda-revente-tirages",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<spectacle_id>\d+)/buy$",
|
||||
views.revente_buy,
|
||||
name="bda-revente-buy",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<revente_id>\d+)/confirm$",
|
||||
views.revente_confirm,
|
||||
name="bda-revente-confirm",
|
||||
),
|
||||
re_path(
|
||||
url(
|
||||
r"^revente/(?P<tirage_id>\d+)/shotgun$",
|
||||
views.revente_shotgun,
|
||||
name="bda-revente-shotgun",
|
||||
),
|
||||
re_path(
|
||||
r"^mails-rappel/(?P<spectacle_id>\d+)$", views.send_rappel, name="bda-rappels"
|
||||
),
|
||||
re_path(
|
||||
r"^catalogue/(?P<request_type>[a-z]+)$", views.catalogue, name="bda-catalogue"
|
||||
),
|
||||
url(r"^mails-rappel/(?P<spectacle_id>\d+)$", views.send_rappel, name="bda-rappels"),
|
||||
url(r"^catalogue/(?P<request_type>[a-z]+)$", views.catalogue, name="bda-catalogue"),
|
||||
]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default_app_config = "bds.apps.BdsConfig"
|
|
@ -1,4 +1,5 @@
|
|||
from django.apps import AppConfig, apps as global_apps
|
||||
from django import apps as global_apps
|
||||
from django.apps import AppConfig
|
||||
from django.db.models import Q
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
{% load bulma_utils %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestHomeView(TestCase):
|
|||
user, backend="django.contrib.auth.backends.ModelBackend"
|
||||
)
|
||||
resp = self.client.get(reverse("bds:home"))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEquals(resp.status_code, 200)
|
||||
|
||||
|
||||
class TestRegistrationView(TestCase):
|
||||
|
@ -48,12 +48,12 @@ class TestRegistrationView(TestCase):
|
|||
# Logged-in but unprivileged GET
|
||||
client.force_login(user, backend="django.contrib.auth.backends.ModelBackend")
|
||||
resp = client.get(url)
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
self.assertEquals(resp.status_code, 403)
|
||||
|
||||
# Burô user GET
|
||||
give_bds_buro_permissions(user)
|
||||
resp = client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEquals(resp.status_code, 200)
|
||||
|
||||
@mock.patch("gestioncof.signals.messages")
|
||||
def test_get(self, mock_messages):
|
||||
|
@ -68,9 +68,9 @@ class TestRegistrationView(TestCase):
|
|||
# Logged-in but unprivileged GET
|
||||
client.force_login(user, backend="django.contrib.auth.backends.ModelBackend")
|
||||
resp = client.get(url)
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
self.assertEquals(resp.status_code, 403)
|
||||
|
||||
# Burô user GET
|
||||
give_bds_buro_permissions(user)
|
||||
resp = client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEquals(resp.status_code, 200)
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
# Generated by Django 3.2.13 on 2022-06-30 10:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("events", "0004_unique_constraints"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name="extrafield",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="extrafieldcontent",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="option",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="optionchoice",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="registration",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="extrafield",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("event", "name"), name="unique_extra_field"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="extrafieldcontent",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("field", "registration"), name="unique_extra_field_content"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="option",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("event", "name"), name="unique_event_option"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="optionchoice",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("option", "choice"), name="unique_option_choice"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="registration",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("event", "user"), name="unique_registration"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -72,13 +72,9 @@ class Option(models.Model):
|
|||
multi_choices = models.BooleanField(_("choix multiples"), default=False)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["event", "name"], name="unique_event_option"
|
||||
)
|
||||
]
|
||||
verbose_name = _("option d'événement")
|
||||
verbose_name_plural = _("options d'événement")
|
||||
unique_together = [["event", "name"]]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -91,13 +87,9 @@ class OptionChoice(models.Model):
|
|||
choice = models.CharField(_("choix"), max_length=200)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["option", "choice"], name="unique_option_choice"
|
||||
)
|
||||
]
|
||||
verbose_name = _("choix d'option d'événement")
|
||||
verbose_name_plural = _("choix d'option d'événement")
|
||||
unique_together = [["option", "choice"]]
|
||||
|
||||
def __str__(self):
|
||||
return self.choice
|
||||
|
@ -126,9 +118,7 @@ class ExtraField(models.Model):
|
|||
field_type = models.CharField(_("type de champ"), max_length=9, choices=FIELD_TYPE)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["event", "name"], name="unique_extra_field")
|
||||
]
|
||||
unique_together = [["event", "name"]]
|
||||
|
||||
|
||||
class ExtraFieldContent(models.Model):
|
||||
|
@ -147,13 +137,9 @@ class ExtraFieldContent(models.Model):
|
|||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["field", "registration"], name="unique_extra_field_content"
|
||||
)
|
||||
]
|
||||
verbose_name = _("contenu d'un champ événement supplémentaire")
|
||||
verbose_name_plural = _("contenus d'un champ événement supplémentaire")
|
||||
unique_together = [["field", "registration"]]
|
||||
|
||||
def __str__(self):
|
||||
max_length = 50
|
||||
|
@ -177,13 +163,9 @@ class Registration(models.Model):
|
|||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["event", "user"], name="unique_registration"
|
||||
)
|
||||
]
|
||||
verbose_name = _("inscription à un événement")
|
||||
verbose_name_plural = _("inscriptions à un événement")
|
||||
unique_together = [["event", "user"]]
|
||||
|
||||
def __str__(self):
|
||||
return "inscription de {} à {}".format(self.user, self.event)
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
"""
|
||||
ASGI entrypoint. Configures Django and then runs the application
|
||||
defined in the ASGI_APPLICATION setting.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
from channels.routing import get_default_application
|
||||
from channels.asgi import get_channel_layer
|
||||
|
||||
if "DJANGO_SETTINGS_MODULE" not in os.environ:
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gestioasso.settings.local")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gestioasso.settings")
|
||||
|
||||
django.setup()
|
||||
application = get_default_application()
|
||||
channel_layer = get_channel_layer()
|
||||
|
|
|
@ -1,20 +1,3 @@
|
|||
from channels.auth import AuthMiddlewareStack
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from django.core.asgi import get_asgi_application
|
||||
from django.urls import path
|
||||
from channels.routing import include
|
||||
|
||||
from kfet.routing import KFRouter
|
||||
|
||||
application = ProtocolTypeRouter(
|
||||
{
|
||||
# WebSocket chat handler
|
||||
"websocket": AuthMiddlewareStack(
|
||||
URLRouter(
|
||||
[
|
||||
path("ws/k-fet", KFRouter),
|
||||
]
|
||||
)
|
||||
),
|
||||
"http": get_asgi_application(),
|
||||
}
|
||||
)
|
||||
routing = [include("kfet.routing.routing", path=r"^/ws/k-fet")]
|
||||
|
|
|
@ -85,6 +85,7 @@ MIDDLEWARE = (
|
|||
+ MIDDLEWARE
|
||||
+ [
|
||||
"djconfig.middleware.DjConfigMiddleware",
|
||||
"wagtail.core.middleware.SiteMiddleware",
|
||||
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
|
||||
]
|
||||
)
|
||||
|
@ -108,8 +109,6 @@ MEDIA_URL = "/gestion/media/"
|
|||
CORS_ORIGIN_WHITELIST = ("bda.ens.fr", "www.bda.ens.fr" "cof.ens.fr", "www.cof.ens.fr")
|
||||
|
||||
|
||||
ASGI_APPLICATION = "gestioasso.routing.application"
|
||||
|
||||
# ---
|
||||
# Auth-related stuff
|
||||
# ---
|
||||
|
@ -148,7 +147,7 @@ CACHES = {
|
|||
|
||||
CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "shared.channels.ChannelLayer",
|
||||
"BACKEND": "asgi_redis.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts": [
|
||||
(
|
||||
|
@ -161,9 +160,11 @@ CHANNEL_LAYERS = {
|
|||
)
|
||||
]
|
||||
},
|
||||
"ROUTING": "gestioasso.routing.routing",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ---
|
||||
# reCAPTCHA settings
|
||||
# https://github.com/praekelt/django-recaptcha
|
||||
|
@ -205,7 +206,7 @@ MAIL_DATA = {
|
|||
"REPLYTO": "cof@ens.fr",
|
||||
},
|
||||
"rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@ens.fr>"},
|
||||
"kfet": {
|
||||
"rappel_negatif": {
|
||||
"FROM": "La K-Fêt <chefs-k-fet@ens.fr>",
|
||||
"REPLYTO": "La K-Fêt <chefs-k-fet@ens.fr>",
|
||||
},
|
||||
|
|
|
@ -101,7 +101,7 @@ TEMPLATES = [
|
|||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
||||
"NAME": DBNAME,
|
||||
"USER": DBUSER,
|
||||
"PASSWORD": DBPASSWD,
|
||||
|
@ -111,7 +111,6 @@ DATABASES = {
|
|||
|
||||
SITE_ID = 1
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
||||
# ---
|
||||
# Internationalization
|
||||
|
|
|
@ -47,7 +47,8 @@ CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"
|
|||
# Use the default in memory asgi backend for local development
|
||||
CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "channels.layers.InMemoryChannelLayer",
|
||||
"BACKEND": "asgiref.inmemory.ChannelLayer",
|
||||
"ROUTING": "gestioasso.routing.routing",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default_app_config = "gestioncof.apps.GestioncofConfig"
|
|
@ -6,7 +6,7 @@ from django.contrib.auth.models import Group, Permission, User
|
|||
from django.db.models import Q
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from gestioncof.models import (
|
||||
Club,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default_app_config = "gestioncof.cms.apps.COFCMSAppConfig"
|
|
@ -2,7 +2,7 @@ from datetime import date, timedelta
|
|||
|
||||
from django import template
|
||||
from django.utils import formats, timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from ..models import COFActuPage, COFRootPage
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
|
|||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.forms.formsets import BaseFormSet, formset_factory
|
||||
from django.forms.widgets import CheckboxSelectMultiple, RadioSelect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from djconfig.forms import ConfigForm
|
||||
|
||||
from bda.models import Spectacle
|
||||
|
@ -276,9 +276,7 @@ class RegistrationProfileForm(forms.ModelForm):
|
|||
self.fields["mailing_bda_revente"].initial = True
|
||||
self.fields["mailing_unernestaparis"].initial = True
|
||||
|
||||
class Meta:
|
||||
model = CofProfile
|
||||
fields = [
|
||||
self.fields.keyOrder = [
|
||||
"login_clipper",
|
||||
"phone",
|
||||
"occupation",
|
||||
|
@ -292,6 +290,22 @@ class RegistrationProfileForm(forms.ModelForm):
|
|||
"comments",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
model = CofProfile
|
||||
fields = (
|
||||
"login_clipper",
|
||||
"phone",
|
||||
"occupation",
|
||||
"departement",
|
||||
"is_cof",
|
||||
"type_cotiz",
|
||||
"mailing_cof",
|
||||
"mailing_bda",
|
||||
"mailing_bda_revente",
|
||||
"mailing_unernestaparis",
|
||||
"comments",
|
||||
)
|
||||
|
||||
|
||||
STATUS_CHOICES = (
|
||||
("no", "Non"),
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
# Generated by Django 3.2.13 on 2022-06-30 10:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("gestioncof", "0018_petitscours_email"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name="eventregistration",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="petitcoursability",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="surveyanswer",
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="eventregistration",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("user", "event"), name="unique_event_registration"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="petitcoursability",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("user", "niveau", "matiere"), name="unique_competence_level"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="surveyanswer",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("user", "survey"), name="unique_survey_answer"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -2,7 +2,7 @@ from django.contrib.auth.models import User
|
|||
from django.db import models
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from bda.models import Spectacle
|
||||
from shared.utils import choices_length
|
||||
|
@ -194,12 +194,8 @@ class EventRegistration(models.Model):
|
|||
paid = models.BooleanField("A payé", default=False)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["user", "event"], name="unique_event_registration"
|
||||
)
|
||||
]
|
||||
verbose_name = "Inscription"
|
||||
unique_together = ("user", "event")
|
||||
|
||||
def __str__(self):
|
||||
return "Inscription de {} à {}".format(self.user, self.event.title)
|
||||
|
@ -251,12 +247,8 @@ class SurveyAnswer(models.Model):
|
|||
answers = models.ManyToManyField(SurveyQuestionAnswer, related_name="selected_by")
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["user", "survey"], name="unique_survey_answer"
|
||||
)
|
||||
]
|
||||
verbose_name = "Réponses"
|
||||
unique_together = ("user", "survey")
|
||||
|
||||
def __str__(self):
|
||||
return "Réponse de %s sondage %s" % (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django_cas_ng.signals import cas_user_authenticated
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block page_size %}col-sm-8{% endblock %}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
<script type="text/javascript">
|
||||
var supernifty_tristate = function() {
|
||||
var
|
||||
|
|
|
@ -194,9 +194,7 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase):
|
|||
)
|
||||
|
||||
er = e.eventregistration_set.get(user=self.users["user"])
|
||||
self.assertQuerysetEqual(
|
||||
er.options.all(), map(repr, [oc1, oc3]), transform=repr, ordered=False
|
||||
)
|
||||
self.assertQuerysetEqual(er.options.all(), map(repr, [oc1, oc3]), ordered=False)
|
||||
self.assertCountEqual(
|
||||
er.comments.values_list("content", flat=True), ["comment 1"]
|
||||
)
|
||||
|
@ -301,10 +299,10 @@ class RegistrationAutocompleteViewTests(MockLDAPMixin, ViewTestCaseMixin, TestCa
|
|||
raise ValueError("Unexpected section name: {}".format(section.name))
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
others, map(str, expected_others), transform=str, ordered=False
|
||||
others, map(str, expected_others), ordered=False, transform=str
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
members, map(str, expected_members), transform=str, ordered=False
|
||||
members, map(str, expected_members), ordered=False, transform=str
|
||||
)
|
||||
self.assertSetEqual(
|
||||
set(clippers), set(map(LDAPSearch().result_verbose_name, expected_clippers))
|
||||
|
@ -650,10 +648,7 @@ class ClubListViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertQuerysetEqual(
|
||||
r.context["owned_clubs"],
|
||||
map(repr, [self.c1, self.c2]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
r.context["owned_clubs"], map(repr, [self.c1, self.c2]), ordered=False
|
||||
)
|
||||
|
||||
|
||||
|
@ -955,10 +950,7 @@ class EventViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
er = self.e.eventregistration_set.get(user=self.users["user"])
|
||||
self.assertQuerysetEqual(
|
||||
er.options.all(),
|
||||
map(repr, [self.oc1, self.oc3, self.oc4]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
er.options.all(), map(repr, [self.oc1, self.oc3, self.oc4]), ordered=False
|
||||
)
|
||||
# TODO: Make the view care about comments.
|
||||
# self.assertQuerysetEqual(
|
||||
|
@ -983,9 +975,7 @@ class EventViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertIn(self.post_expected_message, get_messages(r.wsgi_request))
|
||||
|
||||
er.refresh_from_db()
|
||||
self.assertQuerysetEqual(
|
||||
er.options.all(), map(repr, [self.oc3]), transform=repr, ordered=False
|
||||
)
|
||||
self.assertQuerysetEqual(er.options.all(), map(repr, [self.oc3]), ordered=False)
|
||||
# TODO: Make the view care about comments.
|
||||
# self.assertQuerysetEqual(
|
||||
# er.comments.all(), map(repr, []),
|
||||
|
@ -1039,10 +1029,7 @@ class EventStatusViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertQuerysetEqual(
|
||||
r.context["user_choices"],
|
||||
map(repr, expected),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
r.context["user_choices"], map(repr, expected), ordered=False
|
||||
)
|
||||
|
||||
def test_filter_none(self):
|
||||
|
@ -1109,10 +1096,7 @@ class SurveyViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
a = self.s.surveyanswer_set.get(user=self.users["user"])
|
||||
self.assertQuerysetEqual(
|
||||
a.answers.all(),
|
||||
map(repr, [self.qa1, self.qa3, self.qa4]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
a.answers.all(), map(repr, [self.qa1, self.qa3, self.qa4]), ordered=False
|
||||
)
|
||||
|
||||
def test_post_edit(self):
|
||||
|
@ -1131,9 +1115,7 @@ class SurveyViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertIn(self.post_expected_message, get_messages(r.wsgi_request))
|
||||
|
||||
a.refresh_from_db()
|
||||
self.assertQuerysetEqual(
|
||||
a.answers.all(), map(repr, [self.qa3]), transform=repr, ordered=False
|
||||
)
|
||||
self.assertQuerysetEqual(a.answers.all(), map(repr, [self.qa3]), ordered=False)
|
||||
|
||||
def test_post_delete(self):
|
||||
a = self.s.surveyanswer_set.create(user=self.users["user"])
|
||||
|
@ -1214,10 +1196,7 @@ class SurveyStatusViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertQuerysetEqual(
|
||||
r.context["user_answers"],
|
||||
map(repr, expected),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
r.context["user_answers"], map(repr, expected), ordered=False
|
||||
)
|
||||
|
||||
def test_filter_none(self):
|
||||
|
|
|
@ -20,7 +20,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
|||
from django.template import loader
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from django_cas_ng.views import LogoutView as CasLogoutView
|
||||
from icalendar import Calendar, Event as Vevent
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
default_app_config = "kfet.apps.KFetConfig"
|
||||
KFET_DELETED_TRIGRAMME = "☠☠☠"
|
||||
KFET_DELETED_USERNAME = "kfet_deleted_user"
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
default_app_config = "kfet.auth.apps.KFetAuthConfig"
|
||||
|
||||
KFET_GENERIC_USERNAME = "kfet_genericteam"
|
||||
KFET_GENERIC_TRIGRAMME = "GNR"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class KFetAuthConfig(AppConfig):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from shared.forms import ProtectedModelForm
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib.auth.models import Group, Permission
|
||||
from django.db import models
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
KFET_APP_LABELS = ["kfet", "kfetauth"]
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.contrib.auth.signals import user_logged_in
|
|||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from .utils import get_kfet_generic_user
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ class UserGroupFormTests(TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
groups_field.queryset,
|
||||
[repr(g.group_ptr) for g in self.kfet_groups],
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.http import QueryDict
|
|||
from django.shortcuts import redirect, render
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django.views.generic import View
|
||||
from django.views.generic.edit import CreateView, UpdateView
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default_app_config = "kfet.cms.apps.KFetCMSAppConfig"
|
|
@ -1,4 +1,4 @@
|
|||
from django.templatetags.static import static
|
||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||
from django.utils.html import format_html
|
||||
from wagtail.core import hooks
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from wagtail.admin.edit_handlers import (
|
||||
FieldPanel,
|
||||
FieldRowPanel,
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import get_channel_layer
|
||||
|
||||
from .utils import DjangoJsonWebsocketConsumer, PermConsumerMixin
|
||||
|
||||
|
||||
class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer):
|
||||
groups = ["kfet.kpsul"]
|
||||
perms_connect = ["kfet.is_team"]
|
||||
|
||||
async def kpsul(self, event):
|
||||
await self.send_json(event)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def group_send(cls, group, data):
|
||||
channel_layer = get_channel_layer()
|
||||
await channel_layer.group_send(group, data)
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.core import validators
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.forms import modelformset_factory
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from djconfig.forms import ConfigForm
|
||||
|
||||
from gestioncof.models import CofProfile
|
||||
|
|
|
@ -2,7 +2,6 @@ import re
|
|||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.mail import EmailMessage
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models, transaction
|
||||
|
@ -10,7 +9,7 @@ from django.db.models import F
|
|||
from django.template import loader
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from gestioncof.models import CofProfile
|
||||
from shared.utils import choices_length
|
||||
|
@ -270,32 +269,6 @@ class Account(models.Model):
|
|||
def __init__(self, trigramme):
|
||||
self.trigramme = trigramme
|
||||
|
||||
def send_creation_email(self):
|
||||
"""
|
||||
Envoie un mail à la création du trigramme.
|
||||
"""
|
||||
mail_data = settings.MAIL_DATA["kfet"]
|
||||
|
||||
email = EmailMessage(
|
||||
subject="Création d'un trigramme",
|
||||
body=loader.render_to_string(
|
||||
"kfet/mails/creation_trigramme.txt",
|
||||
context={
|
||||
"account": self,
|
||||
"site": Site.objects.get_current(),
|
||||
"url_read": reverse("kfet.account.read", args=(self.trigramme)),
|
||||
"url_update": reverse("kfet.account.update", args=(self.trigramme)),
|
||||
"url_delete": reverse("kfet.account.delete", args=(self.trigramme))
|
||||
},
|
||||
),
|
||||
from_email=mail_data["FROM"],
|
||||
to=[self.email],
|
||||
reply_to=[mail_data["REPLYTO"]],
|
||||
)
|
||||
|
||||
# On envoie le mail
|
||||
email.send()
|
||||
|
||||
|
||||
def get_deleted_account():
|
||||
return Account.objects.get(trigramme=KFET_DELETED_TRIGRAMME)
|
||||
|
@ -325,7 +298,7 @@ class AccountNegative(models.Model):
|
|||
"""
|
||||
Envoie un mail de rappel signalant que la personne est en négatif.
|
||||
"""
|
||||
mail_data = settings.MAIL_DATA["kfet"]
|
||||
mail_data = settings.MAIL_DATA["rappel_negatif"]
|
||||
|
||||
email = EmailMessage(
|
||||
subject="Compte K-Psul négatif",
|
||||
|
@ -348,6 +321,7 @@ class AccountNegative(models.Model):
|
|||
# On enregistre le fait que l'envoi a bien eu lieu
|
||||
self.last_rappel = timezone.now()
|
||||
self.save()
|
||||
return
|
||||
|
||||
|
||||
class CheckoutQuerySet(models.QuerySet):
|
||||
|
|
|
@ -12,15 +12,13 @@ class OpenKfetConsumer(PermConsumerMixin, DjangoJsonWebsocketConsumer):
|
|||
|
||||
"""
|
||||
|
||||
async def open_status(self, event):
|
||||
await self.send_json(event)
|
||||
def connection_groups(self, user, **kwargs):
|
||||
"""Select which group the user should be connected."""
|
||||
if kfet_is_team(user):
|
||||
return ["kfet.open.team"]
|
||||
return ["kfet.open.base"]
|
||||
|
||||
async def connect(self):
|
||||
def connect(self, message, *args, **kwargs):
|
||||
"""Send current status on connect."""
|
||||
await super().connect()
|
||||
|
||||
group = "team" if kfet_is_team(self.user) else "base"
|
||||
|
||||
await self.channel_layer.group_add(f"kfet.open.{group}", self.channel_name)
|
||||
|
||||
await self.send_json(kfet_open.export(self.user))
|
||||
super().connect(message, *args, **kwargs)
|
||||
self.send(kfet_open.export(message.user))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from datetime import timedelta
|
||||
|
||||
from channels.layers import get_channel_layer
|
||||
from django.utils import timezone
|
||||
|
||||
from ..decorators import kfet_is_team
|
||||
|
@ -78,7 +77,7 @@ class OpenKfet(CachedMixin, object):
|
|||
|
||||
"""
|
||||
status = self.status()
|
||||
base = {"status": status, "type": "open.status"}
|
||||
base = {"status": status}
|
||||
restrict = {
|
||||
"admin_status": self.admin_status(status),
|
||||
"force_close": self.force_close,
|
||||
|
@ -96,14 +95,13 @@ class OpenKfet(CachedMixin, object):
|
|||
base, team = self._export()
|
||||
return team if kfet_is_team(user) else base
|
||||
|
||||
async def send_ws(self):
|
||||
def send_ws(self):
|
||||
"""Send internal state to websocket channels."""
|
||||
from .consumers import OpenKfetConsumer
|
||||
|
||||
base, team = self._export()
|
||||
|
||||
channel_layer = get_channel_layer()
|
||||
|
||||
await channel_layer.group_send("kfet.open.base", base)
|
||||
await channel_layer.group_send("kfet.open.team", team)
|
||||
OpenKfetConsumer.group_send("kfet.open.base", base)
|
||||
OpenKfetConsumer.group_send("kfet.open.team", team)
|
||||
|
||||
|
||||
kfet_open = OpenKfet()
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
from channels.routing import URLRouter
|
||||
from django.urls import path
|
||||
from channels.routing import route_class
|
||||
|
||||
from .consumers import OpenKfetConsumer
|
||||
from . import consumers
|
||||
|
||||
OpenRouter = URLRouter(
|
||||
[
|
||||
path("", OpenKfetConsumer.as_asgi()),
|
||||
]
|
||||
)
|
||||
routing = [route_class(consumers.OpenKfetConsumer)]
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
import json
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from unittest import mock
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.auth import AuthMiddlewareStack
|
||||
from channels.consumer import get_channel_layer
|
||||
from channels.testing import WebsocketCommunicator
|
||||
from channels.channel import Group
|
||||
from channels.test import ChannelTestCase, WSClient
|
||||
from django.contrib.auth.models import AnonymousUser, Permission, User
|
||||
from django.test import Client, TestCase
|
||||
from django.test import Client
|
||||
from django.utils import timezone
|
||||
|
||||
from . import OpenKfet
|
||||
from .consumers import OpenKfetConsumer
|
||||
|
||||
|
||||
def ws_communicator(cls, path: str, headers=[]):
|
||||
return WebsocketCommunicator(AuthMiddlewareStack(cls.as_asgi()), path, headers)
|
||||
|
||||
|
||||
class OpenKfetTest(TestCase):
|
||||
class OpenKfetTest(ChannelTestCase):
|
||||
"""OpenKfet object unit-tests suite."""
|
||||
|
||||
def setUp(self):
|
||||
|
@ -84,7 +79,7 @@ class OpenKfetTest(TestCase):
|
|||
def test_export_user(self):
|
||||
"""Export is limited for an anonymous user."""
|
||||
export = self.kfet_open.export(AnonymousUser())
|
||||
self.assertSetEqual(set(["status", "type"]), set(export))
|
||||
self.assertSetEqual(set(["status"]), set(export))
|
||||
|
||||
def test_export_team(self):
|
||||
"""Export all values for a team member."""
|
||||
|
@ -94,32 +89,24 @@ class OpenKfetTest(TestCase):
|
|||
)
|
||||
user.user_permissions.add(is_team)
|
||||
export = self.kfet_open.export(user)
|
||||
self.assertSetEqual(
|
||||
set(["status", "admin_status", "force_close", "type"]), set(export)
|
||||
)
|
||||
self.assertSetEqual(set(["status", "admin_status", "force_close"]), set(export))
|
||||
|
||||
async def test_send_ws(self):
|
||||
channel_layer = get_channel_layer()
|
||||
base_channel = await channel_layer.new_channel()
|
||||
team_channel = await channel_layer.new_channel()
|
||||
def test_send_ws(self):
|
||||
Group("kfet.open.base").add("test.open.base")
|
||||
Group("kfet.open.team").add("test.open.team")
|
||||
|
||||
await channel_layer.group_add("kfet.open.base", base_channel)
|
||||
await channel_layer.group_add("kfet.open.team", team_channel)
|
||||
self.kfet_open.send_ws()
|
||||
|
||||
await self.kfet_open.send_ws()
|
||||
recv_base = self.get_next_message("test.open.base", require=True)
|
||||
base = json.loads(recv_base["text"])
|
||||
self.assertSetEqual(set(["status"]), set(base))
|
||||
|
||||
base = await channel_layer.receive(base_channel)
|
||||
|
||||
self.assertSetEqual(set(["status", "type"]), set(base))
|
||||
|
||||
team = await channel_layer.receive(team_channel)
|
||||
|
||||
self.assertSetEqual(
|
||||
set(["status", "admin_status", "force_close", "type"]), set(team)
|
||||
)
|
||||
recv_admin = self.get_next_message("test.open.team", require=True)
|
||||
admin = json.loads(recv_admin["text"])
|
||||
self.assertSetEqual(set(["status", "admin_status", "force_close"]), set(admin))
|
||||
|
||||
|
||||
class OpenKfetViewsTest(TestCase):
|
||||
class OpenKfetViewsTest(ChannelTestCase):
|
||||
"""OpenKfet views unit-tests suite."""
|
||||
|
||||
def setUp(self):
|
||||
|
@ -190,136 +177,119 @@ class OpenKfetViewsTest(TestCase):
|
|||
self.assertEqual(403, resp.status_code)
|
||||
|
||||
|
||||
class OpenKfetConsumerTest(TestCase):
|
||||
class OpenKfetConsumerTest(ChannelTestCase):
|
||||
"""OpenKfet consumer unit-tests suite."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def test_standard_user(self):
|
||||
"""Lambda user is added to kfet.open.base group."""
|
||||
# setup anonymous client
|
||||
c = WSClient()
|
||||
|
||||
# connect
|
||||
c.send_and_consume(
|
||||
"websocket.connect", path="/ws/k-fet/open", fail_on_none=True
|
||||
)
|
||||
|
||||
# initialization data is replied on connection
|
||||
self.assertIsNotNone(c.receive())
|
||||
|
||||
# client belongs to the 'kfet.open' group...
|
||||
OpenKfetConsumer.group_send("kfet.open.base", {"test": "plop"})
|
||||
self.assertEqual(c.receive(), {"test": "plop"})
|
||||
|
||||
# ...but not to the 'kfet.open.admin' one
|
||||
OpenKfetConsumer.group_send("kfet.open.team", {"test": "plop"})
|
||||
self.assertIsNone(c.receive())
|
||||
|
||||
@mock.patch("gestioncof.signals.messages")
|
||||
def test_team_user(self, mock_messages):
|
||||
"""Team user is added to kfet.open.team group."""
|
||||
# setup team user and its client
|
||||
t = User.objects.create_user("team", "", "team")
|
||||
is_team = Permission.objects.get(
|
||||
codename="is_team", content_type__app_label="kfet"
|
||||
)
|
||||
t.user_permissions.add(is_team)
|
||||
c = WSClient()
|
||||
c.force_login(t, backend="django.contrib.auth.backends.ModelBackend")
|
||||
|
||||
cls.team_user = t
|
||||
|
||||
async def test_standard_user(self):
|
||||
"""Lambda user is added to kfet.open.base group."""
|
||||
# setup anonymous client
|
||||
c = ws_communicator(OpenKfetConsumer, "/ws/k-fet/open")
|
||||
|
||||
connected, _ = await c.connect()
|
||||
|
||||
self.assertTrue(connected)
|
||||
# connect
|
||||
c.send_and_consume(
|
||||
"websocket.connect", path="/ws/k-fet/open", fail_on_none=True
|
||||
)
|
||||
|
||||
# initialization data is replied on connection
|
||||
message = await c.receive_json_from()
|
||||
self.assertIsNotNone(message)
|
||||
self.assertIsNotNone(c.receive())
|
||||
|
||||
# client belongs to the 'kfet.open' group...
|
||||
channel_layer = get_channel_layer()
|
||||
|
||||
await channel_layer.group_send(
|
||||
"kfet.open.base", {"test": "plop", "type": "open.status"}
|
||||
)
|
||||
message = await c.receive_json_from()
|
||||
|
||||
self.assertEqual(message, {"test": "plop"})
|
||||
|
||||
# ...but not to the 'kfet.open.admin' one
|
||||
await channel_layer.group_send(
|
||||
"kfet.open.team", {"test": "plop", "type": "open.status"}
|
||||
)
|
||||
self.assertTrue(await c.receive_nothing())
|
||||
|
||||
async def test_team_user(self):
|
||||
"""Team user is added to kfet.open.team group."""
|
||||
|
||||
# On simule l'appartenance de l'user à la team kfet car l'utilisation de
|
||||
# tests async avec postgres fait tout planter si on modifie la db dans un
|
||||
# des sous tests.
|
||||
with mock.patch("gestioncof.signals.messages"), mock.patch(
|
||||
"kfet.open.consumers.kfet_is_team", return_value=True
|
||||
):
|
||||
c = ws_communicator(OpenKfetConsumer, "/ws/k-fet/open")
|
||||
|
||||
connected, _ = await c.connect()
|
||||
|
||||
channel_layer = get_channel_layer()
|
||||
|
||||
self.assertTrue(connected)
|
||||
|
||||
# initialization data is replied on connection
|
||||
message = await c.receive_json_from()
|
||||
self.assertIsNotNone(message)
|
||||
|
||||
# client belongs to the 'kfet.open.team' group...
|
||||
await channel_layer.group_send(
|
||||
"kfet.open.team", {"test": "plop", "type": "open.status"}
|
||||
)
|
||||
message = await c.receive_json_from()
|
||||
|
||||
self.assertEqual(message, {"test": "plop"})
|
||||
# client belongs to the 'kfet.open.admin' group...
|
||||
OpenKfetConsumer.group_send("kfet.open.team", {"test": "plop"})
|
||||
self.assertEqual(c.receive(), {"test": "plop"})
|
||||
|
||||
# ... but not to the 'kfet.open' one
|
||||
await channel_layer.group_send(
|
||||
"kfet.open.base", {"test": "plop", "type": "open.status"}
|
||||
)
|
||||
self.assertTrue(await c.receive_nothing())
|
||||
OpenKfetConsumer.group_send("kfet.open.base", {"test": "plop"})
|
||||
self.assertIsNone(c.receive())
|
||||
|
||||
|
||||
class OpenKfetScenarioTest(TestCase):
|
||||
class OpenKfetScenarioTest(ChannelTestCase):
|
||||
"""OpenKfet functionnal tests suite."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
# root user
|
||||
cls.r = User.objects.create_superuser("team", "", "team")
|
||||
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)
|
||||
cls.c = Client()
|
||||
self.c = Client()
|
||||
# anonymous client (for websockets)
|
||||
self.c_ws = WSClient()
|
||||
|
||||
# root client
|
||||
cls.r_c = Client()
|
||||
|
||||
with mock.patch("gestioncof.signals.messages"):
|
||||
cls.r_c.login(username="team", password="team")
|
||||
|
||||
def setUp(self):
|
||||
# Create channels to listen to messages
|
||||
channel_layer = get_channel_layer()
|
||||
|
||||
self.channel = async_to_sync(channel_layer.new_channel)()
|
||||
self.team_channel = async_to_sync(channel_layer.new_channel)()
|
||||
|
||||
async_to_sync(channel_layer.group_add)("kfet.open.base", self.channel)
|
||||
async_to_sync(channel_layer.group_add)("kfet.open.team", self.team_channel)
|
||||
|
||||
self.receive_msg = lambda c: async_to_sync(channel_layer.receive)(c)
|
||||
# root user
|
||||
self.r = User.objects.create_superuser("root", "", "root")
|
||||
# its client (for views)
|
||||
self.r_c = Client()
|
||||
self.r_c.login(username="root", password="root")
|
||||
# its client (for websockets)
|
||||
self.r_c_ws = WSClient()
|
||||
self.r_c_ws.force_login(
|
||||
self.r, backend="django.contrib.auth.backends.ModelBackend"
|
||||
)
|
||||
|
||||
self.kfet_open = OpenKfet(
|
||||
cache_prefix="test_kfetopen_%s" % random.randrange(2**20)
|
||||
)
|
||||
self.addCleanup(self.kfet_open.clear_cache)
|
||||
|
||||
async def ws_connect(self, ws_communicator):
|
||||
c, _ = await ws_communicator.connect()
|
||||
def ws_connect(self, ws_client):
|
||||
ws_client.send_and_consume(
|
||||
"websocket.connect", path="/ws/k-fet/open", fail_on_none=True
|
||||
)
|
||||
return ws_client.receive(json=True)
|
||||
|
||||
self.assertTrue(c)
|
||||
return await ws_communicator.receive_json_from()
|
||||
def test_scenario_0(self):
|
||||
"""Clients connect."""
|
||||
# test for anonymous user
|
||||
msg = self.ws_connect(self.c_ws)
|
||||
self.assertSetEqual(set(["status"]), set(msg))
|
||||
|
||||
# test for root user
|
||||
msg = self.ws_connect(self.r_c_ws)
|
||||
self.assertSetEqual(set(["status", "admin_status", "force_close"]), set(msg))
|
||||
|
||||
def test_scenario_1(self):
|
||||
"""Clients connect, door opens, enable force close."""
|
||||
self.ws_connect(self.c_ws)
|
||||
self.ws_connect(self.r_c_ws)
|
||||
|
||||
# door sent "I'm open!"
|
||||
self.c.post("/k-fet/open/raw_open", {"raw_open": True, "token": "plop"})
|
||||
|
||||
# anonymous user agree
|
||||
msg = self.receive_msg(self.channel)
|
||||
msg = self.c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.OPENED, msg["status"])
|
||||
|
||||
# root user too
|
||||
msg = self.receive_msg(self.team_channel)
|
||||
msg = self.r_c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.OPENED, msg["status"])
|
||||
self.assertEqual(OpenKfet.OPENED, msg["admin_status"])
|
||||
|
||||
|
@ -327,11 +297,11 @@ class OpenKfetScenarioTest(TestCase):
|
|||
self.r_c.post("/k-fet/open/force_close", {"force_close": True})
|
||||
|
||||
# so anonymous user see it's closed
|
||||
msg = self.receive_msg(self.channel)
|
||||
msg = self.c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.CLOSED, msg["status"])
|
||||
|
||||
# root user too
|
||||
msg = self.receive_msg(self.team_channel)
|
||||
msg = self.r_c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.CLOSED, msg["status"])
|
||||
# but root knows things
|
||||
self.assertEqual(OpenKfet.FAKE_CLOSED, msg["admin_status"])
|
||||
|
@ -342,42 +312,20 @@ class OpenKfetScenarioTest(TestCase):
|
|||
self.kfet_open.raw_open = True
|
||||
self.kfet_open.force_close = True
|
||||
|
||||
async_to_sync(OpenKfet().send_ws)()
|
||||
|
||||
msg = self.receive_msg(self.channel)
|
||||
msg = self.ws_connect(self.c_ws)
|
||||
self.assertEqual(OpenKfet.CLOSED, msg["status"])
|
||||
|
||||
msg = self.receive_msg(self.team_channel)
|
||||
msg = self.ws_connect(self.r_c_ws)
|
||||
self.assertEqual(OpenKfet.CLOSED, msg["status"])
|
||||
self.assertEqual(OpenKfet.FAKE_CLOSED, msg["admin_status"])
|
||||
self.assertTrue(msg["force_close"])
|
||||
|
||||
self.r_c.post("/k-fet/open/force_close", {"force_close": False})
|
||||
|
||||
msg = self.receive_msg(self.channel)
|
||||
msg = self.c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.OPENED, msg["status"])
|
||||
|
||||
msg = self.receive_msg(self.team_channel)
|
||||
msg = self.r_c_ws.receive(json=True)
|
||||
self.assertEqual(OpenKfet.OPENED, msg["status"])
|
||||
self.assertEqual(OpenKfet.OPENED, msg["admin_status"])
|
||||
self.assertFalse(msg["force_close"])
|
||||
|
||||
async def test_scenario_3(self):
|
||||
"""Clients connect."""
|
||||
# anonymous client (for websockets)
|
||||
self.c_ws = ws_communicator(OpenKfetConsumer, "/ws/k-fet/open")
|
||||
|
||||
# test for anonymous user
|
||||
msg = await self.ws_connect(self.c_ws)
|
||||
self.assertSetEqual(set(["status"]), set(msg))
|
||||
|
||||
# test for root user
|
||||
with mock.patch(
|
||||
"kfet.open.consumers.kfet_is_team", return_value=True
|
||||
), mock.patch("kfet.open.open.kfet_is_team", return_value=True):
|
||||
self.r_c_ws = ws_communicator(OpenKfetConsumer, "/ws/k-fet/open")
|
||||
|
||||
msg = await self.ws_connect(self.r_c_ws)
|
||||
self.assertSetEqual(
|
||||
set(["status", "admin_status", "force_close"]), set(msg)
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from asgiref.sync import async_to_sync
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
@ -19,7 +18,7 @@ def raw_open(request):
|
|||
raise PermissionDenied
|
||||
raw_open = request.POST.get("raw_open") in TRUE_STR
|
||||
kfet_open.raw_open = raw_open
|
||||
async_to_sync(kfet_open.send_ws)()
|
||||
kfet_open.send_ws()
|
||||
return HttpResponse()
|
||||
|
||||
|
||||
|
@ -28,5 +27,5 @@ def raw_open(request):
|
|||
def force_close(request):
|
||||
force_close = request.POST.get("force_close") in TRUE_STR
|
||||
kfet_open.force_close = force_close
|
||||
async_to_sync(kfet_open.send_ws)()
|
||||
kfet_open.send_ws()
|
||||
return HttpResponse()
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
from channels.routing import URLRouter
|
||||
from django.urls import path
|
||||
from channels.routing import include, route_class
|
||||
|
||||
from kfet.open.routing import OpenRouter
|
||||
from . import consumers
|
||||
|
||||
from .consumers import KPsul
|
||||
|
||||
KFRouter = URLRouter(
|
||||
[
|
||||
path("k-psul/", KPsul.as_asgi()),
|
||||
path("open", OpenRouter),
|
||||
routing = [
|
||||
route_class(consumers.KPsul, path=r"^/k-psul/$"),
|
||||
include("kfet.open.routing.routing", path=r"^/open"),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -78,7 +78,7 @@ class KfetWebsocket {
|
|||
|
||||
listen() {
|
||||
var that = this;
|
||||
this.socket = new ReconnectingWebSocket(this.url, [], { minReconnectionDelay: 100 });
|
||||
this.socket = new ReconnectingWebSocket(this.url);
|
||||
|
||||
this.socket.onmessage = function (e) {
|
||||
var data = $.extend({}, that.default_msg, JSON.parse(e.data));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "kfet/base_form.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Nouveau compte{% endblock %}
|
||||
{% block header-title %}Création d'un compte{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "kfet/base.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Nouveau compte{% endblock %}
|
||||
{% block header-title %}Création d'un compte{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'kfet/base_form.html' %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %}Permissions - Édition{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "kfet/base_col_2.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
{% load kfet_tags %}
|
||||
{% load l10n %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'kfet/base_col_2.html' %}
|
||||
{% load static kfet_tags %}
|
||||
{% load staticfiles kfet_tags %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script type="text/javascript" src="{% static 'kfet/vendor/Chart.min.js' %}"></script>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'kfet/base_col_2.html' %}
|
||||
{% load l10n static widget_tweaks bootstrap %}
|
||||
{% load l10n staticfiles widget_tweaks bootstrap %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/vendor/multiple-select/multiple-select.css' %}">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "kfet/base_col_1.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
{% load kfet_tags %}
|
||||
|
||||
{% block title %}Accueil{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'kfet/base.html' %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" style="text/css" href="{% static 'kfet/css/kpsul_grid.css' %}">
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
Salut {{ account.name }},
|
||||
|
||||
Ton compte K-Fêt a bien été créé le {{ account.created_at }} avec le trigramme {{ account.trigramme }}.
|
||||
|
||||
Tu peux désormais :
|
||||
- Accéder à ton historique personnel des consommations : https://{{ site }}{{ url_read }}
|
||||
- Modifier tes informations : https://{{ site }}{{ url_update }}
|
||||
- Supprimer ton compte : https://{{ site }}{{ url_delete }}
|
||||
|
||||
En espérant te revoir bientôt,
|
||||
--
|
||||
L'équipe K-Fêt
|
|
@ -1,5 +1,6 @@
|
|||
{% extends 'kfet/base_col_2.html' %}
|
||||
{% load l10n static widget_tweaks %}
|
||||
{% load staticfiles %}
|
||||
{% load l10n staticfiles widget_tweaks %}
|
||||
|
||||
{% block title %}Transferts{% endblock %}
|
||||
{% block header-title %}Transferts{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "kfet/base_col_1.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/css/transfers_form.css' %}">
|
||||
|
|
|
@ -94,7 +94,6 @@ class PermHelpersTest(TestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
user.user_permissions.all(),
|
||||
map(repr, [self.perm1, self.perm2, self.perm_team]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ from datetime import datetime, timedelta
|
|||
from decimal import Decimal
|
||||
from unittest import mock
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import get_channel_layer
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
@ -520,7 +518,6 @@ class AccountGroupCreateViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
group.permissions.all(),
|
||||
map(repr, [self.perms["kfet.is_team"], self.perms["kfet.manage_perms"]]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
@ -574,7 +571,6 @@ class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
self.group.permissions.all(),
|
||||
map(repr, [self.perms["kfet.is_team"], self.perms["kfet.manage_perms"]]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
@ -602,7 +598,6 @@ class AccountNegativeListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
r.context["negatives"],
|
||||
map(repr, [self.accounts["user"].negative]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
@ -703,7 +698,7 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
|
|||
for stat, expected in zip(content["stats"], expected_stats):
|
||||
expected_url = expected.pop("url")
|
||||
self.assertUrlsEqual(stat["url"], expected_url)
|
||||
self.assertEqual(stat, {**stat, **expected})
|
||||
self.assertDictContainsSubset(expected, stat)
|
||||
|
||||
|
||||
class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -812,7 +807,7 @@ class AccountStatBalanceListViewTests(ViewTestCaseMixin, TestCase):
|
|||
for stat, expected in zip(content["stats"], expected_stats):
|
||||
expected_url = expected.pop("url")
|
||||
self.assertUrlsEqual(stat["url"], expected_url)
|
||||
self.assertEqual(stat, {**stat, **expected})
|
||||
self.assertDictContainsSubset(expected, stat)
|
||||
|
||||
|
||||
class AccountStatBalanceViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -880,7 +875,6 @@ class CheckoutListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
r.context["checkouts"],
|
||||
map(repr, [self.checkout1, self.checkout2]),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
@ -1071,7 +1065,6 @@ class CheckoutStatementListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertQuerysetEqual(
|
||||
r.context["checkoutstatements"],
|
||||
map(repr, expected_statements),
|
||||
transform=repr,
|
||||
ordered=False,
|
||||
)
|
||||
|
||||
|
@ -1298,9 +1291,7 @@ class ArticleCategoryListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
r.context["categories"],
|
||||
map(repr, [self.category1, self.category2]),
|
||||
transform=repr,
|
||||
r.context["categories"], map(repr, [self.category1, self.category2])
|
||||
)
|
||||
|
||||
|
||||
|
@ -1375,9 +1366,7 @@ class ArticleListViewTests(ViewTestCaseMixin, TestCase):
|
|||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertQuerysetEqual(
|
||||
r.context["articles"],
|
||||
map(repr, [self.article1, self.article2]),
|
||||
transform=repr,
|
||||
r.context["articles"], map(repr, [self.article1, self.article2])
|
||||
)
|
||||
|
||||
|
||||
|
@ -1647,7 +1636,7 @@ class ArticleStatSalesListViewTests(ViewTestCaseMixin, TestCase):
|
|||
for stat, expected in zip(content["stats"], expected_stats):
|
||||
expected_url = expected.pop("url")
|
||||
self.assertUrlsEqual(stat["url"], expected_url)
|
||||
self.assertEqual(stat, {**stat, **expected})
|
||||
self.assertDictContainsSubset(expected, stat)
|
||||
|
||||
|
||||
class ArticleStatSalesViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -1716,7 +1705,7 @@ class KPsulCheckoutDataViewTests(ViewTestCaseMixin, TestCase):
|
|||
|
||||
expected = {"name": "Checkout", "balance": "10.00"}
|
||||
|
||||
self.assertEqual(content, {**content, **expected})
|
||||
self.assertDictContainsSubset(expected, content)
|
||||
|
||||
self.assertSetEqual(
|
||||
set(content.keys()),
|
||||
|
@ -1819,13 +1808,10 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.account.balance = Decimal("50.00")
|
||||
self.account.save()
|
||||
|
||||
# Create a channel to listen to KPsul's messages
|
||||
channel_layer = get_channel_layer()
|
||||
self.channel = async_to_sync(channel_layer.new_channel)()
|
||||
|
||||
async_to_sync(channel_layer.group_add)("kfet.kpsul", self.channel)
|
||||
|
||||
self.receive_msg = lambda: async_to_sync(channel_layer.receive)(self.channel)
|
||||
# Mock consumer of K-Psul websocket to catch what we're sending
|
||||
kpsul_consumer_patcher = mock.patch("kfet.consumers.KPsul")
|
||||
self.kpsul_consumer_mock = kpsul_consumer_patcher.start()
|
||||
self.addCleanup(kpsul_consumer_patcher.stop)
|
||||
|
||||
# Reset cache of kfet config
|
||||
kfet_config._conf_init = False
|
||||
|
@ -2057,12 +2043,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertEqual(self.article.stock, 18)
|
||||
|
||||
# Check websocket data
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"groups": [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -2324,12 +2307,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("110.75"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"groups": [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -2498,12 +2478,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("89.25"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"groups": [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -2658,12 +2635,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"groups": [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -2776,9 +2750,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
ws_data_ope = ws_data["groups"][0]["entries"][0]
|
||||
|
||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||
"entries"
|
||||
][0]
|
||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||
|
||||
|
@ -2816,9 +2790,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
ws_data_ope = ws_data["groups"][0]["entries"][0]
|
||||
|
||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||
"entries"
|
||||
][0]
|
||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("0.80"))
|
||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||
|
||||
|
@ -2854,9 +2828,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("106.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
ws_data_ope = ws_data["groups"][0]["entries"][0]
|
||||
|
||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||
"entries"
|
||||
][0]
|
||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||
|
||||
|
@ -2890,9 +2864,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.accounts["addcost"].refresh_from_db()
|
||||
self.assertEqual(self.accounts["addcost"].balance, Decimal("15.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
ws_data_ope = ws_data["groups"][0]["entries"][0]
|
||||
|
||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||
"entries"
|
||||
][0]
|
||||
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
||||
|
||||
|
@ -2925,9 +2899,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.accounts["addcost"].refresh_from_db()
|
||||
self.assertEqual(self.accounts["addcost"].balance, Decimal("0.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
ws_data_ope = ws_data["groups"][0]["entries"][0]
|
||||
|
||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||
"entries"
|
||||
][0]
|
||||
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
||||
|
||||
|
@ -3149,12 +3123,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertEqual(article2.stock, -6)
|
||||
|
||||
# Check websocket data
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"groups": [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -3247,14 +3218,10 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.account.balance = Decimal("50.00")
|
||||
self.account.save()
|
||||
|
||||
# Create a channel to listen to KPsul's messages
|
||||
channel_layer = get_channel_layer()
|
||||
|
||||
self.channel = async_to_sync(channel_layer.new_channel)()
|
||||
|
||||
async_to_sync(channel_layer.group_add)("kfet.kpsul", self.channel)
|
||||
|
||||
self.receive_msg = lambda: async_to_sync(channel_layer.receive)(self.channel)
|
||||
# Mock consumer of K-Psul websocket to catch what we're sending
|
||||
kpsul_consumer_patcher = mock.patch("kfet.consumers.KPsul")
|
||||
self.kpsul_consumer_mock = kpsul_consumer_patcher.start()
|
||||
self.addCleanup(kpsul_consumer_patcher.stop)
|
||||
|
||||
def _assertResponseOk(self, response):
|
||||
"""
|
||||
|
@ -3304,11 +3271,7 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
on_acc=self.account,
|
||||
checkout=self.checkout,
|
||||
content=[
|
||||
{
|
||||
"type": Operation.PURCHASE,
|
||||
"article": self.article,
|
||||
"article_nb": 2,
|
||||
}
|
||||
{"type": Operation.PURCHASE, "article": self.article, "article_nb": 2}
|
||||
],
|
||||
)
|
||||
operation = group.opes.get()
|
||||
|
@ -3382,15 +3345,9 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
{
|
||||
"type": "kpsul",
|
||||
"checkouts": [],
|
||||
"articles": [{"id": self.article.pk, "stock": 22}],
|
||||
},
|
||||
self.kpsul_consumer_mock.group_send.assert_called_with(
|
||||
"kfet.kpsul",
|
||||
{"checkouts": [], "articles": [{"id": self.article.pk, "stock": 22}]},
|
||||
)
|
||||
|
||||
def test_purchase_with_addcost(self):
|
||||
|
@ -3450,11 +3407,11 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("95.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
ws_data_checkouts = self.kpsul_consumer_mock.group_send.call_args[0][1][
|
||||
"checkouts"
|
||||
]
|
||||
self.assertListEqual(
|
||||
ws_data["checkouts"],
|
||||
[{"id": self.checkout.pk, "balance": Decimal("95.00")}],
|
||||
ws_data_checkouts, [{"id": self.checkout.pk, "balance": Decimal("95.00")}]
|
||||
)
|
||||
|
||||
def test_purchase_cash_with_addcost(self):
|
||||
|
@ -3490,11 +3447,11 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
addcost_account.refresh_from_db()
|
||||
self.assertEqual(addcost_account.balance, Decimal("9.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
ws_data_checkouts = self.kpsul_consumer_mock.group_send.call_args[0][1][
|
||||
"checkouts"
|
||||
]
|
||||
self.assertListEqual(
|
||||
ws_data["checkouts"],
|
||||
[{"id": self.checkout.pk, "balance": Decimal("94.00")}],
|
||||
ws_data_checkouts, [{"id": self.checkout.pk, "balance": Decimal("94.00")}]
|
||||
)
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
|
@ -3576,12 +3533,9 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("89.25"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"checkouts": [{"id": self.checkout.pk, "balance": Decimal("89.25")}],
|
||||
"articles": [],
|
||||
},
|
||||
|
@ -3666,12 +3620,9 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("110.75"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
self.kpsul_consumer_mock.group_send.assert_called_with(
|
||||
"kfet.kpsul",
|
||||
{
|
||||
"type": "kpsul",
|
||||
"checkouts": [{"id": self.checkout.pk, "balance": Decimal("110.75")}],
|
||||
"articles": [],
|
||||
},
|
||||
|
@ -3756,11 +3707,9 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.checkout.refresh_from_db()
|
||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||
|
||||
ws_data = self.receive_msg()
|
||||
|
||||
self.assertDictEqual(
|
||||
ws_data,
|
||||
{"type": "kpsul", "checkouts": [], "articles": []},
|
||||
self.kpsul_consumer_mock.group_send.assert_called_with(
|
||||
"kfet.kpsul",
|
||||
{"checkouts": [], "articles": []},
|
||||
)
|
||||
|
||||
@mock.patch("django.utils.timezone.now")
|
||||
|
@ -4100,7 +4049,7 @@ class KPsulArticlesData(ViewTestCaseMixin, TestCase):
|
|||
]
|
||||
|
||||
for expected, article in zip(expected_list, articles):
|
||||
self.assertEqual(article, {**article, **expected})
|
||||
self.assertDictContainsSubset(expected, article)
|
||||
self.assertSetEqual(
|
||||
set(article.keys()),
|
||||
set(
|
||||
|
@ -4200,7 +4149,7 @@ class AccountReadJSONViewTests(ViewTestCaseMixin, TestCase):
|
|||
content = json.loads(r.content.decode("utf-8"))
|
||||
|
||||
expected = {"name": "first last", "trigramme": "000", "balance": "0.00"}
|
||||
self.assertEqual(content, {**content, **expected})
|
||||
self.assertDictContainsSubset(expected, content)
|
||||
|
||||
self.assertSetEqual(
|
||||
set(content.keys()),
|
||||
|
@ -4444,9 +4393,7 @@ class InventoryListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
inventories = r.context["inventories"]
|
||||
self.assertQuerysetEqual(
|
||||
inventories, map(repr, [self.inventory]), transform=repr
|
||||
)
|
||||
self.assertQuerysetEqual(inventories, map(repr, [self.inventory]))
|
||||
|
||||
|
||||
class InventoryCreateViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -4633,7 +4580,7 @@ class OrderListViewTests(ViewTestCaseMixin, TestCase):
|
|||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
orders = r.context["orders"]
|
||||
self.assertQuerysetEqual(orders, map(repr, [self.order]), transform=repr)
|
||||
self.assertQuerysetEqual(orders, map(repr, [self.order]))
|
||||
|
||||
|
||||
class OrderReadViewTests(ViewTestCaseMixin, TestCase):
|
||||
|
@ -4848,9 +4795,7 @@ class OrderToInventoryViewTests(ViewTestCaseMixin, TestCase):
|
|||
inventory,
|
||||
{"by": self.accounts["team1"], "at": self.now, "order": self.order},
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
inventory.articles.all(), map(repr, [self.article]), transform=repr
|
||||
)
|
||||
self.assertQuerysetEqual(inventory.articles.all(), map(repr, [self.article]))
|
||||
|
||||
compte = InventoryArticle.objects.get(article=self.article)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import json
|
||||
import math
|
||||
|
||||
from channels.generic.websocket import AsyncJsonWebsocketConsumer
|
||||
from channels.channel import Group
|
||||
from channels.generic.websockets import JsonWebsocketConsumer
|
||||
from django.core.cache import cache
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
|
||||
|
@ -62,7 +63,7 @@ class CachedMixin:
|
|||
# Consumers
|
||||
|
||||
|
||||
class DjangoJsonWebsocketConsumer(AsyncJsonWebsocketConsumer):
|
||||
class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
|
||||
"""Custom Json Websocket Consumer.
|
||||
|
||||
Encode to JSON with DjangoJSONEncoder.
|
||||
|
@ -70,10 +71,7 @@ class DjangoJsonWebsocketConsumer(AsyncJsonWebsocketConsumer):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
async def encode_json(cls, content):
|
||||
# Remove the type value, only used by Channels to choose the group to send to
|
||||
content.pop("type")
|
||||
|
||||
def encode_json(cls, content):
|
||||
return json.dumps(content, cls=DjangoJSONEncoder)
|
||||
|
||||
|
||||
|
@ -91,11 +89,31 @@ class PermConsumerMixin:
|
|||
http_user = True # Enable message.user
|
||||
perms_connect = []
|
||||
|
||||
async def connect(self):
|
||||
def connect(self, message, **kwargs):
|
||||
"""Check permissions on connection."""
|
||||
self.user = self.scope["user"]
|
||||
|
||||
if self.user.has_perms(self.perms_connect):
|
||||
await super().connect()
|
||||
if message.user.has_perms(self.perms_connect):
|
||||
super().connect(message, **kwargs)
|
||||
else:
|
||||
await self.close()
|
||||
self.close()
|
||||
|
||||
def raw_connect(self, message, **kwargs):
|
||||
# Same as original raw_connect method of JsonWebsocketConsumer
|
||||
# We add user to connection_groups call.
|
||||
groups = self.connection_groups(user=message.user, **kwargs)
|
||||
for group in groups:
|
||||
Group(group, channel_layer=message.channel_layer).add(message.reply_channel)
|
||||
self.connect(message, **kwargs)
|
||||
|
||||
def raw_disconnect(self, message, **kwargs):
|
||||
# Same as original raw_connect method of JsonWebsocketConsumer
|
||||
# We add user to connection_groups call.
|
||||
groups = self.connection_groups(user=message.user, **kwargs)
|
||||
for group in groups:
|
||||
Group(group, channel_layer=message.channel_layer).discard(
|
||||
message.reply_channel
|
||||
)
|
||||
self.disconnect(message, **kwargs)
|
||||
|
||||
def connection_groups(self, user, **kwargs):
|
||||
"""`message.user` is available as `user` arg. Original behavior."""
|
||||
return super().connection_groups(user=user, **kwargs)
|
||||
|
|
|
@ -44,11 +44,10 @@ from django.views.generic.detail import BaseDetailView
|
|||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from gestioncof.models import CofProfile
|
||||
from kfet import KFET_DELETED_TRIGRAMME
|
||||
from kfet import KFET_DELETED_TRIGRAMME, consumers
|
||||
from kfet.auth.decorators import kfet_password_auth
|
||||
from kfet.autocomplete import kfet_account_only_autocomplete, kfet_autocomplete
|
||||
from kfet.config import kfet_config
|
||||
from kfet.consumers import KPsul
|
||||
from kfet.decorators import teamkfet_required
|
||||
from kfet.forms import (
|
||||
AccountForm,
|
||||
|
@ -244,7 +243,6 @@ def account_create(request):
|
|||
account_form = AccountNoTriForm(request.POST, instance=account)
|
||||
account_form.save()
|
||||
messages.success(request, "Compte créé : %s" % account.trigramme)
|
||||
account.send_creation_email()
|
||||
return redirect("kfet.account.create")
|
||||
except Account.UserHasAccount as e:
|
||||
messages.error(
|
||||
|
@ -1055,13 +1053,8 @@ def kpsul_update_addcost(request):
|
|||
|
||||
kfet_config.set(addcost_for=account, addcost_amount=amount)
|
||||
|
||||
data = {
|
||||
"addcost": {"for": account and account.trigramme or None, "amount": amount},
|
||||
"type": "kpsul",
|
||||
}
|
||||
|
||||
KPsul.group_send("kfet.kpsul", data)
|
||||
|
||||
data = {"addcost": {"for": account and account.trigramme or None, "amount": amount}}
|
||||
consumers.KPsul.group_send("kfet.kpsul", data)
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
|
@ -1245,7 +1238,7 @@ def kpsul_perform_operations(request):
|
|||
)
|
||||
|
||||
# Websocket data
|
||||
websocket_data = {"type": "kpsul"}
|
||||
websocket_data = {}
|
||||
websocket_data["groups"] = [
|
||||
{
|
||||
"add": True,
|
||||
|
@ -1292,9 +1285,7 @@ def kpsul_perform_operations(request):
|
|||
websocket_data["articles"].append(
|
||||
{"id": article["id"], "stock": article["stock"]}
|
||||
)
|
||||
|
||||
KPsul.group_send("kfet.kpsul", websocket_data)
|
||||
|
||||
consumers.KPsul.group_send("kfet.kpsul", websocket_data)
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
|
@ -1489,7 +1480,7 @@ def cancel_operations(request):
|
|||
articles = Article.objects.values("id", "stock").filter(pk__in=articles_pk)
|
||||
|
||||
# Websocket data
|
||||
websocket_data = {"checkouts": [], "articles": [], "type": "kpsul"}
|
||||
websocket_data = {"checkouts": [], "articles": []}
|
||||
for checkout in checkouts:
|
||||
websocket_data["checkouts"].append(
|
||||
{"id": checkout["id"], "balance": checkout["balance"]}
|
||||
|
@ -1498,8 +1489,7 @@ def cancel_operations(request):
|
|||
websocket_data["articles"].append(
|
||||
{"id": article["id"], "stock": article["stock"]}
|
||||
)
|
||||
|
||||
KPsul.group_send("kfet.kpsul", websocket_data)
|
||||
consumers.KPsul.group_send("kfet.kpsul", websocket_data)
|
||||
|
||||
data["canceled"] = list(opes)
|
||||
data["opegroups_to_update"] = list(opegroups)
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gestioasso.settings")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gestioasso.settings.local")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.contrib.auth.models import User
|
|||
from django.db import models
|
||||
from django.db.models import Min
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from shared.utils import choices_length
|
||||
|
||||
|
@ -44,13 +44,9 @@ class PetitCoursAbility(models.Model):
|
|||
|
||||
class Meta:
|
||||
app_label = "gestioncof"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["user", "niveau", "matiere"], name="unique_competence_level"
|
||||
)
|
||||
]
|
||||
verbose_name = "Compétence petits cours"
|
||||
verbose_name_plural = "Compétences des petits cours"
|
||||
unique_together = ("user", "niveau", "matiere")
|
||||
|
||||
def __str__(self):
|
||||
return "{:s} - {!s} - {:s}".format(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "petitscours/base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block page_size %}col-sm-8{% endblock %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "petitscours/base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>Demandes de petits cours</h2>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
<table class="table table-striped">
|
||||
<tr class="danger"><td><strong>Date</strong></td><td> {{ demande.created }}</td></tr>
|
||||
<tr class="warning"><td><strong>Nom/prénom</strong></td><td> {{ demande.name }}</td></tr>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script src="{% static 'vendor/jquery/jquery-ui.min.js' %}" type="text/javascript"></script>
|
||||
|
|
|
@ -10,14 +10,14 @@ Le COF a reçu une demande de petit cours qui te correspond. Tu es en haut de la
|
|||
|
||||
¤ Lieu (si préféré) : {{ demande.lieu }}
|
||||
|
||||
{% if matieres|length > 1 %}¤ Matières :
|
||||
{% for matiere in matieres %} ¤ {{ matiere }}
|
||||
{% endfor %}{% else %}¤ Matière : {% for matiere in matieres %}{{ matiere }}
|
||||
{% endfor %}{% endif %}
|
||||
¤ Niveau : {{ demande.get_niveau_display }}
|
||||
|
||||
¤ Remarques diverses (désolé pour les balises HTML) : {{ demande.remarques }}
|
||||
|
||||
{% if matieres|length > 1 %}¤ Matières :
|
||||
{% for matiere in matieres %} ¤ {{ matiere }}
|
||||
{% endfor %}{% else %}¤ Matière : {% for matiere in matieres %}{{ matiere }}
|
||||
{% endfor %}{% endif %}
|
||||
Voilà, cette personne te contactera peut-être sous peu, tu pourras voir les détails directement avec elle (prix, modalités, ...). Pour indication, 30 Euro/h semble être la moyenne.
|
||||
|
||||
Si tu te rends compte qu'en fait tu ne peux pas/plus donner de cours en ce moment, ça serait cool que tu décoches la case "Recevoir des propositions de petits cours" sur GestioCOF. Ensuite dès que tu voudras réapparaître tu pourras recocher la case et tu seras à nouveau sur la liste.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "petitscours/base_title.html" %}
|
||||
{% load static %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>
|
||||
|
|
|
@ -15,8 +15,8 @@ server {
|
|||
rewrite ^/gestion$ http://localhost:8080/gestion/ redirect;
|
||||
|
||||
# Les pages statiques sont servies à part.
|
||||
location /static { try_files $uri $uri/ =404; }
|
||||
location /media { try_files $uri $uri/ =404; }
|
||||
location /gestion/static { try_files $uri $uri/ =404; }
|
||||
location /gestion/media { try_files $uri $uri/ =404; }
|
||||
|
||||
# On proxy-pass les requêtes vers les pages dynamiques à daphne
|
||||
location / {
|
||||
|
|
|
@ -11,7 +11,7 @@ WorkingDirectory=/vagrant
|
|||
Environment="DJANGO_SETTINGS_MODULE=gestioasso.settings.dev"
|
||||
ExecStart=/home/vagrant/venv/bin/daphne \
|
||||
-u /srv/gestiocof/gestiocof.sock \
|
||||
gestioasso.asgi:application
|
||||
cof.asgi:channel_layer
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
@ -10,10 +10,7 @@ Group=vagrant
|
|||
TimeoutSec=300
|
||||
WorkingDirectory=/vagrant
|
||||
Environment="DJANGO_SETTINGS_MODULE=gestioasso.settings.dev"
|
||||
ExecStart=/home/vagrant/venv/bin/python manage.py runworker \
|
||||
'kfet.open.team' \
|
||||
'kfet.open.base' \
|
||||
'kpsul'
|
||||
ExecStart=/home/vagrant/venv/bin/python manage.py runworker
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
@ -3,6 +3,6 @@ django-debug-toolbar==3.2.*
|
|||
ipython
|
||||
|
||||
# Tools
|
||||
black==22.3.0
|
||||
black
|
||||
flake8
|
||||
isort
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
-r requirements.txt
|
||||
|
||||
# Postgresql bindings
|
||||
psycopg2==2.9.*
|
||||
psycopg2<2.8
|
||||
|
||||
# Redis
|
||||
django-redis-cache==3.0.*
|
||||
redis==3.5.*
|
||||
channels-redis==3.4.*
|
||||
django-redis-cache==2.1.*
|
||||
redis~=2.10.6
|
||||
asgi-redis==1.4.*
|
||||
|
||||
# ASGI protocol and HTTP server
|
||||
daphne==3.0.*
|
||||
asgiref~=1.1.2
|
||||
daphne==1.3.0
|
||||
|
||||
# ldap bindings
|
||||
python-ldap
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
Django==3.2.*
|
||||
Django==2.2.*
|
||||
Pillow==7.2.0
|
||||
authens==0.1b4
|
||||
channels==3.0.*
|
||||
authens==0.1b0
|
||||
channels==1.1.*
|
||||
configparser==3.5.0
|
||||
django-autocomplete-light==3.9.4
|
||||
django-autocomplete-light==3.3.*
|
||||
django-bootstrap-form==3.3
|
||||
django-cas-ng==4.3.*
|
||||
django-cors-headers==3.13.0
|
||||
django-djconfig==0.10.0
|
||||
django-hCaptcha==0.2.0
|
||||
django-cas-ng==3.6.*
|
||||
django-cors-headers==2.2.0
|
||||
django-djconfig==0.8.0
|
||||
django-hCaptcha==0.1.0
|
||||
django-js-reverse==0.9.1
|
||||
django-widget-tweaks==1.4.1
|
||||
icalendar==4.0.7
|
||||
python-dateutil==2.8.1
|
||||
statistics==1.0.3.5
|
||||
wagtail-modeltranslation==0.11.*
|
||||
wagtail==2.13.*
|
||||
wagtail-modeltranslation==0.10.*
|
||||
wagtail==2.7.*
|
||||
wagtailmenus==3.0.*
|
||||
|
|
|
@ -3,8 +3,8 @@ source =
|
|||
bda
|
||||
bds
|
||||
clubs
|
||||
cof
|
||||
events
|
||||
gestioasso
|
||||
gestioncof
|
||||
kfet
|
||||
petitscours
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
import datetime
|
||||
import random
|
||||
from decimal import Decimal
|
||||
|
||||
import msgpack
|
||||
from channels_redis.core import RedisChannelLayer
|
||||
|
||||
|
||||
def encode_kf(obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return {"__decimal__": True, "as_str": str(obj)}
|
||||
elif isinstance(obj, datetime.datetime):
|
||||
return {"__datetime__": True, "as_str": obj.strftime("%Y%m%dT%H:%M:%S.%f")}
|
||||
return obj
|
||||
|
||||
|
||||
def decode_kf(obj):
|
||||
if "__decimal__" in obj:
|
||||
obj = Decimal(obj["as_str"])
|
||||
elif "__datetime__" in obj:
|
||||
obj = datetime.datetime.strptime(obj["as_str"], "%Y%m%dT%H:%M:%S.%f")
|
||||
return obj
|
||||
|
||||
|
||||
class ChannelLayer(RedisChannelLayer):
|
||||
def serialize(self, message):
|
||||
"""Serializes to a byte string."""
|
||||
value = msgpack.packb(message, default=encode_kf, use_bin_type=True)
|
||||
|
||||
if self.crypter:
|
||||
value = self.crypter.encrypt(value)
|
||||
|
||||
# As we use an sorted set to expire messages
|
||||
# we need to guarantee uniqueness, with 12 bytes.
|
||||
random_prefix = random.getrandbits(8 * 12).to_bytes(12, "big")
|
||||
return random_prefix + value
|
||||
|
||||
def deserialize(self, message):
|
||||
"""Deserializes from a byte string."""
|
||||
# Removes the random prefix
|
||||
message = message[12:]
|
||||
|
||||
if self.crypter:
|
||||
message = self.crypter.decrypt(message, self.expiry + 10)
|
||||
return msgpack.unpackb(message, object_hook=decode_kf, raw=False)
|
32
shell.nix
32
shell.nix
|
@ -1,12 +1,29 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
{ pkgs ? import <nixpkgs> { }, ... }:
|
||||
|
||||
let
|
||||
python = pkgs.python39;
|
||||
python = pkgs.python38;
|
||||
|
||||
django-types = python.pkgs.buildPythonPackage rec {
|
||||
pname = "django-types";
|
||||
version = "0.17.0";
|
||||
|
||||
format = "pyproject";
|
||||
|
||||
src = pkgs.fetchPypi {
|
||||
inherit pname version;
|
||||
hash = "sha256-wcQqt4h2xXxyg0LVqwYHJas3H8jcg7uFuuC+BoRqrXA=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = with python.pkgs; [ poetry-core ];
|
||||
|
||||
# setup.cfg tries to pull in nonexistent LICENSE.txt file
|
||||
# postPatch = "rm setup.cfg";
|
||||
|
||||
# propagatedBuildInputs = [ django typing-extensions ];
|
||||
};
|
||||
in
|
||||
|
||||
|
||||
pkgs.mkShell {
|
||||
shellHook = ''
|
||||
export DJANGO_SETTINGS_MODULE=gestioasso.settings.local
|
||||
|
@ -17,10 +34,7 @@ pkgs.mkShell {
|
|||
pip install -r requirements-devel.txt | grep -v 'Requirement already satisfied:'
|
||||
'';
|
||||
|
||||
packages =
|
||||
[ python ]
|
||||
++ (with python.pkgs; [
|
||||
django-types
|
||||
packages = [ python django-types ] ++ (with python.pkgs; [
|
||||
pip
|
||||
virtualenv
|
||||
python-ldap
|
||||
|
|
Loading…
Reference in a new issue