views.py 23 KB

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