浏览代码

update wiki

HPNL 10 月之前
父节点
当前提交
bfd246e1d6
共有 11 个文件被更改,包括 495 次插入3 次删除
  1. 15 0
      .gitignore
  2. 25 1
      admin.py
  3. 48 0
      migrations/0001_initial.py
  4. 26 0
      migrations/0002_auto_20240123_1357.py
  5. 29 0
      migrations/0003_auto_20240123_1638.py
  6. 18 0
      migrations/0004_alter_wiki_w_contenu.py
  7. 58 1
      models.py
  8. 102 0
      templates/listing.html
  9. 46 0
      templates/read.html
  10. 20 0
      urls.py
  11. 108 1
      views.py

+ 15 - 0
.gitignore

@@ -0,0 +1,15 @@
+__pycache__/__init__.cpython-312.pyc
+__pycache__/admin.cpython-312.pyc
+__pycache__/apps.cpython-312.pyc
+__pycache__/models.cpython-312.pyc
+__pycache__/urls.cpython-312.pyc
+__pycache__/views.cpython-312.pyc
+migrations/__pycache__/__init__.cpython-312.pyc
+migrations/__pycache__/0001_initial.cpython-312.pyc
+migrations/__pycache__/0002_auto_20240123_1357.cpython-312.pyc
+migrations/__pycache__/0003_auto_20240123_1638.cpython-312.pyc
+migrations/__pycache__/0004_alter_wiki_w_contenu.cpython-312.pyc
+migrations/__pycache__/0004_auto_20240123_1644.cpython-312.pyc
+migrations/__pycache__/0005_auto_20240123_1658.cpython-312.pyc
+migrations/__pycache__/0006_auto_20240124_0910.cpython-312.pyc
+migrations/__pycache__/0007_remove_wiki_w_data.cpython-312.pyc

+ 25 - 1
admin.py

@@ -1,3 +1,27 @@
+from import_export.admin import ImportExportModelAdmin
+
 from django.contrib import admin
+from wiki.models import *
+
+def bt_w_publier(modeladmin, request, queryset):
+	queryset.update(w_publier=True)
+bt_w_publier.short_description = "Passer en Public"
+def bt_w_not_publier(modeladmin, request, queryset):
+	queryset.update(w_publier=False)
+bt_w_not_publier.short_description = "Passer en Priver"
+
+class Wiki_Admin(ImportExportModelAdmin):
+	form = Wiki_Admin_Form
+	list_display = ('w_titre', 'w_description', 'w_publier','w_publdate','w_reading')
+	list_filter = ('w_publier','w_cat','w_publdate')
+	filter_horizontal = ('w_cat',)
+	actions = [bt_w_publier, bt_w_not_publier]
+	search_fields = ['w_titre','w_contenu']
+admin.site.register(Wiki, Wiki_Admin)
+
+class Cat_Wiki_Admin(admin.ModelAdmin):
+	list_display = ('cw_titre', 'cw_titre_slgify')
+	pass
+admin.site.register(Cat_Wiki, Cat_Wiki_Admin)
+
 
-# Register your models here.

+ 48 - 0
migrations/0001_initial.py

@@ -0,0 +1,48 @@
+# Generated by Django 3.2.23 on 2024-01-23 13:53
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Cat_Wiki',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('cw_titre', models.CharField(max_length=128, unique=True, verbose_name='Titre')),
+                ('cw_titre_slgify', models.CharField(blank=True, editable=False, max_length=128, verbose_name='Titre Slugify')),
+            ],
+            options={
+                'verbose_name': 'Catégories',
+                'verbose_name_plural': 'Catégories',
+            },
+        ),
+        migrations.CreateModel(
+            name='Wiki',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('w_titre', models.CharField(max_length=128, unique=True, verbose_name='Titre')),
+                ('w_titre_slugify', models.CharField(blank=True, editable=False, max_length=128, verbose_name='Titre Slugify')),
+                ('w_mots_clefs', models.CharField(blank=True, max_length=512, verbose_name='Mots clefs')),
+                ('w_description', models.TextField(blank=True, verbose_name='Description')),
+                ('w_description_img', models.URLField(blank=True, max_length=128, verbose_name='Url de la miniature')),
+                ('w_contenu', models.TextField(blank=True, verbose_name='Contenu')),
+                ('w_right', models.TextField(blank=True, verbose_name='Contenu à droite')),
+                ('w_publier', models.BooleanField(default=False, verbose_name='Publié')),
+                ('w_reading', models.IntegerField(default=0, verbose_name='Nb Lectures')),
+                ('w_publdate', models.DateTimeField(blank=True, null=True, verbose_name='Publié le')),
+                ('w_cat', models.ManyToManyField(blank=True, to='wiki.Cat_Wiki')),
+            ],
+            options={
+                'verbose_name': 'Gestion du Wiki',
+                'verbose_name_plural': 'Gestion du Wiki',
+                'ordering': ['-w_publdate'],
+            },
+        ),
+    ]

