Mr Duhaz il y a 7 mois
Parent
commit
ee5b3c4d72

+ 6 - 0
.gitignore

@@ -78,3 +78,9 @@ __pycache__/views.cpython-39.pyc
 >>>>>>> f006307a6dc26bb0bf0f207c1b2da5a603ceef6b
 =======
 >>>>>>> 280cb3b4f2e2036cecc83affff6c522c979dfaf1
+migrations/__pycache__/0016_groupe.cpython-312.pyc
+migrations/__pycache__/0017_groupe_g_description.cpython-312.pyc
+migrations/__pycache__/0018_speed_dial_sd_groupe.cpython-312.pyc
+migrations/__pycache__/0019_alter_speed_dial_sd_groupe.cpython-312.pyc
+migrations/__pycache__/0020_alter_speed_dial_sd_titre.cpython-312.pyc
+migrations/__pycache__/0021_auto_20240423_1338.cpython-312.pyc

+ 7 - 1
admin.py

@@ -38,7 +38,7 @@ admin.site.register(Page, Page_Admin)
 
 class Speed_Dial_Admin(admin.ModelAdmin):
 	pass
-	list_display = ('sd_titre', 'sd_adresse', 'sd_icone', 'sd_color', 'sd_poid')
+	list_display = ('sd_titre', 'sd_adresse' ,'sd_groupe', 'sd_icone', 'sd_color', 'sd_poid')
 	actions = [bt_sd_poid_plus, bt_sd_poid_moin]
 admin.site.register(Speed_Dial, Speed_Dial_Admin)
 
@@ -48,6 +48,12 @@ class Data_Admin(admin.ModelAdmin):
 	list_display = ('d_titre', 'd_titre_slugify', 'd_type', 'd_variable',)
 admin.site.register(Data, Data_Admin)
 
+class Groupe_Admin(admin.ModelAdmin):
+	pass
+	exclude = ('g_nom_slugify',)
+	list_display = ('g_nom', 'g_description')
+admin.site.register(Groupe, Groupe_Admin)
+
 class Contact_Admin(admin.ModelAdmin):
 	pass
 	list_display = ('c_type', 'c_name', 'c_email', 'c_description', 'c_statut',)

+ 25 - 0
migrations/0016_groupe.py

@@ -0,0 +1,25 @@
+# Generated by Django 3.2.23 on 2024-04-22 13:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0015_auto_20240119_1346'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Groupe',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('g_nom', models.CharField(max_length=128, unique=True, verbose_name='Nom du groupe')),
+                ('g_nom_slugify', models.CharField(blank=True, editable=False, max_length=128, verbose_name='Nom Slugify')),
+            ],
+            options={
+                'verbose_name': 'Groupe',
+                'verbose_name_plural': 'Groupes',
+            },
+        ),
+    ]

+ 18 - 0
migrations/0017_groupe_g_description.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2.23 on 2024-04-22 13:29
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0016_groupe'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='groupe',
+            name='g_description',
+            field=models.TextField(blank=True, verbose_name='Description'),
+        ),
+    ]

+ 19 - 0
migrations/0018_speed_dial_sd_groupe.py

@@ -0,0 +1,19 @@
+# Generated by Django 3.2.23 on 2024-04-22 13:34
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0017_groupe_g_description'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='speed_dial',
+            name='sd_groupe',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='core.speed_dial', verbose_name='Groupe'),
+        ),
+    ]

+ 19 - 0
migrations/0019_alter_speed_dial_sd_groupe.py

@@ -0,0 +1,19 @@
+# Generated by Django 3.2.23 on 2024-04-22 13:36
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0018_speed_dial_sd_groupe'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='speed_dial',
+            name='sd_groupe',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='core.groupe', verbose_name='Groupe'),
+        ),
+    ]

+ 18 - 0
migrations/0020_alter_speed_dial_sd_titre.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2.23 on 2024-04-23 09:43
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0019_alter_speed_dial_sd_groupe'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='speed_dial',
+            name='sd_titre',
+            field=models.CharField(max_length=128, verbose_name='Titre'),
+        ),
+    ]

+ 23 - 0
migrations/0021_auto_20240423_1338.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.2.23 on 2024-04-23 13:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0020_alter_speed_dial_sd_titre'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='page',
+            name='p_groupe',
+            field=models.BooleanField(default=False, verbose_name='Afficher les groupes'),
+        ),
+        migrations.AddField(
+            model_name='page',
+            name='p_speedial',
+            field=models.BooleanField(default=False, verbose_name='Afficher le Speedial'),
+        ),
+    ]

