views.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 .forms import *
  13. from .models import *
  14. from .api import test_last_client_NUnic
  15. from gest_clin.models import Clinique as Clinique
  16. from gest_clin.models import Services as Clin_Services
  17. def update(request):
  18. items = PIS.objects.all()
  19. #for item in items:
  20. # if item.PIC_Site == None :
  21. # site = Clinique.objects.get(CLIN_Anag = item.PIC_L_Site)
  22. # item.PIC_Site = site
  23. # item.save()
  24. for item in items:
  25. # if item.PIC_Service == None :
  26. # site = Clinique.objects.get(CLIN_Anag = "HPN")
  27. # service = Services.objects.get(SERVICE_Anag = item.PIC_Service.SERVICE_Anag)
  28. # new_service, created = Clin_Services.objects.get_or_create(
  29. # SERVICE_Nom = service.SERVICE_Nom,
  30. # SERVICE_Anag = service.SERVICE_Anag,
  31. # defaults={'SERVICE_Clin': site},
  32. # )
  33. # item.PIC_Service = new_service
  34. # item.save()
  35. if item.PIS_Site == None :
  36. print(" * Update *")
  37. site = Clinique.objects.get(CLIN_Anag = item.PIS_L_Site)
  38. print(site)
  39. item.PIS_Site = site
  40. item.save()
  41. # items = PIC.objects.all()
  42. # for item in items:
  43. # if item.PIC_Site.CLIN_Anag == "GENT":
  44. # item.PIC_Site.CLIN_Anag = "GEN"
  45. # if item.PIC_L_Statut == "OK":
  46. # item.PIC_L_Statut = "RAS"
  47. # item.save()
  48. return HttpResponse("OK")
  49. #@login_required(login_url='core_login')
  50. def switch_show_list(request):
  51. template = loader.get_template('parc_info_switch_index.html')
  52. get_search = request.GET.get('get_search', '')
  53. get_id = request.GET.get('get_id', '')
  54. page = gen_page_base()
  55. if get_search :
  56. print(get_search)
  57. page.search = get_search
  58. if get_id :
  59. print(get_id)
  60. page.item_id = get_id
  61. page.p_adresse = reverse('parc_info_switch_show_list')
  62. page.p_titre = "Listing des Switchs"
  63. page.p_right = "Les Outils :"
  64. html = template.render({
  65. 'page': page,
  66. 'user': request.user,
  67. }, request)
  68. return HttpResponse(html)
  69. def switch_edit_info(request, id):
  70. get_search = request.GET.get('get_search', '')
  71. template = loader.get_template('parc_info_switch_edit.html')
  72. if id == None or id == '0':
  73. item = Swich()
  74. else :
  75. item = Swich.objects.get(id = id)
  76. if request.method == 'POST':
  77. form = Edit_switch_form(request.POST, instance=item)
  78. if form.is_valid():
  79. form.save()
  80. get_value = "?get_id=" + str(item.id)
  81. if get_search:
  82. get_value = get_value + '&get_search=' + get_search
  83. return HttpResponseRedirect(reverse('parc_info_switch_show_list')+get_value)
  84. else:
  85. form = Edit_switch_form(instance=item)
  86. html = template.render({
  87. 'form': form,
  88. 'item': item,
  89. }, request)
  90. return HttpResponse(html)
  91. def switch_update_port(request, switch_id):
  92. get_search = request.GET.get('get_search', '')
  93. template = loader.get_template('parc_info_switch_update.html')
  94. item = Swich.objects.get(id = switch_id)
  95. if request.method == 'POST':
  96. form = Update_switch_port(request.POST, instance=item)
  97. if form.is_valid():
  98. form.save()
  99. get_value = "?get_id=" + str(item.id)
  100. if get_search:
  101. get_value = get_value + '&get_search=' + get_search
  102. item = Swich.objects.get(id = switch_id)
  103. print (item)
  104. update = item.SW_Update_Port.splitlines()
  105. if item.SW_OS == "HP":
  106. for line in update:
  107. line_split = line.split()
  108. print (line_split[0], line_split[5], line_split[6:])
  109. if line_split[5] != "1":
  110. try:
  111. port = Port_Link.objects.filter(PL_Swich = item).get(PL_Port_NG = line_split[0])
  112. print("a mettre a jour")
  113. except:
  114. print("a crée")
  115. port = Port_Link(PL_Swich = item, PL_Port_NG = line_split[0])
  116. port.PL_VLAN = line_split[5]
  117. port.PL_Commentaires = ' '.join(line_split[6:])
  118. port.save()
  119. elif item.SW_OS == "CISCO":
  120. for line in update:
  121. line_split = line.split()
  122. print (line_split[0], line_split[3], line_split[1])
  123. try:
  124. port = Port_Link.objects.filter(PL_Swich = item).get(PL_Port_NG = line_split[0])
  125. print("a mettre a jour")
  126. except:
  127. print("a crée")
  128. port = Port_Link(PL_Swich = item, PL_Port_NG = line_split[0])
  129. port.PL_VLAN = line_split[3]
  130. port.PL_Commentaires = line_split[1]
  131. port.save()
  132. elif item.SW_OS == "ARUBA":
  133. for line in update:
  134. line_split = line.split()
  135. if line_split[2] == "Down" or line_split[2] == "Up":
  136. print (line_split[0], line_split[7], line_split[1])
  137. try:
  138. port = Port_Link.objects.filter(PL_Swich = item).get(PL_Port_NG = line_split[0])
  139. print("a mettre a jour")
  140. except:
  141. print("a crée")
  142. port = Port_Link(PL_Swich = item, PL_Port_NG = line_split[0])
  143. port.PL_VLAN = line_split[7]
  144. port.PL_Commentaires = line_split[1]
  145. port.save()
  146. item.SW_Update_Port = None
  147. item.save()
  148. return HttpResponseRedirect(reverse('parc_info_switch_show_list')+get_value)
  149. else:
  150. form = Update_switch_port(instance=item)
  151. html = template.render({
  152. 'form': form,
  153. 'item': item,
  154. }, request)
  155. return HttpResponse(html)
  156. def switch_edit_port(request, switch_id, port_id):
  157. get_search = request.GET.get('get_search', '')
  158. template = loader.get_template('parc_info_switch_port.html')
  159. if port_id == None or port_id == '0':
  160. item = Port_Link()
  161. item.PL_Swich = Swich.objects.get(id = switch_id)
  162. else :
  163. item = Port_Link.objects.get(id = port_id)
  164. if request.method == 'POST':
  165. form = Edit_switch_port_form(request.POST, instance=item)
  166. if form.is_valid():
  167. form.save()
  168. get_value = "?get_id=" + str(item.PL_Swich.id)
  169. if get_search:
  170. get_value = get_value + '&get_search=' + get_search
  171. return HttpResponseRedirect(reverse('parc_info_switch_show_list')+get_value)
  172. else:
  173. form = Edit_switch_port_form(instance=item)
  174. html = template.render({
  175. 'form': form,
  176. 'item': item,
  177. }, request)
  178. return HttpResponse(html)
  179. #@login_required(login_url='core_login')
  180. def srv_show_list(request):
  181. template = loader.get_template('parc_info_srv_index.html')
  182. get_search = request.GET.get('get_search', '')
  183. get_id = request.GET.get('get_id', '')
  184. page = gen_page_base()
  185. if get_search :
  186. print(get_search)
  187. page.search = get_search
  188. if get_id :
  189. print(get_id)
  190. page.item_id = get_id
  191. page.p_adresse = reverse('parc_info_srv_show_list')
  192. page.p_titre = "Listing des serveurs"
  193. page.p_contenu = "Listing des serveur présent dans le parc informatique"
  194. page.p_right = "Les Outils :"
  195. html = template.render({
  196. 'page': page,
  197. 'user': request.user,
  198. }, request)
  199. return HttpResponse(html)
  200. def srv_edit_info(request, id_srv):
  201. get_search = request.GET.get('get_search', '')
  202. template = loader.get_template('parc_info_srv_edit.html')
  203. if id_srv == None or id_srv == '0':
  204. item = PIS()
  205. else :
  206. item = PIS.objects.get(id = id_srv)
  207. #print(item)
  208. if request.method == 'POST':
  209. form = Edit_srv_form(request.POST, instance=item)
  210. if form.is_valid():
  211. form.save()
  212. get_value = "?get_id=" + str(item.id)
  213. if get_search:
  214. get_value = get_value + '&get_search=' + get_search
  215. return HttpResponseRedirect(reverse('parc_info_srv_show_list')+get_value)
  216. else:
  217. form = Edit_srv_form(instance=item)
  218. html = template.render({
  219. 'form': form,
  220. 'item': item,
  221. }, request)
  222. return HttpResponse(html)
  223. #@login_required(login_url='core_login')
  224. def user_show_list(request):
  225. template = loader.get_template('parc_info_user_index.html')
  226. get_search = request.GET.get('get_search', '')
  227. get_id = request.GET.get('get_id', '')
  228. page = gen_page_base()
  229. if get_search :
  230. print(get_search)
  231. page.search = get_search
  232. if get_id :
  233. print(get_id)
  234. page.item_id = get_id
  235. page.p_adresse = reverse('parc_info_user_show_list')
  236. page.p_titre = "Listing des équipements utilisateurs"
  237. page.p_contenu = "Listing des équipements utilisateurs présent dans le parc informatique"
  238. page.p_right = "<h3>Menu</h3><p><a href='/parc/clients/enstock'>Listing des équipements en stock</a><br><a href='/parc/clients/aprep'>Listing des équipements en préparation</a><br><a href='/parc/clients/deprod'>Listing des équipements en inapt</a></p><h3>Les Outils</h3>"
  239. page.search_see = "ok"
  240. services = Services.objects.all()
  241. html = template.render({
  242. 'page': page,
  243. 'user': request.user,
  244. 'services': services,
  245. }, request)
  246. return HttpResponse(html)
  247. def user_edit_info(request, id_user):
  248. get_search = request.GET.get('get_search', '')
  249. template = loader.get_template('parc_info_user_edit.html')
  250. if id_user == None or id_user == '0':
  251. item_org = PIC()
  252. item = PIC()
  253. else :
  254. item_org = PIC.objects.get(id = id_user)
  255. item = PIC.objects.get(id = id_user)
  256. if request.method == 'POST':
  257. form = Edit_user_mini_form(request.POST, instance=item)
  258. if form.is_valid():
  259. form.save()
  260. item = PIC.objects.get(id = item.id) #Update Value
  261. if item.PIC_Nom_netbios == None and item.PIC_NUnic == None :
  262. item.PIC_Nom_netbios = item.PIC_Site.CLIN_Anag + "-"
  263. if item.PIC_L_Chassi_Type != "IMP":
  264. item.PIC_Nom_netbios = item.PIC_Nom_netbios + item.PIC_Service.SERVICE_Anag + "-"
  265. if item.PIC_L_Chassi_Type == "PC":
  266. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "W"
  267. item.PIC_NUnic = test_last_client_NUnic("PC")
  268. elif item.PIC_L_Chassi_Type == "PORTABLE":
  269. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "L"
  270. item.PIC_NUnic = test_last_client_NUnic("PC")
  271. elif item.PIC_L_Chassi_Type == "CL":
  272. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "T"
  273. item.PIC_NUnic = test_last_client_NUnic("PC")
  274. elif item.PIC_L_Chassi_Type == "PANEL-PC":
  275. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "D"
  276. item.PIC_NUnic = test_last_client_NUnic("PC")
  277. elif item.PIC_L_Chassi_Type == "IMP":
  278. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "P"
  279. item.PIC_NUnic = test_last_client_NUnic("IMP")
  280. item.PIC_Nom_netbios = item.PIC_Nom_netbios + str(item.PIC_NUnic).zfill(4)
  281. print(item.PIC_NUnic)
  282. print(item.PIC_Nom_netbios)
  283. item.save()
  284. elif item.PIC_Nom_netbios == None:
  285. item.PIC_Nom_netbios = item.PIC_Site.CLIN_Anag + "-"
  286. if item.PIC_L_Chassi_Type != "IMP":
  287. item.PIC_Nom_netbios = item.PIC_Nom_netbios + item.PIC_Service.SERVICE_Anag + "-"
  288. if item.PIC_L_Chassi_Type == "PC":
  289. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "W"
  290. elif item.PIC_L_Chassi_Type == "PORTABLE":
  291. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "L"
  292. elif item.PIC_L_Chassi_Type == "CL":
  293. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "T"
  294. elif item.PIC_L_Chassi_Type == "PANEL-PC":
  295. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "D"
  296. elif item.PIC_L_Chassi_Type == "IMP":
  297. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "P"
  298. item.PIC_Nom_netbios = item.PIC_Nom_netbios + str(item.PIC_NUnic).zfill(4)
  299. print(item.PIC_NUnic)
  300. print(item.PIC_Nom_netbios)
  301. item.save()
  302. #update history
  303. if item_org.PIC_Site == None:
  304. history = PIC_History()
  305. history.H_PIC = item
  306. history.H_Commentaire = "Le site a été mise sur : " + item.PIC_Site.CLIN_Anag
  307. history.save()
  308. elif item_org.PIC_Site.CLIN_Anag != item.PIC_Site.CLIN_Anag:
  309. history = PIC_History()
  310. history.H_PIC = item
  311. history.H_Commentaire = "Le site a été modifié : " + item_org.PIC_Site.CLIN_Anag + " > " + item.PIC_Site.CLIN_Anag
  312. history.save()
  313. if item_org.PIC_L_Chassi_Type != item.PIC_L_Chassi_Type :
  314. history = PIC_History()
  315. history.H_PIC = item
  316. history.H_Commentaire = "Le type a été modifié : " + item_org.PIC_L_Chassi_Type + " > " + item.PIC_L_Chassi_Type
  317. history.save()
  318. if item_org.PIC_Nom_netbios == None :
  319. history = PIC_History()
  320. history.H_PIC = item
  321. history.H_Commentaire = "Le nom netbios a été mise sur : " +item.PIC_Nom_netbios
  322. history.save()
  323. elif item_org.PIC_Nom_netbios != item.PIC_Nom_netbios :
  324. history = PIC_History()
  325. history.H_PIC = item
  326. history.H_Commentaire = "Le nom netbios a été modifié : " + item_org.PIC_Nom_netbios + " > " + item.PIC_Nom_netbios
  327. history.save()
  328. if item_org.PIC_Service == None :
  329. history = PIC_History()
  330. history.H_PIC = item
  331. history.H_Commentaire = "Le service a été mise sur : " + item.PIC_Service.SERVICE_Nom
  332. history.save()
  333. elif item_org.PIC_Service != item.PIC_Service :
  334. history = PIC_History()
  335. history.H_PIC = item
  336. history.H_Commentaire = "Le service a été modifié : " + item_org.PIC_Service.SERVICE_Nom + " > " + item.PIC_Service.SERVICE_Nom
  337. history.save()
  338. if item_org.PIC_Local != item.PIC_Local :
  339. history = PIC_History()
  340. history.H_PIC = item
  341. history.H_Commentaire = "La localisation a été modifié : " + item_org.PIC_Local + " > " + item.PIC_Local
  342. history.save()
  343. if item_org.PIC_Utilisateur == None :
  344. history = PIC_History()
  345. history.H_PIC = item
  346. history.H_Commentaire = "L'utilisateur a été mise sur : " + item.PIC_Utilisateur
  347. history.save()
  348. elif item_org.PIC_Utilisateur != item.PIC_Utilisateur :
  349. history = PIC_History()
  350. history.H_PIC = item
  351. history.H_Commentaire = "L'utilisateur a été modifié : " + item_org.PIC_Utilisateur + " > " + item.PIC_Utilisateur
  352. history.save()
  353. get_value = "?get_id=" + str(item.id)
  354. if get_search:
  355. get_value = get_value + '&get_search=' + get_search
  356. return HttpResponseRedirect(reverse('parc_info_user_show_list')+get_value)
  357. else:
  358. form = Edit_user_mini_form(instance=item_org)
  359. html = template.render({
  360. 'form': form,
  361. 'item': item_org,
  362. }, request)
  363. return HttpResponse(html)
  364. def user_edit_statut(request, id_user):
  365. get_search = request.GET.get('get_search', '')
  366. template = loader.get_template('parc_info_user_statut.html')
  367. if id_user == None or id_user == '0':
  368. item_org = PIC()
  369. item = PIC()
  370. else :
  371. item_org = PIC.objects.get(id = id_user)
  372. item = PIC.objects.get(id = id_user)
  373. #print(item)
  374. if request.method == 'POST':
  375. form = Edit_user_statut_form(request.POST, instance=item)
  376. if form.is_valid():
  377. form.save()
  378. if item_org.PIC_L_Statut != item.PIC_L_Statut :
  379. history = PIC_History()
  380. history.H_PIC = item
  381. history.H_Commentaire = "Le statut a été modifié : " + item_org.PIC_L_Statut + " > " + item.PIC_L_Statut
  382. history.save()
  383. get_value = "?get_id=" + str(item.id)
  384. if get_search:
  385. get_value = get_value + '&get_search=' + get_search
  386. return HttpResponseRedirect(reverse('parc_info_user_show_list')+get_value)
  387. else:
  388. form = Edit_user_statut_form(instance=item)
  389. html = template.render({
  390. 'form': form,
  391. 'item': item,
  392. }, request)
  393. return HttpResponse(html)
  394. #@login_required(login_url='core_login')
  395. def user_show_list_en_stock(request):
  396. template = loader.get_template('parc_info_user_index.html')
  397. page = gen_page_base()
  398. page.p_adresse = reverse('parc_info_user_show_list_en_stock')
  399. page.p_titre = "Liste des matériels en STOCK"
  400. page.p_contenu = "Liste des matériels en STOCK"
  401. page.p_right = "&nbsp"
  402. page.p_include = "parc_info_api_user_get_list.html"
  403. data_query = PIC.objects.filter(PIC_L_Statut = 'EN STOCK').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  404. html = template.render({
  405. 'page': page,
  406. 'data_query':data_query,
  407. 'user': request.user,
  408. }, request)
  409. return HttpResponse(html)
  410. #@login_required(login_url='core_login')
  411. def user_show_list_aprep(request):
  412. template = loader.get_template('parc_info_user_index.html')
  413. page = gen_page_base()
  414. page.p_adresse = reverse('parc_info_user_show_list_en_stock')
  415. page.p_titre = "Liste des matériels encours de préparation"
  416. page.p_contenu = "Liste des matériels encours de préparation"
  417. page.p_right = "&nbsp"
  418. page.p_include = "parc_info_api_user_get_list.html"
  419. data_query = PIC.objects.filter(PIC_L_Statut = 'PREPROD').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  420. html = template.render({
  421. 'page': page,
  422. 'data_query':data_query,
  423. 'user': request.user,
  424. }, request)
  425. return HttpResponse(html)
  426. #@login_required(login_url='core_login')
  427. def user_show_list_deprod(request):
  428. template = loader.get_template('parc_info_user_index.html')
  429. page = gen_page_base()
  430. page.p_adresse = reverse('parc_info_user_show_list_deprod')
  431. page.p_titre = "Liste des matériels en plus en service"
  432. page.p_contenu = "Liste des matériels en plus en service"
  433. page.p_right = "<p>Liste des matériels plus en service car celui-ci est HS ou n'est pour adapté au besoin actuel.</p>"
  434. page.p_include = "parc_info_api_user_get_list.html"
  435. data_query = PIC.objects.filter(PIC_L_Statut = 'INAPTE').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  436. html = template.render({
  437. 'page': page,
  438. 'data_query':data_query,
  439. 'user': request.user,
  440. }, request)
  441. return HttpResponse(html)
  442. #@login_required(login_url='core_login')
  443. def user_show_list_imp(request):
  444. template = loader.get_template('parc_info_user_index.html')
  445. page = gen_page_base()
  446. page.p_adresse = reverse('parc_info_user_show_list_imp')
  447. page.p_titre = "Liste des imprimantes"
  448. page.p_contenu = "Liste des imprimantes"
  449. page.p_right = "&nbsp"
  450. page.p_include = "parc_info_api_user_get_imp.html"
  451. data_query = PIC.objects.filter(PIC_L_Chassi_Type = 'IMP').order_by('PIC_Site__CLIN_Anag','PIC_Service__SERVICE_Nom','PIC_NUnic')
  452. html = template.render({
  453. 'page': page,
  454. 'data_query':data_query,
  455. 'user': request.user,
  456. }, request)
  457. return HttpResponse(html)
  458. #@login_required(login_url='core_login')
  459. def stat_user_by_service(request):
  460. page = gen_page_base()
  461. template = loader.get_template('parc_info_stat_user_by_service.html')
  462. items = PIC.objects.exclude(PIC_L_Statut__in = ['INAPTE', 'EN STOCK']).exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_Site__CLIN_Anag','PIC_Service__SERVICE_Nom')
  463. items_imp = PIC.objects.exclude(PIC_L_Statut__in = ['INAPTE', 'EN STOCK']).filter(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_Site__CLIN_Anag','PIC_Service__SERVICE_Nom')
  464. for item in items:
  465. item.accessoir = Accessory_Link.objects.filter(pic = item)
  466. html = template.render({
  467. 'items': items,
  468. 'items_imp': items_imp,
  469. 'page': page,
  470. }, request)
  471. return HttpResponse(html)
  472. #@login_required(login_url='core_login')
  473. def stat_user_without_snow(request):
  474. page = gen_page_base()
  475. template = loader.get_template('parc_info_stat_user_without_snow.html')
  476. item = PIC.objects.exclude(PIC_L_Statut__in = ['INAPTE', 'EN STOCK']).filter(PIC_L_Chassi_Type__in = ['PC','PORTABLE','PANEL-PC']).filter(PIC_with_Snow = False).order_by('PIC_Site__CLIN_Anag','PIC_Service__SERVICE_Nom')
  477. html = template.render({
  478. 'item': item,
  479. 'page': page,
  480. }, request)
  481. return HttpResponse(html)
  482. def import_snow_data(request):
  483. import openpyxl
  484. workbook = openpyxl.load_workbook(filename='./static/import/ComputersList.xlsx', read_only=True)
  485. first_sheet = workbook.get_sheet_names()[0]
  486. worksheet = workbook.get_sheet_by_name(first_sheet)
  487. for row in worksheet.iter_rows():
  488. tmp_Nom_netbios = str(row[0].value)
  489. print(tmp_Nom_netbios)
  490. need_update = 0
  491. try :
  492. item = PIC.objects.exclude(PIC_L_Statut__in = ['INAPTE', 'EN STOCK']).get(PIC_Nom_netbios = tmp_Nom_netbios)
  493. print("PC > ok exist")
  494. need_update = 1
  495. except:
  496. try :
  497. item = PIS.objects.exclude(PIS_Archive = True).get(PIS_Nom_netbios = tmp_Nom_netbios)
  498. print("SRV > ok exist")
  499. need_update = 2
  500. except:
  501. pass
  502. if need_update == 1:
  503. item.PIC_with_Snow = True
  504. item.PIC_Adresse_IP = str(row[1].value)
  505. item.PIC_Marque = str(row[2].value)
  506. item.PIC_Type = str(row[3].value)
  507. item.PIC_OS = str(row[5].value)
  508. item.PIC_SN = str(row[12].value)
  509. tmp_Utilisateur = str(row[8].value)
  510. tmp_Utilisateur = tmp_Utilisateur.split( )
  511. try :
  512. tmp_sp_tmp_Utilisateur = tmp_Utilisateur[-1]
  513. tmp_sp_tmp_Utilisateur = tmp_sp_tmp_Utilisateur.replace('\\', '').replace('(STJACQUES', '').replace(')', '')
  514. item.PIC_Utilisateur_Fq = tmp_sp_tmp_Utilisateur
  515. except :
  516. pass
  517. tmp_PIC_CPU = str(row[9].value)
  518. tmp_PIC_CPU = tmp_PIC_CPU.split(' @')
  519. item.PIC_CPU = tmp_PIC_CPU[0]
  520. item.PIC_CPU = item.PIC_CPU.replace(' CPU', '').replace('11th Gen ', '')
  521. item.PIC_RAM = int(float(row[11].value / 1024))
  522. item.save()
  523. elif need_update == 2:
  524. item.PIS_with_Snow = True
  525. item.PIS_Adresse_IP = str(row[1].value)
  526. if str(row[2].value) == "VMware, Inc.":
  527. item.PIS_Type = "MACHINE VIRTUELLE"
  528. item.PIS_CPU = str(row[10].value)
  529. else:
  530. item.PIS_Type = str(row[2].value)
  531. item.PIS_SN = str(row[12].value)
  532. tmp_PIS_CPU = str(row[9].value)
  533. tmp_PIS_CPU = tmp_PIS_CPU.split(' @')
  534. item.PIS_CPU = tmp_PIS_CPU[0]
  535. item.PIS_CPU = item.PIS_CPU.replace(' CPU', '').replace('11th Gen ', '')
  536. item.PIS_OS = str(row[5].value)
  537. item.PIS_RAM = int(float(row[11].value / 1024))
  538. item.save()
  539. return HttpResponse("ok")