+ 26 - 0
migrations/0002_auto_20240123_1357.py

@@ -0,0 +1,26 @@
+# Generated by Django 3.2.23 on 2024-01-23 13:57
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('wiki', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='wiki',
+            name='w_description_img',
+        ),
+        migrations.RemoveField(
+            model_name='wiki',
+            name='w_mots_clefs',
+        ),
+        migrations.AlterField(
+            model_name='wiki',
+            name='w_cat',
+            field=models.ManyToManyField(blank=True, to='wiki.Cat_Wiki', verbose_name='Catégories'),
+        ),
+    ]

+ 29 - 0
migrations/0003_auto_20240123_1638.py

@@ -0,0 +1,29 @@
+# Generated by Django 3.2.23 on 2024-01-23 16:38
+
+from django.db import migrations, models
+import django_quill.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('wiki', '0002_auto_20240123_1357'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='wiki',
+            name='w_contenu',
+            field=django_quill.fields.QuillField(),
+        ),
+        migrations.AlterField(
+            model_name='wiki',
+            name='w_description',
+            field=models.TextField(blank=True, verbose_name='Résumé'),
+        ),
+        migrations.AlterField(
+            model_name='wiki',
+            name='w_publdate',
+            field=models.DateTimeField(auto_now_add=True, verbose_name='Mise à jour le'),
+        ),
+    ]

+ 18 - 0
migrations/0004_alter_wiki_w_contenu.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2.23 on 2024-01-24 09:44
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('wiki', '0003_auto_20240123_1638'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='wiki',
+            name='w_contenu',
+            field=models.TextField(blank=True, verbose_name='Contenu'),
+        ),
+    ]

+ 58 - 1
models.py

@@ -1,3 +1,60 @@
 from django.db import models
+from django import forms
 
-# Create your models here.
+from django.template.defaultfilters import slugify
+
+from trumbowyg.widgets import TrumbowygWidget
+
+class Cat_Wiki(models.Model) :
+	cw_titre = models.CharField("Titre", max_length = 128, unique = True)
+	cw_titre_slgify = models.CharField("Titre Slugify", max_length = 128, blank = True, editable = False)
+
+	class Meta :
+		verbose_name = 'Catégories'
+		verbose_name_plural = 'Catégories'
+
+	def save(self, *args, **kwargs) :
+		self.cw_titre_slgify = slugify(self.cw_titre)
+		super(Cat_Wiki, self).save(*args, **kwargs)
+
+	def __unicode__(self):
+		return self.cw_titre
+	def __str__(self):
+		return '%s' % (self.cw_titre)
+
+class Wiki(models.Model) : #Architecture pour le Wiki
+	w_titre = models.CharField("Titre", max_length = 128, unique = True)
+	w_titre_slugify = models.CharField("Titre Slugify", max_length = 128, blank = True, editable = False)
+	w_cat = models.ManyToManyField(Cat_Wiki, verbose_name="Catégories" , blank = True)
+	w_description = models.TextField("Résumé", blank = True)
+	w_contenu = models.TextField("Contenu", blank = True)
+	w_right = models.TextField("Contenu à droite", blank = True)
+	w_publier = models.BooleanField("Publié", default = False)
+	w_reading = models.IntegerField("Nb Lectures", default = 0)
+	w_publdate = models.DateTimeField("Mise à jour le", auto_now_add=True)
+
+	class Meta :
+		verbose_name = 'Gestion du Wiki'
+		verbose_name_plural = 'Gestion du Wiki'
+		ordering = ['-w_publdate']
+
+	def save(self, *args, **kwargs) :
+		self.w_titre_slugify = slugify(self.w_titre)
+		super(Wiki, self).save(*args, **kwargs)
+
+	def __unicode__(self):
+		return self.w_titre
+	def __str__(self):
+		return '%s' % (self.w_titre)
+
+class Wiki_search_Form(forms.Form):
+	w_search = forms.CharField(label='Vous recherchez un page ?', max_length=100)
+
+class Wiki_Admin_Form(forms.ModelForm):
+	class Meta:
+		model = Wiki
+		exclude = ['w_titre_slugify','w_reading']
+		widgets = {
+			'w_contenu': TrumbowygWidget(attrs={'rows':4, 'cols':15}),
+			'w_right': TrumbowygWidget(attrs={'rows':4, 'cols':15}),
+			}

