diff --git a/.gitignore b/.gitignore index f12190af..ab791b2e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ venv/ /src media/ *.log +*.sqlite3 + +# PyCharm +.idea +.cache diff --git a/README.md b/README.md index 1a3d575e..01f4ead2 100644 --- a/README.md +++ b/README.md @@ -66,119 +66,65 @@ car par défaut Django n'écoute que sur l'adresse locale de la machine virtuell or vous voudrez accéder à GestioCOF depuis votre machine physique. L'url à entrer dans le navigateur est `localhost:8000`. + #### Serveur de développement type production -Sur la VM Vagrant, un serveur apache est configuré pour servir GestioCOF de -façon similaire à la version en production : on utilise +Juste histoire de jouer, pas indispensable pour développer : + +La VM Vagrant héberge en plus un serveur nginx configuré pour servir GestioCOF +comme en production : on utilise [Daphne](https://github.com/django/daphne/) et `python manage.py runworker` -derrière un reverse-proxy apache. Le tout est monitoré par -[supervisor](http://supervisord.org/). +derrière un reverse-proxy nginx. Ce serveur se lance tout seul et est accessible en dehors de la VM à l'url -`localhost:8080`. Toutefois il ne se recharge pas tout seul lorsque le code -change, il faut relancer le worker avec `sudo supervisorctl restart worker` pour -visualiser la dernière version du code. +`localhost:8080/gestion/`. Toutefois il ne se recharge pas tout seul lorsque le +code change, il faut relancer le worker avec `sudo systemctl restart +worker.service` pour visualiser la dernière version du code. + ### Installation manuelle -Si vous optez pour une installation manuelle plutôt que d'utiliser Vagrant, il -est fortement conseillé d'utiliser un environnement virtuel pour Python. +Vous pouvez opter pour une installation manuelle plutôt que d'utiliser Vagrant, +il est fortement conseillé d'utiliser un environnement virtuel pour Python. -Il vous faudra installer pip, les librairies de développement de python, un -client et un serveur MySQL ainsi qu'un serveur redis ; sous Debian et dérivées -(Ubuntu, ...) : +Il vous faudra installer pip, les librairies de développement de python ainsi +que sqlite3, un moteur de base de données léger et simple d'utilisation. Sous +Debian et dérivées (Ubuntu, ...) : - sudo apt-get install python-pip python-dev libmysqlclient-dev redis-server + sudo apt-get install python3-pip python3-dev sqlite3 Si vous décidez d'utiliser un environnement virtuel Python (virtualenv; fortement conseillé), déplacez-vous dans le dossier où est installé GestioCOF (le dossier où se trouve ce README), et créez-le maintenant : - virtualenv env -p $(which python3) + python3 -m venv venv -L'option `-p` sert à préciser l'exécutable python à utiliser. Vous devez choisir -python3, si c'est la version de python par défaut sur votre système, ceci n'est -pas nécessaire. Pour l'activer, il faut faire +Pour l'activer, il faut faire - . env/bin/activate + . venv/bin/activate dans le même dossier. Vous pouvez maintenant installer les dépendances Python depuis le fichier `requirements-devel.txt` : + pip install -U pip pip install -r requirements-devel.txt -Copiez le fichier `cof/settings_dev.py` dans `cof/settings.py`. +Pour terminer, copier le fichier `cof/settings/secret_example.py` vers +`cof/settings/secret.py`. Sous Linux ou Mac, préférez plutôt un lien symbolique +pour profiter de façon transparente des mises à jour du fichier: -#### Installation avec MySQL + ln -s secret_example.py cof/settings/secret.py -Il faut maintenant installer MySQL. Si vous n'avez pas déjà MySQL installé sur -votre serveur, il faut l'installer ; sous Debian et dérivées (Ubuntu, ...) : - - sudo apt-get install mysql-server - -Il vous demandera un mot de passe pour le compte d'administration MySQL, -notez-le quelque part (ou n'en mettez pas, le serveur n'est accessible que -localement par défaut). Si vous utilisez une autre distribution, consultez la -documentation de votre distribution pour savoir comment changer ce mot de passe -et démarrer le serveur MySQL (c'est automatique sous Ubuntu). - -Vous devez alors créer un utilisateur local et une base `cof_gestion`, avec le -mot de passe de votre choix (remplacez `mot_de_passe`) : - - mysql -uroot -e "CREATE DATABASE cof_gestion; GRANT ALL PRIVILEGES ON cof_gestion.* TO 'cof_gestion'@'localhost' IDENTIFIER BY 'mot_de_passe'" - -Éditez maintenant le fichier `cof/settings.py` pour y intégrer ces changements ; -la définition de `DATABASES` doit ressembler à (à nouveau, remplacez -`mot_de_passe` de façon appropriée) : - - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'cof_gestion', - 'USER': 'cof_gestion', - 'PASSWORD': 'mot_de_passe', - } - } - -#### Installation avec SQLite - -GestioCOF est installé avec MySQL sur la VM COF, et afin d'avoir un -environnement de développement aussi proche que possible de ce qui tourne en -vrai pour éviter les mauvaises surprises, il est conseillé d'utiliser MySQL sur -votre machine de développement également. Toutefois, GestioCOF devrait -fonctionner avec d'autres moteurs SQL, et certains préfèrent utiliser SQLite -pour sa légèreté et facilité d'installation. - -Si vous décidez d'utiliser SQLite, il faut l'installer ; sous Debian et dérivées : - - sudo apt-get install sqlite3 - -puis éditer le fichier `cof/settings.py` pour que la définition de `DATABASES` -ressemble à : - - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } - } #### Fin d'installation -Il ne vous reste plus qu'à initialiser les modèles de Django avec la commande suivante : +Il ne vous reste plus qu'à initialiser les modèles de Django et peupler la base +de donnée avec les données nécessaires au bon fonctionnement de GestioCOF + des +données bidons bien pratiques pour développer avec la commande suivante : - python manage.py migrate - -Charger les mails indispensables au bon fonctionnement de GestioCOF : - - python manage.py syncmails - -Une base de donnée pré-remplie est disponible en lançant les commandes : - - python manage.py loaddata gestion sites accounts groups articles - python manage.py loaddevdata + bash provisioning/prepare_django.sh Vous êtes prêts à développer ! Lancer GestioCOF en faisant @@ -188,7 +134,7 @@ Vous êtes prêts à développer ! Lancer GestioCOF en faisant Pour mettre à jour les paquets Python, utiliser la commande suivante : - pip install --upgrade -r requirements.txt -r requirements-devel.txt + pip install --upgrade -r requirements-devel.txt Pour mettre à jour les modèles après une migration, il faut ensuite faire : @@ -197,6 +143,6 @@ Pour mettre à jour les modèles après une migration, il faut ensuite faire : ## Documentation utilisateur -Une brève documentation utilisateur pour se familiariser plus vite avec l'outil -est accessible sur le -[wiki](https://git.eleves.ens.fr/cof-geek/gestioCOF/wikis/home). +Une brève documentation utilisateur est accessible sur le +[wiki](https://git.eleves.ens.fr/cof-geek/gestioCOF/wikis/home) pour avoir une +idée de la façon dont le COF utilise GestioCOF. diff --git a/bda/__init__.py b/bda/__init__.py index e69de29b..8b137891 100644 --- a/bda/__init__.py +++ b/bda/__init__.py @@ -0,0 +1 @@ + diff --git a/bda/admin.py b/bda/admin.py index fc10c326..0cc66d43 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -13,32 +13,76 @@ from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\ Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente +class ReadOnlyMixin(object): + readonly_fields_update = () + + def get_readonly_fields(self, request, obj=None): + readonly_fields = super().get_readonly_fields(request, obj) + if obj is None: + return readonly_fields + else: + return readonly_fields + self.readonly_fields_update + + class ChoixSpectacleInline(admin.TabularInline): model = ChoixSpectacle sortable_field_name = "priority" +class AttributionTabularAdminForm(forms.ModelForm): + listing = None + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + spectacles = Spectacle.objects.select_related('location') + if self.listing is not None: + spectacles = spectacles.filter(listing=self.listing) + self.fields['spectacle'].queryset = spectacles + + +class WithoutListingAttributionTabularAdminForm(AttributionTabularAdminForm): + listing = False + + +class WithListingAttributionTabularAdminForm(AttributionTabularAdminForm): + listing = True + + class AttributionInline(admin.TabularInline): model = Attribution extra = 0 + listing = None def get_queryset(self, request): - qs = super(AttributionInline, self).get_queryset(request) - return qs.filter(spectacle__listing=False) + qs = super().get_queryset(request) + if self.listing is not None: + qs.filter(spectacle__listing=self.listing) + return qs -class AttributionInlineListing(admin.TabularInline): - model = Attribution +class WithListingAttributionInline(AttributionInline): + form = WithListingAttributionTabularAdminForm + listing = True + + +class WithoutListingAttributionInline(AttributionInline): exclude = ('given', ) - extra = 0 - - def get_queryset(self, request): - qs = super(AttributionInlineListing, self).get_queryset(request) - return qs.filter(spectacle__listing=True) + form = WithoutListingAttributionTabularAdminForm + listing = False -class ParticipantAdmin(admin.ModelAdmin): - inlines = [AttributionInline, AttributionInlineListing] +class ParticipantAdminForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['choicesrevente'].queryset = ( + Spectacle.objects + .select_related('location') + ) + + +class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin): + inlines = [WithListingAttributionInline, WithoutListingAttributionInline] def get_queryset(self, request): return Participant.objects.annotate(nb_places=Count('attributions'), @@ -65,6 +109,8 @@ class ParticipantAdmin(admin.ModelAdmin): actions_on_bottom = True list_per_page = 400 readonly_fields = ("total",) + readonly_fields_update = ('user', 'tirage') + form = ParticipantAdminForm def send_attribs(self, request, queryset): datatuple = [] @@ -94,6 +140,20 @@ class ParticipantAdmin(admin.ModelAdmin): class AttributionAdminForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if 'spectacle' in self.fields: + self.fields['spectacle'].queryset = ( + Spectacle.objects + .select_related('location') + ) + if 'participant' in self.fields: + self.fields['participant'].queryset = ( + Participant.objects + .select_related('user', 'tirage') + ) + def clean(self): cleaned_data = super(AttributionAdminForm, self).clean() participant = cleaned_data.get("participant") @@ -106,7 +166,7 @@ class AttributionAdminForm(forms.ModelForm): return cleaned_data -class AttributionAdmin(admin.ModelAdmin): +class AttributionAdmin(ReadOnlyMixin, admin.ModelAdmin): def paid(self, obj): return obj.participant.paid paid.short_description = 'A payé' @@ -116,6 +176,7 @@ class AttributionAdmin(admin.ModelAdmin): 'participant__user__first_name', 'participant__user__last_name') form = AttributionAdminForm + readonly_fields_update = ('spectacle', 'participant') class ChoixSpectacleAdmin(admin.ModelAdmin): @@ -160,6 +221,24 @@ class SalleAdmin(admin.ModelAdmin): search_fields = ('name', 'address') +class SpectacleReventeAdminForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['answered_mail'].queryset = ( + Participant.objects + .select_related('user', 'tirage') + ) + self.fields['seller'].queryset = ( + Participant.objects + .select_related('user', 'tirage') + ) + self.fields['soldTo'].queryset = ( + Participant.objects + .select_related('user', 'tirage') + ) + + class SpectacleReventeAdmin(admin.ModelAdmin): """ Administration des reventes de spectacles @@ -182,6 +261,7 @@ class SpectacleReventeAdmin(admin.ModelAdmin): actions = ['transfer', 'reinit'] actions_on_bottom = True + form = SpectacleReventeAdminForm def transfer(self, request, queryset): """ diff --git a/bda/algorithm.py b/bda/algorithm.py index bf9b690f..7f18ce18 100644 --- a/bda/algorithm.py +++ b/bda/algorithm.py @@ -22,8 +22,7 @@ class Algorithm(object): show.requests - on crée des tables de demandes pour chaque personne, afin de pouvoir modifier les rankings""" - self.max_group = \ - 2 * choices.aggregate(Max('priority'))['priority__max'] + self.max_group = 2*max(choice.priority for choice in choices) self.shows = [] showdict = {} for show in shows: diff --git a/bda/forms.py b/bda/forms.py index 2029645b..c0417d1e 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -1,35 +1,40 @@ # -*- coding: utf-8 -*- -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - from django import forms from django.forms.models import BaseInlineFormSet from django.utils import timezone + from bda.models import Attribution, Spectacle -class BaseBdaFormSet(BaseInlineFormSet): - def clean(self): - """Checks that no two articles have the same title.""" - super(BaseBdaFormSet, self).clean() - if any(self.errors): - # Don't bother validating the formset unless each form is valid on - # its own - return - spectacles = [] - for i in range(0, self.total_form_count()): - form = self.forms[i] - if not form.cleaned_data: - continue - spectacle = form.cleaned_data['spectacle'] - delete = form.cleaned_data['DELETE'] - if not delete and spectacle in spectacles: - raise forms.ValidationError( - "Vous ne pouvez pas vous inscrire deux fois pour le " - "même spectacle.") - spectacles.append(spectacle) +class InscriptionInlineFormSet(BaseInlineFormSet): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # self.instance is a Participant object + tirage = self.instance.tirage + + # set once for all "spectacle" field choices + # - restrict choices to the spectacles of this tirage + # - force_choices avoid many db requests + spectacles = tirage.spectacle_set.select_related('location') + choices = [(sp.pk, str(sp)) for sp in spectacles] + self.force_choices('spectacle', choices) + + def force_choices(self, name, choices): + """Set choices of a field. + + As ModelChoiceIterator (default use to get choices of a + ModelChoiceField), it appends an empty selection if requested. + + """ + for form in self.forms: + field = form.fields[name] + if field.empty_label is not None: + field.choices = [('', field.empty_label)] + choices + else: + field.choices = choices class TokenForm(forms.Form): @@ -38,7 +43,7 @@ class TokenForm(forms.Form): class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): def label_from_instance(self, obj): - return "%s" % obj.spectacle + return "%s" % str(obj.spectacle) class ResellForm(forms.Form): @@ -50,9 +55,13 @@ class ResellForm(forms.Form): def __init__(self, participant, *args, **kwargs): super(ResellForm, self).__init__(*args, **kwargs) - self.fields['attributions'].queryset = participant.attribution_set\ - .filter(spectacle__date__gte=timezone.now())\ + self.fields['attributions'].queryset = ( + participant.attribution_set + .filter(spectacle__date__gte=timezone.now()) .exclude(revente__seller=participant) + .select_related('spectacle', 'spectacle__location', + 'participant__user') + ) class AnnulForm(forms.Form): @@ -64,11 +73,15 @@ class AnnulForm(forms.Form): def __init__(self, participant, *args, **kwargs): super(AnnulForm, self).__init__(*args, **kwargs) - self.fields['attributions'].queryset = participant.attribution_set\ + self.fields['attributions'].queryset = ( + participant.attribution_set .filter(spectacle__date__gte=timezone.now(), revente__isnull=False, revente__notif_sent=False, revente__soldTo__isnull=True) + .select_related('spectacle', 'spectacle__location', + 'participant__user') + ) class InscriptionReventeForm(forms.Form): @@ -79,8 +92,11 @@ class InscriptionReventeForm(forms.Form): def __init__(self, tirage, *args, **kwargs): super(InscriptionReventeForm, self).__init__(*args, **kwargs) - self.fields['spectacles'].queryset = tirage.spectacle_set.filter( - date__gte=timezone.now()) + self.fields['spectacles'].queryset = ( + tirage.spectacle_set + .select_related('location') + .filter(date__gte=timezone.now()) + ) class SoldForm(forms.Form): @@ -93,7 +109,9 @@ class SoldForm(forms.Form): super(SoldForm, self).__init__(*args, **kwargs) self.fields['attributions'].queryset = ( participant.attribution_set - .filter(revente__isnull=False, - revente__soldTo__isnull=False) - .exclude(revente__soldTo=participant) + .filter(revente__isnull=False, + revente__soldTo__isnull=False) + .exclude(revente__soldTo=participant) + .select_related('spectacle', 'spectacle__location', + 'participant__user') ) diff --git a/bda/models.py b/bda/models.py index 15acf686..41462d70 100644 --- a/bda/models.py +++ b/bda/models.py @@ -7,18 +7,30 @@ from custommail.shortcuts import send_mass_custom_mail from django.contrib.sites.models import Site from django.db import models +from django.db.models import Count from django.contrib.auth.models import User from django.conf import settings from django.utils import timezone, formats +def get_generic_user(): + generic, _ = User.objects.get_or_create( + username="bda_generic", + defaults={"email": "bda@ens.fr", "first_name": "Bureau des arts"} + ) + return generic + + class Tirage(models.Model): title = models.CharField("Titre", max_length=300) ouverture = models.DateTimeField("Date et heure d'ouverture du tirage") fermeture = models.DateTimeField("Date et heure de fermerture du tirage") tokens = models.TextField("Graine(s) du tirage", blank=True) active = models.BooleanField("Tirage actif", default=False) - appear_catalogue = models.BooleanField("Tirage à afficher dans le catalogue", default=False) + appear_catalogue = models.BooleanField( + "Tirage à afficher dans le catalogue", + default=False + ) enable_do_tirage = models.BooleanField("Le tirage peut être lancé", default=False) @@ -93,32 +105,29 @@ class Spectacle(models.Model): Envoie un mail de rappel à toutes les personnes qui ont une place pour ce spectacle. """ - # On récupère la liste des participants - members = {} - for attr in Attribution.objects.filter(spectacle=self).all(): - member = attr.participant.user - if member.id in members: - members[member.id][1] = 2 - else: - members[member.id] = [member, 1] - # FIXME : faire quelque chose de ça, un utilisateur bda_generic ? - # # Pour le BdA - # members[0] = ['BdA', 1, 'bda@ens.fr'] - # members[-1] = ['BdA', 2, 'bda@ens.fr'] + # On récupère la liste des participants + le BdA + members = list( + User.objects + .filter(participant__attributions=self) + .annotate(nb_attr=Count("id")).order_by() + ) + bda_generic = get_generic_user() + bda_generic.nb_attr = 1 + members.append(bda_generic) # On écrit un mail personnalisé à chaque participant datatuple = [( 'bda-rappel', - {'member': member[0], 'nb_attr': member[1], 'show': self}, + {'member': member, "nb_attr": member.nb_attr, 'show': self}, settings.MAIL_DATA['rappels']['FROM'], - [member[0].email]) - for member in members.values() + [member.email]) + for member in members ] send_mass_custom_mail(datatuple) # On enregistre le fait que l'envoi a bien eu lieu self.rappel_sent = timezone.now() self.save() # On renvoie la liste des destinataires - return members.values() + return members @property def is_past(self): diff --git a/bda/templates/bda/mails-rappel.html b/bda/templates/bda/mails-rappel.html index 73625d1c..c10503b0 100644 --- a/bda/templates/bda/mails-rappel.html +++ b/bda/templates/bda/mails-rappel.html @@ -3,41 +3,46 @@ {% block realcontent %}

Mails de rappels

{% if sent %} -

Les mails de rappel pour le spectacle {{ show.title }} ont bien été envoyés aux personnes suivantes

- +

Les mails de rappel pour le spectacle {{ show.title }} ont bien été envoyés aux personnes suivantes

+ {% else %} -

Voulez vous envoyer les mails de rappel pour le spectacle - {{ show.title }} ?

- {% if show.rappel_sent %} -

Attention, les mails ont déjà été envoyés le - {{ show.rappel_sent }}

- {% endif %} +

Voulez vous envoyer les mails de rappel pour le spectacle {{ show.title }} ?

{% endif %} - {% if not sent %} -
- {% csrf_token %} -
- -
-
- {% endif %} +
+ {% if not sent %} +
+ {% csrf_token %} +
+ +
+
+ {% endif %} +
+ +
+ +

+ Note : le template de ce mail peut être modifié à + cette adresse +

+ +
-
-

Forme des mails

Une seule place

- {% for part in exemple_mail_1place %} -
{{ part }}
- {% endfor %} + {% for part in exemple_mail_1place %} +
{{ part }}
+ {% endfor %}

Deux places

{% for part in exemple_mail_2places %} -
{{ part }}
+
{{ part }}
{% endfor %} + {% endblock %} diff --git a/bda/templates/bda-participants.html b/bda/templates/bda/participants.html similarity index 77% rename from bda/templates/bda-participants.html rename to bda/templates/bda/participants.html index 289d1761..85af4a2e 100644 --- a/bda/templates/bda-participants.html +++ b/bda/templates/bda/participants.html @@ -36,17 +36,26 @@

Ajouter une attribution

-
- - -
- - + + +
+ Page d'envoi manuel des mails de rappel +
+ {% block extra_head %}{% endblock %} diff --git a/gestioncof/templates/gestioncof/banner_update.html b/gestioncof/templates/gestioncof/banner_update.html new file mode 100644 index 00000000..b2432eae --- /dev/null +++ b/gestioncof/templates/gestioncof/banner_update.html @@ -0,0 +1,23 @@ +{% extends "base_title.html" %} +{% load bootstrap %} +{% load i18n %} + +{% block page_size %}col-sm-8{%endblock%} + +{% block realcontent %} +

{% trans "Global configuration" %}

+
+
+ {% csrf_token %} + + {% for field in form %} + {{ field | bootstrap }} + {% endfor %} + +
+
+ +
+
+{% endblock %} diff --git a/gestioncof/templates/gestioncof/base_header.html b/gestioncof/templates/gestioncof/base_header.html index a7e29eb7..21441875 100644 --- a/gestioncof/templates/gestioncof/base_header.html +++ b/gestioncof/templates/gestioncof/base_header.html @@ -16,6 +16,14 @@

{% if user.first_name %}{{ user.first_name }}{% else %}{{ user.username }}{% endif %}, {% if user.profile.is_cof %}au COF{% else %}non-COF{% endif %}

+ +{% if config.gestion_banner %} + +{% endif %} + {% if messages %} {% for message in messages %}
diff --git a/gestioncof/templates/home.html b/gestioncof/templates/home.html index 5f783a48..acc04f30 100644 --- a/gestioncof/templates/home.html +++ b/gestioncof/templates/home.html @@ -1,4 +1,5 @@ {% extends "gestioncof/base_header.html" %} +{% load wagtailcore_tags %} {% block homelink %} {% endblock %} @@ -55,7 +56,8 @@

