views.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from django.shortcuts import render
  2. from django.template import loader
  3. from django.urls import reverse
  4. from django.http import HttpResponse, HttpResponseRedirect
  5. from django.utils.html import strip_tags
  6. from django.core.paginator import Paginator
  7. from django.contrib import messages
  8. from django.contrib.auth import authenticate, login, logout
  9. from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
  10. from django.contrib.auth.models import User
  11. from django.db.models import Q
  12. #from wiki.forms import *
  13. from core.views import gen_page_base, gen_page_sys
  14. from wiki.models import *
  15. def wiki_index(request, cat):
  16. #print(cat)
  17. template = loader.get_template('listing.html')
  18. page = gen_page_base()
  19. page.p_adresse = reverse('wiki_index')
  20. page.p_titre = "Les pages du Wiki"
  21. page.p_contenu = ""
  22. page.p_right = "Retrouvez les tous les pages sur le wiki"
  23. page.p_description = strip_tags(page.p_right)
  24. page.p_mots_clefs = ""
  25. w_search = request.GET.get('w_search')
  26. if w_search != None:
  27. page.wiki_search = Wiki_search_Form(initial={'w_search': w_search,})
  28. q= Q(w_titre__icontains=w_search) | Q(w_mots_clefs__icontains=w_search) | Q(w_description__icontains=w_search)
  29. else:
  30. page.wiki_search = Wiki_search_Form()
  31. if cat == "index":
  32. if w_search != None:
  33. wiki_art = Wiki.objects.filter( w_publier = True ).filter(q).order_by( 'w_titre' )
  34. else :
  35. wiki_art = Wiki.objects.filter( w_publier = True ).order_by( 'w_titre' )
  36. page.wiki_cat = Cat_Wiki.objects.all()[:15]
  37. elif cat == "all":
  38. wiki_art = Wiki.objects.filter( w_publier = True ).order_by( 'w_titre' )
  39. page.wiki_cat = Cat_Wiki.objects.all()[:15]
  40. else :
  41. if w_search != None:
  42. wiki_art = Wiki.objects.filter( w_publier = True ).filter( w_cat__cw_titre_slgify = cat ).filter(q).order_by( 'w_titre' )
  43. else :
  44. wiki_art = Wiki.objects.filter( w_publier = True ).filter( w_cat__cw_titre_slgify = cat ).order_by( 'w_titre' )
  45. page.wiki_cat = Cat_Wiki.objects.filter( cw_titre_slgify = cat )[:15]
  46. page.retour = "wiki_index"
  47. paginator = Paginator(wiki_art, 100)
  48. page.number = request.GET.get('page')
  49. page.wiki_art = paginator.get_page(page.number)
  50. #print(page.wiki_art.paginator.num_pages)
  51. page.wiki_art.nbpage = range(page.wiki_art.paginator.num_pages)
  52. for cat in page.wiki_cat.all():
  53. page.p_mots_clefs = page.p_mots_clefs + cat.cw_titre + ', '
  54. page.wiki_top10 = Wiki.objects.filter( w_publier = True ).order_by( '-w_reading' )[:10]
  55. html = template.render({
  56. 'page': page,
  57. 'user': request.user,
  58. }, request)
  59. return HttpResponse(html)
  60. def wiki_play(request, art):
  61. template = loader.get_template('read.html')
  62. page = gen_page_base()
  63. page.p_adresse = reverse('wiki_index')
  64. page.wiki_art = Wiki.objects.filter(w_titre_slugify = art)[:1]
  65. for art in page.wiki_art:
  66. page.p_titre = art.w_titre
  67. page.p_contenu = art.w_description
  68. page.p_description = strip_tags(art.w_description)
  69. if art.w_right != "":
  70. page.p_right = art.w_right
  71. else:
  72. page.p_right = " "
  73. page.p_mots_clefs = ""
  74. for cat in art.w_cat.all():
  75. page.p_mots_clefs = page.p_mots_clefs + cat.cw_titre + ', '
  76. art.w_reading = art.w_reading + 1
  77. art.save()
  78. print(page)
  79. html = template.render({
  80. 'page': page,
  81. 'user': request.user,
  82. }, request)
  83. return HttpResponse(html)