+ 102 - 0
templates/listing.html

@@ -0,0 +1,102 @@
+{% extends 'base_no_card.html' %}
+{% load crispy_forms_tags %}
+{% load static %}
+
+{% block exted_menu %}
+{% for cat in page.wiki_cat %}
+	<li class="nav-item"><a class="nav-link" href="{% url 'wiki_tag' cat.cw_titre_slgify %}">{{cat.cw_titre}}</a></li>
+{% endfor %}
+<li class="nav-item"><a class="nav-link" href="{% url 'wiki_tag' 'all' %}">Tous les pages</a></li>
+{% endblock %}
+
+{% block main %}
+<div class="card-columns p-3">
+		{% for item in page.wiki_art %}
+			<p><i class="fas fa-play"></i> <a href="{% url 'wiki_play' item.w_titre_slugify %}">{{item.w_titre|capfirst}}</a></p>
+		{% empty %}
+			<p>Pas de page de disponible</p>
+		{% endfor %}
+</div>
+{% endblock %}
+
+{% block right_panel %}
+{% if page.p_right != "" %}
+<div class="card" style="background-color: rgba(250,250,250,0.88);" >
+<div class="card-body">
+	<form action="" method="get">
+		<div class="row align-items-center">
+			
+			<div class="col-lg-8 col-sm-12">
+				{{page.wiki_search|crispy}}
+			</div>
+			<div class="col mt-sm-1">
+				<input type="submit" class="btn btn-success w-100" value="Rechercher">
+			</div>
+		</div>
+	</form>
+	<hr>
+	{% if page.wiki_art.paginator.num_pages != 1 %}
+	<p class="card-text">
+	<nav aria-label="...">
+		<ul class="pagination justify-content-center">
+			{% if page.wiki_art.has_previous %}
+				<li class="page-item">
+					<a class="page-link" href="?page={{ page.wiki_art.previous_page_number }}"> << </a>
+				</li>
+			{% else %}
+				<li class="page-item disabled">
+					<span class="page-link"> << </span>
+				</li>
+			{% endif %}
+			{% for nw_page in page.wiki_art.nbpage %}
+				{% if page.wiki_art.number == forloop.counter %}
+					<li class="page-item active" aria-current="page"><span class="page-link">{{forloop.counter}}</span></li>
+				{% else %}
+					<li class="page-item"><a class="page-link" href="?page={{forloop.counter}}">{{forloop.counter}}</a></li>
+				{% endif %}
+			{% endfor %}
+			{% if page.wiki_art.has_next %}
+				<li class="page-item">
+					<a class="page-link" href="?page={{ page.wiki_art.next_page_number }}"> >> </a>
+				</li>
+			{% else %}
+				<li class="page-item disabled">
+					<span class="page-link"> >> </span>
+				</li>
+			{% endif %}
+		</ul>
+	</nav>
+	<p>
+	{% endif %}
+	<p class="card-text">{{page.p_right|safe}}</p>
+	<h4> <i class="fas fa-tags"></i> Les Catégories </h4>
+	<p class="card-text">
+	{% for cat in page.wiki_cat %}
+		<a href="{% url 'wiki_tag' cat.cw_titre_slgify %}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true">{{cat.cw_titre}}</a>
+	{% endfor %}
+	
+	{% if page.wiki_filter == True %}
+		<a href="{% url 'wiki_index' %}" class="btn btn-danger mb-2" tabindex="-1" role="button" aria-disabled="true"><i class="fas fa-filter text-white"></i> Retirer les filtres</a>
+	{% else %}
+		<a href="{% url 'wiki_tag' 'all' %}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true">Tous les pages</a>
+	{% endif %}
+
+	</p>
+
+	<h4> <i class="fas fa-bomb"></i> Les pages les plus consulté </h4>
+	<p class="card-text">
+	{% for item in page.wiki_top10 %}
+		<i class="far fa-play-circle"></i> <a class="text-dark" data-bs-toggle="tooltip" data-bs-placement="top" title="{{item.w_titre}}" href="{% url 'wiki_play' item.w_titre_slugify %}">{{item.w_titre|truncatechars:40}}</a><br>
+	{% endfor %}
+	</p>
+
+	{% if page.retour %}
+	<p class="card-text">
+		<a href="{% url page.retour %}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true"><i class="fas fa-undo-alt"></i> Retour</a>
+	</p>
+	{% endif %}
+	
+</div>
+</div>
+{% endif %}
+{% endblock %}

