| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- from django.shortcuts import render
- from sicurezza.views import *
- from .forms import *
- from .models import *
- from datetime import datetime
- # Create your views here.
- def NoteList(request):
- session = getSessionParms(request)
- userauth = session['_userauth_']
- note2edit = session['_note2edit_']
- request.session['from']='Note:NoteList'
- utenteautorizzato = User.objects.get(pk=userauth)
- value={}
- value['utenteautorizzato'] = utenteautorizzato
- value['navbar'] = True
- print("livello autorizzazione",utenteautorizzato.securitylevel_id)
- securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
- securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
- securitylist = getSecurityList(securityrow)
- value['securitylist'] = securitylist
- value['securityrow'] = securityrow
- value['securityrowLen'] = len(securityrow)
- if request.method=="POST":
- if "Nuova Nota" in request.POST:
- print('nuova nota')
- request.session['_note2edit_'] = 0
- return HttpResponseRedirect(reverse('Note:NoteEdit',args={}))
- if "edit" in request.POST:
- print('id da editare',request.POST['edit'])
- request.session['_note2edit_'] = request.POST['edit']
- return HttpResponseRedirect(reverse('Note:NoteEdit',args={}))
- if "disable" in request.POST :
- print('id da disattivare',request.POST['disable'])
- idpost = request.POST['disable']
- u = Note.objects.get(pk=idpost)
- if not u.locked:
- u.enabled=False
- u.save()
- if "enable" in request.POST:
- print('id da attivare',request.POST['enable'])
- idpost = request.POST['enable']
- u = Note.objects.get(pk=idpost)
- u.enabled=True
- u.save()
- value['note'] = Note.objects.all().order_by('timestamp')
- return render(request,"Note.List.html",value)
- def NoteEdit(request):
- session = getSessionParms(request)
- userauth = session['_userauth_']
- note2edit = session['_note2edit_']
- request.session['from']='Note:NoteList'
- utenteautorizzato = User.objects.get(pk=userauth)
- value={}
- value['utenteautorizzato'] = utenteautorizzato
- value['navbar'] = True
- print("livello autorizzazione",utenteautorizzato.securitylevel_id)
- securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
- securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
- securitylist = getSecurityList(securityrow)
- value['securitylist'] = securitylist
- value['securityrow'] = securityrow
- value['securityrowLen'] = len(securityrow)
- value['livello'] = SecurityLevel.objects.all().filter(enabled=True).order_by('nome')
- nota = Note()
- try:
- nota = Note.objects.get(pk=note2edit)
- except Note.DoesNotExist as dne:
- print('valore note2edit non valido',note2edit)
- if request.method == 'POST':
- print('metodo',request.method)
- # non effettua il salvataggio, ma ritorna alla lista FTP
- if 'Ritorno' in request.POST:
- return HttpResponseRedirect(reverse('Note:NoteList'))
- formnota = formNota(request.POST)
- if formnota.is_valid():
- print('formnota.is_valid()',formnota.is_valid())
- nota.soggetto=formnota.cleaned_data.get('soggetto')
- nota.oggetto=formnota.cleaned_data.get('oggetto')
- nota.timestamp=datetime.now()
- nota.enabled= formnota.cleaned_data.get('enabled')
- nota.tobedeleted = formnota.cleaned_data.get('tobedeleted')
- nota.livello_id = formnota.cleaned_data.get('livello')
- nota.save()
- temp = {}
- temp['soggetto'] = nota.soggetto
- temp['oggetto'] = nota.oggetto
- temp['timestamp'] = nota.timestamp
- temp['livello'] = nota.livello_id
- temp['enabled'] = nota.enabled
- temp['tobedeleted'] = nota.tobedeleted
- value['nota'] = formNota(temp)
- return render(request,'Note.Edit.html',value)
- def NoteView(request,nn=0):
- session = getSessionParms(request)
- userauth = session['_userauth_']
- request.session['from']='Note:NoteList'
- utenteautorizzato = User.objects.get(pk=userauth)
- value={}
- value['utenteautorizzato'] = utenteautorizzato
- value['navbar'] = True
- print("livello autorizzazione",utenteautorizzato.securitylevel_id)
- securitylevel = getSecurityLevel(utenteautorizzato.securitylevel_id)
- securityrow = getSecurityRow(utenteautorizzato.securitylevel_id)
- securitylist = getSecurityList(securityrow)
- value['securitylist'] = securitylist
- value['securityrow'] = securityrow
- value['securityrowLen'] = len(securityrow)
- value['livello'] = SecurityLevel.objects.all().filter(enabled=True).order_by('nome')
- nota = None
- note = None
- try:
- nota = Note.objects.get(pk=nn)
- except Note.DoesNotExist as dne:
- print(dne)
- if not nota:
- note = Note.objects.all().filter(livello__lte=securitylevel).order_by('timestamp')
- value['nota'] = nota
- value['note'] = note
- return render(request,'Note.View.html',value)
|