+ 21 - 1
models.py

@@ -30,6 +30,23 @@ page_color = (
 	(u'white', u'Blanc'),
 )
 
+class Groupe (models.Model) : #group pour organisation
+	g_nom = models.CharField("Nom du groupe", max_length = 128, unique = True)
+	g_nom_slugify = models.CharField("Nom Slugify", max_length = 128, blank = True, editable = False)
+	g_description = models.TextField("Description", blank = True)
+
+	class Meta :
+		verbose_name = 'Groupe'
+		verbose_name_plural = 'Groupes'
+
+	def save(self, *args, **kwargs) :
+		self.g_nom_slugify = slugify(self.g_nom)
+		super(Groupe, self).save(*args, **kwargs)
+	def __unicode__(self):
+		return self.g_nom
+	def __str__(self):
+		return '%s' % (self.g_nom)
+
 class Data (models.Model) : #stocage de donnée dynamique
 	d_titre = models.CharField("Nom", max_length = 128, unique = True)
 	d_titre_slugify = models.CharField("Nom Slugify", max_length = 128, blank = True, editable = False)
@@ -82,6 +99,8 @@ class Page (models.Model) : #Architecture pour les pages static est dynamique
 	p_description = models.TextField("Description", blank = True)
 	p_contenu = models.TextField("Contenu", blank = True)
 	p_right = models.TextField("Contenu à droite", blank = True)
+	p_groupe = models.BooleanField("Afficher les groupes", default = False)
+	p_speedial = models.BooleanField("Afficher le Speedial", default = False)
 	p_publier = models.BooleanField("Publié", default = False)
 	p_see_title_and_des_in_templates = models.BooleanField("Description et titre visible dans les templates", default = True)
 
@@ -104,7 +123,8 @@ class Page (models.Model) : #Architecture pour les pages static est dynamique
 		return '%s' % (self.p_titre)
 	
 class Speed_Dial (models.Model) : # model pour génération de page SpeedDial
-	sd_titre = models.CharField("Titre", max_length = 128, unique = True)
+	sd_titre = models.CharField("Titre", max_length = 128)
+	sd_groupe = models.ForeignKey(Groupe,verbose_name="Groupe", blank = True, null = True, on_delete=models.PROTECT)
 	sd_icone = models.CharField("Code de l'icone", max_length = 64, blank = True)
 	sd_color = models.CharField("Couleur du cadre",choices=page_color, max_length=10, default='primary')
 	sd_adresse = models.CharField("Adresse", max_length = 256)

+ 19 - 19
templates/base.html

@@ -139,25 +139,25 @@
 		</div>
 		<div class="col-lg-3 p-lg-1 p-md-0 mb-sm-1">
 			{% if page.c_card_rp == 'True'%}<div class="card" style="background-color: rgba(250,250,250,0.88);" >{% endif %}
-				{% if page.c_includ_rp != 'None'%}{% include page.c_includ_rp %}{% endif %}
-				{% block right_panel %}
-				{% endblock %}
-				{% if not request.user.is_authenticated and page.p_right and not "account/" in request.path %}
-					<div class="card-body">
-						<h5 class="card-title"> Une Pub </h5>
-						<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
-						<!-- Pub-1 -->
-						<ins class="adsbygoogle"
-							style="display:block"
-							data-ad-client="ca-pub-0171697375250839"
-							data-ad-slot="9918621322"
-							data-ad-format="auto"
-							data-full-width-responsive="true">
-						</ins>
-						<script>
-							(adsbygoogle = window.adsbygoogle || []).push({});
-						</script>
-				{% endif %}
+			{% if page.c_includ_rp != 'None'%}{% include page.c_includ_rp %}{% endif %}
+			{% block right_panel %}
+			{% endblock %}
+			{% if not request.user.is_authenticated and page.p_right and not "account/" in request.path %}
+				<div class="card-body">
+					<h5 class="card-title"> Une Pub </h5>
+					<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
+					<!-- Pub-1 -->
+					<ins class="adsbygoogle"
+						style="display:block"
+						data-ad-client="ca-pub-0171697375250839"
+						data-ad-slot="9918621322"
+						data-ad-format="auto"
+						data-full-width-responsive="true">
+					</ins>
+					<script>
+						(adsbygoogle = window.adsbygoogle || []).push({});
+					</script>
+			{% endif %}
 			{% if page.c_card_rp != 'None'%}</div>{% endif %}
 		</div>
 	</div>