+ 46 - 0
templates/read.html

@@ -0,0 +1,46 @@
+{% extends 'base.html' %}
+{% load crispy_forms_tags %}
+{% load static %}
+
+{% block main %}
+
+<div class="card-body">
+{% if page.wiki_art %}
+	{% for item in page.wiki_art %}
+		<p class="card-text">{{item.w_contenu|safe}}</p>
+	{% endfor %}
+{% endif %}
+</div>
+{% endblock %}
+
+{% block right_panel %}
+<div class="card" style="background-color: rgba(250,250,250,0.88);" >
+<div class="card-body">
+	
+	{% for item in page.wiki_art %}
+	{% if item.w_description_img != "" %}
+		<p><img src="{{item.w_description_img}}"></p>
+		<h4> Indroduction </h4>
+		<p>{{item.w_description|safe|urlize}}</p>
+		<p class="card-text">{{page.p_right|safe|urlize}}</p>
+	{% endif %}
+	<p>
+		<b>Nombre de Lectures </b>: {{item.w_reading}}<br>
+		<b>Date de mise en ligne </b>: {{item.w_publdate|date:"m N Y à H:i"}}
+	</p>
+	<h4> Les Catégories </h4>
+	<p>
+		{% for cat in item.w_cat.all %}
+			<a href="{% url 'wiki_tag' cat.cw_titre_slgify %}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true">{{cat.cw_titre}}</a>
+		{% endfor %}
+	{% endfor %}
+	</p>
+
+	{% if page.retour %}
+		<p class="card-text">
+			<a href="{% url page.retour %}" class="btn btn-dark mb-2" tabindex="-1" role="button" aria-disabled="true"><i class="fas fa-undo-alt"></i> Retour</a>
+		</p>
+	{% endif %}
+</div>
+</div>
+{% endblock %}

+ 20 - 0
urls.py

@@ -0,0 +1,20 @@
+from django.urls import path, re_path
+from django.views.generic import RedirectView, TemplateView
+
+from wiki import views
+
+urlpatterns = [
+
+	path('', views.wiki_index, {'cat': "index",}, name='wiki_index'),
+
+	re_path(r'cat/(?P<cat>[a-zA-Z0-9_.,-]+)$', views.wiki_index, name='wiki_cat'),
+	re_path(r'category/(?P<cat>[a-zA-Z0-9_.,-]+)/$', RedirectView.as_view(url='/blog/cat/%(bcat)s')),
+
+	re_path(r'tag/(?P<cat>[a-zA-Z0-9_.,-]+)$', views.wiki_index, name='wiki_tag'),
+	re_path(r'tag/(?P<cat>[a-zA-Z0-9_.,-]+)/$', views.wiki_index, name='wiki_tag_ext'),
+
+	re_path(r'(?P<art>[a-zA-Z0-9_.,-]+)$', views.wiki_play, name='wiki_play'),
+	re_path(r'(?P<art>[a-zA-Z0-9_.,-]+)/$', views.wiki_play, name='wiki_play_ext'),
+
+	
+]

