1
0

views.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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
  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. if get_search :
  21. print(get_search)
  22. page.search = get_search
  23. if get_id :
  24. print(get_id)
  25. page.item_id = get_id
  26. page.p_adresse = reverse('parc_info_taches_show_list')
  27. page.p_titre = "Listing des utilisateurs"
  28. page.p_contenu = "Listing des utilisateurs"
  29. page.p_right = "Les Outils :"
  30. html = template.render({
  31. 'page': page,
  32. 'user': request.user,
  33. }, request)
  34. return HttpResponse(html)
  35. def user_get(request, id):
  36. template = loader.get_template('page.html')
  37. page = gen_page_base()
  38. page.p_adresse = reverse('parc_info_taches_show_list')
  39. page.p_titre = "Détail d'un utilisateur"
  40. page.p_contenu = "Détail d'un utilisateur"
  41. page.p_right = ""
  42. page.p_include = "gest_user_api_get.html"
  43. item = GES_User.objects.get(id = id)
  44. link_user_to_app(item.id, 'update')
  45. item.apps = GES_APPLink.objects.filter(GES_APPLink_User = item.id)
  46. html = template.render({
  47. 'page': page,
  48. 'item':item,
  49. 'user': request.user,
  50. }, request)
  51. return HttpResponse(html)
  52. def user_edit(request, id):
  53. get_search = request.GET.get('get_search', '')
  54. template = loader.get_template('base.html')
  55. page = gen_page_base()
  56. page.p_adresse = reverse('gest_user_index')
  57. page.p_titre = "Modification d'un utilisateur"
  58. page.p_contenu = "Modification d'un utilisateur"
  59. page.p_right = "&nbsp"
  60. page.p_include = "gest_user_api_edit.html"
  61. if id == None or id == '0':
  62. item = GES_User()
  63. else :
  64. item = GES_User.objects.get(id = id)
  65. print(item)
  66. if request.method == 'POST':
  67. form = GES_User_form(request.POST, instance=item)
  68. form.url = "gest_user_edit"
  69. if form.is_valid():
  70. form.save()
  71. get_value = "?get_id=" + str(item.id)
  72. if get_search:
  73. get_value = get_value + '&get_search=' + get_search
  74. return HttpResponseRedirect(reverse('gest_user_index')+get_value)
  75. else:
  76. form = GES_User_form(instance=item)
  77. form.url = "gest_user_edit"
  78. html = template.render({
  79. 'form': form,
  80. 'page': page,
  81. 'item': item,
  82. }, request)
  83. return HttpResponse(html)
  84. def app_edit(request, id):
  85. get_search = request.GET.get('get_search', '')
  86. template = loader.get_template('base.html')
  87. page = gen_page_base()
  88. page.p_adresse = reverse('gest_user_index')
  89. page.p_titre = "Modification d'un utilisateur"
  90. page.p_contenu = "Modification d'un utilisateur"
  91. page.p_right = "&nbsp"
  92. page.p_include = "gest_user_api_edit.html"
  93. if id == None or id == '0':
  94. item = GES_APPLink()
  95. else :
  96. item = GES_APPLink.objects.get(id = id)
  97. print(item)
  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. get_value = "?get_id=" + str(item.GES_APPLink_User.id)
  104. if get_search:
  105. get_value = get_value + '&get_search=' + get_search
  106. return HttpResponseRedirect(reverse('gest_user_index')+get_value)
  107. else:
  108. form = GES_APPLink_form(instance=item)
  109. form.url = "gest_app_edit"
  110. html = template.render({
  111. 'form': form,
  112. 'page': page,
  113. 'item': item,
  114. }, request)
  115. return HttpResponse(html)