+ 9 - 1
templates/page.html

@@ -21,7 +21,7 @@
 				<div class="card bg-{{item.sd_color}}" style="padding: 1px;">
 					<div class="card-body d-flex flex-row" style=" background : white; opacity: 0.85;">
 						<div class="p-2"><a class="text-decoration-none" href="{{item.sd_adresse}}" target="_blank"><i class="{% if item.sd_icone != '' %}{{item.sd_icone }}{% else %}fas fa-external-link-square-alt{% endif %}"></i></a></div>
-						<div class="p-2 w-80" onmouseover="this.style.cursor='pointer';" onclick="bt_open_url('{{item.sd_adresse|escapejs}}')">{{item.sd_titre}}</div>
+						<div class="p-2 w-80" onmouseover="this.style.cursor='pointer';" onclick="bt_open_url('{{item.sd_adresse|escapejs}}')">{% if item.sd_groupe %}[{{ item.sd_groupe }}] {% endif %}{{item.sd_titre}}</div>
 					</div>
 				</div>
 			</div>
@@ -56,6 +56,14 @@
 			</form>
 	{% endif %}
 	{{page.p_right|safe}}
+	{% if page.groupe %}
+		<h4> <i class="fas fa-tags"></i> Les Groupes </h4>
+		<p class="card-text">
+		{% for grp in page.groupe %}
+			<a href="{{request.path}}?grp={{grp.g_nom_slugify}}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true">{{grp.g_nom}}</a>
+		{% endfor %}
+		<a href="{{request.path}}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true">Aucun</a>
+	{% endif %}
 </div>
 {% endif %}
 {% endblock %}

+ 30 - 4
views.py

@@ -27,11 +27,25 @@ def gen_menu(position):
 		menu = Page.objects.none()
 	return menu
 
-def gen_speeddial():
+def get_groupe():
 	try:
-		speeddial = Speed_Dial.objects.order_by('-sd_poid')
+		goupes = Groupe.objects.all()
 	except:
-		speeddial = Speed_Dial.objects.none()
+		goupes = Groupe.objects.none()
+	return goupes
+
+def gen_speeddial(grp):
+	print(grp)
+	if grp != None:
+		try:
+			speeddial = Speed_Dial.objects.filter(sd_groupe__g_nom_slugify = grp).order_by('-sd_poid')
+		except:
+			speeddial = Speed_Dial.objects.none()
+	else:
+		try:
+			speeddial = Speed_Dial.objects.order_by('-sd_poid')
+		except:
+			speeddial = Speed_Dial.objects.none()
 	return speeddial
 
 def get_data_value(name):
@@ -133,6 +147,9 @@ def gen_page_sys(p_titre_slugify):
 		page.p_titre = "404 ! Erreur sur la page demmandé"
 		page.p_icone = "fas fa-bug"
 
+	if page.p_groupe == True:
+		page.groupe = get_groupe()
+
 	page.p_menu_haut = gen_menu('haut')
 	page.p_menu_pied = gen_menu('pied')
 	page.p_meta_title = page.p_titre
@@ -152,8 +169,14 @@ def gen_page_sys(p_titre_slugify):
 
 def index(request):
 	page = gen_page_sys('bienvenus')
-	page.speeddial = gen_speeddial()
+	page.p_get_groupe = request.GET.get('grp')
 
+	if page.p_speedial == True:
+		try:
+			page.speeddial = gen_speeddial(page.p_get_groupe)
+		except:
+			page.speeddial = gen_speeddial(None)
+	
 	template = loader.get_template('page.html')
 	context = {
 		'page' : page,
@@ -166,6 +189,7 @@ def page(request, p_url):
 	template = loader.get_template('page.html')
 	try:
 		page = Page.objects.get(p_adresse = p_url)
+		
 		page.p_menu_haut = gen_menu('haut')
 		page.p_menu_pied = gen_menu('pied')
 		page.p_meta_title = page.p_titre
@@ -179,6 +203,8 @@ def page(request, p_url):
 		page = gen_page_base()
 		page.p_contenu = "<h1>Erreur la page demandé n'existe pas </h1>"
 
+	page.p_get_groupe = request.GET.get('grp')
+
 	context = {
 		'page' : page,
 	}