+ 108 - 1
views.py

@@ -1,3 +1,110 @@
 from django.shortcuts import render
+from django.template import loader
+from django.urls import reverse
 
-# Create your views here.
+from django.http import HttpResponse, HttpResponseRedirect
+from django.utils.html import strip_tags
+
+from django.core.paginator import Paginator
+
+from django.contrib import messages
+from django.contrib.auth import authenticate, login, logout
+from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
+from django.contrib.auth.models import User
+
+from django.db.models import Q
+
+#from wiki.forms import *
+from core.views import gen_page_base, gen_page_sys
+from wiki.models import *
+
+def wiki_index(request, cat):
+
+#print(cat)
+
+	template = loader.get_template('listing.html')
+	page = gen_page_base()
+	page.p_adresse = reverse('wiki_index')
+	page.p_titre = "Les pages du Wiki"
+	page.p_contenu = ""
+	page.p_right = "Retrouvez les tous les pages sur le wiki"
+	page.p_description = strip_tags(page.p_right)
+	page.p_mots_clefs = ""
+	
+
+	w_search = request.GET.get('w_search')
+
+	if w_search != None:
+		page.wiki_search = Wiki_search_Form(initial={'w_search': w_search,})
+		q= Q(w_titre__icontains=w_search) | Q(w_mots_clefs__icontains=w_search) | Q(w_description__icontains=w_search)
+	else:
+		page.wiki_search = Wiki_search_Form()
+	if cat == "index":
+		if w_search != None:
+			wiki_art = Wiki.objects.filter( w_publier = True ).filter(q).order_by( '-w_publdate' )[:5]
+		else :
+			wiki_art = Wiki.objects.filter( w_publier = True ).order_by( '-w_publdate' )[:5]
+		page.wiki_cat = Cat_Wiki.objects.all()[:15]
+
+	elif cat == "all":
+		wiki_art = Wiki.objects.filter( w_publier = True ).order_by( '-w_publdate' )
+		page.wiki_cat = Cat_Wiki.objects.all()[:15]
+	else :
+		if w_search != None:
+			wiki_art = Wiki.objects.filter( w_publier = True ).filter( w_cat__cw_titre_slgify = cat ).filter(q).order_by( '-w_publdate' )
+		else :
+			wiki_art = Wiki.objects.filter( w_publier = True ).filter( w_cat__cw_titre_slgify = cat ).order_by( '-w_publdate' )
+		page.wiki_cat = Cat_Wiki.objects.filter( cw_titre_slgify = cat )[:15]
+		page.retour = "wiki_index"
+
+	paginator = Paginator(wiki_art, 15)
+	page.number = request.GET.get('page')
+
+	page.wiki_art = paginator.get_page(page.number)
+	#print(page.wiki_art.paginator.num_pages)
+	
+	page.wiki_art.nbpage = range(page.wiki_art.paginator.num_pages)
+
+	for cat in page.wiki_cat.all():
+		page.p_mots_clefs = page.p_mots_clefs + cat.cw_titre + ', '
+
+	page.wiki_top10 = Wiki.objects.filter( w_publier = True ).order_by( '-w_reading' )[:10]
+
+	html = template.render({
+		'page': page,
+		'user': request.user,
+		}, request)
+		
+	return HttpResponse(html)
+
+def wiki_play(request, art):
+
+	template = loader.get_template('read.html')
+	page = gen_page_base()
+	page.p_adresse = reverse('wiki_index')
+	page.wiki_art = Wiki.objects.filter(w_titre_slugify = art)[:1]
+
+	for art in page.wiki_art:
+		page.p_titre = art.w_titre
+		page.p_contenu = art.w_description
+		page.p_description = strip_tags(art.w_description)
+		if art.w_right != "":
+			page.p_right = art.w_right
+		else:
+			page.p_right = "&nbsp;"
+
+		page.p_mots_clefs = ""
+		for cat in art.w_cat.all():
+			page.p_mots_clefs = page.p_mots_clefs + cat.cw_titre + ', '
+
+		art.w_reading = art.w_reading + 1
+		art.save()
+
+		print(page)
+
+	html = template.render({
+		'page': page,
+		'user': request.user,
+		}, request)
+		
+	return HttpResponse(html)