K-Fêt

    -
  • Page d'accueil
  • + {# TODO: Since Django 1.9, we can store result with "as", allowing proper value management (if None) #} +
  • Page d'accueil
  • Calendrier
  • {% if perms.kfet.is_team %}
  • K-Psul
  • diff --git a/gestioncof/views.py b/gestioncof/views.py index a29ffb88..c5701510 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import unicodecsv import uuid from datetime import timedelta @@ -9,12 +7,18 @@ from custommail.shortcuts import send_custom_mail from django.shortcuts import redirect, get_object_or_404, render from django.http import Http404, HttpResponse, HttpResponseForbidden from django.contrib.auth.decorators import login_required -from django.contrib.auth.views import login as django_login_view +from django.contrib.auth.views import ( + login as django_login_view, logout as django_logout_view, +) from django.contrib.auth.models import User from django.contrib.sites.models import Site +from django.core.urlresolvers import reverse_lazy +from django.views.generic import FormView from django.utils import timezone +from django.utils.translation import ugettext_lazy as _ from django.contrib import messages -import django.utils.six as six + +from django_cas_ng.views import logout as cas_logout_view from gestioncof.models import Survey, SurveyAnswer, SurveyQuestion, \ SurveyQuestionAnswer @@ -24,10 +28,11 @@ from gestioncof.models import EventCommentField, EventCommentValue, \ CalendarSubscription from gestioncof.models import CofProfile, Club from gestioncof.decorators import buro_required, cof_required -from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \ - SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \ - RegistrationProfileForm, EventForm, CalendarForm, EventFormset, \ - RegistrationPassUserForm, ClubsForm +from gestioncof.forms import ( + UserProfileForm, EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, + RegistrationUserForm, RegistrationProfileForm, EventForm, CalendarForm, + EventFormset, RegistrationPassUserForm, ClubsForm, GestioncofConfigForm +) from bda.models import Tirage, Spectacle @@ -81,20 +86,29 @@ def login_ext(request): @login_required -def logout(request): - try: - profile = request.user.profile - except CofProfile.DoesNotExist: - profile, created = CofProfile.objects.get_or_create(user=request.user) - if profile.login_clipper: - return redirect("django_cas_ng.views.logout") +def logout(request, next_page=None): + if next_page is None: + next_page = request.GET.get('next', None) + + profile = getattr(request.user, 'profile', None) + + if profile and profile.login_clipper: + msg = _('Déconnexion de GestioCOF et CAS réussie. À bientôt {}.') + logout_view = cas_logout_view else: - return redirect("django.contrib.auth.views.logout") + msg = _('Déconnexion de GestioCOF réussie. À bientôt {}.') + logout_view = django_logout_view + + messages.success(request, msg.format(request.user.get_short_name())) + return logout_view(request, next_page=next_page) @login_required def survey(request, survey_id): - survey = get_object_or_404(Survey, id=survey_id) + survey = get_object_or_404( + Survey.objects.prefetch_related('questions', 'questions__answers'), + id=survey_id, + ) if not survey.survey_open or survey.old: raise Http404 success = False @@ -399,12 +413,8 @@ def registration_form2(request, login_clipper=None, username=None, def registration(request): if request.POST: request_dict = request.POST.copy() - # num ne peut pas être défini manuellement - if "num" in request_dict: - del request_dict["num"] member = None login_clipper = None - success = False # ----- # Remplissage des formulaires @@ -439,7 +449,6 @@ def registration(request): member = user_form.save() profile, _ = CofProfile.objects.get_or_create(user=member) was_cof = profile.is_cof - request_dict["num"] = profile.num # Maintenant on remplit le formulaire de profil profile_form = RegistrationProfileForm(request_dict, instance=profile) @@ -493,16 +502,18 @@ def registration(request): for club in clubs_form.cleaned_data['clubs']: club.membres.add(member) club.save() - success = True - # Messages - if success: - msg = ("L'inscription de {:s} ({:s}) a été " - "enregistrée avec succès" - .format(member.get_full_name(), member.email)) - if member.profile.is_cof: - msg += "Il est désormais membre du COF n°{:d} !".format( - member.profile.num) - messages.success(request, msg, extra_tags='safe') + + # --- + # Success + # --- + + msg = ("L'inscription de {:s} ({:s}) a été " + "enregistrée avec succès." + .format(member.get_full_name(), member.email)) + if profile.is_cof: + msg += "\nIl est désormais membre du COF n°{:d} !".format( + member.profile.id) + messages.success(request, msg, extra_tags='safe') return render(request, "gestioncof/registration_post.html", {"user_form": user_form, "profile_form": profile_form, @@ -566,10 +577,10 @@ def export_members(request): writer = unicodecsv.writer(response) for profile in CofProfile.objects.filter(is_cof=True).all(): user = profile.user - bits = [profile.num, user.username, user.first_name, user.last_name, + bits = [profile.id, user.username, user.first_name, user.last_name, user.email, profile.phone, profile.occupation, profile.departement, profile.type_cotiz] - writer.writerow([six.text_type(bit) for bit in bits]) + writer.writerow([str(bit) for bit in bits]) return response @@ -585,10 +596,10 @@ def csv_export_mega(filename, qs): comments = "---".join( [comment.content for comment in reg.comments.all()]) bits = [user.username, user.first_name, user.last_name, user.email, - profile.phone, profile.num, + profile.phone, profile.id, profile.comments if profile.comments else "", comments] - writer.writerow([six.text_type(bit) for bit in bits]) + writer.writerow([str(bit) for bit in bits]) return response @@ -607,8 +618,8 @@ def export_mega_remarksonly(request): user = reg.user profile = user.profile bits = [user.username, user.first_name, user.last_name, user.email, - profile.phone, profile.num, profile.comments, val.content] - writer.writerow([six.text_type(bit) for bit in bits]) + profile.phone, profile.id, profile.comments, val.content] + writer.writerow([str(bit) for bit in bits]) return response @@ -760,3 +771,18 @@ def calendar_ics(request, token): response = HttpResponse(content=vcal.to_ical()) response['Content-Type'] = "text/calendar" return response + + +class ConfigUpdate(FormView): + form_class = GestioncofConfigForm + template_name = "gestioncof/banner_update.html" + success_url = reverse_lazy("home") + + def dispatch(self, request, *args, **kwargs): + if request.user is None or not request.user.is_superuser: + raise Http404 + return super().dispatch(request, *args, **kwargs) + + def form_valid(self, form): + form.save() + return super().form_valid(form) diff --git a/kfet/apps.py b/kfet/apps.py index 29f9f98e..3dd2c0e8 100644 --- a/kfet/apps.py +++ b/kfet/apps.py @@ -12,3 +12,9 @@ class KFetConfig(AppConfig): def ready(self): import kfet.signals + self.register_config() + + def register_config(self): + import djconfig + from kfet.forms import KFetConfigForm + djconfig.register(KFetConfigForm) diff --git a/kfet/backends.py b/kfet/backends.py index ba3bce9d..fb9538d0 100644 --- a/kfet/backends.py +++ b/kfet/backends.py @@ -1,15 +1,12 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - 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', '') @@ -18,13 +15,15 @@ class KFetBackend(object): return None try: - password_sha256 = hashlib.sha256(password.encode('utf-8')).hexdigest() + password_sha256 = ( + hashlib.sha256(password.encode('utf-8')) + .hexdigest() + ) account = Account.objects.get(password=password_sha256) - user = account.cofprofile.user + return account.cofprofile.user except Account.DoesNotExist: return None - return user class GenericTeamBackend(object): def authenticate(self, username=None, token=None): @@ -46,6 +45,10 @@ class GenericTeamBackend(object): def get_user(self, user_id): try: - return User.objects.get(pk=user_id) + return ( + User.objects + .select_related('profile__account_kfet') + .get(pk=user_id) + ) except User.DoesNotExist: return None diff --git a/kfet/cms/__init__.py b/kfet/cms/__init__.py new file mode 100644 index 00000000..0f6cab45 --- /dev/null +++ b/kfet/cms/__init__.py @@ -0,0 +1 @@ +default_app_config = 'kfet.cms.apps.KFetCMSAppConfig' diff --git a/kfet/cms/apps.py b/kfet/cms/apps.py new file mode 100644 index 00000000..1db0e043 --- /dev/null +++ b/kfet/cms/apps.py @@ -0,0 +1,10 @@ +from django.apps import AppConfig + + +class KFetCMSAppConfig(AppConfig): + name = 'kfet.cms' + label = 'kfetcms' + verbose_name = 'CMS K-Fêt' + + def ready(self): + from . import hooks diff --git a/kfet/cms/context_processors.py b/kfet/cms/context_processors.py new file mode 100644 index 00000000..34f175d1 --- /dev/null +++ b/kfet/cms/context_processors.py @@ -0,0 +1,20 @@ +from kfet.models import Article + + +def get_articles(request=None): + articles = ( + Article.objects + .filter(is_sold=True, hidden=False) + .select_related('category') + .order_by('category__name', 'name') + ) + pressions, others = [], [] + for article in articles: + if article.category.name == 'Pression': + pressions.append(article) + else: + others.append(article) + return { + 'pressions': pressions, + 'articles': others, + } diff --git a/kfet/cms/fixtures/kfet_wagtail_17_05.json b/kfet/cms/fixtures/kfet_wagtail_17_05.json new file mode 100644 index 00000000..f6a46c30 --- /dev/null +++ b/kfet/cms/fixtures/kfet_wagtail_17_05.json @@ -0,0 +1,1456 @@ +[ +{ + "fields": { + "root_page": 9, + "port": 8000, + "site_name": "Global", + "hostname": "localhost", + "is_default_site": true + }, + "pk": 2, + "model": "wagtailcore.site" +}, +{ + "fields": { + "live": true, + "show_in_menus": false, + "numchild": 1, + "title": "Root", + "slug": "root", + "depth": 1, + "expire_at": null, + "search_description": "", + "content_type": [ + "wagtailcore", + "page" + ], + "owner": null, + "expired": false, + "first_published_at": null, + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001", + "latest_revision_created_at": null, + "url_path": "/", + "locked": false, + "seo_title": "" + }, + "pk": 1, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 5, + "title": "Bienvenue en K-Fêt", + "slug": "k-fet", + "depth": 3, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "000100010001", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/", + "locked": false, + "seo_title": "Accueil" + }, + "pk": 3, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 0, + "title": "Mode d'emploi", + "slug": "mode-demploi", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010001", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/mode-demploi/", + "locked": false, + "seo_title": "" + }, + "pk": 4, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 0, + "title": "L'\u00e9quipe", + "slug": "equipe", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010002", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/equipe/", + "locked": false, + "seo_title": "" + }, + "pk": 5, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 0, + "title": "La carte", + "slug": "carte", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010003", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/carte/", + "locked": false, + "seo_title": "" + }, + "pk": 6, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 0, + "title": "Les soir\u00e9es", + "slug": "soirees", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010004", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/soirees/", + "locked": false, + "seo_title": "" + }, + "pk": 7, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 0, + "title": "Le flipper", + "slug": "flipper", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010005", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/flipper/", + "locked": false, + "seo_title": "" + }, + "pk": 8, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": true, + "numchild": 1, + "title": "Global", + "slug": "global", + "depth": 2, + "expire_at": null, + "search_description": "", + "content_type": [ + "wagtailcore", + "page" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "00010001", + "latest_revision_created_at": null, + "url_path": "/global/", + "locked": false, + "seo_title": "" + }, + "pk": 9, + "model": "wagtailcore.page" +}, +{ + "fields": { + "live": true, + "show_in_menus": false, + "numchild": 0, + "title": "Mentions l\u00e9gales", + "slug": "mentions-legales", + "depth": 4, + "expire_at": null, + "search_description": "", + "content_type": [ + "kfetcms", + "kfetpage" + ], + "owner": [ + "root" + ], + "expired": false, + "first_published_at": "2017-05-28T04:20:00.000Z", + "has_unpublished_changes": false, + "go_live_at": null, + "path": "0001000100010006", + "latest_revision_created_at": null, + "url_path": "/global/k-fet/mentions-legales/", + "locked": false, + "seo_title": "" + }, + "pk": 10, + "model": "wagtailcore.page" +}, +{ + "fields": { + "name": "Root", + "numchild": 1, + "path": "0001", + "depth": 1 + }, + "pk": 1, + "model": "wagtailcore.collection" +}, +{ + "fields": { + "name": "K-F\u00eat", + "numchild": 0, + "path": "00010001", + "depth": 2 + }, + "pk": 2, + "model": "wagtailcore.collection" +}, +{ + "pk": 1, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Hugo", + "nick_name": "", + "photo": 3, + "last_name": "Manet" + } +}, +{ + "pk": 2, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Lisa", + "nick_name": "", + "photo": 4, + "last_name": "Gourdon" + } +}, +{ + "pk": 3, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Pierre", + "nick_name": "", + "photo": 5, + "last_name": "Quesselaire" + } +}, +{ + "pk": 4, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Thibault", + "nick_name": "", + "photo": 6, + "last_name": "Scoquard" + } +}, +{ + "pk": 5, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Arnaud", + "nick_name": "", + "photo": 7, + "last_name": "Fanthomme" + } +}, +{ + "pk": 6, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Vincent", + "nick_name": "", + "photo": 8, + "last_name": "Balerdi" + } +}, +{ + "pk": 7, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Nathana\u00ebl", + "nick_name": "", + "photo": 9, + "last_name": "Willaime" + } +}, +{ + "pk": 8, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "\u00c9lisabeth", + "nick_name": "", + "photo": 10, + "last_name": "Miller" + } +}, +{ + "pk": 9, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Arthur", + "nick_name": "B2O", + "photo": 11, + "last_name": "Lesage" + } +}, +{ + "pk": 10, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Sarah", + "nick_name": "", + "photo": 12, + "last_name": "Asset" + } +}, +{ + "pk": 11, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Alexandre", + "nick_name": "", + "photo": 13, + "last_name": "Legrand" + } +}, +{ + "pk": 12, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "\u00c9tienne", + "nick_name": "", + "photo": 14, + "last_name": "Baudel" + } +}, +{ + "pk": 13, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Marine", + "nick_name": "", + "photo": 15, + "last_name": "Snape" + } +}, +{ + "pk": 14, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Anatole", + "nick_name": "", + "photo": 16, + "last_name": "Gosset" + } +}, +{ + "pk": 15, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Jacko", + "nick_name": "", + "photo": 17, + "last_name": "Rastikian" + } +}, +{ + "pk": 16, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Alexandre", + "nick_name": "", + "photo": 18, + "last_name": "Jannaud" + } +}, +{ + "pk": 17, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Aur\u00e9lien", + "nick_name": "", + "photo": 19, + "last_name": "Delobelle" + } +}, +{ + "pk": 18, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Sylvain", + "nick_name": "", + "photo": 20, + "last_name": "Douteau" + } +}, +{ + "pk": 19, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Rapha\u00ebl", + "nick_name": "", + "photo": 21, + "last_name": "Lescanne" + } +}, +{ + "pk": 20, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Romain", + "nick_name": "", + "photo": 22, + "last_name": "Gourvil" + } +}, +{ + "pk": 21, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Marie", + "nick_name": "", + "photo": 23, + "last_name": "Labeye" + } +}, +{ + "pk": 22, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Oscar", + "nick_name": "", + "photo": 24, + "last_name": "Blumberg" + } +}, +{ + "pk": 23, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Za\u00efd", + "nick_name": "", + "photo": 25, + "last_name": "Allybokus" + } +}, +{ + "pk": 24, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Damien", + "nick_name": "", + "photo": 26, + "last_name": "Garreau" + } +}, +{ + "pk": 25, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Andr\u00e9a", + "nick_name": "", + "photo": 27, + "last_name": "Londonez-Lopez" + } +}, +{ + "pk": 26, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Tristan", + "nick_name": "", + "photo": 28, + "last_name": "Roussel" + } +}, +{ + "pk": 27, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Guillaume", + "nick_name": "", + "photo": 29, + "last_name": "Vernade" + } +}, +{ + "pk": 28, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Lucas", + "nick_name": "", + "photo": 30, + "last_name": "Mercier" + } +}, +{ + "pk": 29, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Fran\u00e7ois", + "nick_name": "M\u00e9talleux", + "photo": 31, + "last_name": "Maillot" + } +}, +{ + "pk": 30, + "model": "kfetcms.memberteam", + "fields": { + "first_name": "Fabrice", + "nick_name": "", + "photo": 32, + "last_name": "Catoire" + } +}, +{ + "pk": 3, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    La K-F\\u00eat, c'est quoi ?

    \\n\\n

    \\n Eh bien la K-F\\u00eat, c'est le bar des \\u00e9l\\u00e8ves de l'\\u00c9cole normale\\n sup\\u00e9rieure. Elle est situ\\u00e9e dans les locaux de l'\\u00c9cole, au pied de\\n l'escalier C (plan). On y trouve \\u00e0 boire, bien s\\u00fbr,\\n des bi\\u00e8res en nombre pl\\u00e9thorique mais aussi caf\\u00e9s, th\\u00e9s, softs et de quoi\\n grignoter. Ah oui un point important, on ne va pas \\u00e0 la K-F\\u00eat, on va EN K-F\\u00eat.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Mais on n'y fait que boire et manger ?

    \\n\\n

    \\n Que nenni, \\u00f4 jeune et innocent conscrit-e ! La K-F\\u00eat n'est pas un bouge\\n sordide o\\u00f9 des piliers de bar passent leurs journ\\u00e9es \\u00e0 picoler. Enfin pas\\n uniquement. C'est aussi un lieu de divertissement avec\\n son flipper (la mythique, la seule, l'unique,\\n la g\\u00e9niale Amazon Hunt), son baby-foot et le lieu d'\\u00e9lection des \\nbridgeur-se-s, du club jeux, des joueur-se-s de poker voire des quelques\\n irr\\u00e9ductibles du boulot qui y viennent bosser en profitant du point \\nd'acc\\u00e8s wifi. \\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Ah \\u00e7a a l'air bien mais... qui s'en occupe ? C'est ouvert quand ?

    \\n\\n

    \\n L'\\u00e9quipe d'\\u00e9l\\u00e8ves motiv\\u00e9-e-s qui s'occupent de la K-F\\u00eat s'appelle, en toute logique, l'\\u00e9quipe K-F\\u00eat.\\n Elle est men\\u00e9e par un-e leader charismatique et bien-aim\\u00e9-e, \\naccompagn\\u00e9-e de ses troupes de fid\\u00e8les, les K-F\\u00eat wo-men, boys et girls.\\n Le local de la K-F\\u00eat n'est ouvert que si un-e K-F\\u00eat wo-man est \\npr\\u00e9sente. \\u00c0 savoir la plupart du temps entre 12h et 3h du matin.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Et je peux y faire ce que je veux ?

    \\n\\n

    \\n Oui et non. Nous ne sommes pas ta grand-m\\u00e8re et nous n'allons\\n certainement pas t'emp\\u00eacher de faire la f\\u00eate, ni de d\\u00e9guster des pintes\\n jusqu'au petit p\\u00f4t. Par contre nous attendons de toi que tu ne sois pas\\n un-e gros-se con-ne. A priori pas de raison de le croire, mais jette tout de m\\u00eame\\n un \\u0153il sur le mode d'emploi de la K-F\\u00eat, \\u00e7a\\n pourrait t'\\u00e9viter de perdre un genoux ou deux...\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    J'adore la K-F\\u00eat, j'aimerais y organiser une soir\\u00e9e, c'est possible ?

    \\n\\n

    \\n Bien s\\u00fbr\\u00a0! Pour cela commence par lire ce petit\\n guide histoire de savoir dans quoi tu t'engages puis contacte ton-ta chef-fe K-F\\u00eat ador\\u00e9-e pour v\\u00e9rifier que la date de ta\\n soir\\u00e9e n'est pas d\\u00e9j\\u00e0 prise par une autre f\\u00eate et obtenir son\\n accord.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    J'ai une question \\u00e0 vous poser. O\\u00f9 puis-je vous contacter ?

    \\n\\n

    \\n Commence d\\u00e9j\\u00e0 par jeter un oeil sur le mode\\n d'emploi de la K-F\\u00eat. Si la r\\u00e9ponse \\u00e0 tes interrogations ne s'y\\n trouve pas, rien n'est perdu. En effet le service informatique de \\nl'\\u00c9cole, dans sa grande mansu\\u00e9tude, a mis \\u00e0 disposition de l'\\u00e9quipe \\nK-F\\u00eat une adresse e-mail, k-fet@ens.fr. Mais sinon, passe en K-F\\u00eat, il y aura sans doute un K-F\\u00eat wo-man qui saura r\\u00e9pondre \\u00e0 ta question.\\n

    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "pk": 4, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    Article 0 : La K-F\\u00eat n'existe pas.

    \", \"type\": \"rich\"}, {\"value\": \"

    La K-F\\u00eat, c'est magique, comment \\u00e7a marche ?

    La K-F\\u00eat n'a \\nrien de magique, il n'y a pas de petits d\\u00e9mons qui font le m\\u00e9nage, pas \\nplus que d'arbustes g\\u00e9n\\u00e9tiquement modifi\\u00e9s aux OGM sur lesquels poussent\\n les bouteilles de bi\\u00e8res. La K-F\\u00eat c'est avant tout une \\u00e9quipe qui sacrifie une partie de son temps libre pour que tout se passe pour le mieux.

    \", \"type\": \"rich\"}, {\"value\": \"

    Que puis-je faire pour vous aider un peu ?

    D\\u00e9j\\u00e0 ne pas poser \\nde probl\\u00e8mes, c'est \\u00e0 dire ne pas r\\u00e9veiller tout l'internat en sortant, \\nessayer de ne pas finir dans un \\u00e9tat trop avanc\\u00e9 d'alcoolisation, etc...\\n Mine de rien \\u00e7a nous \\u00e9viterait quelques probl\\u00e8mes.

    Ensuite, comme\\n tu le sais s\\u00fbrement les bi\\u00e8res sont consign\\u00e9es, il est donc pr\\u00e9f\\u00e9rable \\npour nous que tu n'embarques pas les bouteilles en souvenir dans ta \\nthurne. Mieux, tu peux nous faire gagner du temps de rangement en les \\nramenant au bar en partant. Et encore mieux, tu peux jeter tes d\\u00e9chets \\n(gobelets, boite de pringles, etc...). Si tu fais d\\u00e9j\\u00e0 tout \\u00e7a tu nous \\nsimplifieras grandement la vie.

    \", \"type\": \"rich\"}, {\"value\": \"

    Le syst\\u00e8me mon\\u00e9taire de la K-F\\u00eat

    En bon \\u00e9tat souverain et \\nind\\u00e9pendant, la K-F\\u00eat a sa propre monnaie : l'unit\\u00e9 K-F\\u00eat (UKF). Elle \\nvaut 10 centimes d'euro. La K-F\\u00eat ne battant pas monnaie, les UKF que tu\\n poss\\u00e8des sont not\\u00e9es sur ton compte, identifi\\u00e9 par un trigramme (une \\nsuite de trois caract\\u00e8res) et que tu peux recharger en liquide ou par \\nch\\u00e8que. Note que si tu y tiens vraiment, tu peux payer en liquide, mais \\nposs\\u00e9der un compte est bien plus pratique.

    \", \"type\": \"rich\"}, {\"value\": \"

    Comment commander \\u00e0 boire ou \\u00e0 manger ?

    Pour commander \\u00e0 boire ou \\u00e0 manger, il suffit de demander \\u00e0 un membre de l'\\u00e9quipe K-F\\u00eat.\\n Et \\u00e7a marche encore mieux si la demande est effectu\\u00e9e avec le sourire \\nau d\\u00e9but et un merci \\u00e0 la fin : l'\\u00e9quipe est constitu\\u00e9e de volontaires \\nb\\u00e9n\\u00e9voles, et mieux vaut ne pas les prendre pour des chiens. EN AUCUN \\nCAS on ne passe derri\\u00e8re le bar si on n'est pas membre de l'\\u00e9quipe K-F\\u00eat.

    \", \"type\": \"rich\"}, {\"value\": \"

    Puis-je fumer en K-F\\u00eat ?

    Non ! Imagine-toi les jours de \\nsoir\\u00e9es, la K-F\\u00eat remplie et tout le monde qui fume... On finirait tous \\navec des poumons aussi crades que le sol de la K-F\\u00eat. Ce serait quand \\nm\\u00eame dommage pour la recherche fran\\u00e7aise qu'on cr\\u00e8ve tous avant 30 ans, \\nnon ?

    Par contre tu peux fumer dehors, il y a m\\u00eame des cendriers \\njuste pour toi, par contre tu remarqueras que les chambres de l'internat\\n se trouvent juste au dessus de toi. T\\u00e2che donc de ne pas faire trop de \\nbruit.

    \", \"type\": \"rich\"}, {\"value\": \"

    Et amener ma propre bouteille ?

    D\\u00e9j\\u00e0 c'est apporter, enfin en\\n tout cas avant de la boire. Ensuite la K-F\\u00eat est un lieu de \\nconvivialit\\u00e9 o\\u00f9 les bi\\u00e8res te sont vendues au prix co\\u00fbtant,\\n franchement ce serait pas fair-play de te la jouer solo. Alors \\n\\u00e9videment il y a des exceptions, par exemple si tu reviens de Belgique \\net que tu veux faire go\\u00fbter de la Wesvleteren \\u00e0 tes amis de l'\\u00e9quipe K-F\\u00eat,\\n ou si tu veux organiser une d\\u00e9gustation de vins avec la charcuterie qui\\n va bien. Tu comprendras qu'un pack de Kro c'est quand m\\u00eame pas la m\\u00eame \\nclasse...

    \", \"type\": \"rich\"}, {\"value\": \"

    Je peux passer ma musique ?

    Bien s\\u00fbr, nous sommes tr\\u00e8s loin \\nde penser tout conna\\u00eetre en mati\\u00e8re de musique. Mais comme nous sommes \\nentre gens civilis\\u00e9s, et que je te rappelle que tu n'as pas le droit de \\npasser derri\\u00e8re le bar, il convient de demander \\u00e0 un-e membre de l'\\u00e9quipe K-F\\u00eat\\n afin qu'ille t'indique qui est \\u00e0 l'origine de ces chansons que tu \\nn'appr\\u00e9cies apparemment pas. Apr\\u00e8s avoir obtenu son accord tu peux \\ndemander \\u00e0 quelqu'un de mettre ta playlist, qui peut-\\u00eatre sur un lecteur\\n mp3, sur Deezer ou juste sur l'ordi, mais dans ce dernier cas ce sera plus dur puisque tu n'y aura pas acc\\u00e8s directement.

    Le plus simple pour toi (et pour nous) est donc de pr\\u00e9voir des playlists sur Deezer\\n d'avance et de nous les proposer. Par contre, sois gentil-le, n'insiste\\n pas si nous ne voulons pas de ta musique traditionnelle hongroise. Par \\nailleurs, si un trop grand nombre de personnes nous demande de passer de\\n la musique, l'\\u00e9quipe K-F\\u00eat peut ne pas acc\\u00e9der \\u00e0 ta requ\\u00eate.

    \", \"type\": \"rich\"}, {\"value\": \"

    Comment organiser une soir\\u00e9e en K-F\\u00eat ?

    Tout membre du COF \\npeut organiser une soir\\u00e9e en K-F\\u00eat \\u00e0 la condition qu'elle soit publique \\net annonc\\u00e9e une semaine \\u00e0 l'avance par des affiches dans l'\\u00e9cole et un \\nmot dans le BOcal. Il faut bien sur aussi l'accord du COF qui s'occupe \\nde voir si \\u00e7a ne pose pas de probl\\u00e8me \\u00e0 l'admin, celui de la K-F\\u00eat team \\npour qu'il y ait des K-F\\u00eat wo-men pour servir et s\\u00fbrement du BOUM pour \\nqu'il s'occupe de la musique. Nous t'avons tout r\\u00e9sum\\u00e9 ici\\n ; merci qui ? Une fois que tu as accompli ces formalit\\u00e9s, il ne te \\nreste plus qu'\\u00e0 imprimer et coller des affiches pour que ta soir\\u00e9e soit \\nun succ\\u00e8s !

    \", \"type\": \"rich\"}, {\"value\": \"

    D'autres remarques ?

    Des tonnes, en voici quelques unes :

    • Ce n'est pas caf\\u00e8t, ni kfet, ni caf\\u00e9t\\u00e9ria, c'est K-F\\u00eat, avec les majuscules.
    • On dit \\\"en K-F\\u00eat\\\".
    • On ne passe pas derri\\u00e8re le bar,\\n je sais je l'ai d\\u00e9j\\u00e0 dit, mais \\u00e7a a du mal \\u00e0 rentrer. S'il n'y a \\npersonne pour servir c'est que les K-F\\u00eat people sont soit occup\\u00e9-e-s \\nquelque chose d'important en arri\\u00e8re-K-F\\u00eat, soit sont pos\\u00e9-e-s dans le \\ncanap\\u00e9 \\u00e0 c\\u00f4t\\u00e9 du bar, soit sont en train de jouer \\u00e0 l'Amazon. Demande-leur, ou prends ton mal en patience.
    • La K-F\\u00eat n'est pas une porcherie, tu n'es pas oblig\\u00e9-e de laisser tout ton bordel quand tu pars.
    • Merci d'avoir lu jusque l\\u00e0.
    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "pk": 5, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": [{\"value\": \"

    Les ancien-ne-s Chef-fe-s K-F\\u00eat

    Les ancien-ne-s Chef-fe-s K-F\\u00eat doivent bien \\u00eatre pr\\u00e9sent\\u00e9-e-s avant \\nl'\\u00e9quipe actuelle. C'est gr\\u00e2ce \\u00e0 elleux qu'elle tourne encore, gr\\u00e2ce \\u00e0 \\nelleux qu'elle a bien tourn\\u00e9, et puis, de pr\\u00e8s comme de loin, illes \\nveillent encore sur nous. Ce sont les diff\\u00e9rentes facettes de la K-F\\u00eat \\nhistorique, bien que d'un certain point de vue, illes se ressemblent \\ntou-te-s : les Chef-fe-s K-F\\u00eat sont une dynastie, ils n'ont pas \\u00e9t\\u00e9 \\nChef-fe-s apr\\u00e8s avoir prouv\\u00e9 quoi que ce soit, illes l'ont \\u00e9t\\u00e9 parce que\\n ce r\\u00f4le leur revenait de droit. On na\\u00eet Chef-fe K-F\\u00eat, on ne le devient\\n pas. Et on le reste toujours, dans l'\\u00e2me.

    \", \"type\": \"rich\"}, {\"value\": {\"members\": [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], \"show_only\": 12}, \"type\": \"group_team\"}], \"type\": \"group\"}, {\"value\": [{\"value\": \"

    Le chef

    Le-la chef-fe K-F\\u00eat, celui-celle qui a le droit de vie et de mort sur les \\u00e2mes \\u00e9gar\\u00e9es qui fr\\u00e9quentent la K-F\\u00eat.

    \", \"type\": \"rich\"}, {\"value\": {\"members\": [1, 2], \"show_only\": null}, \"type\": \"group_team\"}], \"type\": \"group\"}, {\"value\": [{\"value\": \"

    Les K-F\\u00eat Wo-Men

    Les K-F\\u00eat wo-men poss\\u00e8dent les cl\\u00e9s de la K-F\\u00eat. Ce sont elleux qui peuvent d\\u00e9cider ou non d'ouvrir la K-F\\u00eat.

    \", \"type\": \"rich\"}, {\"value\": {\"members\": [3, 4, 5, 6, 7, 8, 9, 10, 11, 12], \"show_only\": null}, \"type\": \"group_team\"}], \"type\": \"group\"}, {\"value\": [{\"value\": \"

    Les Vieux-illes

    Les vieux-illes sont d'ancien-ne-s K-F\\u00eat wo-men qui ne viennent plus \\naussi souvent qu'avant, illes servent toujours, mais n'ont en g\\u00e9n\\u00e9ral \\nplus les cl\\u00e9s. Illes existent n\\u00e9anmoins, et on les garde (pour \\ncertain-e-s) parce qu'au fond, on les aime quand m\\u00eame, et qu'en plus, \\nilles en savent plus que n'importe qui sur la K-F\\u00eat.

    \", \"type\": \"rich\"}], \"type\": \"group\"}, {\"value\": \"

    Les K-F\\u00eat boys et girls

    \\n\\n

    Les K-F\\u00eat boys and girls font de main d'\\u0153uvre bon march\\u00e9 pour la \\nK-F\\u00eat, illes peuvent passer derri\\u00e8re le bar, prendre vos commandes et \\nrecharger votre compte si par malheur il est \\u00e0 sec. La liste de \\ncelleux-ci est trop longue pour tou-te-s les citer, pour les reconna\\u00eetre\\n regarde les gens qui passent derri\\u00e8re le bar tout en conservant leur \\nint\\u00e9grit\\u00e9 physique.

    \", \"type\": \"rich\"}, {\"value\": \"

    Comment devient-on K-F\\u00eat people ?

    Grande question que tout le monde se pose un jour ou l'autre. Pour \\nacc\\u00e9der au titre prestigieux de K-F\\u00eat boy-girl, il est n\\u00e9cessaire mais \\npas suffisant d'\\u00eatre assid\\u00fbment pr\\u00e9sent-e en K-F\\u00eat, et d'\\u00eatre pr\\u00eat-e \\u00e0 \\ntrimer pour elle. Si tu es souvent en K-F\\u00eat, que tu es sympathique et \\nmotiv\\u00e9-e, et surtout en fin de compte si le-la chef-fe le veut bien, tu \\npourras devenir K-F\\u00eat boy-girl et passer derri\\u00e8re le bar pour servir. \\nEnsuite, si tu es motiv\\u00e9-e et efficace, ou simplement si t'es un-e pote \\ndu-de la chef-fe et qu'ille n'a aucun scrupule, tu pourras devenir K-F\\u00eat\\n wo-man et avoir la cl\\u00e9.

    Et comme la K-F\\u00eat c'est avant tout beaucoup d'emmerdes on a pas envie\\n de te forcer la main, on veut que cela vienne de toi. Donc si tu te \\nsens pr\\u00eat-e \\u00e0 participer \\u00e0 la vie mouvement\\u00e9e de la K-F\\u00eat fais-en part \\nau-\\u00e0 la chef-fe. Ille ne va pas te manger.

    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "pk": 6, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    Le service de la bi\\u00e8re est, historiquement, la mission et le sacerdoce \\ndu K-F\\u00eat people. Ille y est d\\u00e9vou\\u00e9-e corps et \\u00e2me, et accomplit sa t\\u00e2che\\n avec ardeur et passion. Voyons comment se d\\u00e9clinent les occasions \\nd'approcher du nirvana brassicole. Les prix donn\\u00e9s sont en UKF. Si tu \\nn'as pas compris, va voir par ici.

    \", \"type\": \"rich\"}, {\"value\": null, \"type\": \"carte\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "column-md-2 column-lg-3" + } +}, +{ + "pk": 7, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    Tu veux organiser une soir\\u00e9e en K-F\\u00eat ? Pas de probl\\u00e8me !

    \", \"type\": \"rich\"}, {\"value\": \"

    Quand puis-je organiser une soir\\u00e9e ?

    \\n\\n

    \\n Tu peux organiser une soir\\u00e9e le jour que tu souhaites, \\u00e0 condition que la\\n date ne soit pas d\\u00e9j\\u00e0 prise par quelqu'un d'autre. Sache par contre que la\\n K-F\\u00eat ne te sera pas enti\\u00e8rement d\\u00e9di\\u00e9e et que les utilisateur-rice-s habituel-le-s\\n continueront de la fr\\u00e9quenter (et risquent fortement de squatter ta\\n soir\\u00e9e). Donc si tu veux un peu d'intimit\\u00e9 les soir\\u00e9es du week-end sont plus\\n conseill\\u00e9es (mais l'\\u00e9quipe risque de ne pas \\u00eatre pr\\u00e9sente), mais aussi\\n plus pris\\u00e9es, d\\u00e9p\\u00eache-toi de r\\u00e9server la tienne.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Quelles d\\u00e9marches dois-je effectuer ?

    \\n

    \\n D\\u00e9j\\u00e0 pr\\u00e9venir poliment l'\\u00e9quipe K-F\\u00eat, et\\n surtout le-la chef-fe pour v\\u00e9rifier que la date est encore libre, et qu'il y\\n aura au moins quelqu'un pour t'ouvrir la K-F\\u00eat. Ensuite, si ta soir\\u00e9e\\n n'est pas une simple bouffe qui finit avant minuit il faut pr\\u00e9venir les\\n vigiles via l'administration au moyen d'une demande d'autorisation de\\n soir\\u00e9e qui se trouve sur la section du p\\u00f4le Pr\\u00e9vention et S\\u00e9curit\\u00e9 sur l'intranet : demande d'autorisation de soir\\u00e9e.\\n \\u00c0 faire au moins une semaine avant ta soir\\u00e9e.\\n

    \\n

    \\n Si en plus tu as besoin que le BOUM s'occupe de la musique et/ou PLS des\\n lumi\\u00e8res c'est elleux qu'il faut contacter. Histoire de t'\\u00e9viter\\n d'avoir \\u00e0 chercher voici leur adresse\\u00a0: boum (at) ens (point) fr\\n et pls (at) ens (point) fr.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    C'est enfin le grand jour, je fais quoi ?

    \\n

    \\n D\\u00e9j\\u00e0 le m\\u00e9nage, oui je sais c'est chiant mais c'est le prix \\u00e0 payer pour\\n profiter du local. Demande \\u00e0 ce qu'un-e K-F\\u00eat wo-man t'ouvre et tu devrais avoir\\n \\u00e0 ta disposition tout ce qu'il faut pour faire briller la K-F\\u00eat (ou au moins on essaiera de\\n trouver ce qu'il faut). Fais par\\n contre attention aux bouteilles de bi\\u00e8re qui sont consign\\u00e9es, s'il n'y a\\n personne pour les ranger contente-toi de les mettre sur le bar, quelqu'un\\n s'en chargera plus tard. Les meubles peuvent \\u00eatre d\\u00e9plac\\u00e9s dans une salle\\n voisine si tu le souhaites, il faudra juste penser \\u00e0 les remettre en place.\\n

    \\n

    \\n Ensuite dans l'id\\u00e9al tu connais tous tes potes, donc en donner une liste \\u00e0\\n la loge permet d'\\u00e9viter quelques probl\\u00e8mes et quelques aller-retours.\\n Au-del\\u00e0 de 21h, les ext\\u00e9rieur-e-s ne peuvent rentrer qu'avec un-e Ulmien-ne ayant sa carte\\n sur lui-elle.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Je pourrai passer ma musique ?

    \\n\\n

    \\n Si le BOUM est pr\\u00e9sent, faut voir avec elleux : boum (at) ens (point) fr
    \\n Sinon, pr\\u00e9pare ta musique sur un lecteur mp3 ou une playlist\\n Deezer. Lors de la soir\\u00e9e,\\n demande \\u00e0 un-e K-F\\u00eat wo-man de passer ce que tu as pr\\u00e9par\\u00e9.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Et pour ce qui est de la nourriture, des boissons ?

    \\n

    \\n Tu peux apporter toute la nourriture que tu souhaites\\u00a0; pr\\u00e9vois assez\\n large, il y a beaucoup de K-F\\u00eat people \\u00e0 nourrir. Pour ce qui est de la\\n boisson, il faut te limiter aux boissons de cat\\u00e9gorie 2, c'est \\u00e0 dire\\n bi\\u00e8res, vins et boissons \\u00e0 base de vin, champagne et bien s\\u00fbr les boissons sans alcool.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Et pendant la soir\\u00e9e ?

    \\n

    \\n Ce soir c'est ton soir, il est donc bien s\\u00fbr \\u00e9vident que tu dois\\n rester pr\\u00e9sent-e et joignable du d\\u00e9but \\u00e0 la fin de la soir\\u00e9e. Id\\u00e9alement ce\\n doit aussi \\u00eatre le cas de tes \\\"Responsables ordre et discipline\\\". Vous ne serez pas\\n trop de deux ou trois pour r\\u00e9gler les probl\\u00e8mes qui pourraient survenir,\\n tes potes bourr\\u00e9-e-s, tes potes qui fument, tes potes qui font du bordel dans la cage d'escalier,\\n etc... Tous les probl\\u00e8mes qui pourraient survenir te seront imput\\u00e9s donc\\n pr\\u00e9viens-les, c'est tes potes apr\\u00e8s tout, non ?\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Apr\\u00e8s c'est bon ?

    \\n

    \\n Eh non, pas encore, apr\\u00e8s (ou le lendemain de) ta soir\\u00e9e il te faudra encore ranger,\\n faire le m\\u00e9nage et passer un coup de javel. Oui encore, mais bon, pense \\u00e0 toutes les fois o\\u00f9\\n c'est nous qui le faisons pour le bien de tou-te-s. Une fois n'est pas\\n coutume demande \\u00e0 un-e K-F\\u00eat wo-man de t'ouvrir et de te fournir tout le\\n mat\\u00e9riel dont tu pourrais avoir besoin, et l\\u00e0 o\\u00f9 c'est vraiment classe\\n c'est que tu peux m\\u00eame faire \\u00e7a en musique si tu le souhaites. N'oublie\\n pas non plus de rapporter les meubles que tu pourrais avoir sortis et que\\n les poubelles ne disparaissent pas toutes seules.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Une derni\\u00e8re remarque ?

    \\n\\n

    \\n Ouais, la K-F\\u00eat c'est pas chez m\\u00e9m\\u00e9, alors c'est peut-\\u00eatre ta soir\\u00e9e mais\\n si un-e membre de l'\\u00e9quipe K-F\\u00eat te dit quelque\\n chose (de baisser le son, de virer telle ou telle personne...) tu acceptes avec le sourire.\\n En particulier tu ne passes pas derri\\u00e8re le bar.\\n

    \", \"type\": \"rich\"}, {\"value\": \"

    Je ne parle pas bien fran\\u00e7ais, vous pourriez me faire un r\\u00e9sum\\u00e9 ?

    \\n

    \\n Organiser ta soir\\u00e9e c'est facile :\\n

    \\n
    • Envoie un mail \\u00e0 la K-F\\u00eat pour demander l'autorisation\\n : k-fet (at) ens (point) fr.
    • Lorsque c'est bon, remplis\\n le papier de l'admin, et\\n donne-le au-\\u00e0 la chef-fe K-F\\u00eat.
    • Pour la musique, l'alcool, contacte la K-F\\u00eat.
    • Le jour de la soir\\u00e9e, viens faire le m\\u00e9nage et donne une liste des\\n ext\\u00e9rieur-e-s \\u00e0 la loge.
    • Pendant la soir\\u00e9e, surveille tes invit\\u00e9s (pas trop de bruit \\u00e0\\n l'ext\\u00e9rieur de la K-F\\u00eat, pas de gens trop bourr\\u00e9s qui font des b\\u00eatises\\n avec les alarmes ou les sorties de secours...)
    • Apr\\u00e8s la soir\\u00e9e (le lendemain si tu veux) reviens faire le m\\u00e9nage.
    \\n

    \\n Voila, facile, non ?\\n

    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "pk": 8, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    Et le baby-foot

    \", \"type\": \"rich\"}, {\"value\": \"

    LE flipper

    \\n\\n\\n\\n

    \\n\\tIl existe en K-F\\u00eat une machine unique, inimitable, tout droit venue des\\n ann\\u00e9es folles et b\\u00e9nies o\\u00f9 les concepteurs de flippers connaissaient \\nencore leur m\\u00e9tier, o\\u00f9 les tilts \\u00e9taient m\\u00e9rit\\u00e9s et le jeu un art de \\nvivre. L'esth\\u00e8te appr\\u00e9cie et reconna\\u00eet imm\\u00e9diatement la beaut\\u00e9 sobre et \\nsauvage de l'Amazon Hunt II. D'admirateur, il se m\\u00e9tamorphose \\nin\\u00e9luctablement en joueur-se, puis en amant-e. Car l'Amazon est une \\nfemme, fatale \\u00e0 bien des \\u00e9gards, tou-te-s les grand-e-s joueur-euse-s \\nvous le diront. Dans la pr\\u00e9histoire de la K-F\\u00eat, des demi-dieux-d\\u00e9esses \\ndu flipper d\\u00e9sormais pass\\u00e9-e-s dans la l\\u00e9gende ont r\\u00e9dig\\u00e9 un trait\\u00e9 \\n(certain-e-s diront une bible, voire la Bible).

    \", \"type\": \"rich\"}, {\"value\": \"

    Le baby-foot

    \", \"type\": \"rich\"}, {\"value\": \"

    La d\\u00e9funte fun machine

    \\n\\n\\n\\nCette machine n'est plus. Mais elle reste dans le coeur de ceux qui \\nl'ont connue. C'est pourquoi cette section n'a pas \\u00e9t\\u00e9 retir\\u00e9e.

    Pour attaquer le cas \\u00e9trange de la machine bizarre qui tra\\u00eene \\u00e0 c\\u00f4t\\u00e9, \\ndisons simplement qu'elle s'appelle Monster Bash. On me souffle en r\\u00e9gie\\n que pour une fun machine, elle n'est pas si mal. De fait, elle t\\u00e9moigne\\n d'un humour d\\u00e9cal\\u00e9, absurde et parfois involontaire : ainsi, la \\ntraduction oscille entre le path\\u00e9tique et l'ignoble, en passant par le \\nburlesque. Le but est de r\\u00e9veiller et vaincre six monstres, parmi \\nlesquels Dracula et Frankenstein, pour les asservir et les rassembler \\ndans le plus grand groupe de rock de l'histoire : les \\u00abmonsters of rock\\u00bb\\n (traduction : \\u00abmonstres du rocher\\u00bb). Il n'y a pas pour le moment de \\ntrait\\u00e9 th\\u00e9orique de la Monster Bash, la jeu se r\\u00e9sumant de toute fa\\u00e7on \\u00e0\\n \\u00abmoi voir, moi actionner flip\\u00bb. Ce qui n'emp\\u00eache pas la machine en \\nquestion d'avoir son public d'habitu\\u00e9-e-s, bien au contraire. \\n

    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "pk": 10, + "model": "kfetcms.kfetpage", + "fields": { + "main_size": "", + "content": "[{\"value\": \"

    Responsable de la publication

    • Il s'agit de la pr\\u00e9sidence du COF :
      Association des \\u00c9l\\u00e8ves de l'\\u00c9cole Normale Sup\\u00e9rieure

      45 rue d'Ulm

      75005 Paris
    \", \"type\": \"rich\"}, {\"value\": \"

    Informations prestataires

    • L'h\\u00e9bergement est fourni \\u00e0 titre gracieux par le CRI:
      \\u00c9cole Normale Sup\\u00e9rieure
      Centre de Ressources Informatiques
      45 rue d'Ulm
      75005 Paris
    • Le d\\u00e9veloppement est assur\\u00e9 par COF-Geek.
    \", \"type\": \"rich\"}]", + "layout": "kfet/base_col_mult.html", + "no_header": false, + "col_count": "" + } +}, +{ + "model": "wagtaildocs.document", + "pk": 1, + "fields": { + "created_at": "2017-05-30T04:20:00.000Z", + "uploaded_by_user": [ + "root" + ], + "collection": 2, + "title": "K-F\u00eat - Plan d'acc\u00e8s", + "file": "documents/kfet_acces.pdf" + } +}, +{ + "model": "wagtaildocs.document", + "pk": 2, + "fields": { + "created_at": "2017-05-30T04:20:00.000Z", + "uploaded_by_user": [ + "root" + ], + "collection": 2, + "title": "K-F\u00eat - Demande d'autorisation", + "file": "documents/kfet_autorisation.pdf" + } +}, +{ + "model": "wagtaildocs.document", + "pk": 3, + "fields": { + "created_at": "2017-05-30T04:20:00.000Z", + "uploaded_by_user": [ + "root" + ], + "collection": 2, + "title": "K-F\u00eat - Trait\u00e9 de Flipper Th\u00e9orique", + "file": "documents/kfet_flipper.pdf" + } +}, +{ + "model": "wagtailimages.image", + "pk": 1, + "fields": { + "created_at": "2017-05-30T04:20:00.000Z", + "focal_point_width": null, + "height": 300, + "file": "original_images/kfet_amazon.jpg", + "collection": 2, + "focal_point_x": null, + "file_size": null, + "focal_point_height": null, + "focal_point_y": null, + "title": "K-F\u00eat - Amazon Hunt", + "width": 200, + "uploaded_by_user": [ + "root" + ] + } +}, +{ + "model": "wagtailimages.image", + "pk": 2, + "fields": { + "created_at": "2017-05-30T04:20:00.000Z", + "focal_point_width": null, + "height": 300, + "file": "original_images/kfet_funmachine.jpg", + "collection": 2, + "focal_point_x": null, + "file_size": null, + "focal_point_height": null, + "focal_point_y": null, + "title": "K-F\u00eat - Fun Machine", + "width": 200, + "uploaded_by_user": [ + "root" + ] + } +}, +{ + "fields": { + "width": 3020, + "file_size": null, + "file": "original_images/hugo_manet.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 3020, + "focal_point_width": null, + "focal_point_y": null, + "title": "Hugo Manet", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 3 +}, +{ + "fields": { + "width": 1566, + "file_size": null, + "file": "original_images/lisa_gourdon.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 1634, + "focal_point_width": null, + "focal_point_y": null, + "title": "Lisa Gourdon", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 4 +}, +{ + "fields": { + "width": 117, + "file_size": null, + "file": "original_images/pierre_quesselaire.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 153, + "focal_point_width": null, + "focal_point_y": null, + "title": "Pierre Quesselaire", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 5 +}, +{ + "fields": { + "width": 606, + "file_size": null, + "file": "original_images/thibault_scoquart.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 487, + "focal_point_width": null, + "focal_point_y": null, + "title": "Thibault Scoquard", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 6 +}, +{ + "fields": { + "width": 640, + "file_size": null, + "file": "original_images/arnaud_fanthomme.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 320, + "focal_point_width": null, + "focal_point_y": null, + "title": "Arnaud Fanthomme", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 7 +}, +{ + "fields": { + "width": 125, + "file_size": null, + "file": "original_images/vincent_balerdi.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 163, + "focal_point_width": null, + "focal_point_y": null, + "title": "Vincent Balerdi", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 8 +}, +{ + "fields": { + "width": 125, + "file_size": null, + "file": "original_images/nathanel_willaime.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 176, + "focal_point_width": null, + "focal_point_y": null, + "title": "Nathana\u00ebl Willaime", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 9 +}, +{ + "fields": { + "width": 125, + "file_size": null, + "file": "original_images/elisabeth_miller.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 146, + "focal_point_width": null, + "focal_point_y": null, + "title": "\u00c9lisabeth Miller", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 10 +}, +{ + "fields": { + "width": 720, + "file_size": null, + "file": "original_images/arthur_lesage.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 720, + "focal_point_width": null, + "focal_point_y": null, + "title": "Arthur Lesage", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 11 +}, +{ + "fields": { + "width": 445, + "file_size": null, + "file": "original_images/sarah_asset.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 436, + "focal_point_width": null, + "focal_point_y": null, + "title": "Sarah Asset", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 12 +}, +{ + "fields": { + "width": 480, + "file_size": null, + "file": "original_images/alexandre_legrand.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 360, + "focal_point_width": null, + "focal_point_y": null, + "title": "Alexandre Legrand", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 13 +}, +{ + "fields": { + "width": 4608, + "file_size": null, + "file": "original_images/etienne_baudel.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 3456, + "focal_point_width": null, + "focal_point_y": null, + "title": "\u00c9tienne Baudel", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 14 +}, +{ + "fields": { + "width": 358, + "file_size": null, + "file": "original_images/marine_snape.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 435, + "focal_point_width": null, + "focal_point_y": null, + "title": "Marine Snape", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 15 +}, +{ + "fields": { + "width": 121, + "file_size": null, + "file": "original_images/anatole_gosset.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 200, + "focal_point_width": null, + "focal_point_y": null, + "title": "Anatole Gosset", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 16 +}, +{ + "fields": { + "width": 253, + "file_size": null, + "file": "original_images/jacko_rastikian.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 338, + "focal_point_width": null, + "focal_point_y": null, + "title": "Jacko Rastikian", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 17 +}, +{ + "fields": { + "width": 285, + "file_size": null, + "file": "original_images/alexandre_jannaud.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 380, + "focal_point_width": null, + "focal_point_y": null, + "title": "Alexandre Jannaud", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 18 +}, +{ + "fields": { + "width": 283, + "file_size": null, + "file": "original_images/aurelien_delobelle.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 371, + "focal_point_width": null, + "focal_point_y": null, + "title": "Aur\u00e9lien Delobelle", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 19 +}, +{ + "fields": { + "width": 125, + "file_size": null, + "file": "original_images/sylvain_douteau.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 161, + "focal_point_width": null, + "focal_point_y": null, + "title": "Sylvain Douteau", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 20 +}, +{ + "fields": { + "width": 125, + "file_size": null, + "file": "original_images/raphael_lescanne.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 176, + "focal_point_width": null, + "focal_point_y": null, + "title": "Rapha\u00ebl Lescanne", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 21 +}, +{ + "fields": { + "width": 124, + "file_size": null, + "file": "original_images/romain_gourvil.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 157, + "focal_point_width": null, + "focal_point_y": null, + "title": "Romain Gourvil", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 22 +}, +{ + "fields": { + "width": 133, + "file_size": null, + "file": "original_images/marie_labeye.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 163, + "focal_point_width": null, + "focal_point_y": null, + "title": "Marie Labeye", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 23 +}, +{ + "fields": { + "width": 127, + "file_size": null, + "file": "original_images/oscar_blumberg.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 159, + "focal_point_width": null, + "focal_point_y": null, + "title": "Oscar Blumberg", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 24 +}, +{ + "fields": { + "width": 210, + "file_size": null, + "file": "original_images/zaid_allybokus.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 311, + "focal_point_width": null, + "focal_point_y": null, + "title": "Za\u00efd Allybokus", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 25 +}, +{ + "fields": { + "width": 495, + "file_size": null, + "file": "original_images/damien_garreau.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 548, + "focal_point_width": null, + "focal_point_y": null, + "title": "Damien Garreau", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 26 +}, +{ + "fields": { + "width": 323, + "file_size": null, + "file": "original_images/andrea_londono.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 458, + "focal_point_width": null, + "focal_point_y": null, + "title": "Andr\u00e9a Londono-Lopez", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 27 +}, +{ + "fields": { + "width": 120, + "file_size": null, + "file": "original_images/tristan_roussel.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 155, + "focal_point_width": null, + "focal_point_y": null, + "title": "Tristan Roussel", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 28 +}, +{ + "fields": { + "width": 427, + "file_size": null, + "file": "original_images/guillaume_vernade.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 640, + "focal_point_width": null, + "focal_point_y": null, + "title": "Guillaume Vernade", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 29 +}, +{ + "fields": { + "width": 2304, + "file_size": null, + "file": "original_images/lucas_mercier.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 3020, + "focal_point_width": null, + "focal_point_y": null, + "title": "Lucas Mercier", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 30 +}, +{ + "fields": { + "width": 199, + "file_size": null, + "file": "original_images/francois_maillot.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 240, + "focal_point_width": null, + "focal_point_y": null, + "title": "Fran\u00e7ois Maillot", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 31 +}, +{ + "fields": { + "width": 965, + "file_size": null, + "file": "original_images/fabrice_catoire.jpg", + "focal_point_height": null, + "focal_point_x": null, + "height": 1255, + "focal_point_width": null, + "focal_point_y": null, + "title": "Fabrice Catoire", + "collection": 2, + "uploaded_by_user": [ + "root" + ], + "created_at": "2017-05-30T04:20:00.000Z" + }, + "model": "wagtailimages.image", + "pk": 32 +}, +{ + "model": "wagtailmenus.flatmenu", + "fields": { + "max_levels": 1, + "handle": "kfet-nav", + "site": [ + "localhost", + 8000 + ], + "use_specific": 1, + "heading": "", + "title": "K-F\u00eat - Navigation" + }, + "pk": 1 +}, +{ + "pk": 1, + "fields": { + "link_page": 3, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "Accueil", + "link_url": "", + "sort_order": 0, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +}, +{ + "pk": 2, + "fields": { + "link_page": 4, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "", + "link_url": "", + "sort_order": 1, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +}, +{ + "pk": 3, + "fields": { + "link_page": 5, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "", + "link_url": "", + "sort_order": 2, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +}, +{ + "pk": 4, + "fields": { + "link_page": 6, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "", + "link_url": "", + "sort_order": 3, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +}, +{ + "pk": 5, + "fields": { + "link_page": 7, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "", + "link_url": "", + "sort_order": 4, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +}, +{ + "pk": 6, + "fields": { + "link_page": 8, + "menu": 1, + "allow_subnav": true, + "handle": "", + "link_text": "", + "link_url": "", + "sort_order": 5, + "url_append": "" + }, + "model": "wagtailmenus.flatmenuitem" +} +] diff --git a/kfet/cms/hooks.py b/kfet/cms/hooks.py new file mode 100644 index 00000000..e58aeef5 --- /dev/null +++ b/kfet/cms/hooks.py @@ -0,0 +1,12 @@ +from django.contrib.staticfiles.templatetags.staticfiles import static +from django.utils.html import format_html + +from wagtail.wagtailcore import hooks + + +@hooks.register('insert_editor_css') +def editor_css(): + return format_html( + '', + static('kfetcms/css/editor.css'), + ) diff --git a/kfet/cms/management/commands/kfet_loadwagtail.py b/kfet/cms/management/commands/kfet_loadwagtail.py new file mode 100644 index 00000000..86b94d3e --- /dev/null +++ b/kfet/cms/management/commands/kfet_loadwagtail.py @@ -0,0 +1,35 @@ +from django.contrib.auth.models import Group +from django.core.management import call_command +from django.core.management.base import BaseCommand + +from wagtail.wagtailcore.models import Page, Site + + +class Command(BaseCommand): + help = "Importe des données pour Wagtail" + + def add_arguments(self, parser): + parser.add_argument('--file', default='kfet_wagtail_17_05') + + def handle(self, *args, **options): + + self.stdout.write("Import des données wagtail") + + # Nettoyage des données initiales posées par Wagtail dans la migration + # wagtailcore/0002 + + Group.objects.filter(name__in=('Moderators', 'Editors')).delete() + + try: + homepage = Page.objects.get( + title="Welcome to your new Wagtail site!" + ) + homepage.delete() + Site.objects.filter(root_page=homepage).delete() + except Page.DoesNotExist: + pass + + # Import des données + # Par défaut, il s'agit d'une copie du site K-Fêt (17-05) + + call_command('loaddata', options['file']) diff --git a/kfet/cms/migrations/0001_initial.py b/kfet/cms/migrations/0001_initial.py new file mode 100644 index 00000000..951637c7 --- /dev/null +++ b/kfet/cms/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import wagtail.wagtailsnippets.blocks +import wagtail.wagtailcore.blocks +import wagtail.wagtailcore.fields +import django.db.models.deletion +import kfet.cms.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0033_remove_golive_expiry_help_text'), + ('wagtailimages', '0019_delete_filter'), + ] + + operations = [ + migrations.CreateModel( + name='KFetPage', + fields=[ + ('page_ptr', models.OneToOneField(serialize=False, primary_key=True, parent_link=True, auto_created=True, to='wagtailcore.Page')), + ('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')), + ('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')), + ('main_size', models.CharField(max_length=255, blank=True, verbose_name='Taille de la colonne de contenu')), + ('col_count', models.CharField(max_length=255, blank=True, verbose_name='Nombre de colonnes', help_text="S'applique au page dont le contenu est scindé sur plusieurs colonnes")), + ], + options={ + 'verbose_name': 'page K-Fêt', + 'verbose_name_plural': 'pages K-Fêt', + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='MemberTeam', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), + ('first_name', models.CharField(blank=True, max_length=255, verbose_name='Prénom', default='')), + ('last_name', models.CharField(blank=True, max_length=255, verbose_name='Nom', default='')), + ('nick_name', models.CharField(verbose_name='Alias', blank=True, default='', max_length=255)), + ('photo', models.ForeignKey(null=True, related_name='+', on_delete=django.db.models.deletion.SET_NULL, verbose_name='Photo', blank=True, to='wagtailimages.Image')), + ], + options={ + 'verbose_name': 'K-Fêt-eux-se', + }, + ), + ] diff --git a/kfet/cms/migrations/0002_alter_kfetpage_colcount.py b/kfet/cms/migrations/0002_alter_kfetpage_colcount.py new file mode 100644 index 00000000..fe91d3e6 --- /dev/null +++ b/kfet/cms/migrations/0002_alter_kfetpage_colcount.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfetcms', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='kfetpage', + name='col_count', + field=models.CharField(blank=True, max_length=255, verbose_name='Nombre de colonnes', help_text="S'applique au page dont le contenu est scindé sur plusieurs colonnes."), + ), + ] diff --git a/kfet/cms/migrations/__init__.py b/kfet/cms/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kfet/cms/models.py b/kfet/cms/models.py new file mode 100644 index 00000000..0dff183f --- /dev/null +++ b/kfet/cms/models.py @@ -0,0 +1,174 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from wagtail.wagtailadmin.edit_handlers import ( + FieldPanel, FieldRowPanel, MultiFieldPanel, StreamFieldPanel +) +from wagtail.wagtailcore import blocks +from wagtail.wagtailcore.fields import StreamField +from wagtail.wagtailcore.models import Page +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel +from wagtail.wagtailsnippets.blocks import SnippetChooserBlock +from wagtail.wagtailsnippets.models import register_snippet + +from kfet.cms.context_processors import get_articles + + +@register_snippet +class MemberTeam(models.Model): + first_name = models.CharField( + verbose_name=_('Prénom'), + blank=True, default='', max_length=255, + ) + last_name = models.CharField( + verbose_name=_('Nom'), + blank=True, default='', max_length=255, + ) + nick_name = models.CharField( + verbose_name=_('Alias'), + blank=True, default='', max_length=255, + ) + photo = models.ForeignKey( + 'wagtailimages.Image', + verbose_name=_('Photo'), + on_delete=models.SET_NULL, + null=True, blank=True, + related_name='+', + ) + + class Meta: + verbose_name = _('K-Fêt-eux-se') + + panels = [ + FieldPanel('first_name'), + FieldPanel('last_name'), + FieldPanel('nick_name'), + ImageChooserPanel('photo'), + ] + + def __str__(self): + return self.get_full_name() + + def get_full_name(self): + return '{} {}'.format(self.first_name, self.last_name).strip() + + +class MenuBlock(blocks.StaticBlock): + class Meta: + icon = 'list-ul' + label = _('Carte') + template = 'kfetcms/block_menu.html' + + def get_context(self, *args, **kwargs): + context = super().get_context(*args, **kwargs) + context.update(get_articles()) + return context + + +class GroupTeamBlock(blocks.StructBlock): + show_only = blocks.IntegerBlock( + label=_('Montrer seulement'), + required=False, + help_text=_( + 'Nombre initial de membres affichés. Laisser vide pour tou-te-s ' + 'les afficher.' + ), + ) + members = blocks.ListBlock( + SnippetChooserBlock(MemberTeam), + label=_('K-Fêt-eux-ses'), + classname='team-group', + ) + + class Meta: + icon = 'group' + label = _('Groupe de K-Fêt-eux-ses') + template = 'kfetcms/block_teamgroup.html' + + +class ChoicesStreamBlock(blocks.StreamBlock): + rich = blocks.RichTextBlock(label=_('Éditeur')) + carte = MenuBlock() + group_team = GroupTeamBlock() + + +class KFetStreamBlock(ChoicesStreamBlock): + group = ChoicesStreamBlock(label=_('Contenu groupé')) + + +class KFetPage(Page): + + content = StreamField(KFetStreamBlock, verbose_name=_('Contenu')) + + # Layout fields + + TEMPLATE_COL_1 = 'kfet/base_col_1.html' + TEMPLATE_COL_2 = 'kfet/base_col_2.html' + TEMPLATE_COL_MULT = 'kfet/base_col_mult.html' + + no_header = models.BooleanField( + verbose_name=_('Sans en-tête'), + default=False, + help_text=_( + "Coché, l'en-tête (avec le titre) de la page n'est pas affiché." + ), + ) + layout = models.CharField( + verbose_name=_('Template'), + choices=[ + (TEMPLATE_COL_1, _('Une colonne : centrée sur la page')), + (TEMPLATE_COL_2, _('Deux colonnes : fixe à gauche, contenu à droite')), + (TEMPLATE_COL_MULT, _('Contenu scindé sur plusieurs colonnes')), + ], + default=TEMPLATE_COL_MULT, max_length=255, + help_text=_( + "Comment cette page devrait être affichée ?" + ), + ) + main_size = models.CharField( + verbose_name=_('Taille de la colonne de contenu'), + blank=True, max_length=255, + ) + col_count = models.CharField( + verbose_name=_('Nombre de colonnes'), + blank=True, max_length=255, + help_text=_( + "S'applique au page dont le contenu est scindé sur plusieurs colonnes." + ), + ) + + # Panels + + content_panels = Page.content_panels + [ + StreamFieldPanel('content'), + ] + + layout_panel = [ + FieldPanel('no_header'), + FieldPanel('layout'), + FieldRowPanel([ + FieldPanel('main_size'), + FieldPanel('col_count'), + ]), + ] + + settings_panels = [ + MultiFieldPanel(layout_panel, _('Affichage')) + ] + Page.settings_panels + + # Base template + template = "kfetcms/base.html" + + class Meta: + verbose_name = _('page K-Fêt') + verbose_name_plural = _('pages K-Fêt') + + def get_context(self, request, *args, **kwargs): + context = super().get_context(request, *args, **kwargs) + + page = context['page'] + + if not page.seo_title: + page.seo_title = page.title + + return context diff --git a/kfet/cms/static/kfetcms/css/base.css b/kfet/cms/static/kfetcms/css/base.css new file mode 100644 index 00000000..b580ef94 --- /dev/null +++ b/kfet/cms/static/kfetcms/css/base.css @@ -0,0 +1,93 @@ +.main.cms { + padding: 20px 15px; +} + +@media (min-width: 768px) { + .main.cms { + padding: 35px 30px; + } +} + +.cms { + text-align: justify; + font-size: 1.1em; +} + +@media (min-width:768px) { + .cms { + font-size: 1.2em; + line-height: 1.6em; + } +} + +/* Titles */ + +.cms h2, .cms h3 { + clear: both; + margin: 0 0 15px; + padding-bottom: 10px; + border-bottom: 1px solid #c8102e; + text-align: left; + font-weight: bold; +} + +@media (min-width: 768px) { + .cms h2, .cms h3 { + padding-bottom: 15px; + } +} + +/* Paragraphs */ + +.cms p { + margin-bottom: 20px; + text-indent: 2em; +} + +.cms p + :not(h2):not(h3):not(div) { + margin-top: -10px; +} + +@media (min-width: 768px) { + .cms p { + padding-bottom: 15px; + } + + .cms p + :not(h2):not(h3):not(div) { + margin-top: -30px; + } +} + + +/* Lists */ + +.cms ol, .cms ul { + padding: 0 0 0 15px; + margin: 0 0 10px; +} + +.cms ul { + list-style-type: square; +} + +.cms ol > li, .cms ul > li { + padding-left: 5px; +} + + +/* Images */ + +.cms .richtext-image { + max-height: 100%; + margin: 5px 0 15px; +} + +.cms .richtext-image.left { + float: left; + margin-right: 30px; +} + +.cms .richtext-image.right { + float: right; + margin-left: 30px; +} diff --git a/kfet/cms/static/kfetcms/css/editor.css b/kfet/cms/static/kfetcms/css/editor.css new file mode 100644 index 00000000..f97e9895 --- /dev/null +++ b/kfet/cms/static/kfetcms/css/editor.css @@ -0,0 +1,18 @@ +.snippets.listing thead, .snippets.listing thead tr { + border: 0; +} + +.snippets.listing tbody { + display: block; + column-count: 2; +} + +.snippets.listing tbody tr { + display: block; +} + +@media (min-width: 992px) { + .snippets.listing tbody { + column-count: 3; + } +} diff --git a/kfet/cms/static/kfetcms/css/index.css b/kfet/cms/static/kfetcms/css/index.css new file mode 100644 index 00000000..647515e3 --- /dev/null +++ b/kfet/cms/static/kfetcms/css/index.css @@ -0,0 +1,3 @@ +@import url("base.css"); +@import url("menu.css"); +@import url("team.css"); diff --git a/kfet/cms/static/kfetcms/css/menu.css b/kfet/cms/static/kfetcms/css/menu.css new file mode 100644 index 00000000..f1952c69 --- /dev/null +++ b/kfet/cms/static/kfetcms/css/menu.css @@ -0,0 +1,58 @@ +.carte { + margin-bottom: 15px; + font-family: "Roboto Slab"; +} + +.carte .carte-title { + padding-top: 0; + margin-top: 0; + margin-bottom: 0; +} + +.carte .carte-list { + width: 100%; + padding: 15px; + list-style-type: none; +} + +.carte .carte-item { + position: relative; + text-align: right; + white-space: nowrap; + padding: 0; +} + +.carte .carte-item .filler { + position: absolute; + left: 0; + right: 0; + border-bottom: 2px dotted #333; + height: 75%; +} + +.carte .carte-item > span { + position: relative; +} + +.carte .carte-item .carte-label { + background: white; + float: left; + padding-right: 10px; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + +.carte .carte-item .carte-ukf { + padding: 0 10px; + background: #ffdbc7; +} + +.carte-inverted .carte-list, +.carte-inverted .carte-item .carte-label { + background: #ffdbc7; +} + +.carte-inverted .carte-item .carte-ukf { + background: white; +} diff --git a/kfet/cms/static/kfetcms/css/team.css b/kfet/cms/static/kfetcms/css/team.css new file mode 100644 index 00000000..e663fc66 --- /dev/null +++ b/kfet/cms/static/kfetcms/css/team.css @@ -0,0 +1,47 @@ +.team-group { + margin-bottom: 20px; +} + +.team-group .col-btn { + margin-bottom: 20px; +} + +.team-group .member-more { + display: none; +} + +.team-member { + padding: 0; + margin-bottom: 20px; + min-height: 190px; + background-color: inherit; + border: 0; +} + +.team-member img { + max-width: 100%; + max-height: 125px; + width: auto; + height: auto; + display: block; +} + +.team-member .infos { + height: 50px; + margin-top: 15px; +} + +@media (min-width: 768px) { + .team-group { + margin-left: 20px; + margin-right: 20px; + } + + .team-member { + min-height: 215px; + } + + .team-member img { + max-height: 150px; + } +} diff --git a/kfet/cms/templates/kfetcms/base.html b/kfet/cms/templates/kfetcms/base.html new file mode 100644 index 00000000..3b9f40d6 --- /dev/null +++ b/kfet/cms/templates/kfetcms/base.html @@ -0,0 +1,41 @@ +{% extends page.layout %} +{% load static wagtailcore_tags wagtailuserbar %} + +{# CSS/JS #} + +{% block extra_head %} +{{ block.super }} + +{% endblock %} + +{# Titles #} + +{% block title %}{{ page.seo_title }}{% endblock %} +{% block header-title %}{{ page.title }}{% endblock %} + +{# Layout #} + +{% block main-size %}{{ page.main_size|default:block.super }}{% endblock %} +{% block mult-count %}{{ page.col_count|default:block.super }}{% endblock %} + +{% block main-class %}cms main-bg{% endblock %} + +{# Content #} + +{% block main %} + +{% for block in page.content %} +
    + {% include_block block %} +
    +{% endfor %} + +{% wagtailuserbar %} + +{% endblock %} + +{# Footer #} + +{% block footer %} +{% include "kfet/base_footer.html" %} +{% endblock %} diff --git a/kfet/cms/templates/kfetcms/block_menu.html b/kfet/cms/templates/kfetcms/block_menu.html new file mode 100644 index 00000000..382a7770 --- /dev/null +++ b/kfet/cms/templates/kfetcms/block_menu.html @@ -0,0 +1,11 @@ +{% load static %} + +{% if pressions %} + {% include "kfetcms/block_menu_category.html" with title="Pressions du moment" articles=pressions class="carte-inverted" %} +{% endif %} + +{% regroup articles by category as categories %} + +{% for category in categories %} + {% include "kfetcms/block_menu_category.html" with title=category.grouper.name articles=category.list %} +{% endfor %} diff --git a/kfet/cms/templates/kfetcms/block_menu_category.html b/kfet/cms/templates/kfetcms/block_menu_category.html new file mode 100644 index 00000000..ef7d4ce0 --- /dev/null +++ b/kfet/cms/templates/kfetcms/block_menu_category.html @@ -0,0 +1,12 @@ +
    +

    {{ title }}

    +
      + {% for article in articles %} +
    • +
      + {{ article.name }} + {{ article.price_ukf }} UKF +
    • + {% endfor %} +
    +
    diff --git a/kfet/cms/templates/kfetcms/block_teamgroup.html b/kfet/cms/templates/kfetcms/block_teamgroup.html new file mode 100644 index 00000000..fab43d68 --- /dev/null +++ b/kfet/cms/templates/kfetcms/block_teamgroup.html @@ -0,0 +1,66 @@ +{% load wagtailcore_tags wagtailimages_tags %} + + +{% with groupteam=value len=value.members|length %} + +
    + + {% if len == 2 %} +
    + {% endif %} + + {% for member in groupteam.members %} +
    +
    + {% image member.photo max-200x500 %} +
    + {{ member.get_full_name }} +
    + {% if member.nick_name %} + alias {{ member.nick_name }} + {% endif %} +
    +
    +
    + {% endfor %} + + {% if groupteam.show_only != None and len > groupteam.show_only %} +
    + +
    + {% endif %} + +
    + +{% endwith %} + + diff --git a/kfet/config.py b/kfet/config.py new file mode 100644 index 00000000..76da5a79 --- /dev/null +++ b/kfet/config.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +from django.core.exceptions import ValidationError +from django.db import models + +from djconfig import config + + +class KFetConfig(object): + """kfet app configuration. + + Enhance isolation with backend used to store config. + Usable after DjConfig middleware was called. + + """ + prefix = 'kfet_' + + def __getattr__(self, key): + if key == 'subvention_cof': + # Allows accessing to the reduction as a subvention + # Other reason: backward compatibility + reduction_mult = 1 - self.reduction_cof/100 + return (1/reduction_mult - 1) * 100 + return getattr(config, self._get_dj_key(key)) + + def list(self): + """Get list of kfet app configuration. + + Returns: + (key, value) for each configuration entry as list. + + """ + # prevent circular imports + from kfet.forms import KFetConfigForm + return [(field.label, getattr(config, name), ) + for name, field in KFetConfigForm.base_fields.items()] + + def _get_dj_key(self, key): + return '{}{}'.format(self.prefix, key) + + def set(self, **kwargs): + """Update configuration value(s). + + Args: + **kwargs: Keyword arguments. Keys must be in kfet config. + Config entries are updated to given values. + + """ + # prevent circular imports + from kfet.forms import KFetConfigForm + + # get old config + new_cfg = KFetConfigForm().initial + # update to new config + for key, value in kwargs.items(): + dj_key = self._get_dj_key(key) + if isinstance(value, models.Model): + new_cfg[dj_key] = value.pk + else: + new_cfg[dj_key] = value + # save new config + cfg_form = KFetConfigForm(new_cfg) + if cfg_form.is_valid(): + cfg_form.save() + else: + raise ValidationError( + 'Invalid values in kfet_config.set: %(fields)s', + params={'fields': list(cfg_form.errors)}) + + +kfet_config = KFetConfig() diff --git a/kfet/consumers.py b/kfet/consumers.py index dcd69bdf..0f447d2d 100644 --- a/kfet/consumers.py +++ b/kfet/consumers.py @@ -1,26 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * +from .utils import DjangoJsonWebsocketConsumer, PermConsumerMixin -from channels import Group -from channels.generic.websockets import JsonWebsocketConsumer -class KPsul(JsonWebsocketConsumer): - - # Set to True if you want them, else leave out - strict_ordering = False - slight_ordering = False - - def connection_groups(self, **kwargs): - return ['kfet.kpsul'] - - def connect(self, message, **kwargs): - pass - - def receive(self, content, **kwargs): - pass - - def disconnect(self, message, **kwargs): - pass +class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer): + groups = ['kfet.kpsul'] + perms_connect = ['kfet.is_team'] diff --git a/kfet/context_processors.py b/kfet/context_processors.py index ef4f2e64..4c7b4fe4 100644 --- a/kfet/context_processors.py +++ b/kfet/context_processors.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - from django.contrib.auth.context_processors import PermWrapper +from kfet.config import kfet_config + + def auth(request): if hasattr(request, 'real_user'): return { @@ -13,3 +12,7 @@ def auth(request): 'perms': PermWrapper(request.real_user), } return {} + + +def config(request): + return {'kfet_config': kfet_config} diff --git a/kfet/forms.py b/kfet/forms.py index e4afaa09..2d07581d 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -1,35 +1,40 @@ # -*- coding: utf-8 -*- +from datetime import timedelta from decimal import Decimal + from django import forms from django.core.exceptions import ValidationError from django.contrib.auth.models import User, Group, Permission 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 djconfig.forms import ConfigForm + from kfet.models import ( Account, Checkout, Article, OperationGroup, Operation, - CheckoutStatement, ArticleCategory, Settings, AccountNegative, Transfer, + CheckoutStatement, ArticleCategory, AccountNegative, Transfer, TransferGroup, Supplier) from gestioncof.models import CofProfile + # ----- # Widgets # ----- class DateTimeWidget(forms.DateTimeInput): - def __init__(self, attrs = None): - super(DateTimeWidget, self).__init__(attrs) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) self.attrs['format'] = '%Y-%m-%d %H:%M' + class Media: css = { - 'all': ('kfet/css/bootstrap-datetimepicker.min.css',) - } - js = ( - 'kfet/js/moment.js', - 'kfet/js/moment-fr.js', - 'kfet/js/bootstrap-datetimepicker.min.js', - ) + 'all': ('kfet/css/bootstrap-datetimepicker.min.css',) + } + js = ('kfet/js/bootstrap-datetimepicker.min.js',) + + # ----- # Account forms # ----- @@ -122,6 +127,7 @@ class UserRestrictTeamForm(UserForm): class Meta(UserForm.Meta): fields = ['first_name', 'last_name', 'email'] + class UserGroupForm(forms.ModelForm): groups = forms.ModelMultipleChoiceField( Group.objects.filter(name__icontains='K-Fêt'), @@ -129,20 +135,33 @@ class UserGroupForm(forms.ModelForm): required=False) def clean_groups(self): - groups = self.cleaned_data.get('groups') - # Si aucun groupe, on le dénomme - if not groups: - groups = self.instance.groups.exclude(name__icontains='K-Fêt') - return groups + 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 + 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 = forms.ModelMultipleChoiceField( - queryset= Permission.objects.filter(content_type__in= - ContentType.objects.filter(app_label='kfet'))) + permissions = KFetPermissionsField() def clean_name(self): name = self.cleaned_data['name'] @@ -316,12 +335,20 @@ class KPsulAccountForm(forms.ModelForm): }), } + class KPsulCheckoutForm(forms.Form): checkout = forms.ModelChoiceField( - queryset=Checkout.objects.filter( - is_protected=False, valid_from__lte=timezone.now(), - valid_to__gte=timezone.now()), - widget=forms.Select(attrs={'id':'id_checkout_select'})) + queryset=( + Checkout.objects + .filter( + is_protected=False, + valid_from__lte=timezone.now(), + valid_to__gte=timezone.now(), + ) + ), + widget=forms.Select(attrs={'id': 'id_checkout_select'}), + ) + class KPsulOperationForm(forms.ModelForm): article = forms.ModelChoiceField( @@ -383,44 +410,53 @@ class AddcostForm(forms.Form): self.cleaned_data['amount'] = 0 super(AddcostForm, self).clean() + # ----- # Settings forms # ----- -class SettingsForm(forms.ModelForm): - class Meta: - model = Settings - fields = ['value_decimal', 'value_account', 'value_duration'] - def clean(self): - name = self.instance.name - value_decimal = self.cleaned_data.get('value_decimal') - value_account = self.cleaned_data.get('value_account') - value_duration = self.cleaned_data.get('value_duration') +class KFetConfigForm(ConfigForm): - type_decimal = ['SUBVENTION_COF', 'ADDCOST_AMOUNT', 'OVERDRAFT_AMOUNT'] - type_account = ['ADDCOST_FOR'] - type_duration = ['OVERDRAFT_DURATION', 'CANCEL_DURATION'] + kfet_reduction_cof = forms.DecimalField( + label='Réduction COF', initial=Decimal('20'), + max_digits=6, decimal_places=2, + help_text="Réduction, à donner en pourcentage, appliquée lors d'un " + "achat par un-e membre du COF sur le montant en euros.", + ) + kfet_addcost_amount = forms.DecimalField( + label='Montant de la majoration (en €)', initial=Decimal('0'), + required=False, + max_digits=6, decimal_places=2, + ) + kfet_addcost_for = forms.ModelChoiceField( + label='Destinataire de la majoration', initial=None, required=False, + help_text='Laissez vide pour désactiver la majoration.', + queryset=(Account.objects + .select_related('cofprofile', 'cofprofile__user') + .all()), + ) + kfet_overdraft_duration = forms.DurationField( + label='Durée du découvert autorisé par défaut', + initial=timedelta(days=1), + ) + kfet_overdraft_amount = forms.DecimalField( + label='Montant du découvert autorisé par défaut (en €)', + initial=Decimal('20'), + max_digits=6, decimal_places=2, + ) + kfet_cancel_duration = forms.DurationField( + label='Durée pour annuler une commande sans mot de passe', + initial=timedelta(minutes=5), + ) - self.cleaned_data['name'] = name - if name in type_decimal: - if not value_decimal: - raise ValidationError('Renseignez une valeur décimale') - self.cleaned_data['value_account'] = None - self.cleaned_data['value_duration'] = None - elif name in type_account: - self.cleaned_data['value_decimal'] = None - self.cleaned_data['value_duration'] = None - elif name in type_duration: - if not value_duration: - raise ValidationError('Renseignez une durée') - self.cleaned_data['value_decimal'] = None - self.cleaned_data['value_account'] = None - super(SettingsForm, self).clean() class FilterHistoryForm(forms.Form): - checkouts = forms.ModelMultipleChoiceField(queryset = Checkout.objects.all()) - accounts = forms.ModelMultipleChoiceField(queryset = Account.objects.all()) + checkouts = forms.ModelMultipleChoiceField(queryset=Checkout.objects.all()) + accounts = forms.ModelMultipleChoiceField(queryset=Account.objects.all()) + from_date = forms.DateTimeField(widget=DateTimeWidget) + to_date = forms.DateTimeField(widget=DateTimeWidget) + # ----- # Transfer forms @@ -499,11 +535,7 @@ class OrderArticleForm(forms.Form): self.category = kwargs['initial']['category'] self.category_name = kwargs['initial']['category__name'] self.box_capacity = kwargs['initial']['box_capacity'] - self.v_s1 = kwargs['initial']['v_s1'] - self.v_s2 = kwargs['initial']['v_s2'] - self.v_s3 = kwargs['initial']['v_s3'] - self.v_s4 = kwargs['initial']['v_s4'] - self.v_s5 = kwargs['initial']['v_s5'] + self.v_all = kwargs['initial']['v_all'] self.v_moy = kwargs['initial']['v_moy'] self.v_et = kwargs['initial']['v_et'] self.v_prev = kwargs['initial']['v_prev'] diff --git a/kfet/management/commands/createopes.py b/kfet/management/commands/createopes.py index 77663b2b..5a7699ae 100644 --- a/kfet/management/commands/createopes.py +++ b/kfet/management/commands/createopes.py @@ -14,7 +14,8 @@ from kfet.models import (Account, Article, OperationGroup, Operation, class Command(BaseCommand): - help = "Crée des opérations réparties uniformément sur une période de temps" + help = ("Crée des opérations réparties uniformément " + "sur une période de temps") def add_arguments(self, parser): # Nombre d'opérations à créer @@ -29,7 +30,6 @@ class Command(BaseCommand): parser.add_argument('--transfers', type=int, default=0, help='Number of transfers to create (default 0)') - def handle(self, *args, **options): self.stdout.write("Génération d'opérations") @@ -44,6 +44,7 @@ class Command(BaseCommand): # Convert to seconds time = options['days'] * 24 * 3600 + now = timezone.now() checkout = Checkout.objects.first() articles = Article.objects.all() accounts = Account.objects.exclude(trigramme='LIQ') @@ -55,6 +56,13 @@ class Command(BaseCommand): except Account.DoesNotExist: con_account = random.choice(accounts) + # use to fetch OperationGroup pk created by bulk_create + at_list = [] + # use to lazy set OperationGroup pk on Operation objects + ope_by_grp = [] + # OperationGroup objects to bulk_create + opegroup_list = [] + for i in range(num_ops): # Randomly pick account @@ -64,8 +72,7 @@ class Command(BaseCommand): account = liq_account # Randomly pick time - at = timezone.now() - timedelta( - seconds=random.randint(0, time)) + at = now - timedelta(seconds=random.randint(0, time)) # Majoration sur compte 'concert' if random.random() < 0.2: @@ -78,13 +85,6 @@ class Command(BaseCommand): # Initialize opegroup amount amount = Decimal('0') - opegroup = OperationGroup.objects.create( - on_acc=account, - checkout=checkout, - at=at, - is_cof=account.cofprofile.is_cof - ) - # Generating operations ope_list = [] for j in range(random.randint(1, 4)): @@ -94,25 +94,26 @@ class Command(BaseCommand): # 0.1 probability to have a charge if typevar > 0.9 and account != liq_account: ope = Operation( - group=opegroup, type=Operation.DEPOSIT, - is_checkout=(random.random() > 0.2), amount=Decimal(random.randint(1, 99)/10) ) - # 0.1 probability to have a withdrawal + # 0.05 probability to have a withdrawal + elif typevar > 0.85 and account != liq_account: + ope = Operation( + type=Operation.WITHDRAW, + amount=-Decimal(random.randint(1, 99)/10) + ) + # 0.05 probability to have an edition elif typevar > 0.8 and account != liq_account: ope = Operation( - group=opegroup, - type=Operation.WITHDRAW, - is_checkout=(random.random() > 0.2), - amount=-Decimal(random.randint(1, 99)/10) + type=Operation.EDIT, + amount=Decimal(random.randint(1, 99)/10) ) else: article = random.choice(articles) nb = random.randint(1, 5) ope = Operation( - group=opegroup, type=Operation.PURCHASE, amount=-article.price*nb, article=article, @@ -129,17 +130,44 @@ class Command(BaseCommand): ope_list.append(ope) amount += ope.amount - Operation.objects.bulk_create(ope_list) - opes_created += len(ope_list) - opegroup.amount = amount - opegroup.save() + opegroup_list.append(OperationGroup( + on_acc=account, + checkout=checkout, + at=at, + is_cof=account.cofprofile.is_cof, + amount=amount, + )) + at_list.append(at) + ope_by_grp.append((at, ope_list, )) + + OperationGroup.objects.bulk_create(opegroup_list) + + # Fetch created OperationGroup objects pk by at + opegroups = (OperationGroup.objects + .filter(at__in=at_list) + .values('id', 'at')) + opegroups_by = {grp['at']: grp['id'] for grp in opegroups} + + all_ope = [] + for _ in range(num_ops): + at, ope_list = ope_by_grp.pop() + for ope in ope_list: + ope.group_id = opegroups_by[at] + all_ope.append(ope) + + Operation.objects.bulk_create(all_ope) + opes_created = len(all_ope) # Transfer generation + + transfer_by_grp = [] + transfergroup_list = [] + at_list = [] + for i in range(num_transfers): # Randomly pick time - at = timezone.now() - timedelta( - seconds=random.randint(0, time)) + at = now - timedelta(seconds=random.randint(0, time)) # Choose whether to have a comment if random.random() > 0.5: @@ -147,24 +175,40 @@ class Command(BaseCommand): else: comment = "" - transfergroup = TransferGroup.objects.create( + transfergroup_list.append(TransferGroup( at=at, comment=comment, - valid_by=random.choice(accounts) - ) + valid_by=random.choice(accounts), + )) + at_list.append(at) # Randomly generate transfer transfer_list = [] for i in range(random.randint(1, 4)): transfer_list.append(Transfer( - group=transfergroup, from_acc=random.choice(accounts), to_acc=random.choice(accounts), amount=Decimal(random.randint(1, 99)/10) )) - Transfer.objects.bulk_create(transfer_list) - transfers += len(transfer_list) + transfer_by_grp.append((at, transfer_list, )) + + TransferGroup.objects.bulk_create(transfergroup_list) + + transfergroups = (TransferGroup.objects + .filter(at__in=at_list) + .values('id', 'at')) + transfergroups_by = {grp['at']: grp['id'] for grp in transfergroups} + + all_transfer = [] + for _ in range(num_transfers): + at, transfer_list = transfer_by_grp.pop() + for transfer in transfer_list: + transfer.group_id = transfergroups_by[at] + all_transfer.append(transfer) + + Transfer.objects.bulk_create(all_transfer) + transfers += len(all_transfer) self.stdout.write( "- {:d} opérations créées dont {:d} commandes d'articles" diff --git a/kfet/management/commands/loadkfetdevdata.py b/kfet/management/commands/loadkfetdevdata.py index 7f2ec9a3..6dd25f29 100644 --- a/kfet/management/commands/loadkfetdevdata.py +++ b/kfet/management/commands/loadkfetdevdata.py @@ -147,3 +147,9 @@ class Command(MyBaseCommand): # --- call_command('createopes', '100', '7', '--transfers=20') + + # --- + # Wagtail CMS + # --- + + call_command('kfet_loadwagtail') diff --git a/kfet/middleware.py b/kfet/middleware.py index dbb192c6..9502d393 100644 --- a/kfet/middleware.py +++ b/kfet/middleware.py @@ -1,15 +1,27 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * +from django.contrib.auth.models import User -from django.http import HttpResponseForbidden from kfet.backends import KFetBackend -from kfet.models import Account + 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: diff --git a/kfet/migrations/0054_delete_settings.py b/kfet/migrations/0054_delete_settings.py new file mode 100644 index 00000000..80ee1d24 --- /dev/null +++ b/kfet/migrations/0054_delete_settings.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + +from kfet.forms import KFetConfigForm + + +def adapt_settings(apps, schema_editor): + Settings = apps.get_model('kfet', 'Settings') + db_alias = schema_editor.connection.alias + obj = Settings.objects.using(db_alias) + + cfg = {} + + def try_get(new, old, type_field): + try: + value = getattr(obj.get(name=old), type_field) + cfg[new] = value + except Settings.DoesNotExist: + pass + + try: + subvention = obj.get(name='SUBVENTION_COF').value_decimal + subvention_mult = 1 + subvention/100 + reduction = (1 - 1/subvention_mult) * 100 + cfg['kfet_reduction_cof'] = reduction + except Settings.DoesNotExist: + pass + try_get('kfet_addcost_amount', 'ADDCOST_AMOUNT', 'value_decimal') + try_get('kfet_addcost_for', 'ADDCOST_FOR', 'value_account') + try_get('kfet_overdraft_duration', 'OVERDRAFT_DURATION', 'value_duration') + try_get('kfet_overdraft_amount', 'OVERDRAFT_AMOUNT', 'value_decimal') + try_get('kfet_cancel_duration', 'CANCEL_DURATION', 'value_duration') + + cfg_form = KFetConfigForm(initial=cfg) + if cfg_form.is_valid(): + cfg_form.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0053_created_at'), + ('djconfig', '0001_initial'), + ] + + operations = [ + migrations.RunPython(adapt_settings), + migrations.RemoveField( + model_name='settings', + name='value_account', + ), + migrations.DeleteModel( + name='Settings', + ), + ] diff --git a/kfet/migrations/0055_move_permissions.py b/kfet/migrations/0055_move_permissions.py new file mode 100644 index 00000000..a418124c --- /dev/null +++ b/kfet/migrations/0055_move_permissions.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +def forwards_perms(apps, schema_editor): + """Safely delete content type for old kfet.GlobalPermissions model. + + Any permissions (except defaults) linked to this content type are updated + to link at its new content type. + Then, delete the content type. This will delete the three defaults + permissions which are assumed unused. + + """ + ContentType = apps.get_model('contenttypes', 'contenttype') + try: + ctype_global = ContentType.objects.get( + app_label="kfet", model="globalpermissions", + ) + except ContentType.DoesNotExist: + # We are not migrating from existing data, nothing to do. + return + + perms = { + 'account': ( + 'is_team', 'manage_perms', 'manage_addcosts', + 'edit_balance_account', 'change_account_password', + 'special_add_account', + ), + 'accountnegative': ('view_negs',), + 'inventory': ('order_to_inventory',), + 'operation': ( + 'perform_deposit', 'perform_negative_operations', + 'override_frozen_protection', 'cancel_old_operations', + 'perform_commented_operations', + ), + } + + Permission = apps.get_model('auth', 'permission') + global_perms = Permission.objects.filter(content_type=ctype_global) + + for modelname, codenames in perms.items(): + model = apps.get_model('kfet', modelname) + ctype = ContentType.objects.get_for_model(model) + ( + global_perms + .filter(codename__in=codenames) + .update(content_type=ctype) + ) + + ctype_global.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0054_delete_settings'), + ('contenttypes', '__latest__'), + ('auth', '__latest__'), + ] + + 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'))}, + ), + migrations.AlterModelOptions( + name='accountnegative', + options={'permissions': (('view_negs', 'Voir la liste des négatifs'),)}, + ), + migrations.AlterModelOptions( + name='inventory', + options={'ordering': ['-at'], 'permissions': (('order_to_inventory', "Générer un inventaire à partir d'une commande"),)}, + ), + migrations.AlterModelOptions( + name='operation', + options={'permissions': (('perform_deposit', 'Effectuer une charge'), ('perform_negative_operations', 'Enregistrer des commandes en négatif'), ('override_frozen_protection', "Forcer le gel d'un compte"), ('cancel_old_operations', 'Annuler des commandes non récentes'), ('perform_commented_operations', 'Enregistrer des commandes avec commentaires'))}, + ), + migrations.RunPython(forwards_perms), + ] diff --git a/kfet/migrations/0056_change_account_meta.py b/kfet/migrations/0056_change_account_meta.py new file mode 100644 index 00000000..3992bf3c --- /dev/null +++ b/kfet/migrations/0056_change_account_meta.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0055_move_permissions'), + ] + + 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'))}, + ), + ] diff --git a/kfet/migrations/0057_merge.py b/kfet/migrations/0057_merge.py new file mode 100644 index 00000000..48f63399 --- /dev/null +++ b/kfet/migrations/0057_merge.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0056_change_account_meta'), + ('kfet', '0054_update_promos'), + ] + + operations = [ + ] diff --git a/kfet/models.py b/kfet/models.py index 2ad1c091..ec146ad9 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - from django.db import models from django.core.urlresolvers import reverse -from django.core.exceptions import PermissionDenied, ValidationError from django.core.validators import RegexValidator from django.contrib.auth.models import User from gestioncof.models import CofProfile @@ -15,11 +10,13 @@ from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.db import transaction from django.db.models import F -from django.core.cache import cache -from datetime import date, timedelta +from datetime import date import re import hashlib +from .config import kfet_config +from .utils import to_ukf + def choices_length(choices): return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0) @@ -27,8 +24,19 @@ def default_promo(): now = date.today() return now.month <= 8 and now.year-1 or now.year -@python_2_unicode_compatible + +class AccountManager(models.Manager): + """Manager for Account Model.""" + + def get_queryset(self): + """Always append related data to this Account.""" + return super().get_queryset().select_related('cofprofile__user', + 'negative') + + class Account(models.Model): + objects = AccountManager() + cofprofile = models.OneToOneField( CofProfile, on_delete = models.PROTECT, related_name = "account_kfet") @@ -56,10 +64,23 @@ class Account(models.Model): unique = True, blank = True, null = True, default = None) + class Meta: + 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"), + ) + def __str__(self): return '%s (%s)' % (self.trigramme, self.name) - # Propriétés pour accéder aux attributs de user et cofprofile et user + # Propriétés pour accéder aux attributs de cofprofile et user @property def user(self): return self.cofprofile.user @@ -83,9 +104,13 @@ class Account(models.Model): return self.cofprofile.is_cof # Propriétés supplémentaires + @property + def balance_ukf(self): + return to_ukf(self.balance, is_cof=self.is_cof) + @property def real_balance(self): - if (hasattr(self, 'negative')): + if hasattr(self, 'negative') and self.negative.balance_offset: return self.balance - self.negative.balance_offset return self.balance @@ -101,6 +126,14 @@ class Account(models.Model): def need_comment(self): return self.trigramme == '#13' + @property + def readable(self): + return self.trigramme != 'GNR' + + @property + def is_team(self): + return self.has_perm('kfet.is_team') + @staticmethod def is_validandfree(trigramme): data = { 'is_valid' : False, 'is_free' : False } @@ -113,8 +146,8 @@ class Account(models.Model): return data def perms_to_perform_operation(self, amount): - overdraft_duration_max = Settings.OVERDRAFT_DURATION() - overdraft_amount_max = Settings.OVERDRAFT_AMOUNT() + overdraft_duration_max = kfet_config.overdraft_duration + overdraft_amount_max = kfet_config.overdraft_amount perms = set() stop_ope = False # Checking is cash account @@ -214,31 +247,79 @@ class Account(models.Model): def delete(self, *args, **kwargs): pass + def update_negative(self): + if self.real_balance < 0: + if hasattr(self, 'negative') and not self.negative.start: + self.negative.start = timezone.now() + self.negative.save() + elif not hasattr(self, 'negative'): + self.negative = ( + AccountNegative.objects.create( + account=self, start=timezone.now(), + ) + ) + elif hasattr(self, 'negative'): + # self.real_balance >= 0 + balance_offset = self.negative.balance_offset + if balance_offset: + ( + Account.objects + .filter(pk=self.pk) + .update(balance=F('balance')-balance_offset) + ) + self.refresh_from_db() + self.negative.delete() + class UserHasAccount(Exception): def __init__(self, trigramme): self.trigramme = trigramme + +class AccountNegativeManager(models.Manager): + """Manager for AccountNegative model.""" + + def get_queryset(self): + return ( + super().get_queryset() + .select_related('account__cofprofile__user') + ) + + class AccountNegative(models.Model): + objects = AccountNegativeManager() + account = models.OneToOneField( - Account, on_delete = models.PROTECT, - related_name = "negative") - start = models.DateTimeField( - blank = True, null = True, default = None) + Account, on_delete=models.PROTECT, + related_name="negative", + ) + start = models.DateTimeField(blank=True, null=True, default=None) balance_offset = models.DecimalField( "décalage de balance", help_text="Montant non compris dans l'autorisation de négatif", - max_digits = 6, decimal_places = 2, - blank = True, null = True, default = None) + max_digits=6, decimal_places=2, + blank=True, null=True, default=None, + ) authz_overdraft_amount = models.DecimalField( "négatif autorisé", - max_digits = 6, decimal_places = 2, - blank = True, null = True, default = None) + max_digits=6, decimal_places=2, + blank=True, null=True, default=None, + ) authz_overdraft_until = models.DateTimeField( "expiration du négatif", - blank = True, null = True, default = None) - comment = models.CharField("commentaire", max_length = 255, blank = True) + blank=True, null=True, default=None, + ) + comment = models.CharField("commentaire", max_length=255, blank=True) + + class Meta: + permissions = ( + ('view_negs', 'Voir la liste des négatifs'), + ) + + @property + def until_default(self): + return self.start + kfet_config.overdraft_duration + -@python_2_unicode_compatible class Checkout(models.Model): created_by = models.ForeignKey( Account, on_delete = models.PROTECT, @@ -390,6 +471,10 @@ class Article(models.Model): def get_absolute_url(self): return reverse('kfet.article.read', kwargs={'pk': self.pk}) + def price_ukf(self): + return to_ukf(self.price) + + class ArticleRule(models.Model): article_on = models.OneToOneField( Article, on_delete = models.PROTECT, @@ -416,6 +501,10 @@ class Inventory(models.Model): class Meta: ordering = ['-at'] + permissions = ( + ('order_to_inventory', "Générer un inventaire à partir d'une commande"), + ) + class InventoryArticle(models.Model): inventory = models.ForeignKey( @@ -592,6 +681,17 @@ class Operation(models.Model): max_digits=6, decimal_places=2, blank=True, null=True, default=None) + class Meta: + permissions = ( + ('perform_deposit', 'Effectuer une charge'), + ('perform_negative_operations', + 'Enregistrer des commandes en négatif'), + ('override_frozen_protection', "Forcer le gel d'un compte"), + ('cancel_old_operations', 'Annuler des commandes non récentes'), + ('perform_commented_operations', + 'Enregistrer des commandes avec commentaires'), + ) + @property def is_checkout(self): return (self.type == Operation.DEPOSIT or @@ -612,136 +712,5 @@ class Operation(models.Model): amount=self.amount) -class GlobalPermissions(models.Model): - class Meta: - managed = False - permissions = ( - ('is_team', 'Is part of the team'), - ('perform_deposit', 'Effectuer une charge'), - ('perform_negative_operations', - 'Enregistrer des commandes en négatif'), - ('override_frozen_protection', "Forcer le gel d'un compte"), - ('cancel_old_operations', 'Annuler des commandes non récentes'), - ('manage_perms', 'Gérer les permissions K-Fêt'), - ('manage_addcosts', 'Gérer les majorations'), - ('perform_commented_operations', 'Enregistrer des commandes avec commentaires'), - ('view_negs', 'Voir la liste des négatifs'), - ('order_to_inventory', "Générer un inventaire à partir d'une commande"), - ('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") - ) - -class Settings(models.Model): - name = models.CharField( - max_length = 45, - unique = True, - db_index = True) - value_decimal = models.DecimalField( - max_digits = 6, decimal_places = 2, - blank = True, null = True, default = None) - value_account = models.ForeignKey( - Account, on_delete = models.PROTECT, - blank = True, null = True, default = None) - value_duration = models.DurationField( - blank = True, null = True, default = None) - - @staticmethod - def setting_inst(name): - return Settings.objects.get(name=name) - - @staticmethod - def SUBVENTION_COF(): - subvention_cof = cache.get('SUBVENTION_COF') - if subvention_cof: - return subvention_cof - try: - subvention_cof = Settings.setting_inst("SUBVENTION_COF").value_decimal - except Settings.DoesNotExist: - subvention_cof = 0 - cache.set('SUBVENTION_COF', subvention_cof) - return subvention_cof - - @staticmethod - def ADDCOST_AMOUNT(): - try: - return Settings.setting_inst("ADDCOST_AMOUNT").value_decimal - except Settings.DoesNotExist: - return 0 - - @staticmethod - def ADDCOST_FOR(): - try: - return Settings.setting_inst("ADDCOST_FOR").value_account - except Settings.DoesNotExist: - return None; - - @staticmethod - def OVERDRAFT_DURATION(): - overdraft_duration = cache.get('OVERDRAFT_DURATION') - if overdraft_duration: - return overdraft_duration - try: - overdraft_duration = Settings.setting_inst("OVERDRAFT_DURATION").value_duration - except Settings.DoesNotExist: - overdraft_duration = timedelta() - cache.set('OVERDRAFT_DURATION', overdraft_duration) - return overdraft_duration - - @staticmethod - def OVERDRAFT_AMOUNT(): - overdraft_amount = cache.get('OVERDRAFT_AMOUNT') - if overdraft_amount: - return overdraft_amount - try: - overdraft_amount = Settings.setting_inst("OVERDRAFT_AMOUNT").value_decimal - except Settings.DoesNotExist: - overdraft_amount = 0 - cache.set('OVERDRAFT_AMOUNT', overdraft_amount) - return overdraft_amount - - @staticmethod - def CANCEL_DURATION(): - cancel_duration = cache.get('CANCEL_DURATION') - if cancel_duration: - return cancel_duration - try: - cancel_duration = Settings.setting_inst("CANCEL_DURATION").value_duration - except Settings.DoesNotExist: - cancel_duration = timedelta() - cache.set('CANCEL_DURATION', cancel_duration) - return cancel_duration - - @staticmethod - def create_missing(): - s, created = Settings.objects.get_or_create(name='SUBVENTION_COF') - if created: - s.value_decimal = 25 - s.save() - s, created = Settings.objects.get_or_create(name='ADDCOST_AMOUNT') - if created: - s.value_decimal = 0.5 - s.save() - s, created = Settings.objects.get_or_create(name='ADDCOST_FOR') - s, created = Settings.objects.get_or_create(name='OVERDRAFT_DURATION') - if created: - s.value_duration = timedelta(days=1) # 24h - s.save() - s, created = Settings.objects.get_or_create(name='OVERDRAFT_AMOUNT') - if created: - s.value_decimal = 20 - s.save() - s, created = Settings.objects.get_or_create(name='CANCEL_DURATION') - if created: - s.value_duration = timedelta(minutes=5) # 5min - s.save() - - @staticmethod - def empty_cache(): - cache.delete_many([ - 'SUBVENTION_COF', 'OVERDRAFT_DURATION', 'OVERDRAFT_AMOUNT', - 'CANCEL_DURATION', 'ADDCOST_AMOUNT', 'ADDCOST_FOR', - ]) - class GenericTeamToken(models.Model): token = models.CharField(max_length = 50, unique = True) diff --git a/kfet/open/__init__.py b/kfet/open/__init__.py new file mode 100644 index 00000000..fb88af65 --- /dev/null +++ b/kfet/open/__init__.py @@ -0,0 +1 @@ +from .open import OpenKfet, kfet_open # noqa diff --git a/kfet/open/consumers.py b/kfet/open/consumers.py new file mode 100644 index 00000000..b28a4664 --- /dev/null +++ b/kfet/open/consumers.py @@ -0,0 +1,25 @@ +from ..decorators import kfet_is_team +from ..utils import DjangoJsonWebsocketConsumer, PermConsumerMixin + +from .open import kfet_open + + +class OpenKfetConsumer(PermConsumerMixin, DjangoJsonWebsocketConsumer): + """Consumer for K-Fêt Open. + + WS groups: + kfet.open.base: Only carries the values visible for all users. + kfet.open.team: Carries all values (raw status...). + + """ + + 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'] + + def connect(self, message, *args, **kwargs): + """Send current status on connect.""" + super().connect(message, *args, **kwargs) + self.send(kfet_open.export(message.user)) diff --git a/kfet/open/open.py b/kfet/open/open.py new file mode 100644 index 00000000..7fd90c21 --- /dev/null +++ b/kfet/open/open.py @@ -0,0 +1,109 @@ +from datetime import timedelta + +from django.utils import timezone + +from ..decorators import kfet_is_team +from ..utils import CachedMixin + + +class OpenKfet(CachedMixin, object): + """Manage "open" status of a place. + + Stores raw data (e.g. sent by raspberry), and user-set values + (as force_close). + Setting differents `cache_prefix` allows different places management. + Current state persists through cache. + + """ + # status is unknown after this duration + time_unknown = timedelta(minutes=15) + + # status + OPENED = 'opened' + CLOSED = 'closed' + UNKNOWN = 'unknown' + # admin status + FAKE_CLOSED = 'fake_closed' + + # cached attributes config + cached = { + '_raw_open': False, + '_last_update': None, + 'force_close': False, + } + cache_prefix = 'kfetopen' + + @property + def raw_open(self): + """Defined as property to update `last_update` on `raw_open` update.""" + return self._raw_open + + @raw_open.setter + def raw_open(self, value): + self._last_update = timezone.now() + self._raw_open = value + + @property + def last_update(self): + """Prevent `last_update` to be set.""" + return self._last_update + + @property + def is_open(self): + """Take into account force_close.""" + return False if self.force_close else self.raw_open + + def status(self): + if (self.last_update is None or + timezone.now() - self.last_update >= self.time_unknown): + return self.UNKNOWN + return self.OPENED if self.is_open else self.CLOSED + + def admin_status(self, status=None): + if status is None: + status = self.status() + if status == self.CLOSED and self.raw_open: + return self.FAKE_CLOSED + return status + + def _export(self): + """Export internal state. + + Used by WS initialization and updates. + + Returns: + (tuple): (base, team) + - team for team users. + - base for others. + + """ + status = self.status() + base = { + 'status': status, + } + restrict = { + 'admin_status': self.admin_status(status), + 'force_close': self.force_close, + } + return base, {**base, **restrict} + + def export(self, user): + """Export internal state for a given user. + + Returns: + (dict): Internal state. Only variables visible for the user are + exported, according to its permissions. + + """ + base, team = self._export() + return team if kfet_is_team(user) else base + + def send_ws(self): + """Send internal state to websocket channels.""" + from .consumers import OpenKfetConsumer + base, team = self._export() + OpenKfetConsumer.group_send('kfet.open.base', base) + OpenKfetConsumer.group_send('kfet.open.team', team) + + +kfet_open = OpenKfet() diff --git a/kfet/open/routing.py b/kfet/open/routing.py new file mode 100644 index 00000000..681bfab2 --- /dev/null +++ b/kfet/open/routing.py @@ -0,0 +1,8 @@ +from channels.routing import route_class + +from . import consumers + + +routing = [ + route_class(consumers.OpenKfetConsumer) +] diff --git a/kfet/open/static/kfetopen/kfet-open.css b/kfet/open/static/kfetopen/kfet-open.css new file mode 100644 index 00000000..d44318cd --- /dev/null +++ b/kfet/open/static/kfetopen/kfet-open.css @@ -0,0 +1,50 @@ +.kfetopen-st-opened .bullet { background: #73C252; } +.kfetopen-st-closed .bullet { background: #B42B26; } +.kfetopen-st-unknown .bullet { background: #D4BE4C; } +.kfetopen-st-fake_closed .bullet { + background: repeating-linear-gradient( + 45deg, + #73C252, #73C252 5px, #B42B26 5px, #B42B26 10px + ); +} + +.kfetopen { + float: left; +} + +.kfetopen .base { + height: 50px; + padding: 15px; + + display: inline-flex; + align-items: center; +} + +.kfetopen .details { + margin: 0; + padding: 10px !important; + min-width: 200px; + font-family: "Roboto Slab"; + font-size: 16px; + color: black; +} + +.kfetopen .bullet { + width: 10px; + height: 10px; + border-radius: 50%; + transition: background 0.15s; +} + +.kfetopen .warning { + margin-left: 15px; +} + +.kfetopen .status-text { + text-transform: uppercase; +} + +.kfetopen .force-close-btn { + width: 100%; + margin-top: 5px; +} diff --git a/kfet/open/static/kfetopen/kfet-open.js b/kfet/open/static/kfetopen/kfet-open.js new file mode 100644 index 00000000..b86cc5bc --- /dev/null +++ b/kfet/open/static/kfetopen/kfet-open.js @@ -0,0 +1,113 @@ +var OpenWS = new KfetWebsocket({ + relative_url: "open/" +}); + +var OpenKfet = function(force_close_url, admin) { + this.force_close_url = force_close_url; + this.admin = admin; + + this.status = this.UNKNOWN; + this.dom = { + status_text: $('.kfetopen .status-text'), + force_close_btn: $('.kfetopen .force-close-btn'), + warning: $('.kfetopen .warning') + }, + + this.dom.force_close_btn.click( () => this.toggle_force_close() ); + setInterval( () => this.refresh(), this.refresh_interval * 1000); + OpenWS.add_handler( data => this.refresh(data) ); + +}; + +OpenKfet.prototype = { + // Status is unknown after . minutes without update. + time_unknown: 15, + // Maximum interval (seconds) between two UI refresh. + refresh_interval: 20, + + // Prefix for classes describing place status. + class_prefix: 'kfetopen-st-', + // Set status-classes on this dom element. + target: 'body', + + // Status + OPENED: "opened", + CLOSED: "closed", + UNKNOWN: "unknown", + + // Admin status + FAKE_CLOSED: "fake_closed", + + // Display values + status_text: { + opened: "ouverte", + closed: "fermée", + unknown: "_____" + }, + force_text: { + activate: "Fermer manuellement", + deactivate: "Réouvrir la K-Fêt" + }, + + get is_recent() { + return this.last_update && moment().diff(this.last_update, 'minute') <= this.time_unknown; + }, + + refresh: function(data) { + if (data) { + $.extend(this, data); + this.last_update = moment(); + } + if (!this.is_recent) + this.status = this.UNKNOWN; + this.refresh_dom(); + }, + + refresh_dom: function() { + let status = this.status; + this.clear_class(); + + this.add_class(status); + this.dom.status_text.html(this.status_text[status]); + + // admin specific + if (this.admin) { + this.add_class(this.admin_status); + if (this.force_close) { + this.dom.warning.addClass('in'); + this.dom.force_close_btn.html(this.force_text['deactivate']); + } else { + this.dom.warning.removeClass('in'); + this.dom.force_close_btn.html(this.force_text['activate']); + } + } + }, + + toggle_force_close: function(password) { + $.post({ + url: this.force_close_url, + data: {force_close: !this.force_close}, + beforeSend: function ($xhr) { + $xhr.setRequestHeader("X-CSRFToken", csrftoken); + if (password !== undefined) + $xhr.setRequestHeader("KFetPassword", password); + } + }) + .fail(function($xhr) { + switch ($xhr.status) { + case 403: + requestAuth({'errors': {}}, this.toggle_force_close); + break; + } + }); + }, + + clear_class: function() { + let re = new RegExp('(^|\\s)' + this.class_prefix + '\\S+', 'g'); + $(this.target).attr('class', (i, c) => c ? c.replace(re, '') : ''); + }, + + add_class: function(status) { + $(this.target).addClass(this.class_prefix + status); + } +}; diff --git a/kfet/open/templates/kfetopen/init.html b/kfet/open/templates/kfetopen/init.html new file mode 100644 index 00000000..3834b32a --- /dev/null +++ b/kfet/open/templates/kfetopen/init.html @@ -0,0 +1,13 @@ +{% load static %} + + + + + diff --git a/kfet/open/tests.py b/kfet/open/tests.py new file mode 100644 index 00000000..1d6d5529 --- /dev/null +++ b/kfet/open/tests.py @@ -0,0 +1,322 @@ +import json +from datetime import timedelta + +from django.contrib.auth.models import AnonymousUser, Permission, User +from django.test import Client +from django.utils import timezone + +from channels.channel import Group +from channels.test import ChannelTestCase, WSClient + +from . import kfet_open, OpenKfet +from .consumers import OpenKfetConsumer + + +class OpenKfetTest(ChannelTestCase): + """OpenKfet object unit-tests suite.""" + + def setUp(self): + self.kfet_open = OpenKfet() + + def tearDown(self): + self.kfet_open.clear_cache() + + def test_defaults(self): + """Default values.""" + self.assertFalse(self.kfet_open.raw_open) + self.assertIsNone(self.kfet_open.last_update) + self.assertFalse(self.kfet_open.force_close) + self.assertFalse(self.kfet_open.is_open) + + def test_raw_open(self): + """Get and set raw_open; last_update is renewed.""" + for raw_open in [True, False]: + prev_update = self.kfet_open.last_update + self.kfet_open.raw_open = raw_open + self.assertEqual(raw_open, self.kfet_open.raw_open) + self.assertNotEqual(prev_update, self.kfet_open.last_update) + + def test_force_close(self): + """Get and set force_close.""" + for force_close in [True, False]: + self.kfet_open.force_close = force_close + self.assertEqual(force_close, self.kfet_open.force_close) + + def test_is_open(self): + """If force_close is disabled, is_open is raw_open.""" + self.kfet_open.force_close = False + for raw_open in [True, False]: + self.kfet_open.raw_open = raw_open + self.assertEqual(raw_open, self.kfet_open.is_open) + + def test_is_open_force_close(self): + """If force_close is enabled, is_open is False.""" + self.kfet_open.force_close = True + for raw_open in [True, False]: + self.kfet_open.raw_open = raw_open + self.assertFalse(self.kfet_open.is_open) + + def test_status(self): + # (raw_open, force_close, expected status, expected admin) + cases = [ + (False, False, OpenKfet.CLOSED, OpenKfet.CLOSED), + (False, True, OpenKfet.CLOSED, OpenKfet.CLOSED), + (True, False, OpenKfet.OPENED, OpenKfet.OPENED), + (True, True, OpenKfet.CLOSED, OpenKfet.FAKE_CLOSED), + ] + for raw_open, force_close, exp_stat, exp_adm_stat in cases: + self.kfet_open.raw_open = raw_open + self.kfet_open.force_close = force_close + self.assertEqual(exp_stat, self.kfet_open.status()) + self.assertEqual(exp_adm_stat, self.kfet_open.admin_status()) + + def test_status_unknown(self): + self.kfet_open.raw_open = True + self.kfet_open._last_update = timezone.now() - timedelta(days=30) + self.assertEqual(OpenKfet.UNKNOWN, self.kfet_open.status()) + + def test_export_user(self): + """Export is limited for an anonymous user.""" + export = self.kfet_open.export(AnonymousUser()) + self.assertSetEqual( + set(['status']), + set(export), + ) + + def test_export_team(self): + """Export all values for a team member.""" + user = User.objects.create_user('team', '', 'team') + user.user_permissions.add(Permission.objects.get(codename='is_team')) + export = self.kfet_open.export(user) + self.assertSetEqual( + set(['status', 'admin_status', 'force_close']), + set(export), + ) + + def test_send_ws(self): + Group('kfet.open.base').add('test.open.base') + Group('kfet.open.team').add('test.open.team') + + 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), + ) + + 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(ChannelTestCase): + """OpenKfet views unit-tests suite.""" + + def setUp(self): + # get some permissions + perms = { + 'kfet.is_team': Permission.objects.get(codename='is_team'), + 'kfet.can_force_close': Permission.objects.get(codename='can_force_close'), + } + + # authenticated user and its client + self.u = User.objects.create_user('user', '', 'user') + self.c = Client() + self.c.login(username='user', password='user') + + # team user and its clients + self.t = User.objects.create_user('team', '', 'team') + self.t.user_permissions.add(perms['kfet.is_team']) + self.c_t = Client() + self.c_t.login(username='team', password='team') + + # admin user and its client + self.a = User.objects.create_user('admin', '', 'admin') + self.a.user_permissions.add( + perms['kfet.is_team'], perms['kfet.can_force_close'], + ) + self.c_a = Client() + self.c_a.login(username='admin', password='admin') + + def tearDown(self): + kfet_open.clear_cache() + + def test_door(self): + """Edit raw_status.""" + for sent, expected in [(1, True), (0, False)]: + resp = Client().post('/k-fet/open/raw_open', { + 'raw_open': sent, + 'token': 'plop', + }) + self.assertEqual(200, resp.status_code) + self.assertEqual(expected, kfet_open.raw_open) + + def test_force_close(self): + """Edit force_close.""" + for sent, expected in [(1, True), (0, False)]: + resp = self.c_a.post('/k-fet/open/force_close', {'force_close': sent}) + self.assertEqual(200, resp.status_code) + self.assertEqual(expected, kfet_open.force_close) + + def test_force_close_forbidden(self): + """Can't edit force_close without kfet.can_force_close permission.""" + clients = [Client(), self.c, self.c_t] + for client in clients: + resp = client.post('/k-fet/open/force_close', {'force_close': 0}) + self.assertEqual(403, resp.status_code) + + +class OpenKfetConsumerTest(ChannelTestCase): + """OpenKfet consumer unit-tests suite.""" + + 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()) + + def test_team_user(self): + """Team user is added to kfet.open.team group.""" + # setup team user and its client + t = User.objects.create_user('team', '', 'team') + t.user_permissions.add( + Permission.objects.get(codename='is_team') + ) + c = WSClient() + c.force_login(t) + + # 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.admin' group... + OpenKfetConsumer.group_send('kfet.open.team', {'test': 'plop'}) + self.assertEqual(c.receive(), {'test': 'plop'}) + + # ... but not to the 'kfet.open' one + OpenKfetConsumer.group_send('kfet.open.base', {'test': 'plop'}) + self.assertIsNone(c.receive()) + + +class OpenKfetScenarioTest(ChannelTestCase): + """OpenKfet functionnal tests suite.""" + + def setUp(self): + # anonymous client (for views) + self.c = Client() + # anonymous client (for websockets) + self.c_ws = WSClient() + + # 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) + + def tearDown(self): + kfet_open.clear_cache() + + 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) + + 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.c_ws.receive(json=True) + self.assertEqual(OpenKfet.OPENED, msg['status']) + + # root user too + msg = self.r_c_ws.receive(json=True) + self.assertEqual(OpenKfet.OPENED, msg['status']) + self.assertEqual(OpenKfet.OPENED, msg['admin_status']) + + # admin says "no it's closed" + self.r_c.post('/k-fet/open/force_close', {'force_close': True}) + + # so anonymous user see it's closed + msg = self.c_ws.receive(json=True) + self.assertEqual(OpenKfet.CLOSED, msg['status']) + + # root user too + 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']) + self.assertTrue(msg['force_close']) + + def test_scenario_2(self): + """Starting falsely closed, clients connect, disable force close.""" + kfet_open.raw_open = True + kfet_open.force_close = True + + msg = self.ws_connect(self.c_ws) + self.assertEqual(OpenKfet.CLOSED, msg['status']) + + 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.c_ws.receive(json=True) + self.assertEqual(OpenKfet.OPENED, msg['status']) + + 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']) diff --git a/kfet/open/urls.py b/kfet/open/urls.py new file mode 100644 index 00000000..bd227b96 --- /dev/null +++ b/kfet/open/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url + +from . import views + + +urlpatterns = [ + url(r'^raw_open$', views.raw_open, + name='kfet.open.edit_raw_open'), + url(r'^force_close$', views.force_close, + name='kfet.open.edit_force_close'), +] diff --git a/kfet/open/views.py b/kfet/open/views.py new file mode 100644 index 00000000..4f1efa5f --- /dev/null +++ b/kfet/open/views.py @@ -0,0 +1,32 @@ +from django.conf import settings +from django.core.exceptions import PermissionDenied +from django.contrib.auth.decorators import permission_required +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_POST + +from .open import kfet_open + + +TRUE_STR = ['1', 'True', 'true'] + + +@csrf_exempt +@require_POST +def raw_open(request): + token = request.POST.get('token') + if token != settings.KFETOPEN_TOKEN: + raise PermissionDenied + raw_open = request.POST.get('raw_open') in TRUE_STR + kfet_open.raw_open = raw_open + kfet_open.send_ws() + return HttpResponse() + + +@permission_required('kfet.can_force_close', raise_exception=True) +@require_POST +def force_close(request): + force_close = request.POST.get('force_close') in TRUE_STR + kfet_open.force_close = force_close + kfet_open.send_ws() + return HttpResponse() diff --git a/kfet/routing.py b/kfet/routing.py index 5ea343cb..54de69ae 100644 --- a/kfet/routing.py +++ b/kfet/routing.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * +from channels.routing import include, route_class -from channels.routing import route, route_class -from kfet import consumers +from . import consumers -channel_routing = [ - route_class(consumers.KPsul, path=r"^/ws/k-fet/k-psul/$"), + +routing = [ + route_class(consumers.KPsul, path=r'^/k-psul/$'), + include('kfet.open.routing.routing', path=r'^/open'), ] diff --git a/kfet/signals.py b/kfet/signals.py index 3dd4d677..c677ac9c 100644 --- a/kfet/signals.py +++ b/kfet/signals.py @@ -1,16 +1,21 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - 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')): - messages.info(request, 'Connexion en utilisateur partagé ?' % reverse('kfet.login.genericteam'), extra_tags='safe') + 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( + '' + ' Connexion en utilisateur partagé ?' + '' + .format(reverse('kfet.login.genericteam')) + )) diff --git a/kfet/static/kfet/css/base/buttons.css b/kfet/static/kfet/css/base/buttons.css new file mode 100644 index 00000000..e7498022 --- /dev/null +++ b/kfet/static/kfet/css/base/buttons.css @@ -0,0 +1,88 @@ +/* General ------------------------- */ + +.btn { + border: 0; + outline: none !important; + + transition: background-color, border, color, opacity; + transition-duration: 0.15s; + + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + + font-family: "Roboto Slab"; +} + +.btn, .btn-lg, .btn-group-lg>.btn { + border-radius:0; +} + + +/* Default ------------------------- */ + +.btn-default { + background-color: transparent !important; + color: #555; +} + +.btn-default:hover, +.btn-default.focus, .btn-default:focus { + color: #c8102e; +} + +.btn-default[disabled]:hover, .btn-default.disabled:hover { + color: inherit !important; +} + + +/* Primary ------------------------- */ + +.btn-primary { + background-color:#c63b52; + color:#FFF; +} + +.btn-primary:hover, +.btn-primary.focus, .btn-primary:focus, +.btn-primary.active.focus, .btn-primary.active:focus, .btn-primary.active:hover, +.btn-primary:active.focus, .btn-primary:active:focus, .btn-primary:active:hover { + background-color:#c8102e; + color:#FFF; +} + + +/* Primary + White background ------ */ + +.btn-primary-w { + background: white; + color: black; +} + +.btn-primary-w:hover { + background: #c63b52; + color: white; +} + +.btn-primary-w.focus, .btn-primary-w:focus, +.btn-primary-w.active.focus, .btn-primary-w.active:focus, .btn-primary-w.active:hover, +.btn-primary-w:active.focus, .btn-primary-w:active:focus, .btn-primary-w:active:hover { + background: #c8102e; + color: white; +} + + +/* Nav ----------------------------- */ + +.btn-nav { + background-color: transparent !important; + color: inherit; + border-bottom: 1px solid #ddd; +} + +.btn-nav:hover, +.btn-nav.focus, .btn-nav:focus, +.btn-nav.active.focus, .btn-nav.active:focus, .btn-nav.active:hover, +.btn-nav:active.focus, .btn-nav:active:focus, .btn-nav:active:hover { + border-bottom: 1px solid #c8102e; +} diff --git a/kfet/static/kfet/css/base/fixed.css b/kfet/static/kfet/css/base/fixed.css new file mode 100644 index 00000000..d198c50f --- /dev/null +++ b/kfet/static/kfet/css/base/fixed.css @@ -0,0 +1,151 @@ +.fixed > * + * { + margin-top: 15px; +} + + +/* Aside --------------------------- */ + +/* Aside - Block */ + +aside { + background: white; + padding: 15px; +} + +aside > * + * { + margin-top: 15px; +} + +/* Aside - Misc */ + +aside .glyphicon-question-sign { + font-size: 0.8; +} + +aside h4 { + font-weight: bold; +} + +/* Aside - Heading */ + +aside .heading { + font-family: "Roboto Slab"; + font-size: 25px; + font-weight: bold; + line-height: 1.1; + text-align: center; +} + +aside .heading .big { + font-size: 2em; +} + +aside .heading .sub { + font-size: 0.7em; + font-weight: normal; +} + +@media (min-width: 992px) { + aside .heading { + font-size: 32px; + line-height: 1.3; + } +} + +/* Aside - Buttons */ + +aside .buttons { + margin-left: -15px; + margin-right: -15px; +} + +aside .buttons > * { + flex: 0 1 auto !important; +} + + +/* Aside - Text */ + +aside .text { + line-height: 1.3; + font-size: 14px; +} + +@media (min-width: 992px) { + aside .text { + line-height: 1.6; + font-size: 16px; + } +} + +aside .text ul { + margin-bottom: 0; +} + + +/* Buttons ------------------------- */ + +.fixed .buttons { + display: flex; + flex-flow: row wrap; + justify-content: center; + + text-align: center; +} + +.fixed .buttons > * { + flex: 0 1 auto; + overflow: hidden; +} + +.fixed .buttons > .solo { + flex: 1 100%; +} + +@media (min-width: 768px) { + .fixed .buttons > * { + flex: 1 auto; + } + + .fixed .buttons > .full > * { + width: 100%; + } +} + +.fixed .buttons .btn { + padding: 8px 12px; +} + +@media (min-width: 992px) { + .fixed .buttons .btn { + font-size: 16px; + } +} + + +/* Tabs ---------------------------- */ + +.fixed .tabs-buttons { + margin-bottom: -5px; +} + +.fixed .tabs-buttons > * { + margin-bottom: 5px; +} + +.fixed .tabs-buttons .glyphicon-chevron-right { + margin-left: 5px; + line-height: 1.4; + color: white; +} + +@media (min-width: 768px) { + .fixed .tabs-buttons { + text-align: right; + justify-content: flex-end; + } + + .fixed .tabs-buttons > * { + flex: 1 100%; + } +} diff --git a/kfet/static/kfet/css/base/footer.css b/kfet/static/kfet/css/base/footer.css new file mode 100644 index 00000000..abdf98ed --- /dev/null +++ b/kfet/static/kfet/css/base/footer.css @@ -0,0 +1,18 @@ +.footer { + line-height: 40px; + + background: #c63b52; + color: white; + + text-align: center; + font-size: 14px; + font-family: Roboto; +} + +.footer a { + color: inherit !important; +} + +.footer a:hover, .footer a:focus { + text-decoration: underline; +} diff --git a/kfet/static/kfet/css/base/main.css b/kfet/static/kfet/css/base/main.css new file mode 100644 index 00000000..2ebc90d8 --- /dev/null +++ b/kfet/static/kfet/css/base/main.css @@ -0,0 +1,138 @@ +/* Global layout ------------------- */ + +.main-col, .fixed-col { + padding: 0 0 15px; +} + +@media (min-width: 768px) { + .fixed-col { + position: sticky; + top: 35px; + padding-top: 15px; + } + + .fixed-col + .main-col { + padding: 15px 0 15px 15px; + } +} + +@media (min-width: 992px) { + .main-col { + padding: 15px; + } +} + +.main-col-mult { + column-gap: 45px; +} + +.main-bg { + background: white; +} + +.main-padding { + padding: 15px; +} + +@media (min-width: 768px) { + .main-padding { + padding: 30px; + } +} + + +/* Section ------------------------- */ + +section { + margin-bottom: 15px; + position:relative; +} + +section:last-child { + margin-bottom: 0; +} + + +/* Section - Elements -------------- */ + +section > * { + background: white; + padding: 15px; +} + +section > .full, +section > table, +section > .table-responsive { + padding: 0 !important; + margin-left: 0 !important; + margin-right: 0 !important; +} + +section .full { + margin-left: -15px; + margin-right: -15px; +} + +@media (min-width: 992px) { + section > * { + padding: 30px; + } + + section .full { + margin-left: -30px; + margin-right: -30px; + } +} + +section .row > div:last-child { + margin-bottom: 0 !important; +} + +@media (max-width: 768px) { + section .row > div { + margin-bottom: 10px; + } +} + +@media (max-width: 1200px) { + section .row > div { + margin-bottom: 20px; + } +} + +section ul ul { + padding-left: 30px; +} + +/* Titles & Heading */ + +section h2, +section .heading { + background: transparent; + margin: 20px 15px 15px; + padding: 0; + border-bottom: 3px solid #c8102e; + font-family: "Roboto Slab"; + font-size: 40px; + line-height: 1.1; +} + +section h3 { + border-bottom: 2px solid #c8102e; + margin: 0 0 10px; + padding: 10px 0 10px; + font-size: 25px; + font-weight: bold; +} + +section .heading .buttons { + opacity: 0.7; + top: 10px; + float: right; +} + +section h2:first-child, +section h3:first-child { + padding-top: 0; + margin-top: 0; +} diff --git a/kfet/static/kfet/css/base/messages.css b/kfet/static/kfet/css/base/messages.css new file mode 100644 index 00000000..268f514d --- /dev/null +++ b/kfet/static/kfet/css/base/messages.css @@ -0,0 +1,36 @@ +.messages .alert { + padding:10px 15px; + margin:0; + border:0; + border-radius:0; +} + +.messages .alert:last-child { + margin-bottom: 15px; +} + +.messages .alert .close { + top:0; + right:0; +} + +.messages .alert-info { + color:inherit; + background-color:#ccc; +} + +.messages .alert-error { + color: white; + background-color: #c63b52; +} + +.messages .alert-success { + color: white; + background: #3d9947; +} + +.messages a { + font-weight: bold; + text-decoration: none; +} + diff --git a/kfet/static/kfet/css/base/misc.css b/kfet/static/kfet/css/base/misc.css new file mode 100644 index 00000000..680fb1ee --- /dev/null +++ b/kfet/static/kfet/css/base/misc.css @@ -0,0 +1,118 @@ +/* General ------------------------- */ + +body { + margin-top:50px; + font-family:Roboto; + background:#ddd; +} + +.glyphicon + span, span + .glyphicon { + margin-left: 10px; +} + +/* Titles */ + +h1,h2,h3,h4,h5,h6 { + font-family:"Roboto Slab"; +} + +/* Links */ + +a { + color:#C8202E; +} + +a:focus, a:hover { + color:#C8102E; +} + +/* Inputs */ + +:focus { + outline:none; +} + +textarea { + font-family:'Roboto Mono'; + border-radius:0 !important; +} + +/* Lists */ + +ul, ol { + padding-left: 30px; +} + +ul { + list-style-type: square; +} + +/* Tables */ + +.table { + margin-bottom:0; + border-bottom:1px solid #ddd; + width:100%; + background-color: #FFF; +} + +.table td { + vertical-align:middle !important; +} + +.table td.no-padding { + padding:0; +} + +.table thead { + background:#c8102e; + color:#fff; + font-weight:bold; + font-size:16px; +} + +.table thead td { + padding:8px !important; +} + +.table tr.section { + background: #c63b52 !important; + color:#fff; + font-weight:bold; +} + +.table tr.section td { + border-top:0; + font-size:16px; + padding:8px 30px; +} + +.table tr.more td { + padding: 0; +} + +.table-responsive { + border: 0; + margin-bottom: 0; +} + +/* Toggle on hover ----------------- */ + +.toggle:not(:hover) .hover { + display: none; +} + +.toggle:hover .base { + display: none; +} + +/* Spinning animation -------------- */ + +.glyphicon.spinning { + animation: spin 1s infinite linear; +} + +@keyframes spin { + from { transform: scale(1) rotate(0deg); } + to { transform: scale(1) rotate(360deg); } +} diff --git a/kfet/static/kfet/css/base/nav.css b/kfet/static/kfet/css/base/nav.css new file mode 100644 index 00000000..0efc2873 --- /dev/null +++ b/kfet/static/kfet/css/base/nav.css @@ -0,0 +1,151 @@ +.navbar { + background: #000; + color: #DDD; + border: 0; + font-family: Roboto; +} + +.navbar .navbar-header { + float: left; + display: none; + margin-left: -15px; + margin-right: 0; +} + +.navbar .navbar-brand { + padding: 3px 0; + margin: 0 15px !important; +} + +.navbar .navbar-brand img { + height: 44px; +} + +.navbar .navbar-toggle { + border: 0; + border-radius: 0; + padding: 18px 15px; + margin: 0; + min-width: auto; +} + +.navbar .navbar-toggle .icon-bar { + background: #fff; +} + +.navbar-nav { + font-size: 14px; + margin: 0 0 0 -15px; + float: left; +} + +@media (min-width: 460px) { + .navbar .navbar-header { + display: block; + } + + .navbar-nav { + margin-left: 0; + } + + .navbar-nav .nav-pages.dropdown .dropdown-menu > li:first-child { + display: none; + } +} + +.navbar-right { + float: right !important; + margin: 0 -15px 0 0; +} + +.navbar-nav a { + transition: background-color, box-shadow, color; + transition-duration: 0.15s; +} + +.navbar-nav > li { + float: left; + text-align: center; +} + +.navbar-nav > li > a { + min-width: 50px; + padding: 15px 10px; + color: #FFF; +} + +.navbar-nav > .divider { + height: 1px; + background: rgba(255, 255, 255, 0.1); +} + +@media (min-width: 1200px) { + .navbar-nav > li > a { + padding-left: 15px; + padding-right: 15px; + } +} + +.navbar-nav > li > a:hover, .navbar-nav > li > a:focus, +.nav .open > a:hover, .nav .open > a:focus, +.navbar-nav > li.active > a, +.navbar-nav .dropdown:hover > a, .navbar-nav .dropdown:focus > a { + background-color: #C8102E; + color: #FFF; + box-shadow: inset 0 3px 3px -4px #000; +} + +.navbar-nav .dropdown .dropdown-menu { + padding: 0; + border: 0; + border-radius: 0; + background-color: #FFF; + font-size: 14px; + + /* override max-width: 767px of bs */ + position: absolute; + float: left; + box-shadow: 0 6px 12px rgba(0,0,0,.175); +} + +.navbar-nav .dropdown .dropdown-menu > li > a { + padding: 8px 10px; + line-height: inherit; + color: #000; +} + +.navbar-nav .dropdown .dropdown-menu > li > a:hover, +.navbar-nav .dropdown .dropdown-menu > li > a:focus { + color: #c8102e; + background-color: transparent; +} + +.navbar-nav .dropdown .dropdown-menu .divider { + margin: 0; +} + +.navbar-nav .dropdown .dropdown-menu { + display: block; + visibility: hidden; + opacity: 0; + transition: opacity 0.15s; +} + +.navbar-nav .dropdown:hover > .dropdown-menu, +.navbar-nav .dropdown:focus > .dropdown-menu, +.navbar-nav .dropdown.open > .dropdown-menu { + visibility: visible; + opacity: 1; +} + +@media (min-width: 992px) { + .navbar-nav .dropdown .dropdown-menu > li > a { + padding-left: 20px; + padding-right: 20px; + } +} + +.nav-app .dropdown-menu { + right: 0; + left: auto; +} diff --git a/kfet/static/kfet/css/history.css b/kfet/static/kfet/css/history.css index 976f5782..9cd4cd28 100644 --- a/kfet/static/kfet/css/history.css +++ b/kfet/static/kfet/css/history.css @@ -9,17 +9,21 @@ #history .day { height:40px; line-height:40px; - background-color:#c8102e; + background-color:rgba(200,16,46,1); color:#fff; padding-left:20px; + font-family:"Roboto Slab"; font-size:16px; font-weight:bold; + position:sticky; + top:50px; + z-index:10; } #history .opegroup { height:30px; line-height:30px; - background-color:rgba(200,16,46,0.85); + background-color: #c63b52; color:#fff; font-weight:bold; padding-left:20px; diff --git a/kfet/static/kfet/css/home.css b/kfet/static/kfet/css/home.css deleted file mode 100644 index 718159c3..00000000 --- a/kfet/static/kfet/css/home.css +++ /dev/null @@ -1,54 +0,0 @@ -ul.carte { - width: 100%; - list-style-type: none; - padding-left: 15px; - padding-right: 15px; - display: inline-block; - *display: inline; - zoom: 1; - position: relative; - clip: auto; - overflow: hidden; -} -/* -ul.carte > li { - border-style: none none solid none; - border-width: 1px; - border-color: #DDD; -} -*/ -li.carte-line { - position: relative; - text-align: right; - white-space: nowrap; -} -.filler { - position: absolute; - left: 0; - right: 0; - border-bottom: 3px dotted #333; - height: 70%; -} -.carte-label { - background: white; - float: left; - padding-right: 4px; - position: relative; - max-width: calc(100% - 40px); - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.carte-ukf { - background: white; - padding-left: 4px; - position: relative; -} - - -.unbreakable.carte-inverted .carte-ukf, -.unbreakable.carte-inverted .carte-label, -.unbreakable.carte-inverted { - background: #FFDBC7; -} diff --git a/kfet/static/kfet/css/index.css b/kfet/static/kfet/css/index.css index f21fdaba..8e28cce0 100644 --- a/kfet/static/kfet/css/index.css +++ b/kfet/static/kfet/css/index.css @@ -1,254 +1,116 @@ -@import url("nav.css"); +/* Libs */ +@import url("libs/columns.css"); + +/* Libs customizations */ +@import url("libs/jconfirm-kfet.css"); +@import url("libs/multiple-select-kfet.css"); + +/* Base */ +@import url("base/misc.css"); +@import url("base/buttons.css"); + +/* Blocks */ +@import url("base/main.css"); +@import url("base/nav.css"); +@import url("base/messages.css"); +@import url("base/fixed.css"); +@import url("base/footer.css"); + +/* Components */ @import url("kpsul.css"); -@import url("jconfirm-kfet.css"); @import url("history.css"); -body { - margin-top:50px; - font-family:Roboto; - background:#ddd; + + +.header { + padding: 15px 20px; + + background-color: rgba(200,16,46,1); + color: #FFF; } -h1,h2,h3,h4,h5,h6 { - font-family:Oswald; -} - -a { - color:#333; -} - -a:focus, a:hover { - color:#C8102E; -} - -:focus { - outline:none; -} - -textarea { - font-family:'Roboto Mono'; - border-radius:0 !important; -} - -.table { - margin-bottom:0; - border-bottom:1px solid #ddd; -} - -.table { - width:100%; -} - -.table td { - vertical-align:middle !important; -} - -.table td.no-padding { - padding:0; -} - -.table thead { - background:#c8102e; - color:#fff; - font-weight:bold; - font-size:16px; -} - -.table thead td { - padding:8px !important; -} - -.table tr.section { - background:rgba(200,16,46,0.9); - color:#fff; - font-weight:bold; -} - -.table tr.section td { - border-top:0; - font-size:16px; - padding:8px 30px; -} - -.btn, .btn-lg, .btn-group-lg>.btn { - border-radius:0; -} - -.btn-primary { - font-family:Oswald; - background-color:rgba(200,16,46,0.9); - color:#FFF; - border:0; -} - -.btn-primary:hover, .btn-primary.focus, .btn-primary:focus { - background-color:#000; - color:#FFF; -} - -.row-page-header { - background-color:rgba(200,16,46,1); - color:#FFF; - border-bottom:3px solid #000; -} - -.page-header { - border:0; - padding:0; - margin:15px 20px; - text-transform:uppercase; - font-weight:bold; +.header h1 { + padding: 0; + margin: 0; + font-weight: bold; } .nopadding { padding: 0 !important; } -.panel-md-margin{ - background-color: white; - overflow:hidden; - padding-left: 15px; - padding-right: 15px; - padding-bottom: 15px; - padding-top: 1px; -} - -@media (min-width: 992px) { - .panel-md-margin{ - margin:8px; - background-color: white; - } -} - -.col-content-left, .col-content-right { - padding:0; -} - -.content-left-top { - background:#fff; - padding:10px 30px; -} - -.content-left .buttons { - background:#fff; -} - -.content-left .buttons .btn { - display:block; -} - -.content-left-top.frozen-account { - background:#000FBA; +.frozen-account { + background:#5072e0; color:#fff; } -.content-left .block { - padding-top:25px; + +.main .table a:not(.btn) { + color: inherit; } -.content-left .block .line { - font-size:16px; - line-height:30px; +.main .table a:not(.btn):focus , +.main .table a:not(.btn):hover { + color: #C81022; } -.content-left .line.line-big { - font-family:Oswald; - font-size:60px; - font-weight:bold; - text-align:center; -} - -.content-left .line.line-bigsub { - font-size:25px; - font-weight:bold; - text-align:center; -} - -.content-left .line.balance { - font-size:45px; - text-align:center; -} - -.content-right { - margin:0 15px; -} - -.content-right-block { - padding-bottom:5px; - position:relative; -} - -.content-right-block:last-child { - padding-bottom:15px; -} - -.content-right-block > div:not(.buttons-title) { - background:#fff; -} - -.content-right-block-transparent > div:not(.buttons-title) { - background-color: transparent; -} - -.content-right-block .buttons-title { - position:absolute; - top:8px; - right:20px; -} - -.content-right-block > div.row { - margin:0; -} - -.content-right-block h2 { - margin:20px 20px 15px; - padding-bottom:5px; - border-bottom:3px solid #c8102e; - font-size:40px; -} - -.content-right-block h3 { - border-bottom: 1px solid #c8102e; - margin: 20px 15px 15px; - padding-bottom: 10px; - padding-left: 20px; - font-size:25px; -} /* * Pages tableaux seuls */ -.content-center > div { - background:#fff; -} -.content-center tbody tr:not(.section) td { - padding:0px 5px !important; -} - -.content-center .table .form-control { +.table .form-control { padding: 1px 12px ; height:28px; margin:3px 0px; + background: transparent; } - .content-center .auth-form { - margin:15px; + +.table .form-control[disabled], .table .form-control[readonly] { + background: #f5f5f5; +} + +.table-condensed-input tbody tr:not(.section) td { + padding:0px 5px; +} + +.table-condensed input.form-control { + margin: 0 !important; + border-top: 0; + border-bottom: 0; + border-radius: 0; +} + +.auth-form { + padding: 15px 0; + background: #d86c7e; + color: white; +} + +.auth-form.form-horizontal { + padding: 0; + margin: 0; +} + +.auth-form .form-group { + margin-bottom: 0; +} + +.auth-form input { + box-shadow: none !important; + background: transparent; + color: white; + border: 0 !important; + border-radius: 0; + border-bottom: 1px solid white !important; } /* * Pages formulaires seuls */ -.form-only .content-form { - margin:15px; - - background:#fff; - - padding:15px; -} - -.form-only .account_create #id_trigramme { +.account_create #id_trigramme { display:block; width:200px; height:80px; @@ -310,38 +172,48 @@ textarea { padding:5px 20px; } -/* - * Messages +/* Account autocomplete window */ + +#account_results ul { + list-style-type:none; + background:rgba(255,255,255,0.9); + padding:0; +} + +#account_results li { + display:block; + padding:5px 20px; + height:100%; + width:100%; +} + +#account_results .hilight { + background:rgba(200,16,46,0.9); + color:#fff; + text-decoration:none; +} + +/** + * Stats (graphs) */ -.messages .alert { - padding:10px 15px; - margin:0; - border:0; - border-radius:0; +.stat-nav { + margin-bottom: 10px; + font-family: Roboto; } -.messages .alert-dismissible { - padding-right:35px; +.stat-nav li { + float: left; } -.messages .alert .close { - top:0; - right:0; +.stat-nav a { + opacity: 0.6; + font-family: Roboto; } -.messages .alert-info { - color:inherit; - background-color:#ccc; -} - -.messages .alert-error { - color:inherit; - background-color:rgba(200,16,46,0.2); -} - -.messages .alert-success { - color:#333; +.stat-nav a:hover, +.stat-nav a.focus, .stat-nav a:focus { + opacity: 1; } /* @@ -364,7 +236,7 @@ textarea { margin-top:30px; padding-top:1px; padding-bottom:15px; - background:rgba(51,51,51,0.7); + background:rgba(51,51,51,0.9); color:#fff; } @@ -401,171 +273,56 @@ thead .tooltip { height: 100px; } -/* - * Responsive Columns - */ - -.unbreakable { - display:inline-block; - width: 100%; -} - - -.column-row { - padding: 15px 20px; -} - -.column-xs-1, -.column-sm-1, -.column-md-1, -.column-lg-1, -.column-xs-2, -.column-sm-2, -.column-md-2, -.column-lg-2, -.column-xs-3, -.column-sm-3, -.column-md-3, -.column-lg-3, -.column-xs-4, -.column-sm-4, -.column-md-4, -.column-lg-4, -.column-xs-5, -.column-sm-5, -.column-md-5, -.column-lg-5 { - -webkit-column-count: 1; /* Chrome, Safari, Opera */ - -moz-column-count: 1; /* Firefox */ - column-count: 1; -} - - -.column-xs-1 { - -webkit-column-count: 1; /* Chrome, Safari, Opera */ - -moz-column-count: 1; /* Firefox */ - column-count: 1; -} -.column-xs-2 { - -webkit-column-count: 2; /* Chrome, Safari, Opera */ - -moz-column-count: 2; /* Firefox */ - column-count: 2; -} -.column-xs-3 { - -webkit-column-count: 3; /* Chrome, Safari, Opera */ - -moz-column-count: 3; /* Firefox */ - column-count: 3; -} -.column-xs-4 { - -webkit-column-count: 4; /* Chrome, Safari, Opera */ - -moz-column-count: 4; /* Firefox */ - column-count: 4; -} -.column-xs-5 { - -webkit-column-count: 5; /* Chrome, Safari, Opera */ - -moz-column-count: 5; /* Firefox */ - column-count: 5; -} - -@media (min-width: 576px) { - .column-sm-1 { - -webkit-column-count: 1; /* Chrome, Safari, Opera */ - -moz-column-count: 1; /* Firefox */ - column-count: 1; - } - .column-sm-2 { - -webkit-column-count: 2; /* Chrome, Safari, Opera */ - -moz-column-count: 2; /* Firefox */ - column-count: 2; - } - .column-sm-3 { - -webkit-column-count: 3; /* Chrome, Safari, Opera */ - -moz-column-count: 3; /* Firefox */ - column-count: 3; - } - .column-sm-4 { - -webkit-column-count: 4; /* Chrome, Safari, Opera */ - -moz-column-count: 4; /* Firefox */ - column-count: 4; - } - .column-sm-5 { - -webkit-column-count: 5; /* Chrome, Safari, Opera */ - -moz-column-count: 5; /* Firefox */ - column-count: 5; - } -} - -@media (min-width: 768px) { - .column-md-1 { - -webkit-column-count: 1; /* Chrome, Safari, Opera */ - -moz-column-count: 1; /* Firefox */ - column-count: 1; - } - .column-md-2 { - -webkit-column-count: 2; /* Chrome, Safari, Opera */ - -moz-column-count: 2; /* Firefox */ - column-count: 2; - } - .column-md-3 { - -webkit-column-count: 3; /* Chrome, Safari, Opera */ - -moz-column-count: 3; /* Firefox */ - column-count: 3; - } - .column-md-4 { - -webkit-column-count: 4; /* Chrome, Safari, Opera */ - -moz-column-count: 4; /* Firefox */ - column-count: 4; - } - .column-md-5 { - -webkit-column-count: 5; /* Chrome, Safari, Opera */ - -moz-column-count: 5; /* Firefox */ - column-count: 5; - } -} - -@media (min-width: 992px) { - .column-lg-1 { - -webkit-column-count: 1; /* Chrome, Safari, Opera */ - -moz-column-count: 1; /* Firefox */ - column-count: 1; - } - .column-lg-2 { - -webkit-column-count: 2; /* Chrome, Safari, Opera */ - -moz-column-count: 2; /* Firefox */ - column-count: 2; - } - .column-lg-3 { - -webkit-column-count: 3; /* Chrome, Safari, Opera */ - -moz-column-count: 3; /* Firefox */ - column-count: 3; - } - .column-lg-4 { - -webkit-column-count: 4; /* Chrome, Safari, Opera */ - -moz-column-count: 4; /* Firefox */ - column-count: 4; - } - .column-lg-5 { - -webkit-column-count: 5; /* Chrome, Safari, Opera */ - -moz-column-count: 5; /* Firefox */ - column-count: 5; - } -} - -.help-block { - padding-top: 15px; -} /* Inventaires */ +.table-condensed-input input[type=number] { + text-align: center; +} + .inventory_modified { background:rgba(236,100,0,0.15); } .stock_diff { padding-left: 5px; - color:#C8102E; + color:#C8102E; } .inventory_update { - display:none; + display: none; + width: 50px; + margin: 0 auto; +} + + +/* Checkbox select multiple */ + +.checkbox-select-multiple label { + font-weight: normal; + margin-bottom: 0; +} + +/* Statement creation */ + +.statement-create-summary table { + margin: 0 auto; +} + +.statement-create-summary tr td { + text-align: right; +} + +.statement-create-summary tr td:first-child { + padding-right: 15px; + font-weight: bold; +} + +.statement-create-summary tr td:last-child { + width: 80px; +} + +#detail_taken table td, +#detail_balance table td { + padding: 0; } diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index ba88e433..6ae9ebc4 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -18,6 +18,17 @@ input[type=number]::-webkit-outer-spin-button { 100% { background: yellow; } } +/* Announcements banner */ + +#banner { + background-color: #d86b01; + width: 100%; + text-align: center; + padding: 10px; + color: white; + font-size: larger; +} + /* * Top row */ @@ -143,9 +154,10 @@ input[type=number]::-webkit-outer-spin-button { height:50px; padding:0 15px; - background:#c8102e; + background:rgba(200,16,46,1); color:#fff; + font-family:"Roboto Slab"; font-weight:bold; font-size:18px; } @@ -226,24 +238,17 @@ input[type=number]::-webkit-outer-spin-button { height:40px; } -#special_operations button { - height:100%; - width:25%; +#special_operations .btn { + height:40px; - float:left; - - background:#c8102e; - color:#FFF; - - font-size:18px; + font-size:15px; font-weight:bold; + + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; } -#special_operations button:focus, #special_operations button:hover { - outline:none; - background:#000; - color:#fff; -} /* Article autocomplete */ @@ -256,15 +261,14 @@ input[type=number]::-webkit-outer-spin-button { height:100%; float:left; border:0; - border-right:1px solid #c8102e; - border-bottom:1px solid #c8102e; border-radius:0; + border-bottom: 1px solid rgba(200,16,46,0.9); font-size:16px; font-weight:bold; } -#article_selection input+input #article_selection input+span { - border-right:0; +#article_selection input:first-child { + border-right: 1px dashed rgba(200,16,46,0.9); } #article_autocomplete { @@ -313,16 +317,22 @@ input[type=number]::-webkit-outer-spin-button { font-size:14px; } -#articles_data table tr.article>td:first-child { +#articles_data table tr.article td:first-child { padding-left:10px; } +#articles_data table tr.article td + td { + padding-right:10px; + text-align:right; +} + #articles_data table tr.category { height:35px; background-color:#c8102e; + font-family:"Roboto Slab"; font-size:16px; - color:#FFF; font-weight:bold; + color:#FFF; } #articles_data table tr.category>td:first-child { @@ -423,3 +433,7 @@ input[type=number]::-webkit-outer-spin-button { .kpsul_middle_right_col { overflow:auto; } + +.kpsul_middle_right_col #history .day { + top: 0; +} diff --git a/kfet/static/kfet/css/libs/columns.css b/kfet/static/kfet/css/libs/columns.css new file mode 100644 index 00000000..34591061 --- /dev/null +++ b/kfet/static/kfet/css/libs/columns.css @@ -0,0 +1,43 @@ +.unbreakable { + display:inline-block; + width: 100%; +} + +.column-xs-1, .column-sm-1, .column-md-1, .column-lg-1, +.column-xs-2, .column-sm-2, .column-md-2, .column-lg-2, +.column-xs-3, .column-sm-3, .column-md-3, .column-lg-3, +.column-xs-4, .column-sm-4, .column-md-4, .column-lg-4, +.column-xs-5, .column-sm-5, .column-md-5, .column-lg-5 { + column-count: 1; +} + +.column-xs-1 { column-count: 1; } +.column-xs-2 { column-count: 2; } +.column-xs-3 { column-count: 3; } +.column-xs-4 { column-count: 4; } +.column-xs-5 { column-count: 5; } + +@media (min-width: 768px) { + .column-sm-1 { column-count: 1; } + .column-sm-2 { column-count: 2; } + .column-sm-3 { column-count: 3; } + .column-sm-4 { column-count: 4; } + .column-sm-5 { column-count: 5; } +} + +@media (min-width: 992px) { + .column-md-1 { column-count: 1; } + .column-md-2 { column-count: 2; } + .column-md-3 { column-count: 3; } + .column-md-4 { column-count: 4; } + .column-md-5 { column-count: 5; } +} + +@media (min-width: 1200px) { + .column-lg-1 { column-count: 1; } + .column-lg-2 { column-count: 2; } + .column-lg-3 { column-count: 3; } + .column-lg-4 { column-count: 4; } + .column-lg-5 { column-count: 5; } +} + diff --git a/kfet/static/kfet/css/jconfirm-kfet.css b/kfet/static/kfet/css/libs/jconfirm-kfet.css similarity index 80% rename from kfet/static/kfet/css/jconfirm-kfet.css rename to kfet/static/kfet/css/libs/jconfirm-kfet.css index 1aee70f1..d2803434 100644 --- a/kfet/static/kfet/css/jconfirm-kfet.css +++ b/kfet/static/kfet/css/libs/jconfirm-kfet.css @@ -5,7 +5,7 @@ .jconfirm .jconfirm-box { padding:0; border-radius:0 !important; - font-family:"Roboto Mono"; + font-family:Roboto; } .jconfirm .jconfirm-box div.title-c .title { @@ -28,7 +28,6 @@ .jconfirm .jconfirm-box .content { border-bottom:1px solid #ddd; - padding:5px 10px; } .jconfirm .jconfirm-box input { @@ -37,6 +36,7 @@ border:0; + font-family:"Roboto Mono"; font-size:40px; text-align:center; @@ -49,6 +49,7 @@ } .jconfirm .jconfirm-box .buttons button { + min-width:40px; height:100%; margin:0; margin:0 !important; @@ -84,24 +85,3 @@ padding-right: 50px; padding-left: 50px; } - -/* Account autocomplete window */ - -#account_results ul { - list-style-type:none; - background:rgba(255,255,255,0.9); - padding:0; -} - -#account_results li { - display:block; - padding:5px 20px; - height:100%; - width:100%; -} - -#account_results .hilight { - background:rgba(200,16,46,0.9); - color:#fff; - text-decoration:none; -} diff --git a/kfet/static/kfet/css/libs/multiple-select-kfet.css b/kfet/static/kfet/css/libs/multiple-select-kfet.css new file mode 100644 index 00000000..145968d3 --- /dev/null +++ b/kfet/static/kfet/css/libs/multiple-select-kfet.css @@ -0,0 +1,14 @@ +/** + * Multiple Select plugin customizations + */ + +.ms-choice { + height: 34px !important; + line-height: 34px !important; + border: 1px solid #ccc !important; + box-shadow: inset 0 1px 1px rgba(0,0,0,.075) !important; +} + +.ms-choice > div { + top: 4px !important; +} diff --git a/kfet/static/kfet/css/nav.css b/kfet/static/kfet/css/nav.css index 5ffc7b24..bec05ccf 100644 --- a/kfet/static/kfet/css/nav.css +++ b/kfet/static/kfet/css/nav.css @@ -1,67 +1,88 @@ -nav { - background:#000; - color:#DDD; - font-family:Oswald; +.navbar { + background: #000; + color: #DDD; + font-family: Oswald; + border: 0; } -.navbar-nav > li > .dropdown-menu { - border:0; - border-radius:0; +.navbar .navbar-brand { + padding: 3px 25px; } -.navbar-fixed-top { - border:0; +.navbar .navbar-brand img { + height: 44px; } -nav .navbar-brand { - padding:3px 25px; -} - -nav .navbar-brand img { - height:44px; -} - -nav .navbar-toggle .icon-bar { - background-color:#FFF; -} - -nav a { - color:#DDD; +.navbar .navbar-toggle .icon-bar { + background-color: #FFF; } .navbar-nav { - font-weight:bold; - font-size:14px; - text-transform:uppercase; + font-weight: bold; + font-size: 14px; + text-transform: uppercase; + margin: 0 -15px; } -.nav>li>a:focus, .nav>li>a:hover { - background-color:#C8102E; - color:#FFF; -} - -.nav .open>a, .nav .open>a:focus, .nav .open>a:hover { - background-color:#C8102E; -} - -.dropdown-menu { - padding:0; -} - -.dropdown-menu>li>a { - padding:8px 20px; -} - -.dropdown-menu .divider { - margin:0; -} - -@media (max-width: 767px) { - .navbar-nav .open .dropdown-menu { - background-color:#FFF; - } - +@media (min-width: 768px) { .navbar-nav { - margin:0 -15px; + margin: 0px; + } + .navbar-right { + margin-right: -15px; + } +} + +.navbar-nav a { + transition: background-color, box-shadow, color; + transition-duration: 0.15s; +} + +.navbar-nav > li > a { + color: #FFF; +} + +.navbar-nav > li:hover > a, +.navbar-nav > li > a:focus, +.nav .open > a:hover, +.nav .open > a:focus { + background-color: #C8102E; + color: #FFF; + box-shadow: inset 0 5px 5px -5px #000; +} + +.navbar .dropdown .dropdown-menu { + padding: 0; + border: 0; + border-radius: 0; + background-color: #FFF; +} + +.navbar .dropdown .dropdown-menu > li > a { + padding: 8px 20px; + color: #000; +} + +.navbar .dropdown .dropdown-menu > li > a:hover, +.navbar .dropdown .dropdown-meny > li > a:focus { + color: #c8102e; + background-color: transparent; +} + +.navbar .dropdown .dropdown-menu .divider { + margin: 0; +} + +@media (min-width: 768px) { + .navbar .dropdown .dropdown-menu { + display: block; + visibility: hidden; + opacity: 0; + transition: opacity 0.15s; + } + + .navbar .dropdown:hover .dropdown-menu { + visibility: visible; + opacity: 1; } } diff --git a/kfet/static/kfet/img/favicon.png b/kfet/static/kfet/img/favicon.png new file mode 100644 index 00000000..56fb4299 Binary files /dev/null and b/kfet/static/kfet/img/favicon.png differ diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index cc369e32..b34f2005 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -1,14 +1,4 @@ $(document).ready(function() { - $(window).scroll(function() { - if ($(window).width() >= 768 && $(this).scrollTop() > 72.6) { - $('.col-content-left').css({'position':'fixed', 'top':'50px'}); - $('.col-content-right').addClass('col-sm-offset-4 col-md-offset-3'); - } else { - $('.col-content-left').css({'position':'relative', 'top':'0'}); - $('.col-content-right').removeClass('col-sm-offset-4 col-md-offset-3'); - } - }); - if (typeof Cookies !== 'undefined') { // Retrieving csrf token csrftoken = Cookies.get('csrftoken'); @@ -34,19 +24,24 @@ $(document).ready(function() { class KfetWebsocket { static get defaults() { - return {"relative_url": "", "default_msg": {}, "handlers": []}; + return { + relative_url: '', + default_msg: {}, + handlers: [], + base_path: '/ws/k-fet/' + }; } constructor(data) { $.extend(this, this.constructor.defaults, data); + if (window.location.pathname.startsWith('/gestion/')) + this.base_path = '/gestion' + this.base_path; } - - get url() { - var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; - var location_host = window.location.host; - var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; - return websocket_protocol+"://" + location_url + this.relative_url ; + get url() { + var protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; + var host = window.location.host; + return protocol + "://" + host + this.base_path + this.relative_url; } add_handler(handler) { @@ -70,7 +65,7 @@ class KfetWebsocket { } var OperationWebSocket = new KfetWebsocket({ - 'relative_url': '/ws/k-fet/k-psul/', + 'relative_url': 'k-psul/', 'default_msg': {'opegroups':[],'opes':[],'checkouts':[],'articles':[]}, }); @@ -194,3 +189,13 @@ function requestAuth(data, callback, focus_next = null) { }); } + + +/** + * Setup jquery-confirm + */ + +jconfirm.defaults = { + confirmButton: '', + cancelButton: '' +}; diff --git a/kfet/static/kfet/js/statistic.js b/kfet/static/kfet/js/statistic.js index f210c11d..9baa08c4 100644 --- a/kfet/static/kfet/js/statistic.js +++ b/kfet/static/kfet/js/statistic.js @@ -7,7 +7,7 @@ var self = this; var element = $(target); - var content = $("
    "); + var content = $("
    "); var buttons; function dictToArray (dict, start) { @@ -61,13 +61,12 @@ var chart = charts[i]; // format the data - var chart_data = is_time_chart ? handleTimeChart(chart.values) : dictToArray(chart.values, 1); + var chart_data = is_time_chart ? handleTimeChart(chart.values) : dictToArray(chart.values, 0); chart_datasets.push( { label: chart.label, borderColor: chart.color, - backgroundColor: chart.color, fill: is_time_chart, lineTension: 0, data: chart_data, @@ -132,7 +131,7 @@ type: 'line', options: chart_options, data: { - labels: (data.labels || []).slice(1), + labels: data.labels || [], datasets: chart_datasets, } }; @@ -154,9 +153,8 @@ // initialize the interface function initialize (data) { // creates the bar with the buttons - buttons = $("
    ", - {class: "btn-group btn-group-justified", - role: "group", + buttons = $("
    +{% endif %} + +{% endblock %} + +{% block main %} + +
    + + + + + + + + + + + + + + + {% for neg in negatives %} + + + + + + + + + + + {% endfor %} + +
    Tri.NomBalanceRéelleDébutDécouvert autoriséJusqu'auBalance offset
    + + {{ neg.account.trigramme }} + + {{ neg.account.name }}{{ neg.account.balance|floatformat:2 }}€ + {% if neg.balance_offset %} + {{ neg.account.real_balance|floatformat:2 }}€ + {% endif %} + {{ neg.start|date:'d/m/Y H:i:s'}}{{ neg.authz_overdraft_amount|default_if_none:'' }}{{ neg.authz_overdrafy_until|default_if_none:'' }}{{ neg.balance_offset|default_if_none:'' }}
    {% endblock %} diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 3c2ccbcd..eb3122d6 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -1,14 +1,9 @@ -{% extends "kfet/base.html" %} +{% extends "kfet/base_col_2.html" %} {% load staticfiles %} {% load kfet_tags %} {% load l10n %} {% block extra_head %} - - - - - {% if account.user == request.user %} @@ -18,26 +13,18 @@ $(document).ready(function() { var stat_last = new StatsGroup( "{% url 'kfet.account.stat.operation.list' trigramme=account.trigramme %}", - $("#stat_last"), + $("#stat_last") ); var stat_balance = new StatsGroup( "{% url 'kfet.account.stat.balance.list' trigramme=account.trigramme %}", - $("#stat_balance"), + $("#stat_balance") ); - }); +}); {% endif %} {% endblock %} {% block title %} -{% if account.user == request.user %} - Mon compte -{% else %} - Informations du compte {{ account.trigramme }} -{% endif %} -{% endblock %} - -{% block content-header-title %} {% if account.user == request.user %} Mon compte {% else %} @@ -45,62 +32,60 @@ $(document).ready(function() { {% endif %} {% endblock %} -{% block content %} +{% block header-title %} +{% if account.user == request.user %} + Mon compte +{% else %} + Informations du compte {{ account.trigramme }} +{% endif %} +{% endblock %} -
    -
    -
    - {% include 'kfet/left_account.html' %} -
    -
    -
    - {% include "kfet/base_messages.html" %} -
    +{% block footer %} +{% include "kfet/base_footer.html" %} +{% endblock %} + +{% block fixed %} +{% include "kfet/left_account.html" %} +{% endblock %} + +{% block main %} + +
    + + {% if account.user == request.user %} +
    +
    +
    +

    Ma balance

    +
    +

    Ma consommation

    +
    +
    +
    +
    + {% endif %} + +
    +
    {% if addcosts %} -
    -

    Gagné des majorations

    -
    -
      - {% for addcost in addcosts %} -
    • {{ addcost.date|date:'l j F' }}: +{{ addcost.sum_addcosts }}€
    • - {% endfor %} -
    -
    -
    - {% endif %} - {% if account.user == request.user %} -
    -

    Statistiques

    -
    -
    -
    -

    Ma balance

    -
    -
    -
    -
    -
    -
    -
    -

    Ma consommation

    -
    -
    -
    -
    +

    Gagné des majorations

    +
    +
      + {% for addcost in addcosts %} +
    • {{ addcost.date|date:'l j F' }}: +{{ addcost.sum_addcosts }}€
    • + {% endfor %} +
    {% endif %} -
    -

    Historique

    -
    -
    -
    -
    -
    -
    +
    + +
    + +
    {% endblock %} -{% block title %}Informations sur l'article {{ article }}{% endblock %} -{% block content-header-title %}Article - {{ article.name }}{% endblock %} +{% block title %}Article - {{ article.name }}{% endblock %} +{% block header-title %}Informations sur l'article {{ article.name }}{% endblock %} -{% block content %} +{% block fixed %} -
    -
    -
    -
    -
    {{ article.name }}
    -
    {{ article.category }}
    -
    -
    Prix (hors réduc.): {{ article.price }}€
    -
    Stock: {{ article.stock }}
    -
    En vente: {{ article.is_sold | yesno:"Oui,Non" }}
    -
    Affiché: {{ article.hidden | yesno:"Non,Oui" }}
    + + + + +{% endblock %} + +{% block main %} + +
    + +
    + +
    +
    +
    +
    + +

    Inventaires récents

    +
    + {% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %}
    -
    - -
    + +
    +
    + +

    Derniers prix fournisseurs

    +
    + {% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %} +
    + +
    +
    -
    - {% include 'kfet/base_messages.html' %} -
    -
    -

    Historique

    -
    -
    -

    Inventaires

    - - - - - - - - - - {% for inventoryart in inventoryarts %} - - - - - - {% endfor %} - -
    DateStockErreur
    {{ inventoryart.inventory.at }}{{ inventoryart.stock_new }}{{ inventoryart.stock_error }}
    -
    -
    -

    Prix fournisseurs

    - - - - - - - - - - - - {% for supplierart in supplierarts %} - - - - - - - - {% endfor %} - -
    DateFournisseurHTTVADroits
    {{ supplierart.at }}{{ supplierart.supplier.name }}{{ supplierart.price_HT }}{{ supplierart.TVA }}{{ supplierart.rights }}
    -
    -
    -
    -
    -

    Statistiques

    -
    -
    -
    -

    Ventes de {{ article.name }}

    -
    -
    -
    -
    -
    -
    + + +
    +
    +

    Ventes

    +
    +
    + +
    + +
    +
    + {% include "kfet/article_inventories_snippet.html" %} +
    +
    + +
    +
    + {% include "kfet/article_suppliers_snippet.html" %} +
    +
    +
    diff --git a/kfet/templates/kfet/article_suppliers_snippet.html b/kfet/templates/kfet/article_suppliers_snippet.html new file mode 100644 index 00000000..bd5970fd --- /dev/null +++ b/kfet/templates/kfet/article_suppliers_snippet.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + {% for supplierart in supplierarts %} + + + + + + + + {% endfor %} + +
    DateFournisseurHTTVADroits
    {{ supplierart.at }}{{ supplierart.supplier.name }}{{ supplierart.price_HT|default_if_none:"" }}{{ supplierart.TVA|default_if_none:"" }}{{ supplierart.rights|default_if_none:"" }}
    diff --git a/kfet/templates/kfet/article_update.html b/kfet/templates/kfet/article_update.html index a3bfbcc6..3f09e48e 100644 --- a/kfet/templates/kfet/article_update.html +++ b/kfet/templates/kfet/article_update.html @@ -1,27 +1,10 @@ -{% extends 'kfet/base.html' %} -{% load widget_tweaks %} -{% load staticfiles %} +{% extends "kfet/base_form.html" %} -{% block title %}Édition de l'article {{ article.name }}{% endblock %} -{% block content-header-title %}Article {{ article.name }} - Édition{% endblock %} +{% block title %}{{ article.name }} - Édition{% endblock %} +{% block header-title %}Édition de l'article {{ article.name }}{% endblock %} -{% block content %} +{% block main %} -{% include "kfet/base_messages.html" %} - -
    -
    -
    -
    - {% csrf_token %} - {% include 'kfet/form_snippet.html' with form=form %} - {% if not perms.kfet.change_article %} - {% include 'kfet/form_authentication_snippet.html' %} - {% endif %} - {% include 'kfet/form_submit_snippet.html' with value="Mettre à jour" %} -
    -
    -
    -
    +{% include "kfet/form_full_snippet.html" with authz=perms.kfet.change_article submit_text="Mettre à jour"%} {% endblock %} diff --git a/kfet/templates/kfet/base.html b/kfet/templates/kfet/base.html index 173a5fb7..8f90f459 100644 --- a/kfet/templates/kfet/base.html +++ b/kfet/templates/kfet/base.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static menu_tags %} @@ -7,18 +7,31 @@ {% block title %}{% endblock %} | K-Fêt - ENS Ulm + + + + {# CSS #} - + + {# JS #} + + + + + + + {% include "kfetopen/init.html" %} + {% block extra_head %}{% endblock %} {# Vieux IE pas comprendre HTML5 et Media Queries #} @@ -28,18 +41,26 @@ - {% include "kfet/base_nav.html" %} + {% flat_menu "kfet-nav" template="kfet/base_nav.html" apply_active_classes=True %}
    - {% block content-header %} -
    -
    -

    {% block content-header-title %}{% endblock %}

    + {% block header %} + {% if not page or not page.no_header %} +
    +
    +

    + {% block header-title %}{% endblock %} +

    -
    + + {% endif %} {% endblock %} + {% block content %}{% endblock %} - {% include "kfet/base_footer.html" %} + + {% block footer %} + {% endblock footer %}
    +
    diff --git a/kfet/templates/kfet/base_col_1.html b/kfet/templates/kfet/base_col_1.html new file mode 100644 index 00000000..03fea5e7 --- /dev/null +++ b/kfet/templates/kfet/base_col_1.html @@ -0,0 +1,16 @@ +{% extends "kfet/base.html" %} + +{% block header-class %}text-center{% endblock %} + +{% block content %} + +
    +
    + {% include "kfet/base_messages.html" %} +
    + {% block main %}{% endblock %} +
    +
    +
    + +{% endblock %} diff --git a/kfet/templates/kfet/base_col_2.html b/kfet/templates/kfet/base_col_2.html new file mode 100644 index 00000000..d0ac45b7 --- /dev/null +++ b/kfet/templates/kfet/base_col_2.html @@ -0,0 +1,19 @@ +{% extends "kfet/base.html" %} + +{% block content %} + +
    +
    +
    + {% block fixed %}{% endblock %} +
    +
    +
    + {% include "kfet/base_messages.html" %} +
    + {% block main %}{% endblock %} +
    +
    +
    + +{% endblock %} diff --git a/kfet/templates/kfet/base_col_mult.html b/kfet/templates/kfet/base_col_mult.html new file mode 100644 index 00000000..e5bafc19 --- /dev/null +++ b/kfet/templates/kfet/base_col_mult.html @@ -0,0 +1,18 @@ +{% extends "kfet/base.html" %} + +{% block header-class %}text-center{% endblock %} + +{% block content %} + +
    +
    + {% include "kfet/base_messages.html" %} +
    +
    + {% block main %}{% endblock %} +
    +
    +
    +
    + +{% endblock %} diff --git a/kfet/templates/kfet/base_footer.html b/kfet/templates/kfet/base_footer.html index e69de29b..c5333476 100644 --- a/kfet/templates/kfet/base_footer.html +++ b/kfet/templates/kfet/base_footer.html @@ -0,0 +1,17 @@ +{% load wagtailcore_tags %} + +{% with "k-fet@ens.fr" as kfet_mail %} + +
    + +{% endwith %} diff --git a/kfet/templates/kfet/base_form.html b/kfet/templates/kfet/base_form.html new file mode 100644 index 00000000..65fb09d6 --- /dev/null +++ b/kfet/templates/kfet/base_form.html @@ -0,0 +1,9 @@ +{% extends "kfet/base_col_1.html" %} + +{% block main-class %}main-bg main-padding{% endblock %} + +{% block main %} + +{% include "kfet/form_full_snippet.html" %} + +{% endblock %} diff --git a/kfet/templates/kfet/base_messages.html b/kfet/templates/kfet/base_messages.html index 440b8c10..3276bf72 100644 --- a/kfet/templates/kfet/base_messages.html +++ b/kfet/templates/kfet/base_messages.html @@ -1,16 +1,19 @@ +{% if config.gestion_banner %} + +{% endif %} + {% if messages %} -
    +
    {% for message in messages %} -
    -
    - - {% if 'safe' in message.tags %} - {{ message|safe }} - {% else %} - {{ message }} - {% endif %} -
    -
    +
    + + {{ message }} +
    {% endfor %}
    {% endif %} diff --git a/kfet/templates/kfet/base_nav.html b/kfet/templates/kfet/base_nav.html index b5c98375..ba582bcf 100644 --- a/kfet/templates/kfet/base_nav.html +++ b/kfet/templates/kfet/base_nav.html @@ -1,66 +1,128 @@ -{% load staticfiles %} +{% load static %} +{% load wagtailcore_tags %}
+ + {% endif %} + {% if user.is_authenticated and not perms.kfet.is_team %} +
  • + + + +
  • + {% elif not user.is_authenticated %} +
  • + + Connexion + +
  • + {% endif %} + +
    - - - - - - - +{{ filter_form.media }} {% endblock %} {% block title %}Historique{% endblock %} -{% block content-header-title %}Historique{% endblock %} +{% block header-title %}Historique{% endblock %} -{% block content %} +{% block fixed %} -
    -
    -
    -
    -
    -
    opérations
    -
    -

    Filtres

    -
    De
    -
    à
    -
    Caisses {{ filter_form.checkouts }}
    -
    Comptes {{ filter_form.accounts }}
    -
    -
    -
    + + +{% endblock %} + +{% block main %} + + +
    - -{% endblock %} {% block title %}Nouvel inventaire{% endblock %} -{% block content-header-title %}Nouvel inventaire{% endblock %} +{% block header-title %}Création d'un inventaire{% endblock %} -{% block content %} +{% block main-size %}col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2{% endblock %} -{% include 'kfet/base_messages.html' %} -
    -
    -
    - - - - - - - - - - - - - - - {% for form in formset %} - {% ifchanged form.category %} - - - - - {% endifchanged %} - - {{ form.article }} - - - - - - - - - - {% endfor %} - -
    ArticleQuantité par caisseStock ThéoriqueCaisses en réserveCaisses en arrièreVracStock totalCompte terminé
    {{ form.category_name }}
    {{ form.name }}{{ form.box_capacity }}{{ form.stock_old }} -
    -
    - -
    -
    -
    -
    -
    -
    -
    {{ form.stock_new | attr:"readonly"| add_class:"form-control" }}
    -
    -
    - {{ formset.management_form }} - {% if not perms.kfet.add_inventory %} -
    - {% include "kfet/form_authentication_snippet.html" %} -
    - {% endif %} - - {% csrf_token %} -
    +{% block main %} + +
    +
    + + + + + + + + + + + + + + + {% for form in formset %} + {% ifchanged form.category %} + + + + + {% endifchanged %} + + {{ form.article }} + + + + + + + + + + {% endfor %} + + + + + + + + +
    ArticleQuantité par caisseStock théoriqueCaisses en réserveCaisses en arrièreVracStock totalCompte terminé
    {{ form.category_name }}
    {{ form.name }}{{ form.box_capacity }} + {{ form.stock_old }} + + + + + + + + {{ form.stock_new | attr:"readonly"| add_class:"form-control" }} + +
    + +
    +
    + +
    +
    Totaux
    -
    - + {{ formset.management_form }} + {% if not perms.kfet.add_inventory %} +
    + {% include "kfet/form_authentication_snippet.html" %} +
    + {% endif %} + + {% csrf_token %} + - - - - - - - {% endblock %} {% block title %}K-Psul{% endblock %} -{% block content-header %}{% endblock %} +{% block header %}{% endblock %} +{% block footer %}{% endblock %} {% block help %} @@ -113,11 +106,27 @@
    -
    - - - - +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    @@ -182,7 +191,7 @@ $(document).ready(function() { settings = {} function resetSettings() { - $.ajax({ + return $.ajax({ dataType: "json", url : "{% url 'kfet.kpsul.get_settings' %}", method : "POST", @@ -191,7 +200,6 @@ $(document).ready(function() { settings['addcost_for'] = data['addcost_for']; settings['addcost_amount'] = parseFloat(data['addcost_amount']); settings['subvention_cof'] = parseFloat(data['subvention_cof']); - displayAddcost(); }); } @@ -393,6 +401,11 @@ $(document).ready(function() { var last_statement_container = $('#last_statement'); var last_statement_html_default = 'Dernier relevé:
    € le par '; + // If only one checkout is available, select it + var checkout_choices = checkoutInput.find("option[value!='']"); + if (checkout_choices.length == 1) { + $(checkout_choices[0]).prop("selected", true); + } // Display data function displayCheckoutData() { @@ -1426,9 +1439,11 @@ $(document).ready(function() { resetArticles(); resetPreviousOp(); khistory.reset(); - resetSettings(); - getArticles(); - getHistory(); + resetSettings().done(function (){ + getArticles(); + getHistory(); + displayAddcost(); + }); } function resetSelectable() { diff --git a/kfet/templates/kfet/left_account.html b/kfet/templates/kfet/left_account.html index 19352728..18438ff1 100644 --- a/kfet/templates/kfet/left_account.html +++ b/kfet/templates/kfet/left_account.html @@ -1,43 +1,96 @@ {% load kfet_tags %} -
    -
    {{ account.trigramme }}
    -
    {{ account.balance|ukf:account.is_cof }} UKF
    -
    -
    {{ account.name }}
    - {% if perms.kfet.is_team %} -
    {{ account.nickname }}
    - {% endif %} -
    - {% if account.email %} - {{ account.email }} - {% else %} - Pas d'email ! + +
    -
    - {% if account.negative.start %} -
    En négatif depuis {{ account.negative.start }}
    - {% endif %} - {% if account.negative.balance_offset %} -
    Solde réel: {{ account.real_balance }} €
    - {% endif %} - {% if account.negative.authz_overdraft_amount %} -
    Découvert autorisé: {{ account.negative.authz_overdraft_amount }} €
    - {% endif %} - {% if account.negative.authz_overdraft_until %} -
    Découvert autorisé jusqu'à : {{ account.negative.authz_overdraft_until }}
    - {% endif %} + + {% if account.negative %} +
    +

    Négatif

    +
      + {% if account.negative.start %} +
    • Depuis le {{ account.negative.start|date:"d/m/Y à H:i" }}
    • + {% endif %} + {% if account.real_balance != account.balance %} +
    • Solde réel: {{ account.real_balance }} €
    • + {% endif %} +
    • + Plafond : + {{ account.negative.authz_overdraft_amount|default:kfet_config.overdraft_amount }} € + jusqu'au + {{ account.negative.authz_overdraft_until|default:account.negative.until_default|date:"d/m/Y à H:i" }} +
    • +
    +
    + {% endif %} + + + + + +{% if account.user == request.user %} + - +{% endif %} + + diff --git a/kfet/templates/kfet/left_checkout.html b/kfet/templates/kfet/left_checkout.html index e00eede8..fbfdd7dc 100644 --- a/kfet/templates/kfet/left_checkout.html +++ b/kfet/templates/kfet/left_checkout.html @@ -1,13 +1,24 @@ -
    -
    {{ checkout.name }}
    -
    {{ checkout.balance|floatformat:2 }} €
    -
    -
    Valide du {{ checkout.valid_from|date:'l j F Y, G:i' }}
    -
    au {{ checkout.valid_to|date:'l j F Y, G:i' }}
    -
    Créée par {{ checkout.created_by }}
    +
    + +
    +
      +
    • Valide du {{ checkout.valid_from|date:'l j F Y, G:i' }}
    • +
    • au {{ checkout.valid_to|date:'l j F Y, G:i' }}
    • +
    • Créée par {{ checkout.created_by }}
    • +
    +
    + + diff --git a/kfet/templates/kfet/login_genericteam.html b/kfet/templates/kfet/login_genericteam.html index f5f8c863..d2f8eca0 100644 --- a/kfet/templates/kfet/login_genericteam.html +++ b/kfet/templates/kfet/login_genericteam.html @@ -1,7 +1,7 @@ {% extends 'kfet/base.html' %} -{% block content %} - -Connexion utilisateur K-Fêt générique réussie - +{% block extra_head %} + {% endblock %} diff --git a/kfet/templates/kfet/nav_item.html b/kfet/templates/kfet/nav_item.html new file mode 100644 index 00000000..8bc311b8 --- /dev/null +++ b/kfet/templates/kfet/nav_item.html @@ -0,0 +1,18 @@ +{% if not href %} + {% url url as href %} +{% endif %} +
  • + {% if href %} + + {% endif %}{{ text }} + {% if href %} + + {% endif %} +
  • diff --git a/kfet/templates/kfet/order.html b/kfet/templates/kfet/order.html index d1fb0442..53ef1bfb 100644 --- a/kfet/templates/kfet/order.html +++ b/kfet/templates/kfet/order.html @@ -1,106 +1,97 @@ -{% extends 'kfet/base.html' %} +{% extends "kfet/base_col_2.html" %} {% block title %}Commandes{% endblock %} -{% block content-header-title %}Commandes{% endblock %} +{% block header-title %}Commandes{% endblock %} -{% block content %} +{% block fixed %} -
    -
    -
    -
    -
    {{ orders|length }}
    -
    commande{{ orders|length|pluralize }}
    -
    -
    -
    -
    +
    + + +{% endblock %} + +{% block main %} + +
    +

    Fournisseurs

    +
    + + + + + + + + + + + {% for supplier in suppliers %} + + + + + + + + + {% endfor %} + +
    NomMailTél.AdresseCommentaire
    + + Commander + + + + {{ supplier.name }} + + {{ supplier.email }}{{ supplier.phone }}{{ supplier.address }}{{ supplier.comment }}
    +
    +
    + +
    +

    Liste des commandes

    +
    + + + + + + + + + + + {% for order in orders %} + + + + + + + {% endfor %} + +
    DateFournisseurInventaire
    + {% if not order.inventory %} + + Générer inventaire + + {% endif %} + + + {{ order.at }} + + {{ order.supplier }} + {% if order.inventory %} + + #{{ order.inventory.pk }} + + {% endif %} +
    +
    +
    {% endblock %} diff --git a/kfet/templates/kfet/order_create.html b/kfet/templates/kfet/order_create.html index c2d07f76..6ff9b824 100644 --- a/kfet/templates/kfet/order_create.html +++ b/kfet/templates/kfet/order_create.html @@ -1,71 +1,72 @@ -{% extends 'kfet/base.html' %} +{% extends "kfet/base_col_1.html" %} {% load widget_tweaks %} {% block title %}Nouvelle commande{% endblock %} -{% block content-header-title %}Nouvelle commande {{ supplier.name }}{% endblock %} +{% block header-title %}Création d'une commande {{ supplier.name }}{% endblock %} -{% block content %} +{% block main-size %}col-lg-8 col-lg-offset-2{% endblock %} + +{% block main %} -
    -
    {% csrf_token %} - +
    +
    - - - - - + - - - - - + {% for label in scale.get_labels %} + + {% endfor %} {% for form in formset %} {% ifchanged form.category %} - - - + + {% endifchanged %} {{ form.article }} - - - - - - + + {% for v_chunk in form.v_all %} + + {% endfor %} + - + {% endfor %}
    ArticleVentes + Ventes V. moy. + V. moy.
    E.T. + E.T.
    Prév. + Prév.
    StockRec. + Box
    + +
    Rec.
    Commande
    S1S2S3S4S5{{ label }}
    {{ form.category_name }}
    {{ form.category_name }}
    {{ form.name }}{{ form.v_s1 }}{{ form.v_s2 }}{{ form.v_s3 }}{{ form.v_s4 }}{{ form.v_s5 }}{{ form.name }}{{ v_chunk }}{{ form.v_moy }} {{ form.v_et }} {{ form.v_prev }} {{ form.stock }}{{ form.box_capacity|default:"" }} {{ form.c_rec }}{{ form.quantity_ordered | add_class:"form-control" }}{{ form.quantity_ordered | add_class:"form-control" }}
    +
    {{ formset.management_form }} {% if not perms.kfet.add_inventory %}
    @@ -74,8 +75,6 @@ {% endif %} -
    -
    - - - +{% block title %}Transferts{% endblock %} +{% block header-title %}Transferts{% endblock %} + +{% block fixed %} + + + {% endblock %} -{% block title %}Transferts{% endblock %} -{% block content-header-title %}Transferts{% endblock %} +{% block main %} -{% block content %} - -
    -
    -
    -
    -
    - +
    + {% for transfergroup in transfergroups %} +
    + {{ transfergroup.at }} + {{ transfergroup.valid_by.trigramme }} + {{ transfergroup.comment }}
    -
    -
    - {% include 'kfet/base_messages.html' %} -
    -
    -

    Liste des transferts

    -
    - {% for transfergroup in transfergroups %} -
    - {{ transfergroup.at }} - {{ transfergroup.valid_by.trigramme }} - {{ transfergroup.comment }} -
    - {% for transfer in transfergroup.transfers.all %} -
    - {{ transfer.amount }} € - {{ transfer.from_acc.trigramme }} - - {{ transfer.to_acc.trigramme }} -
    - {% endfor %} - {% endfor %} - + {% for transfer in transfergroup.transfers.all %} +
    + {{ transfer.amount }} € + {{ transfer.from_acc.trigramme }} + + {{ transfer.to_acc.trigramme }}
    -
    -
    + {% endfor %} + {% endfor %}
    {% endblock %} {% block title %}Nouveaux transferts{% endblock %} -{% block content-header-title %}Nouveaux transferts{% endblock %} +{% block header-title %}Création de transferts{% endblock %} -{% block content %} +{% block main-size %}col-sm-12{% endblock %} -{% csrf_token %} +{% block main %}
    + {% csrf_token %}
    diff --git a/kfet/templatetags/kfet_tags.py b/kfet/templatetags/kfet_tags.py index e21bb778..f5cd3848 100644 --- a/kfet/templatetags/kfet_tags.py +++ b/kfet/templatetags/kfet_tags.py @@ -1,14 +1,18 @@ # -*- coding: utf-8 -*- +import re + from django import template from django.utils.html import escape from django.utils.safestring import mark_safe -from kfet.models import Settings -from math import floor -import re + +from ..utils import to_ukf + register = template.Library() +register.filter('ukf', to_ukf) + @register.filter() def highlight_text(text, q): @@ -27,7 +31,6 @@ def highlight_user(user, q): return highlight_text(text, q) - @register.filter(is_safe=True) def highlight_clipper(clipper, q): if clipper.fullname: @@ -37,8 +40,14 @@ def highlight_clipper(clipper, q): return highlight_text(text, q) +@register.filter() +def widget_type(field): + return field.field.widget.__class__.__name__ + @register.filter() -def ukf(balance, is_cof): - grant = is_cof and (1 + Settings.SUBVENTION_COF() / 100) or 1 - return floor(balance * 10 * grant) +def slice(l, start, end=None): + if end is None: + end = start + start = 0 + return l[start:end] diff --git a/kfet/tests/__init__.py b/kfet/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kfet/tests/test_config.py b/kfet/tests/test_config.py new file mode 100644 index 00000000..03c9cf3c --- /dev/null +++ b/kfet/tests/test_config.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +from decimal import Decimal + +from django.test import TestCase +from django.utils import timezone + +import djconfig + +from gestioncof.models import User +from kfet.config import kfet_config +from kfet.models import Account + + +class ConfigTest(TestCase): + """Tests suite for kfet configuration.""" + + def setUp(self): + # load configuration as in djconfig middleware + djconfig.reload_maybe() + + def test_get(self): + self.assertTrue(hasattr(kfet_config, 'subvention_cof')) + + def test_subvention_cof(self): + reduction_cof = Decimal('20') + subvention_cof = Decimal('25') + kfet_config.set(reduction_cof=reduction_cof) + + self.assertEqual(kfet_config.subvention_cof, subvention_cof) + + def test_set_decimal(self): + """Test field of decimal type.""" + reduction_cof = Decimal('10') + # IUT + kfet_config.set(reduction_cof=reduction_cof) + # check + self.assertEqual(kfet_config.reduction_cof, reduction_cof) + + def test_set_modelinstance(self): + """Test field of model instance type.""" + user = User.objects.create(username='foo_user') + account = Account.objects.create(trigramme='FOO', + cofprofile=user.profile) + # IUT + kfet_config.set(addcost_for=account) + # check + self.assertEqual(kfet_config.addcost_for, account) + + def test_set_duration(self): + """Test field of duration type.""" + cancel_duration = timezone.timedelta(days=2, hours=4) + # IUT + kfet_config.set(cancel_duration=cancel_duration) + # check + self.assertEqual(kfet_config.cancel_duration, cancel_duration) diff --git a/kfet/tests/test_forms.py b/kfet/tests/test_forms.py new file mode 100644 index 00000000..7f129a3f --- /dev/null +++ b/kfet/tests/test_forms.py @@ -0,0 +1,56 @@ +# -*- 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, + ) diff --git a/kfet/tests.py b/kfet/tests/test_statistic.py similarity index 96% rename from kfet/tests.py rename to kfet/tests/test_statistic.py index 991b2545..d8db7ec8 100644 --- a/kfet/tests.py +++ b/kfet/tests/test_statistic.py @@ -5,11 +5,12 @@ from unittest.mock import patch from django.test import TestCase, Client from django.contrib.auth.models import User, Permission -from .models import Account, Article, ArticleCategory +from kfet.models import Account, Article, ArticleCategory class TestStats(TestCase): - @patch('kfet.signals.messages') + + @patch('gestioncof.signals.messages') def test_user_stats(self, mock_messages): """ Checks that we can get the stat-related pages without any problem. diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py new file mode 100644 index 00000000..ec9d6ffc --- /dev/null +++ b/kfet/tests/test_views.py @@ -0,0 +1,59 @@ +from decimal import Decimal +from unittest.mock import patch + +from django.test import TestCase, Client +from django.contrib.auth.models import User +from django.utils import timezone + +from ..models import Account, OperationGroup, Checkout, Operation + + +class AccountTests(TestCase): + """Account related views""" + + def setUp(self): + # A user and its account + self.user = User.objects.create_user(username="foobar", password="foo") + acc = Account.objects.create( + trigramme="FOO", cofprofile=self.user.profile + ) + + # Dummy operations and operation groups + checkout = Checkout.objects.create( + created_by=acc, name="checkout", + valid_from=timezone.now(), + valid_to=timezone.now() + timezone.timedelta(days=365) + ) + opeg_data = [ + (timezone.now(), Decimal('10')), + (timezone.now() - timezone.timedelta(days=3), Decimal('3')), + ] + OperationGroup.objects.bulk_create([ + OperationGroup( + on_acc=acc, checkout=checkout, at=at, is_cof=False, + amount=amount + ) + for (at, amount) in opeg_data + ]) + self.operation_groups = OperationGroup.objects.order_by("-amount") + Operation.objects.create( + group=self.operation_groups[0], + type=Operation.PURCHASE, + amount=Decimal('10') + ) + Operation.objects.create( + group=self.operation_groups[1], + type=Operation.PURCHASE, + amount=Decimal('3') + ) + + @patch('gestioncof.signals.messages') + def test_account_read(self, mock_messages): + """We can query the "Account - Read" page.""" + client = Client() + self.assertTrue(client.login( + username="foobar", + password="foo" + )) + resp = client.get("/k-fet/accounts/FOO") + self.assertEqual(200, resp.status_code) diff --git a/kfet/urls.py b/kfet/urls.py index bc1f3370..c3499b18 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -1,14 +1,13 @@ # -*- coding: utf-8 -*- -from django.conf.urls import url +from django.conf.urls import include, url from django.contrib.auth.decorators import permission_required -from kfet import views -from kfet import autocomplete + +from kfet import autocomplete, views from kfet.decorators import teamkfet_required + urlpatterns = [ - url(r'^$', views.Home.as_view(), - name='kfet.home'), url(r'^login/genericteam$', views.login_genericteam, name='kfet.login.genericteam'), url(r'^history$', views.history, @@ -193,11 +192,12 @@ urlpatterns = [ permission_required('kfet.change_settings') (views.SettingsList.as_view()), name='kfet.settings'), - url(r'^settings/(?P\d+)/edit$', + url(r'^settings/edit$', permission_required('kfet.change_settings') (views.SettingsUpdate.as_view()), name='kfet.settings.update'), + # ----- # Transfers urls # ----- @@ -242,3 +242,8 @@ urlpatterns = [ url(r'^orders/(?P\d+)/to_inventory$', views.order_to_inventory, name='kfet.order.to_inventory'), ] + +urlpatterns += [ + # K-Fêt Open urls + url('^open/', include('kfet.open.urls')), +] diff --git a/kfet/utils.py b/kfet/utils.py new file mode 100644 index 00000000..3d06bb0b --- /dev/null +++ b/kfet/utils.py @@ -0,0 +1,115 @@ +import math +import json + +from django.core.cache import cache +from django.core.serializers.json import DjangoJSONEncoder + +from channels.channel import Group +from channels.generic.websockets import JsonWebsocketConsumer + +from .config import kfet_config + + +def to_ukf(balance, is_cof=False): + """Convert euro to UKF.""" + subvention = kfet_config.subvention_cof + grant = (1 + subvention / 100) if is_cof else 1 + return math.floor(balance * 10 * grant) + +# Storage + +class CachedMixin: + """Object with cached properties. + + Attributes: + cached (dict): Keys are cached properties. Associated value is the + returned default by getters in case the key is missing from cache. + cache_prefix (str): Used to prefix keys in cache. + + """ + cached = {} + cache_prefix = '' + + def __init__(self, cache_prefix=None, *args, **kwargs): + super().__init__(*args, **kwargs) + if cache_prefix is not None: + self.cache_prefix = cache_prefix + + def cachekey(self, attr): + return '{}__{}'.format(self.cache_prefix, attr) + + def __getattr__(self, attr): + if attr in self.cached: + return cache.get(self.cachekey(attr), self.cached.get(attr)) + elif hasattr(super(), '__getattr__'): + return super().__getattr__(attr) + else: + raise AttributeError("can't get attribute") + + def __setattr__(self, attr, value): + if attr in self.cached: + cache.set(self.cachekey(attr), value) + elif hasattr(super(), '__setattr__'): + super().__setattr__(attr, value) + else: + raise AttributeError("can't set attribute") + + def clear_cache(self): + cache.delete_many([ + self.cachekey(attr) for attr in self.cached.keys() + ]) + + +# Consumers + +class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer): + """Custom Json Websocket Consumer. + + Encode to JSON with DjangoJSONEncoder. + + """ + + @classmethod + def encode_json(cls, content): + return json.dumps(content, cls=DjangoJSONEncoder) + + +class PermConsumerMixin: + """Add support to check permissions on consumers. + + Attributes: + perms_connect (list): Required permissions to connect to this + consumer. + + message.user is appended as argument to each connection_groups method call. + + """ + http_user = True # Enable message.user + perms_connect = [] + + def connect(self, message, **kwargs): + """Check permissions on connection.""" + if message.user.has_perms(self.perms_connect): + super().connect(message, **kwargs) + else: + 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) diff --git a/kfet/views.py b/kfet/views.py index 1ae31283..c7eb677b 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -6,7 +6,7 @@ from urllib.parse import urlencode from django.shortcuts import render, get_object_or_404, redirect from django.core.exceptions import PermissionDenied from django.core.cache import cache -from django.views.generic import ListView, DetailView, TemplateView +from django.views.generic import ListView, DetailView, TemplateView, FormView from django.views.generic.detail import BaseDetailView from django.views.generic.edit import CreateView, UpdateView from django.core.urlresolvers import reverse, reverse_lazy @@ -23,10 +23,15 @@ from django.db.models.functions import Coalesce from django.utils import timezone from django.utils.crypto import get_random_string from django.utils.decorators import method_decorator + +from django_cas_ng.views import logout as cas_logout_view + from gestioncof.models import CofProfile + +from kfet.config import kfet_config from kfet.decorators import teamkfet_required from kfet.models import ( - Account, Checkout, Article, Settings, AccountNegative, + Account, Checkout, Article, AccountNegative, CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle, Inventory, InventoryArticle, Order, OrderArticle, Operation, OperationGroup, TransferGroup, Transfer, ArticleCategory) @@ -37,57 +42,38 @@ from kfet.forms import ( GroupForm, CheckoutForm, CheckoutRestrictForm, CheckoutStatementCreateForm, CheckoutStatementUpdateForm, ArticleForm, ArticleRestrictForm, KPsulOperationGroupForm, KPsulAccountForm, KPsulCheckoutForm, - KPsulOperationFormSet, AddcostForm, FilterHistoryForm, SettingsForm, + KPsulOperationFormSet, AddcostForm, FilterHistoryForm, TransferFormSet, InventoryArticleForm, OrderArticleForm, - OrderArticleToInventoryForm, CategoryForm + OrderArticleToInventoryForm, CategoryForm, KFetConfigForm ) from collections import defaultdict from kfet import consumers from datetime import timedelta from decimal import Decimal -import django_cas_ng import heapq import statistics -from kfet.statistic import ScaleMixin, last_stats_manifest, tot_ventes - - -class Home(TemplateView): - template_name = "kfet/home.html" - - def get_context_data(self, **kwargs): - context = super(TemplateView, self).get_context_data(**kwargs) - articles = Article.objects.all().filter(is_sold=True, hidden=False) - context['pressions'] = articles.filter(category__name='Pression') - context['articles'] = (articles.exclude(category__name='Pression') - .order_by('category')) - return context - - @method_decorator(login_required) - def dispatch(self, *args, **kwargs): - return super(TemplateView, self).dispatch(*args, **kwargs) +from kfet.statistic import ScaleMixin, last_stats_manifest, tot_ventes, WeekScale @teamkfet_required def login_genericteam(request): # Check si besoin de déconnecter l'utilisateur de CAS - profile, _ = CofProfile.objects.get_or_create(user=request.user) - need_cas_logout = False - if profile.login_clipper: - need_cas_logout = True + 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 - logout_cas = django_cas_ng.views.logout(request) + 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) - if need_cas_logout: - # Vue de déconnexion de CAS - return logout_cas + messages.success(request, "Connecté en utilisateur partagé") + + return cas_logout or render(request, "kfet/login_genericteam.html") - return render(request, "kfet/login_genericteam.html") def put_cleaned_data_in_dict(dict, form): for field in form.cleaned_data: @@ -346,31 +332,32 @@ def account_create_ajax(request, username=None, login_clipper=None, 'user_form' : forms['user_form'], }) + # Account - Read @login_required def account_read(request, trigramme): - try: - account = Account.objects.select_related('negative').get(trigramme=trigramme) - except Account.DoesNotExist: - raise Http404 + account = get_object_or_404(Account, trigramme=trigramme) # Checking permissions - if not request.user.has_perm('kfet.is_team') \ - and request.user != account.user: + if not account.readable or ( + not request.user.has_perm('kfet.is_team') and + request.user != account.user): raise PermissionDenied - addcosts = (OperationGroup.objects - .filter(opes__addcost_for=account,opes__canceled_at=None) - .extra({'date':"date(at)"}) - .values('date') - .annotate(sum_addcosts=Sum('opes__addcost_amount')) - .order_by('-date')) + addcosts = ( + OperationGroup.objects + .filter(opes__addcost_for=account, + opes__canceled_at=None) + .extra({'date': "date(at)"}) + .values('date') + .annotate(sum_addcosts=Sum('opes__addcost_amount')) + .order_by('-date') + ) return render(request, "kfet/account_read.html", { - 'account' : account, + 'account': account, 'addcosts': addcosts, - 'settings': { 'subvention_cof': Settings.SUBVENTION_COF() }, }) # Account - Update @@ -517,13 +504,22 @@ def account_update(request, trigramme): 'pwd_form': pwd_form, }) + @permission_required('kfet.manage_perms') def account_group(request): - groups = (Group.objects - .filter(name__icontains='K-Fêt') - .prefetch_related('permissions', 'user_set__profile__account_kfet') + user_pre = Prefetch( + 'user_set', + queryset=User.objects.select_related('profile__account_kfet'), ) - return render(request, 'kfet/account_group.html', { 'groups': groups }) + 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 @@ -532,34 +528,27 @@ class AccountGroupCreate(SuccessMessageMixin, CreateView): success_message = 'Nouveau groupe : %(name)s' success_url = reverse_lazy('kfet.account.group') -class AccountGroupUpdate(UpdateView): +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): - queryset = (AccountNegative.objects + queryset = ( + AccountNegative.objects .select_related('account', 'account__cofprofile__user') - .exclude(account__trigramme='#13')) + .exclude(account__trigramme='#13') + ) template_name = 'kfet/account_negative.html' context_object_name = 'negatives' def get_context_data(self, **kwargs): context = super(AccountNegativeList, self).get_context_data(**kwargs) - context['settings'] = { - 'overdraft_amount': Settings.OVERDRAFT_AMOUNT(), - 'overdraft_duration': Settings.OVERDRAFT_DURATION(), - } - negs_sum = (AccountNegative.objects - .exclude(account__trigramme='#13') - .aggregate( - bal = Coalesce(Sum('account__balance'),0), - offset = Coalesce(Sum('balance_offset'),0), - ) - ) - context['negatives_sum'] = negs_sum['bal'] - negs_sum['offset'] + real_balances = (neg.account.real_balance for neg in self.object_list) + context['negatives_sum'] = sum(real_balances) return context # ----- @@ -762,12 +751,18 @@ class CategoryUpdate(SuccessMessageMixin, UpdateView): # Article - General class ArticleList(ListView): - queryset = (Article.objects - .select_related('category') - .prefetch_related(Prefetch('inventories', - queryset=Inventory.objects.order_by('-at'), - to_attr='inventory')) - .order_by('category', '-is_sold', 'name')) + queryset = ( + Article.objects + .select_related('category') + .prefetch_related( + Prefetch( + 'inventories', + queryset=Inventory.objects.order_by('-at'), + to_attr='inventory', + ) + ) + .order_by('category__name', '-is_sold', 'name') + ) template_name = 'kfet/article.html' context_object_name = 'articles' @@ -879,7 +874,6 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView): return super(ArticleUpdate, self).form_valid(form) - # ----- # K-Psul # ----- @@ -889,29 +883,24 @@ def kpsul(request): data = {} data['operationgroup_form'] = KPsulOperationGroupForm() data['trigramme_form'] = KPsulAccountForm() - initial = {} - try: - checkout = Checkout.objects.filter( - is_protected=False, valid_from__lte=timezone.now(), - valid_to__gte=timezone.now()).get() - initial['checkout'] = checkout - except (Checkout.DoesNotExist, Checkout.MultipleObjectsReturned): - pass - data['checkout_form'] = KPsulCheckoutForm(initial=initial) - operation_formset = KPsulOperationFormSet(queryset=Operation.objects.none()) - data['operation_formset'] = operation_formset + data['checkout_form'] = KPsulCheckoutForm() + data['operation_formset'] = KPsulOperationFormSet( + queryset=Operation.objects.none(), + ) return render(request, 'kfet/kpsul.html', data) + @teamkfet_required def kpsul_get_settings(request): - addcost_for = Settings.ADDCOST_FOR() + addcost_for = kfet_config.addcost_for data = { - 'subvention_cof': Settings.SUBVENTION_COF(), - 'addcost_for' : addcost_for and addcost_for.trigramme or '', - 'addcost_amount': Settings.ADDCOST_AMOUNT(), + 'subvention_cof': kfet_config.subvention_cof, + 'addcost_for': addcost_for and addcost_for.trigramme or '', + 'addcost_amount': kfet_config.addcost_amount, } return JsonResponse(data) + @teamkfet_required def account_read_json(request): trigramme = request.POST.get('trigramme', '') @@ -951,6 +940,7 @@ def kpsul_checkout_data(request): raise Http404 return JsonResponse(data) + @teamkfet_required def kpsul_update_addcost(request): addcost_form = AddcostForm(request.POST) @@ -970,15 +960,15 @@ def kpsul_update_addcost(request): trigramme = addcost_form.cleaned_data['trigramme'] account = trigramme and Account.objects.get(trigramme=trigramme) or None - Settings.objects.filter(name='ADDCOST_FOR').update(value_account=account) - (Settings.objects.filter(name='ADDCOST_AMOUNT') - .update(value_decimal=addcost_form.cleaned_data['amount'])) - cache.delete('ADDCOST_FOR') - cache.delete('ADDCOST_AMOUNT') + amount = addcost_form.cleaned_data['amount'] + + kfet_config.set(addcost_for=account, + addcost_amount=amount) + data = { 'addcost': { - 'for': trigramme and account.trigramme or None, - 'amount': addcost_form.cleaned_data['amount'], + 'for': account and account.trigramme or None, + 'amount': amount, } } consumers.KPsul.group_send('kfet.kpsul', data) @@ -1022,10 +1012,10 @@ def kpsul_perform_operations(request): operations = operation_formset.save(commit=False) # Retrieving COF grant - cof_grant = Settings.SUBVENTION_COF() + cof_grant = kfet_config.subvention_cof # Retrieving addcosts data - addcost_amount = Settings.ADDCOST_AMOUNT() - addcost_for = Settings.ADDCOST_FOR() + addcost_amount = kfet_config.addcost_amount + addcost_for = kfet_config.addcost_for # Initializing vars required_perms = set() # Required perms to perform all operations @@ -1101,22 +1091,15 @@ def kpsul_perform_operations(request): with transaction.atomic(): # If not cash account, # saving account's balance and adding to Negative if not in - if not operationgroup.on_acc.is_cash: - Account.objects.filter(pk=operationgroup.on_acc.pk).update( - balance=F('balance') + operationgroup.amount) - operationgroup.on_acc.refresh_from_db() - if operationgroup.on_acc.balance < 0: - if hasattr(operationgroup.on_acc, 'negative'): - if not operationgroup.on_acc.negative.start: - operationgroup.on_acc.negative.start = timezone.now() - operationgroup.on_acc.negative.save() - else: - negative = AccountNegative( - account=operationgroup.on_acc, start=timezone.now()) - negative.save() - elif (hasattr(operationgroup.on_acc, 'negative') and - not operationgroup.on_acc.negative.balance_offset): - operationgroup.on_acc.negative.delete() + on_acc = operationgroup.on_acc + if not on_acc.is_cash: + ( + Account.objects + .filter(pk=on_acc.pk) + .update(balance=F('balance') + operationgroup.amount) + ) + on_acc.refresh_from_db() + on_acc.update_negative() # Updating checkout's balance if to_checkout_balance: @@ -1216,7 +1199,7 @@ def kpsul_cancel_operations(request): opes = [] # Pas déjà annulée required_perms = set() stop_all = False - cancel_duration = Settings.CANCEL_DURATION() + cancel_duration = kfet_config.cancel_duration to_accounts_balances = defaultdict(lambda:0) # Modifs à faire sur les balances des comptes to_groups_amounts = defaultdict(lambda:0) # ------ sur les montants des groupes d'opé to_checkouts_balances = defaultdict(lambda:0) # ------ sur les balances de caisses @@ -1307,8 +1290,15 @@ def kpsul_cancel_operations(request): (Operation.objects.filter(pk__in=opes) .update(canceled_by=canceled_by, canceled_at=canceled_at)) for account in to_accounts_balances: - Account.objects.filter(pk=account.pk).update( - balance = F('balance') + to_accounts_balances[account]) + ( + Account.objects + .filter(pk=account.pk) + .update(balance=F('balance') + to_accounts_balances[account]) + ) + if not account.is_cash: + # Should always be true, but we want to be sure + account.refresh_from_db() + account.update_negative() for checkout in to_checkouts_balances: Checkout.objects.filter(pk=checkout.pk).update( balance = F('balance') + to_checkouts_balances[checkout]) @@ -1444,34 +1434,28 @@ def kpsul_articles_data(request): .filter(is_sold=True)) return JsonResponse({ 'articles': list(articles) }) + @teamkfet_required def history(request): data = { 'filter_form': FilterHistoryForm(), - 'settings': { - 'subvention_cof': Settings.SUBVENTION_COF(), - } } return render(request, 'kfet/history.html', data) + # ----- # Settings views # ----- -class SettingsList(ListView): - model = Settings - context_object_name = 'settings' + +class SettingsList(TemplateView): template_name = 'kfet/settings.html' - def get_context_data(self, **kwargs): - Settings.create_missing() - return super(SettingsList, self).get_context_data(**kwargs) -class SettingsUpdate(SuccessMessageMixin, UpdateView): - model = Settings - form_class = SettingsForm +class SettingsUpdate(SuccessMessageMixin, FormView): + form_class = KFetConfigForm template_name = 'kfet/settings_update.html' - success_message = 'Paramètre %(name)s mis à jour' + success_message = 'Paramètres mis à jour' success_url = reverse_lazy('kfet.settings') def form_valid(self, form): @@ -1479,9 +1463,10 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView): if not self.request.user.has_perm('kfet.change_settings'): form.add_error(None, 'Permission refusée') return self.form_invalid(form) - # Creating - Settings.empty_cache() - return super(SettingsUpdate, self).form_valid(form) + form.save() + return super().form_valid(form) + + # ----- # Transfer views @@ -1489,13 +1474,25 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView): @teamkfet_required def transfers(request): - transfergroups = (TransferGroup.objects - .prefetch_related('transfers') - .order_by('-at')) + transfers_pre = Prefetch( + 'transfers', + queryset=( + Transfer.objects + .select_related('from_acc', 'to_acc') + ), + ) + + transfergroups = ( + TransferGroup.objects + .select_related('valid_by') + .prefetch_related(transfers_pre) + .order_by('-at') + ) return render(request, 'kfet/transfers.html', { 'transfergroups': transfergroups, }) + @teamkfet_required def transfers_create(request): transfer_formset = TransferFormSet(queryset=Transfer.objects.none()) @@ -1607,7 +1604,7 @@ def cancel_transfers(request): transfers = [] # Pas déjà annulée required_perms = set() stop_all = False - cancel_duration = Settings.CANCEL_DURATION() + cancel_duration = kfet_config.cancel_duration to_accounts_balances = defaultdict(lambda:0) # Modifs à faire sur les balances des comptes for transfer in transfers_all: if transfer.canceled_at: @@ -1639,9 +1636,6 @@ def cancel_transfers(request): if stop: negative_accounts.append(account.trigramme) - print(required_perms) - print(request.user.get_all_permissions()) - if stop_all or not request.user.has_perms(required_perms): missing_perms = get_missing_perms(required_perms, request.user) if missing_perms: @@ -1779,68 +1773,54 @@ class OrderList(ListView): context['suppliers'] = Supplier.objects.order_by('name') return context + @teamkfet_required def order_create(request, pk): supplier = get_object_or_404(Supplier, pk=pk) - articles = (Article.objects - .filter(suppliers=supplier.pk) - .distinct() - .select_related('category') - .order_by('category__name', 'name')) + articles = ( + Article.objects + .filter(suppliers=supplier.pk) + .distinct() + .select_related('category') + .order_by('category__name', 'name') + ) - initial = [] - today = timezone.now().date() - sales_q = (Operation.objects + # Force hit to cache + articles = list(articles) + + sales_q = ( + Operation.objects .select_related('group') .filter(article__in=articles, canceled_at=None) - .values('article')) - sales_s1 = (sales_q - .filter( - group__at__gte = today-timedelta(weeks=5), - group__at__lt = today-timedelta(weeks=4)) + .values('article') .annotate(nb=Sum('article_nb')) ) - sales_s1 = { d['article']:d['nb'] for d in sales_s1 } - sales_s2 = (sales_q - .filter( - group__at__gte = today-timedelta(weeks=4), - group__at__lt = today-timedelta(weeks=3)) - .annotate(nb=Sum('article_nb')) - ) - sales_s2 = { d['article']:d['nb'] for d in sales_s2 } - sales_s3 = (sales_q - .filter( - group__at__gte = today-timedelta(weeks=3), - group__at__lt = today-timedelta(weeks=2)) - .annotate(nb=Sum('article_nb')) - ) - sales_s3 = { d['article']:d['nb'] for d in sales_s3 } - sales_s4 = (sales_q - .filter( - group__at__gte = today-timedelta(weeks=2), - group__at__lt = today-timedelta(weeks=1)) - .annotate(nb=Sum('article_nb')) - ) - sales_s4 = { d['article']:d['nb'] for d in sales_s4 } - sales_s5 = (sales_q - .filter(group__at__gte = today-timedelta(weeks=1)) - .annotate(nb=Sum('article_nb')) - ) - sales_s5 = { d['article']:d['nb'] for d in sales_s5 } + scale = WeekScale(last=True, n_steps=5, std_chunk=False) + chunks = scale.chunkify_qs(sales_q, field='group__at') + + sales = [ + {d['article']: d['nb'] for d in chunk} + for chunk in chunks + ] + + initial = [] for article in articles: - v_s1 = sales_s1.get(article.pk, 0) - v_s2 = sales_s2.get(article.pk, 0) - v_s3 = sales_s3.get(article.pk, 0) - v_s4 = sales_s4.get(article.pk, 0) - v_s5 = sales_s5.get(article.pk, 0) - v_all = [v_s1, v_s2, v_s3, v_s4, v_s5] + # Get sales for each 5 last weeks + v_all = [chunk.get(article.pk, 0) for chunk in sales] + # Take the 3 greatest (eg to avoid 2 weeks of vacations) v_3max = heapq.nlargest(3, v_all) + # Get average and standard deviation v_moy = statistics.mean(v_3max) v_et = statistics.pstdev(v_3max, v_moy) + # Expected sales for next week v_prev = v_moy + v_et + # We want to have 1.5 * the expected sales in stock + # (because sometimes some articles are not delivered) c_rec_tot = max(v_prev * 1.5 - article.stock, 0) + # If ordered quantity is close enough to a level which can led to free + # boxes, we increase it to this level. if article.box_capacity: c_rec_temp = c_rec_tot / article.box_capacity if c_rec_temp >= 10: @@ -1858,11 +1838,7 @@ def order_create(request, pk): 'category__name': article.category.name, 'stock': article.stock, 'box_capacity': article.box_capacity, - 'v_s1': v_s1, - 'v_s2': v_s2, - 'v_s3': v_s3, - 'v_s4': v_s4, - 'v_s5': v_s5, + 'v_all': v_all, 'v_moy': round(v_moy), 'v_et': round(v_et), 'v_prev': round(v_prev), @@ -1870,8 +1846,9 @@ def order_create(request, pk): }) cls_formset = formset_factory( - form = OrderArticleForm, - extra = 0) + form=OrderArticleForm, + extra=0, + ) if request.POST: formset = cls_formset(request.POST, initial=initial) @@ -1888,14 +1865,15 @@ def order_create(request, pk): order.save() saved = True - article = articles.get(pk=form.cleaned_data['article'].pk) + article = form.cleaned_data['article'] q_ordered = form.cleaned_data['quantity_ordered'] if article.box_capacity: q_ordered *= article.box_capacity OrderArticle.objects.create( - order = order, - article = article, - quantity_ordered = q_ordered) + order=order, + article=article, + quantity_ordered=q_ordered, + ) if saved: messages.success(request, 'Commande créée') return redirect('kfet.order.read', order.pk) @@ -1905,11 +1883,15 @@ def order_create(request, pk): else: formset = cls_formset(initial=initial) + scale.label_fmt = "S -{rev_i}" + return render(request, 'kfet/order_create.html', { 'supplier': supplier, - 'formset' : formset, + 'formset': formset, + 'scale': scale, }) + class OrderRead(DetailView): model = Order template_name = 'kfet/order_read.html' @@ -1948,6 +1930,7 @@ class OrderRead(DetailView): context['mail'] = mail return context + @teamkfet_required def order_to_inventory(request, pk): order = get_object_or_404(Order, pk=pk) @@ -1955,28 +1938,36 @@ def order_to_inventory(request, pk): if hasattr(order, 'inventory'): raise Http404 - articles = (Article.objects - .filter(orders=order.pk) - .select_related('category') - .prefetch_related(Prefetch('orderarticle_set', - queryset = OrderArticle.objects.filter(order=order), - to_attr = 'order')) - .prefetch_related(Prefetch('supplierarticle_set', - queryset = (SupplierArticle.objects - .filter(supplier=order.supplier) - .order_by('-at')), - to_attr = 'supplier')) - .order_by('category__name', 'name')) + supplier_prefetch = Prefetch( + 'article__supplierarticle_set', + queryset=( + SupplierArticle.objects + .filter(supplier=order.supplier) + .order_by('-at') + ), + to_attr='supplier', + ) + + order_articles = ( + OrderArticle.objects + .filter(order=order.pk) + .select_related('article', 'article__category') + .prefetch_related( + supplier_prefetch, + ) + .order_by('article__category__name', 'article__name') + ) initial = [] - for article in articles: + for order_article in order_articles: + article = order_article.article initial.append({ 'article': article.pk, 'name': article.name, 'category': article.category_id, 'category__name': article.category.name, - 'quantity_ordered': article.order[0].quantity_ordered, - 'quantity_received': article.order[0].quantity_ordered, + 'quantity_ordered': order_article.quantity_ordered, + 'quantity_received': order_article.quantity_ordered, 'price_HT': article.supplier[0].price_HT, 'TVA': article.supplier[0].TVA, 'rights': article.supplier[0].rights, @@ -1991,31 +1982,50 @@ def order_to_inventory(request, pk): messages.error(request, 'Permission refusée') elif formset.is_valid(): with transaction.atomic(): - inventory = Inventory() - inventory.order = order - inventory.by = request.user.profile.account_kfet - inventory.save() + inventory = Inventory.objects.create( + order=order, by=request.user.profile.account_kfet, + ) + new_supplierarticle = [] + new_inventoryarticle = [] for form in formset: q_received = form.cleaned_data['quantity_received'] article = form.cleaned_data['article'] - SupplierArticle.objects.create( - supplier = order.supplier, - article = article, - price_HT = form.cleaned_data['price_HT'], - TVA = form.cleaned_data['TVA'], - rights = form.cleaned_data['rights']) - (OrderArticle.objects - .filter(order=order, article=article) - .update(quantity_received = q_received)) - InventoryArticle.objects.create( - inventory = inventory, - article = article, - stock_old = article.stock, - stock_new = article.stock + q_received) + + price_HT = form.cleaned_data['price_HT'] + TVA = form.cleaned_data['TVA'] + rights = form.cleaned_data['rights'] + + if any((form.initial['price_HT'] != price_HT, + form.initial['TVA'] != TVA, + form.initial['rights'] != rights)): + new_supplierarticle.append( + SupplierArticle( + supplier=order.supplier, + article=article, + price_HT=price_HT, + TVA=TVA, + rights=rights, + ) + ) + ( + OrderArticle.objects + .filter(order=order, article=article) + .update(quantity_received=q_received) + ) + new_inventoryarticle.append( + InventoryArticle( + inventory=inventory, + article=article, + stock_old=article.stock, + stock_new=article.stock + q_received, + ) + ) article.stock += q_received if q_received > 0: article.is_sold = True article.save() + SupplierArticle.objects.bulk_create(new_supplierarticle) + InventoryArticle.objects.bulk_create(new_inventoryarticle) messages.success(request, "C'est tout bon !") return redirect('kfet.order') else: @@ -2025,6 +2035,7 @@ def order_to_inventory(request, pk): return render(request, 'kfet/order_to_inventory.html', { 'formset': formset, + 'order': order, }) class SupplierUpdate(SuccessMessageMixin, UpdateView): @@ -2200,10 +2211,13 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView): # prepare querysets # TODO: retirer les opgroup dont tous les op sont annulées opegroups = OperationGroup.objects.filter(on_acc=account) - recv_transfers = Transfer.objects.filter(to_acc=account, - canceled_at=None) - sent_transfers = Transfer.objects.filter(from_acc=account, - canceled_at=None) + transfers = ( + Transfer.objects + .filter(canceled_at=None) + .select_related('group') + ) + recv_transfers = transfers.filter(to_acc=account) + sent_transfers = transfers.filter(from_acc=account) # apply filters if begin_date is not None: @@ -2231,13 +2245,11 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView): actions.append({ 'at': (begin_date or account.created_at).isoformat(), 'amount': 0, - 'label': 'début', 'balance': 0, }) actions.append({ 'at': (end_date or timezone.now()).isoformat(), 'amount': 0, - 'label': 'fin', 'balance': 0, }) @@ -2245,21 +2257,18 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView): { 'at': ope_grp.at.isoformat(), 'amount': ope_grp.amount, - 'label': str(ope_grp), 'balance': 0, } for ope_grp in opegroups ] + [ { 'at': tr.group.at.isoformat(), 'amount': tr.amount, - 'label': str(tr), 'balance': 0, } for tr in recv_transfers ] + [ { 'at': tr.group.at.isoformat(), 'amount': -tr.amount, - 'label': str(tr), 'balance': 0, } for tr in sent_transfers ] @@ -2288,7 +2297,7 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView): ) context['charts'] = [{ - "color": "rgb(255, 99, 132)", + "color": "rgb(200, 20, 60)", "label": "Balance", "values": changes, }] @@ -2352,13 +2361,19 @@ class AccountStatOperation(ScaleMixin, PkUrlMixin, JSONDetailView): # à l'article en question et qui ne sont pas annulées # puis on choisi pour chaques intervalle les opérations # effectuées dans ces intervalles de temps - all_operations = (Operation.objects - .filter(group__on_acc=self.object) - .filter(canceled_at=None) - ) + all_operations = ( + Operation.objects + .filter(group__on_acc=self.object, + canceled_at=None) + .values('article_nb', 'group__at') + .order_by('group__at') + ) if types is not None: all_operations = all_operations.filter(type__in=types) - chunks = self.chunkify_qs(all_operations, scale, field='group__at') + chunks = scale.get_by_chunks( + all_operations, field_db='group__at', + field_callback=(lambda d: d['group__at']), + ) return chunks def get_context_data(self, *args, **kwargs): @@ -2374,9 +2389,10 @@ class AccountStatOperation(ScaleMixin, PkUrlMixin, JSONDetailView): # On compte les opérations nb_ventes = [] for chunk in operations: - nb_ventes.append(tot_ventes(chunk)) + ventes = sum(ope['article_nb'] for ope in chunk) + nb_ventes.append(ventes) - context['charts'] = [{"color": "rgb(255, 99, 132)", + context['charts'] = [{"color": "rgb(200, 20, 60)", "label": "NB items achetés", "values": nb_ventes}] return context @@ -2425,30 +2441,40 @@ class ArticleStatSales(ScaleMixin, JSONDetailView): context = {'labels': old_ctx['labels']} scale = self.scale - # On selectionne les opérations qui correspondent - # à l'article en question et qui ne sont pas annulées - # puis on choisi pour chaques intervalle les opérations - # effectuées dans ces intervalles de temps - all_operations = ( + all_purchases = ( Operation.objects - .filter(type=Operation.PURCHASE, - article=self.object, - canceled_at=None, - ) + .filter( + type=Operation.PURCHASE, + article=self.object, + canceled_at=None, + ) + .values('group__at', 'article_nb') + .order_by('group__at') ) - chunks = self.chunkify_qs(all_operations, scale, field='group__at') + liq_only = all_purchases.filter(group__on_acc__trigramme='LIQ') + liq_exclude = all_purchases.exclude(group__on_acc__trigramme='LIQ') + + chunks_liq = scale.get_by_chunks( + liq_only, field_db='group__at', + field_callback=lambda d: d['group__at'], + ) + chunks_no_liq = scale.get_by_chunks( + liq_exclude, field_db='group__at', + field_callback=lambda d: d['group__at'], + ) + # On compte les opérations nb_ventes = [] nb_accounts = [] nb_liq = [] - for qs in chunks: - nb_ventes.append( - tot_ventes(qs)) - nb_liq.append( - tot_ventes(qs.filter(group__on_acc__trigramme='LIQ'))) - nb_accounts.append( - tot_ventes(qs.exclude(group__on_acc__trigramme='LIQ'))) - context['charts'] = [{"color": "rgb(255, 99, 132)", + for chunk_liq, chunk_no_liq in zip(chunks_liq, chunks_no_liq): + sum_accounts = sum(ope['article_nb'] for ope in chunk_no_liq) + sum_liq = sum(ope['article_nb'] for ope in chunk_liq) + nb_ventes.append(sum_accounts + sum_liq) + nb_accounts.append(sum_accounts) + nb_liq.append(sum_liq) + + context['charts'] = [{"color": "rgb(200, 20, 60)", "label": "Toutes consommations", "values": nb_ventes}, {"color": "rgb(54, 162, 235)", diff --git a/manage.py b/manage.py index 7f4e79f6..094ec16f 100644 --- a/manage.py +++ b/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cof.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cof.settings.local") from django.core.management import execute_from_command_line diff --git a/provisioning/apache.conf b/provisioning/apache.conf deleted file mode 100644 index db5bd602..00000000 --- a/provisioning/apache.conf +++ /dev/null @@ -1,39 +0,0 @@ - - ServerName default - DocumentRoot /var/www/html - - ProxyPreserveHost On - ProxyRequests Off - ProxyPass /static/ ! - ProxyPass /media/ ! - # Pour utiliser un sous-dossier (typiquement /gestion/), il faut faire a la - # place des lignes suivantes: - # - # RequestHeader set Daphne-Root-Path /gestion - # ProxyPass /gestion/ws/ ws://127.0.0.1:8001/ws/ - # ProxyPass /gestion http://127.0.0.1:8001/gestion - # ProxyPassReverse /gestion http://127.0.0.1:8001/gestion - # - # Penser egalement a changer les /static/ et /media/ dans la config apache - # ainsi que dans les settings django. - ProxyPass /ws/ ws://127.0.0.1:8001/ws/ - ProxyPass / http://127.0.0.1:8001/ - ProxyPassReverse / http://127.0.0.1:8001/ - - Alias /media /vagrant/media - Alias /static /var/www/static - - Order deny,allow - Allow from all - - - Order deny,allow - Allow from all - - - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - - - -# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/provisioning/bootstrap.sh b/provisioning/bootstrap.sh index 269e4f25..69bbcf4c 100644 --- a/provisioning/bootstrap.sh +++ b/provisioning/bootstrap.sh @@ -8,43 +8,60 @@ DBNAME="cof_gestion" DBPASSWD="4KZt3nGPLVeWSvtBZPSM3fSzXpzEU4" # Installation de paquets utiles -apt-get update && apt-get install -y python3-pip python3-dev python3-venv \ - libmysqlclient-dev libjpeg-dev git redis-server -pip install -U pip +apt-get update && apt-get upgrade -y +apt-get install -y python3-pip python3-dev python3-venv libpq-dev postgresql \ + postgresql-contrib libjpeg-dev nginx git redis-server -# Configuration et installation de mysql. Le mot de passe root est le même que -# le mot de passe pour l'utilisateur local - pour rappel, ceci est une instance -# locale de développement. -echo "mysql-server mysql-server/root_password password $DBPASSWD" | debconf-set-selections -echo "mysql-server mysql-server/root_password_again password $DBPASSWD" | debconf-set-selections +# Postgresql +sudo -u postgres createdb $DBNAME +sudo -u postgres createuser -SdR $DBUSER +sudo -u postgres psql -c "ALTER USER $DBUSER WITH PASSWORD '$DBPASSWD';" +sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DBNAME TO $DBUSER;" -apt-get install -y mysql-server -mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME; GRANT ALL PRIVILEGES ON $DBNAME.* TO '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASSWD'" -mysql -uroot -p$DBPASSWD -e "GRANT ALL PRIVILEGES ON test_$DBNAME.* TO '$DBUSER'@'localhost'" +# Redis +REDIS_PASSWD="dummy" +redis-cli CONFIG SET requirepass $REDIS_PASSWD +redis-cli -a $REDIS_PASSWD CONFIG REWRITE -# Installation et configuration d'Apache -apt-get install -y apache2 -a2enmod proxy proxy_http proxy_wstunnel headers -cp /vagrant/provisioning/apache.conf /etc/apache2/sites-available/gestiocof.conf -a2ensite gestiocof -a2dissite 000-default -service apache2 restart -mkdir /var/www/static -chown -R ubuntu:www-data /var/www/static +# Contenu statique +mkdir -p /srv/gestiocof/media +mkdir -p /srv/gestiocof/static +chown -R ubuntu:www-data /srv/gestiocof + +# Nginx +ln -s -f /vagrant/provisioning/nginx.conf /etc/nginx/sites-enabled/gestiocof.conf +rm -f /etc/nginx/sites-enabled/default +systemctl reload nginx + +# Environnement virtuel python +sudo -H -u ubuntu python3 -m venv ~ubuntu/venv +sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -U pip +sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -r /vagrant/requirements-devel.txt + +# Préparation de Django +cd /vagrant +ln -s -f secret_example.py cof/settings/secret.py +sudo -H -u ubuntu \ + DJANGO_SETTINGS_MODULE='cof.settings.dev' \ + bash -c ". ~/venv/bin/activate && bash provisioning/prepare_django.sh" +/home/ubuntu/venv/bin/python manage.py collectstatic --noinput --settings cof.settings.dev + +# Installation du cron pour les mails de rappels +sudo -H -u ubuntu crontab provisioning/cron.dev + +# Daphne + runworker +cp /vagrant/provisioning/daphne.service /etc/systemd/system/daphne.service +cp /vagrant/provisioning/worker.service /etc/systemd/system/worker.service +systemctl enable daphne.service +systemctl enable worker.service +systemctl start daphne.service +systemctl start worker.service # Mise en place du .bash_profile pour tout configurer lors du `vagrant ssh` cat >> ~ubuntu/.bashrc <> /vagrant/rappels.log ; python /vagrant/manage.py sendrappels >> /vagrant/rappels.log 2>&1 -*/5 * * * * python /vagrant/manage.py manage_revente >> /vagrant/reventes.log 2>&1 +19 */12 * * * date >> /vagrant/rappels.log ; /ubuntu/home/venv/bin/python /vagrant/manage.py sendrappels >> /vagrant/rappels.log 2>&1 +*/5 * * * * /ubuntu/home/venv/bin/python /vagrant/manage.py manage_revente >> /vagrant/reventes.log 2>&1 diff --git a/provisioning/cron.md b/provisioning/cron.md index 840a8716..7aff775b 100644 --- a/provisioning/cron.md +++ b/provisioning/cron.md @@ -9,9 +9,9 @@ envoie les mails de rappels des spectacles à venir (sauf s'ils ont déjà été envoyés). - Un fois toutes les 12 heures me semble bien. -- Penser à utiliser le bon executable python (virtualenvs) et les bonnes - variables d'environnement si besoin. -- Garde les logs peut être une bonne idée. +- Penser à utiliser le bon executable python (virtualenvs) et le bon fichier de + settings pour Django. +- Garder les logs peut être une bonne idée. Exemple : voir le fichier `provisioning/cron.dev`. diff --git a/provisioning/daphne.service b/provisioning/daphne.service new file mode 100644 index 00000000..41327ce5 --- /dev/null +++ b/provisioning/daphne.service @@ -0,0 +1,16 @@ +Description="GestioCOF" +After=syslog.target +After=network.target + +[Service] +Type=simple +User=ubuntu +Group=ubuntu +TimeoutSec=300 +WorkingDirectory=/vagrant +Environment="DJANGO_SETTINGS_MODULE=cof.settings.dev" +ExecStart=/home/ubuntu/venv/bin/daphne -u /srv/gestiocof/gestiocof.sock \ + cof.asgi:channel_layer + +[Install] +WantedBy=multi-user.target diff --git a/provisioning/nginx.conf b/provisioning/nginx.conf new file mode 100644 index 00000000..015e1712 --- /dev/null +++ b/provisioning/nginx.conf @@ -0,0 +1,56 @@ +upstream gestiocof { + # Daphne listens on a unix socket + server unix:/srv/gestiocof/gestiocof.sock; +} + +server { + listen 80; + + server_name localhost; + root /srv/gestiocof/; + + # / → /gestion/ + # /gestion → /gestion/ + rewrite ^/$ /gestion/; + rewrite ^/gestion$ /gestion/; + + # Static files + location /static/ { + access_log off; + add_header Cache-Control "public"; + expires 7d; + } + + # Uploaded media + location /media/ { + access_log off; + add_header Cache-Control "public"; + expires 7d; + } + + location /gestion/ { + # A copy-paste of what we have in production + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-SSL-Client-Serial $ssl_client_serial; + proxy_set_header X-SSL-Client-Verify $ssl_client_verify; + proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn; + proxy_set_header Daphne-Root-Path /gestion; + + location /gestion/ws/ { + # See http://nginx.org/en/docs/http/websocket.html + proxy_buffering off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_pass http://gestiocof/ws/; + } + + location /gestion/ { + proxy_pass http://gestiocof; + } + } +} diff --git a/provisioning/prepare_django.sh b/provisioning/prepare_django.sh index 4ec1a70f..1818a0cd 100644 --- a/provisioning/prepare_django.sh +++ b/provisioning/prepare_django.sh @@ -1,9 +1,6 @@ #!/bin/bash -# Doit être lancé par bootstrap.sh -source ~/venv/bin/activate python manage.py migrate python manage.py loaddata gestion sites articles python manage.py loaddevdata python manage.py syncmails -python manage.py collectstatic --noinput diff --git a/provisioning/supervisor.conf b/provisioning/supervisor.conf deleted file mode 100644 index c806a13d..00000000 --- a/provisioning/supervisor.conf +++ /dev/null @@ -1,20 +0,0 @@ -[program:worker] -command=/home/ubuntu/venv/bin/python /vagrant/manage.py runworker -directory=/vagrant/ -user=ubuntu -environment=DBUSER={DBUSER},DBNAME={DBNAME},DBPASSWD={DBPASSWD},DJANGO_SETTINGS_MODULE="cof.settings_dev" -autostart=true -autorestart=true -redirect_stderr=true -stopasgroup=true -redirect_stderr=true - -[program:interface] -command=/home/ubuntu/venv/bin/daphne -b 127.0.0.1 -p 8001 cof.asgi:channel_layer -environment=DBUSER={DBUSER},DBNAME={DBNAME},DBPASSWD={DBPASSWD},DJANGO_SETTINGS_MODULE="cof.settings_dev" -directory=/vagrant/ -redirect_stderr=true -autostart=true -autorestart=true -stopasgroup=true -user=ubuntu diff --git a/provisioning/worker.service b/provisioning/worker.service new file mode 100644 index 00000000..42836cfe --- /dev/null +++ b/provisioning/worker.service @@ -0,0 +1,16 @@ +[Unit] +Description="GestioCOF" +After=syslog.target +After=network.target + +[Service] +Type=simple +User=ubuntu +Group=ubuntu +TimeoutSec=300 +WorkingDirectory=/vagrant +Environment="DJANGO_SETTINGS_MODULE=cof.settings.dev" +ExecStart=/home/ubuntu/venv/bin/python manage.py runworker + +[Install] +WantedBy=multi-user.target diff --git a/requirements-devel.txt b/requirements-devel.txt index 425dfc36..de272491 100644 --- a/requirements-devel.txt +++ b/requirements-devel.txt @@ -1,3 +1,4 @@ -r requirements.txt -django-debug-toolbar +-e git://github.com/jazzband/django-debug-toolbar.git@88ddc7bdf39c7ff660eac054eab225ac22926754#egg=django-debug-toolbar +django-debug-panel ipython diff --git a/requirements.txt b/requirements.txt index ce081588..f3964212 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,22 +2,29 @@ configparser==3.5.0 Django==1.8.* django-autocomplete-light==2.3.3 django-autoslug==1.9.3 -django-cas-ng==3.5.5 +django-cas-ng==3.5.7 +django-djconfig==0.5.3 django-grappelli==2.8.1 django-recaptcha==1.0.5 -mysqlclient==1.3.7 +django-redis-cache==1.7.1 +psycopg2 Pillow==3.3.0 six==1.10.0 unicodecsv==0.14.1 icalendar==3.10 django-bootstrap-form==3.2.1 -asgiref==0.14.0 -daphne==0.14.3 -asgi-redis==0.14.0 +asgiref==1.1.1 +daphne==1.3.0 +asgi-redis==1.3.0 statistics==1.0.3.5 future==0.15.2 django-widget-tweaks==1.4.1 git+https://git.eleves.ens.fr/cof-geek/django_custommail.git#egg=django_custommail ldap3 -git+https://github.com/Aureplop/channels.git#egg=channels +channels==1.1.5 python-dateutil +wagtail==1.10.* +wagtailmenus==2.2.* + +# Production tools +wheel