1
0

views.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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_id = request.GET.get('get_id', '')
  230. page = gen_page_base()
  231. if get_search :
  232. print(get_search)
  233. page.search = get_search
  234. if get_id :
  235. print(get_id)
  236. page.item_id = get_id
  237. page.p_adresse = reverse('parc_info_user_show_list')
  238. page.p_titre = "Listing des équipements utilisateurs"
  239. page.p_contenu = "Listing des équipements utilisateurs présent dans le parc informatique"
  240. 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>"
  241. page.search_see = "ok"
  242. services = Clin_Services.objects.all()
  243. html = template.render({
  244. 'page': page,
  245. 'user': request.user,
  246. 'services': services,
  247. }, request)
  248. return HttpResponse(html)
  249. def user_edit_info(request, id_user):
  250. get_search = request.GET.get('get_search', '')
  251. template = loader.get_template('parc_info_user_edit.html')
  252. if id_user == None or id_user == '0':
  253. item_org = PIC()
  254. item = PIC()
  255. else :
  256. item_org = PIC.objects.get(id = id_user)
  257. item = PIC.objects.get(id = id_user)
  258. if request.method == 'POST':
  259. form = Edit_user_mini_form(request.POST, instance=item)
  260. if form.is_valid():
  261. form.save()
  262. item = PIC.objects.get(id = item.id) #Update Value
  263. if item.PIC_Nom_netbios == None and item.PIC_NUnic == 0 :
  264. item.PIC_Nom_netbios = item.PIC_Site.CLIN_Anag + "-"
  265. if item.PIC_L_Chassi_Type != "IMP":
  266. item.PIC_Nom_netbios = item.PIC_Nom_netbios + item.PIC_Service.SERVICE_Anag + "-"
  267. if item.PIC_L_Chassi_Type == "PC":
  268. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "W"
  269. item.PIC_NUnic = test_last_client_NUnic("PC")
  270. elif item.PIC_L_Chassi_Type == "PORTABLE":
  271. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "L"
  272. item.PIC_NUnic = test_last_client_NUnic("PC")
  273. elif item.PIC_L_Chassi_Type == "CL":
  274. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "T"
  275. item.PIC_NUnic = test_last_client_NUnic("PC")
  276. elif item.PIC_L_Chassi_Type == "PANEL-PC":
  277. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "D"
  278. item.PIC_NUnic = test_last_client_NUnic("PC")
  279. elif item.PIC_L_Chassi_Type == "IMP":
  280. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "P"
  281. item.PIC_NUnic = test_last_client_NUnic("IMP")
  282. item.PIC_Nom_netbios = item.PIC_Nom_netbios + str(item.PIC_NUnic).zfill(4)
  283. print(item.PIC_NUnic)
  284. print(item.PIC_Nom_netbios)
  285. item.save()
  286. elif item.PIC_Nom_netbios == None:
  287. item.PIC_Nom_netbios = item.PIC_Site.CLIN_Anag + "-"
  288. if item.PIC_L_Chassi_Type != "IMP":
  289. item.PIC_Nom_netbios = item.PIC_Nom_netbios + item.PIC_Service.SERVICE_Anag + "-"
  290. if item.PIC_L_Chassi_Type == "PC":
  291. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "W"
  292. elif item.PIC_L_Chassi_Type == "PORTABLE":
  293. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "L"
  294. elif item.PIC_L_Chassi_Type == "CL":
  295. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "T"
  296. elif item.PIC_L_Chassi_Type == "PANEL-PC":
  297. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "D"
  298. elif item.PIC_L_Chassi_Type == "IMP":
  299. item.PIC_Nom_netbios = item.PIC_Nom_netbios + "P"
  300. item.PIC_Nom_netbios = item.PIC_Nom_netbios + str(item.PIC_NUnic).zfill(4)
  301. print(item.PIC_NUnic)
  302. print(item.PIC_Nom_netbios)
  303. item.save()
  304. #update history
  305. if item_org.PIC_Site == None and item.PIC_Site != None :
  306. history = PIC_History()
  307. history.H_PIC = item
  308. history.H_Commentaire = "Le site a été mise sur : " + item.PIC_Site.CLIN_Anag
  309. history.save()
  310. elif item_org.PIC_Site.CLIN_Anag != item.PIC_Site.CLIN_Anag:
  311. history = PIC_History()
  312. history.H_PIC = item
  313. history.H_Commentaire = "Le site a été modifié : " + item_org.PIC_Site.CLIN_Anag + " > " + item.PIC_Site.CLIN_Anag
  314. history.save()
  315. if item_org.PIC_L_Chassi_Type != item.PIC_L_Chassi_Type :
  316. history = PIC_History()
  317. history.H_PIC = item
  318. history.H_Commentaire = "Le type a été modifié : " + item_org.PIC_L_Chassi_Type + " > " + item.PIC_L_Chassi_Type
  319. history.save()
  320. if item_org.PIC_Nom_netbios == None and item.PIC_Nom_netbios != None :
  321. history = PIC_History()
  322. history.H_PIC = item
  323. history.H_Commentaire = "Le nom netbios a été mise sur : " +item.PIC_Nom_netbios
  324. history.save()
  325. elif item_org.PIC_Nom_netbios != item.PIC_Nom_netbios :
  326. history = PIC_History()
  327. history.H_PIC = item
  328. history.H_Commentaire = "Le nom netbios a été modifié : " + item_org.PIC_Nom_netbios + " > " + item.PIC_Nom_netbios
  329. history.save()
  330. if item_org.PIC_Service == None and item.PIC_Service != None :
  331. history = PIC_History()
  332. history.H_PIC = item
  333. history.H_Commentaire = "Le service a été mise sur : " + item.PIC_Service.SERVICE_Nom
  334. history.save()
  335. elif item_org.PIC_Service != item.PIC_Service :
  336. history = PIC_History()
  337. history.H_PIC = item
  338. history.H_Commentaire = "Le service a été modifié : " + item_org.PIC_Service.SERVICE_Nom + " > " + item.PIC_Service.SERVICE_Nom
  339. history.save()
  340. if item_org.PIC_Local == None and item.PIC_Local != None :
  341. history = PIC_History()
  342. history.H_PIC = item
  343. history.H_Commentaire = "La localisation a été mise sur : : " + item.PIC_Local
  344. history.save()
  345. elif item_org.PIC_Local != item.PIC_Local :
  346. history = PIC_History()
  347. history.H_PIC = item
  348. history.H_Commentaire = "La localisation a été modifié : " + item_org.PIC_Local + " > " + item.PIC_Local
  349. history.save()
  350. if item_org.PIC_Utilisateur == None and item.PIC_Utilisateur != None :
  351. history = PIC_History()
  352. history.H_PIC = item
  353. history.H_Commentaire = "L'utilisateur a été mise sur : " + item.PIC_Utilisateur
  354. history.save()
  355. elif item_org.PIC_Utilisateur != item.PIC_Utilisateur :
  356. history = PIC_History()
  357. history.H_PIC = item
  358. history.H_Commentaire = "L'utilisateur a été modifié : " + item_org.PIC_Utilisateur + " > " + item.PIC_Utilisateur
  359. history.save()
  360. get_value = "?get_id=" + str(item.id)
  361. if get_search:
  362. get_value = get_value + '&get_search=' + get_search
  363. return HttpResponseRedirect(reverse('parc_info_user_show_list')+get_value)
  364. else:
  365. form = Edit_user_mini_form(instance=item_org)
  366. html = template.render({
  367. 'form': form,
  368. 'item': item_org,
  369. }, request)
  370. return HttpResponse(html)
  371. def user_edit_statut(request, id_user):
  372. get_search = request.GET.get('get_search', '')
  373. template = loader.get_template('parc_info_user_statut.html')
  374. if id_user == None or id_user == '0':
  375. item_org = PIC()
  376. item = PIC()
  377. else :
  378. item_org = PIC.objects.get(id = id_user)
  379. item = PIC.objects.get(id = id_user)
  380. #print(item)
  381. if request.method == 'POST':
  382. form = Edit_user_statut_form(request.POST, instance=item)
  383. if form.is_valid():
  384. form.save()
  385. if item_org.PIC_L_Statut != item.PIC_L_Statut :
  386. history = PIC_History()
  387. history.H_PIC = item
  388. history.H_Commentaire = "Le statut a été modifié : " + item_org.PIC_L_Statut + " > " + item.PIC_L_Statut
  389. history.save()
  390. get_value = "?get_id=" + str(item.id)
  391. if get_search:
  392. get_value = get_value + '&get_search=' + get_search
  393. return HttpResponseRedirect(reverse('parc_info_user_show_list')+get_value)
  394. else:
  395. form = Edit_user_statut_form(instance=item)
  396. html = template.render({
  397. 'form': form,
  398. 'item': item,
  399. }, request)
  400. return HttpResponse(html)
  401. @login_required(login_url='core_login')
  402. def user_show_list_en_stock(request):
  403. template = loader.get_template('parc_info_user_index.html')
  404. page = gen_page_base()
  405. page.p_adresse = reverse('parc_info_user_show_list_en_stock')
  406. page.p_titre = "Liste des matériels en STOCK"
  407. page.p_contenu = "Liste des matériels en STOCK"
  408. page.p_right = "&nbsp"
  409. page.p_include = "parc_info_api_user_get_list.html"
  410. data_query = PIC.objects.filter(PIC_L_Statut = 'EN STOCK').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  411. html = template.render({
  412. 'page': page,
  413. 'data_query':data_query,
  414. 'user': request.user,
  415. }, request)
  416. return HttpResponse(html)
  417. @login_required(login_url='core_login')
  418. def user_show_list_aprep(request):
  419. template = loader.get_template('parc_info_user_index.html')
  420. page = gen_page_base()
  421. page.p_adresse = reverse('parc_info_user_show_list_en_stock')
  422. page.p_titre = "Liste des matériels encours de préparation"
  423. page.p_contenu = "Liste des matériels encours de préparation"
  424. page.p_right = "&nbsp"
  425. page.p_include = "parc_info_api_user_get_list.html"
  426. data_query = PIC.objects.filter(PIC_L_Statut = 'PREPROD').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  427. html = template.render({
  428. 'page': page,
  429. 'data_query':data_query,
  430. 'user': request.user,
  431. }, request)
  432. return HttpResponse(html)
  433. @login_required(login_url='core_login')
  434. def user_show_list_deprod(request):
  435. template = loader.get_template('parc_info_user_index.html')
  436. page = gen_page_base()
  437. page.p_adresse = reverse('parc_info_user_show_list_deprod')
  438. page.p_titre = "Liste des matériels en plus en service"
  439. page.p_contenu = "Liste des matériels en plus en service"
  440. 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>"
  441. page.p_include = "parc_info_api_user_get_list.html"
  442. data_query = PIC.objects.filter(PIC_L_Statut = 'INAPTE').exclude(PIC_L_Chassi_Type = 'IMP' ).order_by('PIC_NUnic')
  443. html = template.render({
  444. 'page': page,
  445. 'data_query':data_query,
  446. 'user': request.user,
  447. }, request)
  448. return HttpResponse(html)
  449. @login_required(login_url='core_login')
  450. def user_show_list_imp(request):
  451. template = loader.get_template('parc_info_user_index.html')
  452. page = gen_page_base()
  453. page.p_adresse = reverse('parc_info_user_show_list_imp')
  454. page.p_titre = "Liste des imprimantes"
  455. page.p_contenu = "Liste des imprimantes"
  456. page.p_right = "&nbsp"
  457. page.p_include = "parc_info_api_user_get_imp.html"
  458. data_query = PIC.objects.filter(PIC_L_Chassi_Type = 'IMP').order_by('PIC_Site__CLIN_Anag','PIC_Service__SERVICE_Nom','PIC_NUnic')
  459. html = template.render({
  460. 'page': page,
  461. 'data_query':data_query,
  462. 'user': request.user,
  463. }, request)
  464. return HttpResponse(html)
  465. @login_required(login_url='core_login')
  466. def stat_user_by_service(request):
  467. page = gen_page_base()
  468. template = loader.get_template('parc_info_stat_user_by_service.html')
  469. 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')
  470. 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')
  471. for item in items:
  472. item.accessoir = Accessory_Link.objects.filter(pic = item)
  473. html = template.render({
  474. 'items': items,
  475. 'items_imp': items_imp,
  476. 'page': page,
  477. }, request)
  478. return HttpResponse(html)
  479. @login_required(login_url='core_login')
  480. def stat_user_without_snow(request):
  481. page = gen_page_base()
  482. template = loader.get_template('parc_info_stat_user_without_snow.html')
  483. 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')
  484. html = template.render({
  485. 'item': item,
  486. 'page': page,
  487. }, request)
  488. return HttpResponse(html)
  489. def import_snow_data(request):
  490. import openpyxl
  491. workbook = openpyxl.load_workbook(filename='./static/import/ComputersList.xlsx', read_only=True)
  492. first_sheet = workbook.get_sheet_names()[0]
  493. worksheet = workbook.get_sheet_by_name(first_sheet)
  494. for row in worksheet.iter_rows():
  495. tmp_Nom_netbios = str(row[0].value)
  496. print(tmp_Nom_netbios)
  497. need_update = 0
  498. try :
  499. item = PIC.objects.exclude(PIC_L_Statut__in = ['INAPTE', 'EN STOCK']).get(PIC_Nom_netbios = tmp_Nom_netbios)
  500. print("PC > ok exist")
  501. need_update = 1
  502. except:
  503. try :
  504. item = PIS.objects.exclude(PIS_Archive = True).get(PIS_Nom_netbios = tmp_Nom_netbios)
  505. print("SRV > ok exist")
  506. need_update = 2
  507. except:
  508. pass
  509. if need_update == 1:
  510. item.PIC_with_Snow = True
  511. item.PIC_Adresse_IP = str(row[1].value)
  512. item.PIC_Marque = str(row[2].value)
  513. item.PIC_Type = str(row[3].value)
  514. item.PIC_OS = str(row[5].value)
  515. item.PIC_SN = str(row[12].value)
  516. tmp_Utilisateur = str(row[8].value)
  517. tmp_Utilisateur = tmp_Utilisateur.split( )
  518. try :
  519. tmp_sp_tmp_Utilisateur = tmp_Utilisateur[-1]
  520. tmp_sp_tmp_Utilisateur = tmp_sp_tmp_Utilisateur.replace('\\', '').replace('(STJACQUES', '').replace(')', '')
  521. item.PIC_Utilisateur_Fq = tmp_sp_tmp_Utilisateur
  522. except :
  523. pass
  524. tmp_PIC_CPU = str(row[9].value)
  525. tmp_PIC_CPU = tmp_PIC_CPU.split(' @')
  526. item.PIC_CPU = tmp_PIC_CPU[0]
  527. item.PIC_CPU = item.PIC_CPU.replace(' CPU', '').replace('11th Gen ', '')
  528. item.PIC_RAM = int(float(row[11].value / 1024))
  529. item.save()
  530. elif need_update == 2:
  531. item.PIS_with_Snow = True
  532. item.PIS_Adresse_IP = str(row[1].value)
  533. if str(row[2].value) == "VMware, Inc.":
  534. item.PIS_Type = "MACHINE VIRTUELLE"
  535. item.PIS_CPU = str(row[10].value)
  536. else:
  537. item.PIS_Type = str(row[2].value)
  538. item.PIS_SN = str(row[12].value)
  539. tmp_PIS_CPU = str(row[9].value)
  540. tmp_PIS_CPU = tmp_PIS_CPU.split(' @')
  541. item.PIS_CPU = tmp_PIS_CPU[0]
  542. item.PIS_CPU = item.PIS_CPU.replace(' CPU', '').replace('11th Gen ', '')
  543. item.PIS_OS = str(row[5].value)
  544. item.PIS_RAM = int(float(row[11].value / 1024))
  545. item.save()
  546. return HttpResponse("ok")