1
0

views.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. from django.shortcuts import render
  2. from django.template import loader
  3. from django.urls import reverse
  4. from django.utils import timezone
  5. from django.http import HttpResponse, HttpResponseRedirect
  6. from django.contrib import messages
  7. from django.contrib.auth.decorators import login_required
  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 core.views import gen_page_base, gen_page_sys, get_get_value, get_data_value, update_data_value
  12. from .models import *
  13. from .api import link_user_to_app
  14. #@login_required(login_url='core_login')
  15. def index(request):
  16. template = loader.get_template('gest_user_index.html')
  17. page = gen_page_base()
  18. get_search = request.GET.get('get_search', '')
  19. get_id = request.GET.get('get_id', '')
  20. page.lastapta = get_data_value('dernier-apta')
  21. if get_search :
  22. print(get_search)
  23. page.search = get_search
  24. if get_id :
  25. print(get_id)
  26. page.item_id = get_id
  27. page.p_adresse = reverse('parc_info_taches_show_list')
  28. page.p_titre = "Listing des utilisateurs"
  29. page.p_contenu = "Listing des utilisateurs"
  30. page.p_right = "Les Outils :"
  31. html = template.render({
  32. 'page': page,
  33. 'user': request.user,
  34. }, request)
  35. return HttpResponse(html)
  36. def user_get(request, id):
  37. template = loader.get_template('page.html')
  38. page = gen_page_base()
  39. page.p_adresse = reverse('parc_info_taches_show_list')
  40. page.p_titre = "Détail d'un utilisateur"
  41. page.p_contenu = "Détail d'un utilisateur"
  42. page.p_right = ""
  43. page.p_include = "gest_user_api_get.html"
  44. item = GES_User.objects.get(id = id)
  45. link_user_to_app(item.id, 'update')
  46. item.apps = GES_APPLink.objects.filter(GES_APPLink_User = item.id)
  47. html = template.render({
  48. 'page': page,
  49. 'item':item,
  50. 'user': request.user,
  51. }, request)
  52. return HttpResponse(html)
  53. def user_edit(request, id):
  54. get_search = request.GET.get('get_search', '')
  55. template = loader.get_template('base.html')
  56. page = gen_page_base()
  57. page.p_adresse = reverse('gest_user_index')
  58. page.p_titre = "Modification d'un utilisateur"
  59. page.p_contenu = "Modification d'un utilisateur"
  60. page.p_right = "&nbsp"
  61. page.p_include = "gest_user_api_edit.html"
  62. if id == None or id == '0':
  63. item = GES_User()
  64. else :
  65. item = GES_User.objects.get(id = id)
  66. print(item)
  67. if request.method == 'POST':
  68. form = GES_User_form(request.POST, instance=item)
  69. form.url = "gest_user_edit"
  70. if form.is_valid():
  71. form.save()
  72. get_value = "?get_id=" + str(item.id)
  73. if get_search:
  74. get_value = get_value + '&get_search=' + get_search
  75. return HttpResponseRedirect(reverse('gest_user_index')+get_value)
  76. else:
  77. form = GES_User_form(instance=item)
  78. form.url = "gest_user_edit"
  79. html = template.render({
  80. 'form': form,
  81. 'page': page,
  82. 'item': item,
  83. }, request)
  84. return HttpResponse(html)
  85. def app_edit(request, id):
  86. get_search = request.GET.get('get_search', '')
  87. template = loader.get_template('base.html')
  88. page = gen_page_base()
  89. page.p_adresse = reverse('gest_user_index')
  90. page.p_titre = "Modification d'un utilisateur"
  91. page.p_contenu = "Modification d'un utilisateur"
  92. page.p_right = "&nbsp"
  93. page.p_include = "gest_user_api_edit.html"
  94. if id == None or id == '0':
  95. item = GES_APPLink()
  96. else :
  97. item = GES_APPLink.objects.get(id = id)
  98. if request.method == 'POST':
  99. form = GES_APPLink_form(request.POST, instance=item)
  100. form.url = "gest_app_edit"
  101. if form.is_valid():
  102. form.save()
  103. if item.GES_APPLink_APP.GESAP_Nom == "Apta":
  104. print("hoo un apta")
  105. item = GES_APPLink.objects.get(id = id)
  106. data = get_data_value("dernier-apta")
  107. if item.GES_APPLink_Sup > data :
  108. print ("need update compteur")
  109. data = update_data_value("dernier-apta", item.GES_APPLink_Sup)
  110. get_value = "?get_id=" + str(item.GES_APPLink_User.id)
  111. if get_search:
  112. get_value = get_value + '&get_search=' + get_search
  113. return HttpResponseRedirect(reverse('gest_user_index')+get_value)
  114. else:
  115. form = GES_APPLink_form(instance=item)
  116. form.url = "gest_app_edit"
  117. html = template.render({
  118. 'form': form,
  119. 'page': page,
  120. 'item': item,
  121. }, request)
  122. return HttpResponse(html)