From 8265a7535bd9e9f98dfb8d82288b3cf5ef1752fe Mon Sep 17 00:00:00 2001 From: Nanoy Date: Sat, 19 Jan 2019 23:39:48 +0100 Subject: [PATCH] Page d'accueil --- coopeV3/urls.py | 1 + coopeV3/views.py | 12 +++++-- preferences/forms.py | 1 + .../migrations/0006_auto_20190119_2326.py | 23 ++++++++++++++ preferences/models.py | 1 + .../preferences/general_preferences.html | 9 ++++++ templates/home.html | 31 +++++++++++++++++++ templates/nav.html | 9 ++++-- 8 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 preferences/migrations/0006_auto_20190119_2326.py create mode 100644 templates/home.html diff --git a/coopeV3/urls.py b/coopeV3/urls.py index 83de9b1..bce380c 100644 --- a/coopeV3/urls.py +++ b/coopeV3/urls.py @@ -20,6 +20,7 @@ from . import views urlpatterns = [ path('', views.home, name="home"), + path('home', views.homepage, name="homepage"), path('admin/doc/', include('django.contrib.admindocs.urls')), path('admin/', admin.site.urls), path('users/', include('users.urls')), diff --git a/coopeV3/views.py b/coopeV3/views.py index e1da5b8..84734f9 100644 --- a/coopeV3/views.py +++ b/coopeV3/views.py @@ -1,11 +1,19 @@ -from django.shortcuts import redirect +from django.shortcuts import redirect, render from django.urls import reverse +from preferences.models import GeneralPreferences +from gestion.models import Keg + def home(request): if request.user.is_authenticated: if(request.user.has_perm('gestion.can_manage')): return redirect(reverse('gestion:manage')) else: - return redirect(reverse('users:profile', kwargs={'pk': request.user.pk})) + return redirect(reverse('homepage')) else: return redirect(reverse('users:login')) + +def homepage(request): + gp, _ = GeneralPreferences.objects.get_or_create(pk=1) + kegs = Keg.objects.filter(is_active=True) + return render(request, "home.html", {"home_text": gp.home_text, "kegs": kegs}) diff --git a/preferences/forms.py b/preferences/forms.py index d6224c6..6e92522 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -36,5 +36,6 @@ class GeneralPreferencesForm(forms.ModelForm): 'treasurer': forms.TextInput(attrs={'placeholder': 'Trésorier'}), 'brewer': forms.TextInput(attrs={'placeholder': 'Maître brasseur'}), 'grocer': forms.TextInput(attrs={'placeholder': 'Epic épicier'}), + 'home_text': forms.Textarea(attrs={'placeholder': 'Ce message sera affiché sur la page d\'accueil'}) } diff --git a/preferences/migrations/0006_auto_20190119_2326.py b/preferences/migrations/0006_auto_20190119_2326.py new file mode 100644 index 0000000..0762048 --- /dev/null +++ b/preferences/migrations/0006_auto_20190119_2326.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1 on 2019-01-19 22:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0005_auto_20190106_0513'), + ] + + operations = [ + migrations.AddField( + model_name='generalpreferences', + name='home_text', + field=models.TextField(blank=True), + ), + migrations.AddField( + model_name='historicalgeneralpreferences', + name='home_text', + field=models.TextField(blank=True), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index dd1cc7b..e5eada9 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -34,6 +34,7 @@ class GeneralPreferences(models.Model): use_pinte_monitoring = models.BooleanField(default=False) lost_pintes_allowed = models.PositiveIntegerField(default=0) floating_buttons = models.BooleanField(default=False) + home_text = models.TextField(blank=True) history = HistoricalRecords() class Cotisation(models.Model): diff --git a/preferences/templates/preferences/general_preferences.html b/preferences/templates/preferences/general_preferences.html index 988dea2..44acc57 100644 --- a/preferences/templates/preferences/general_preferences.html +++ b/preferences/templates/preferences/general_preferences.html @@ -127,12 +127,21 @@

Autre

+
+

Boutons flottants

{{form.floating_buttons}}
+
+

Texte de la page d'accueil

+
+
+ {{form.home_text}} +
+
diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..b05a045 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} +{% block entete %}Accueil{% endblock %} +{% block navbar %} + +{% endblock %} +{% block content %} +
+
+

Accueil

+
+
+ {{ home_text }} +
+
+
+
+

Les pressions du moment

+
+
+ Les bières pressions actuellement en Coopé : +
    + {% for keg in kegs %} +
  • {{keg}} ({% if keg.pinte %} Pinte : {{keg.pinte.amount}}€,{% endif %}{% if keg.demi %} Demi : {{keg.demi.amount}}€,{% endif %}{% if keg.galopin %} Galopin : {{keg.galopin.amount}}€{% endif %})
  • + {% endfor %} +
+
+
+{% endblock %} diff --git a/templates/nav.html b/templates/nav.html index d19985f..0c636e5 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,3 +1,6 @@ + + Accueil + {% if request.user.is_authenticated %} Mon profil @@ -18,11 +21,11 @@ {% endif %} +
Classement
{% if perms.preferences.change_generalpreferences %} -
Admin
{% endif %} @@ -45,5 +48,7 @@ Deconnexion {% else %} - Connexion + + Connexion + {% endif %}