diff --git a/README.md b/README.md index 1a3d575e..b6017577 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ Charger les mails indispensables au bon fonctionnement de GestioCOF : 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 loaddata gestion sites articles python manage.py loaddevdata Vous êtes prêts à développer ! Lancer GestioCOF en faisant diff --git a/cof/settings/common.py b/cof/settings/common.py index 261760d6..f7c7bba6 100644 --- a/cof/settings/common.py +++ b/cof/settings/common.py @@ -56,6 +56,22 @@ INSTALLED_APPS = [ 'widget_tweaks', 'custommail', 'djconfig', + 'wagtail.wagtailforms', + 'wagtail.wagtailredirects', + 'wagtail.wagtailembeds', + 'wagtail.wagtailsites', + 'wagtail.wagtailusers', + 'wagtail.wagtailsnippets', + 'wagtail.wagtaildocs', + 'wagtail.wagtailimages', + 'wagtail.wagtailsearch', + 'wagtail.wagtailadmin', + 'wagtail.wagtailcore', + 'wagtail.contrib.modeladmin', + 'wagtailmenus', + 'modelcluster', + 'taggit', + 'kfet.cms', ] MIDDLEWARE_CLASSES = [ @@ -69,6 +85,8 @@ MIDDLEWARE_CLASSES = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'djconfig.middleware.DjConfigMiddleware', + 'wagtail.wagtailcore.middleware.SiteMiddleware', + 'wagtail.wagtailredirects.middleware.RedirectMiddleware', ] ROOT_URLCONF = 'cof.urls' @@ -87,6 +105,7 @@ TEMPLATES = [ 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', + 'wagtailmenus.context_processors.wagtailmenus', 'djconfig.context_processors.config', 'gestioncof.shared.context_processor', 'kfet.context_processors.auth', @@ -143,9 +162,12 @@ LOGIN_URL = "cof-login" LOGIN_REDIRECT_URL = "home" CAS_SERVER_URL = 'https://cas.eleves.ens.fr/' +CAS_VERSION = '3' +CAS_LOGIN_MSG = None CAS_IGNORE_REFERER = True CAS_REDIRECT_URL = '/' CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" + AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'gestioncof.shared.COFCASBackend', @@ -171,3 +193,9 @@ CHANNEL_LAYERS = { } FORMAT_MODULE_PATH = 'cof.locale' + +# Wagtail settings + +WAGTAIL_SITE_NAME = 'GestioCOF' +WAGTAIL_ENABLE_UPDATE_CHECK = False +TAGGIT_CASE_INSENSITIVE = True diff --git a/cof/settings/dev.py b/cof/settings/dev.py index a3a17f99..ffd34c7d 100644 --- a/cof/settings/dev.py +++ b/cof/settings/dev.py @@ -28,6 +28,26 @@ MEDIA_URL = '/media/' # Debug tool bar # --- +# "Versions" panel of django-debug-toolbar <=1.8 is not compatible with +# wagtailmenus. +# See https://github.com/jazzband/django-debug-toolbar/issues/922 +# TODO: Bug should be fixed in ddt 1.9 (not released yet). When fixed, this +# declaration may be removed. +DEBUG_TOOLBAR_PANELS = [ + 'debug_toolbar.panels.timer.TimerPanel', + 'debug_toolbar.panels.settings.SettingsPanel', + 'debug_toolbar.panels.headers.HeadersPanel', + 'debug_toolbar.panels.request.RequestPanel', + 'debug_toolbar.panels.sql.SQLPanel', + 'debug_toolbar.panels.staticfiles.StaticFilesPanel', + 'debug_toolbar.panels.templates.TemplatesPanel', + 'debug_toolbar.panels.cache.CachePanel', + 'debug_toolbar.panels.signals.SignalsPanel', + 'debug_toolbar.panels.logging.LoggingPanel', + 'debug_toolbar.panels.redirects.RedirectsPanel', +] + + def show_toolbar(request): """ On ne veut pas la vérification de INTERNAL_IPS faite par la debug-toolbar diff --git a/cof/urls.py b/cof/urls.py index 06b1087a..886070e9 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -14,6 +14,10 @@ from django.views.generic.base import TemplateView from django.contrib.auth import views as django_views from django_cas_ng import views as django_cas_views +from wagtail.wagtailadmin import urls as wagtailadmin_urls +from wagtail.wagtailcore import urls as wagtail_urls +from wagtail.wagtaildocs import urls as wagtaildocs_urls + from gestioncof import views as gestioncof_views, csv_views from gestioncof.urls import export_patterns, petitcours_patterns, \ surveys_patterns, events_patterns, calendar_patterns, \ @@ -48,7 +52,7 @@ urlpatterns = [ url(r'^outsider/login$', gestioncof_views.login_ext), url(r'^outsider/logout$', django_views.logout, {'next_page': 'home'}), url(r'^login$', gestioncof_views.login, name="cof-login"), - url(r'^logout$', gestioncof_views.logout), + url(r'^logout$', gestioncof_views.logout, name="cof-logout"), # Infos persos url(r'^profile$', gestioncof_views.profile), url(r'^outsider/password-change$', django_views.password_change), @@ -82,6 +86,8 @@ urlpatterns = [ url(r'^utile_cof/diff_cof$', gestioncof_views.liste_diffcof), url(r'^utile_bda/bda_revente$', gestioncof_views.liste_bdarevente), url(r'^k-fet/', include('kfet.urls')), + url(r'^cms/', include(wagtailadmin_urls)), + url(r'^documents/', include(wagtaildocs_urls)), ] if 'debug_toolbar' in settings.INSTALLED_APPS: @@ -90,7 +96,13 @@ if 'debug_toolbar' in settings.INSTALLED_APPS: url(r'^__debug__/', include(debug_toolbar.urls)), ] +if settings.DEBUG: # Si on est en production, MEDIA_ROOT est servi par Apache. # Il faut dire à Django de servir MEDIA_ROOT lui-même en développement. urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +# Wagtail for uncatched +urlpatterns += [ + url(r'', include(wagtail_urls)), +] diff --git a/gestioncof/__init__.py b/gestioncof/__init__.py index e69de29b..b77fdb94 100644 --- a/gestioncof/__init__.py +++ b/gestioncof/__init__.py @@ -0,0 +1 @@ +default_app_config = 'gestioncof.apps.GestioncofConfig' diff --git a/gestioncof/apps.py b/gestioncof/apps.py new file mode 100644 index 00000000..6e24b050 --- /dev/null +++ b/gestioncof/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig + + +class GestioncofConfig(AppConfig): + name = 'gestioncof' + + def ready(self): + import gestioncof.signals diff --git a/gestioncof/shared.py b/gestioncof/shared.py index e4180b49..fabcacb9 100644 --- a/gestioncof/shared.py +++ b/gestioncof/shared.py @@ -1,62 +1,26 @@ -from django.contrib.sites.models import Site from django.conf import settings +from django.contrib.sites.models import Site + from django_cas_ng.backends import CASBackend -from django_cas_ng.utils import get_cas_client -from django.contrib.auth import get_user_model from gestioncof.models import CofProfile -User = get_user_model() - class COFCASBackend(CASBackend): - def authenticate_cas(self, ticket, service, request): - """Verifies CAS ticket and gets or creates User object""" - - client = get_cas_client(service_url=service) - username, attributes, _ = client.verify_ticket(ticket) - if attributes: - request.session['attributes'] = attributes - if not username: - return None + def clean_username(self, username): # Le CAS de l'ENS accepte les logins avec des espaces au début # et à la fin, ainsi qu’avec une casse variable. On normalise pour # éviter les doublons. - username = username.strip().lower() + return username.strip().lower() - profiles = CofProfile.objects.filter(login_clipper=username) - if len(profiles) > 0: - profile = profiles.order_by('-is_cof')[0] - user = profile.user - return user - try: - user = User.objects.get(username=username) - except User.DoesNotExist: - # user will have an "unusable" password - user = User.objects.create_user(username, '') - user.save() - return user - - def authenticate(self, ticket, service, request): - """Authenticates CAS ticket and retrieves user data""" - user = self.authenticate_cas(ticket, service, request) - if user is None: - return user - try: - profile = user.profile - except CofProfile.DoesNotExist: - profile, created = CofProfile.objects.get_or_create(user=user) - profile.save() - if not profile.login_clipper: - profile.login_clipper = user.username - profile.save() - if not user.email: - user.email = settings.CAS_EMAIL_FORMAT % profile.login_clipper - user.save() - if profile.is_buro and not user.is_staff: - user.is_staff = True - user.save() + def configure_user(self, user): + # cannot use "defaults" arg + profile, _ = CofProfile.objects.get_or_create(user=user) + profile.login_clipper = user.username + profile.save() + user.email = settings.CAS_EMAIL_FORMAT % profile.login_clipper + user.save() return user diff --git a/gestioncof/signals.py b/gestioncof/signals.py new file mode 100644 index 00000000..11cb55fc --- /dev/null +++ b/gestioncof/signals.py @@ -0,0 +1,23 @@ +from django.contrib import messages +from django.contrib.auth.signals import user_logged_in +from django.dispatch import receiver +from django.utils.translation import ugettext_lazy as _ + +from django_cas_ng.signals import cas_user_authenticated + + +@receiver(user_logged_in) +def messages_on_out_login(request, user, **kwargs): + if user.backend.startswith('django.contrib.auth'): + msg = _('Connexion à GestioCOF réussie. Bienvenue {}.').format( + user.get_short_name(), + ) + messages.success(request, msg) + + +@receiver(cas_user_authenticated) +def mesagges_on_cas_login(request, user, **kwargs): + msg = _('Connexion à GestioCOF par CAS réussie. Bienvenue {}.').format( + user.get_short_name(), + ) + messages.success(request, msg) 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

- Créer un compte +
+ + + Créer un compte + +
+
+{% if perms.kfet.manage_perms or perms.kfet.view_negs %} +
{% if perms.kfet.manage_perms %} +
Permissions +
{% endif %} {% if perms.kfet.view_negs %} +
Négatifs +
{% endif %}
+{% endif %} {% endblock %} @@ -26,16 +39,15 @@

Liste des comptes

- +
- - + - - + + - + @@ -43,15 +55,14 @@ - - + - + {% endfor %} diff --git a/kfet/templates/kfet/account_group.html b/kfet/templates/kfet/account_group.html index 96508aa4..e7243258 100644 --- a/kfet/templates/kfet/account_group.html +++ b/kfet/templates/kfet/account_group.html @@ -5,7 +5,7 @@ {% block fixed-content %} -
+ @@ -40,7 +40,11 @@

Comptes

diff --git a/kfet/templates/kfet/account_negative.html b/kfet/templates/kfet/account_negative.html index e92f3f70..741ad9dd 100644 --- a/kfet/templates/kfet/account_negative.html +++ b/kfet/templates/kfet/account_negative.html @@ -18,7 +18,7 @@ {% if perms.kfet.change_settings %} -
+ {% endif %} @@ -30,14 +30,13 @@

Liste des comptes en négatifs

-
TrigrammeTri. NomBalanceCOFBalanceCOF DptPromoPromo
- + {{ account.trigramme }} {{ account.trigramme }} {{ account.name }} {{ account.balance }}€{{ account.is_cof|yesno:"Oui,Non" }}{{ account.is_cof|yesno }} {{ account.departement }}{{ account.promo|default_if_none:'' }}{{ account.promo|default_if_none:'' }}
+
- - + - - + + @@ -49,10 +48,9 @@ -
TriTri. NomBalanceRéelleBalanceRéelle Début Découvert autorisé Jusqu'au
- + {{ neg.account.trigramme }} {{ neg.account.trigramme }} {{ neg.account.name }} {{ neg.account.balance|floatformat:2 }}€ diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 282e035f..fc8babc5 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -44,6 +44,10 @@ $(document).ready(function() { {% endif %} {% endblock %} +{% block footer %} +{% include "kfet/base_footer.html" %} +{% endblock %} + {% block fixed-content %} {% include "kfet/left_account.html" %} {% endblock %} diff --git a/kfet/templates/kfet/account_update.html b/kfet/templates/kfet/account_update.html index 86c27b48..47a043a4 100644 --- a/kfet/templates/kfet/account_update.html +++ b/kfet/templates/kfet/account_update.html @@ -20,6 +20,12 @@ {% endif %} {% endblock %} +{% block footer %} +{% if not account.user.is_team %} +{% include "kfet/base_footer.html" %} +{% endif %} +{% endblock %} + {% block main-class %}content-form{% endblock %} {% block main-content %} diff --git a/kfet/templates/kfet/article.html b/kfet/templates/kfet/article.html index 398ef658..86bdc518 100644 --- a/kfet/templates/kfet/article.html +++ b/kfet/templates/kfet/article.html @@ -9,13 +9,18 @@
{{ articles|length }}
article{{ articles|length|pluralize }}
-
+ {% endblock %} @@ -24,10 +29,9 @@

Liste des articles

- +
- @@ -40,16 +44,15 @@ {% for article in articles %} {% ifchanged article.category %} - + {% endifchanged %} - - diff --git a/kfet/templates/kfet/article_read.html b/kfet/templates/kfet/article_read.html index 134fb104..8cd84ded 100644 --- a/kfet/templates/kfet/article_read.html +++ b/kfet/templates/kfet/article_read.html @@ -14,6 +14,14 @@
{{ article.name }}
{{ article.category }}
+
Prix (hors réduc.): {{ article.price }}€
Stock: {{ article.stock }}
@@ -21,11 +29,6 @@
Affiché: {{ article.hidden | yesno:"Non,Oui" }}
- {% endblock %} @@ -36,29 +39,35 @@

Inventaires

-
Nom Prix Stock
{{ article.category.name }}{{ article.category.name }}
+ - + {{ article.name }} {{ article.name }} {{ article.price }}€ {{ article.stock }} {{ article.is_sold | yesno:"En vente,Non vendu"}}
- - - - - - - - - {% for inventoryart in inventoryarts %} - - - - - - {% endfor %} - -
DateStockErreur
{{ inventoryart.inventory.at }}{{ inventoryart.stock_new }}{{ inventoryart.stock_error }}
+
+ + + + + + + + + + {% for inventoryart in inventoryarts %} + + + + + + {% endfor %} + +
DateStockErreur
+ + {{ inventoryart.inventory.at }} + + {{ inventoryart.stock_new }}{{ inventoryart.stock_error }}
+

Prix fournisseurs

- +
diff --git a/kfet/templates/kfet/base.html b/kfet/templates/kfet/base.html index da37abae..b18ee719 100644 --- a/kfet/templates/kfet/base.html +++ b/kfet/templates/kfet/base.html @@ -1,4 +1,5 @@ {% load staticfiles %} +{% load menu_tags %} @@ -7,9 +8,13 @@ {% block title %}{% endblock %} | K-Fêt - ENS Ulm + + + + {# CSS #} - + @@ -28,18 +33,26 @@ - {% include "kfet/base_nav.html" %} + {% main_menu template="kfet/base_nav.html" %}
{% block header %} -
-
-

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

+ {% 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 index a4c26b82..6bd6dd5c 100644 --- a/kfet/templates/kfet/base_col_1.html +++ b/kfet/templates/kfet/base_col_1.html @@ -1,5 +1,7 @@ {% extends "kfet/base.html" %} +{% block header-class %}text-center{% endblock %} + {% block content %}
@@ -9,6 +11,6 @@ {% block main-content %}{% endblock %}
-
+
{% endblock %} diff --git a/kfet/templates/kfet/base_col_2.html b/kfet/templates/kfet/base_col_2.html index 58c36d14..2a1f8cd4 100644 --- a/kfet/templates/kfet/base_col_2.html +++ b/kfet/templates/kfet/base_col_2.html @@ -3,12 +3,12 @@ {% block content %}
-
+
{% block fixed-content %}{% endblock %}
-
+
{% include "kfet/base_messages.html" %}
{% block main-content %}{% endblock %} diff --git a/kfet/templates/kfet/base_footer.html b/kfet/templates/kfet/base_footer.html index e69de29b..be524139 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_messages.html b/kfet/templates/kfet/base_messages.html index 66b67162..5dd68e69 100644 --- a/kfet/templates/kfet/base_messages.html +++ b/kfet/templates/kfet/base_messages.html @@ -1,16 +1,12 @@ {% 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 273cdc0b..629b41da 100644 --- a/kfet/templates/kfet/base_nav.html +++ b/kfet/templates/kfet/base_nav.html @@ -1,70 +1,107 @@ -{% load staticfiles %} +{% load static %} +{% load wagtailcore_tags %}
Date