views.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. from django.shortcuts import render
  2. from sicurezza.views import *
  3. from .forms import *
  4. from .models import *
  5. from datetime import datetime
  6. # Create your views here.
  7. def NoteList(request):
  8. session = getSessionParms(request)
  9. userauth = session['_userauth_']
  10. note2edit = session['_note2edit_']
  11. request.session['from']='Note:NoteList'
  12. utenteautorizzato = User.objects.get(pk=userauth)
  13. value={}
  14. value['utenteautorizzato'] = utenteautorizzato
  15. value['navbar'] = True
  16. print("livello autorizzazione",utenteautorizzato.securitylevel_id)
  17. securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
  18. securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
  19. securitylist = getSecurityList(securityrow)
  20. value['securitylist'] = securitylist
  21. value['securityrow'] = securityrow
  22. value['securityrowLen'] = len(securityrow)
  23. if request.method=="POST":
  24. if "Nuova Nota" in request.POST:
  25. print('nuova nota')
  26. request.session['_note2edit_'] = 0
  27. return HttpResponseRedirect(reverse('Note:NoteEdit',args={}))
  28. if "edit" in request.POST:
  29. print('id da editare',request.POST['edit'])
  30. request.session['_note2edit_'] = request.POST['edit']
  31. return HttpResponseRedirect(reverse('Note:NoteEdit',args={}))
  32. if "disable" in request.POST :
  33. print('id da disattivare',request.POST['disable'])
  34. idpost = request.POST['disable']
  35. u = Note.objects.get(pk=idpost)
  36. if not u.locked:
  37. u.enabled=False
  38. u.save()
  39. if "enable" in request.POST:
  40. print('id da attivare',request.POST['enable'])
  41. idpost = request.POST['enable']
  42. u = Note.objects.get(pk=idpost)
  43. u.enabled=True
  44. u.save()
  45. value['note'] = Note.objects.all().order_by('timestamp')
  46. return render(request,"Note.List.html",value)
  47. def NoteEdit(request):
  48. session = getSessionParms(request)
  49. userauth = session['_userauth_']
  50. note2edit = session['_note2edit_']
  51. request.session['from']='Note:NoteList'
  52. utenteautorizzato = User.objects.get(pk=userauth)
  53. value={}
  54. value['utenteautorizzato'] = utenteautorizzato
  55. value['navbar'] = True
  56. print("livello autorizzazione",utenteautorizzato.securitylevel_id)
  57. securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
  58. securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
  59. securitylist = getSecurityList(securityrow)
  60. value['securitylist'] = securitylist
  61. value['securityrow'] = securityrow
  62. value['securityrowLen'] = len(securityrow)
  63. value['livello'] = SecurityLevel.objects.all().filter(enabled=True).order_by('nome')
  64. nota = Note()
  65. try:
  66. nota = Note.objects.get(pk=note2edit)
  67. except Note.DoesNotExist as dne:
  68. print('valore note2edit non valido',note2edit)
  69. if request.method == 'POST':
  70. print('metodo',request.method)
  71. # non effettua il salvataggio, ma ritorna alla lista FTP
  72. if 'Ritorno' in request.POST:
  73. return HttpResponseRedirect(reverse('Note:NoteList'))
  74. formnota = formNota(request.POST)
  75. if formnota.is_valid():
  76. print('formnota.is_valid()',formnota.is_valid())
  77. nota.soggetto=formnota.cleaned_data.get('soggetto')
  78. nota.oggetto=formnota.cleaned_data.get('oggetto')
  79. nota.timestamp=datetime.now()
  80. nota.enabled= formnota.cleaned_data.get('enabled')
  81. nota.tobedeleted = formnota.cleaned_data.get('tobedeleted')
  82. nota.livello_id = formnota.cleaned_data.get('livello')
  83. nota.save()
  84. temp = {}
  85. temp['soggetto'] = nota.soggetto
  86. temp['oggetto'] = nota.oggetto
  87. temp['timestamp'] = nota.timestamp
  88. temp['livello'] = nota.livello_id
  89. temp['enabled'] = nota.enabled
  90. temp['tobedeleted'] = nota.tobedeleted
  91. value['nota'] = formNota(temp)
  92. return render(request,'Note.Edit.html',value)
  93. def NoteView(request,nn=0):
  94. session = getSessionParms(request)
  95. userauth = session['_userauth_']
  96. request.session['from']='Note:NoteList'
  97. utenteautorizzato = User.objects.get(pk=userauth)
  98. value={}
  99. value['utenteautorizzato'] = utenteautorizzato
  100. value['navbar'] = True
  101. print("livello autorizzazione",utenteautorizzato.securitylevel_id)
  102. securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
  103. securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
  104. securitylist = getSecurityList(securityrow)
  105. value['securitylist'] = securitylist
  106. value['securityrow'] = securityrow
  107. value['securityrowLen'] = len(securityrow)
  108. value['livello'] = SecurityLevel.objects.all().filter(enabled=True).order_by('nome')
  109. nota = None
  110. note = None
  111. try:
  112. nota = Note.objects.get(pk=nn)
  113. except Note.DoesNotExist as dne:
  114. print(dne)
  115. if not nota:
  116. note = Note.objects.all().filter(livello__lte=securitylevel).order_by('timestamp')
  117. value['nota'] = nota
  118. value['note'] = note
  119. return render(request,'Note.View.html',value)