|
@@ -5,6 +5,7 @@ from .models import *
|
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth.models import User
|
|
|
from config.views import *
|
|
from config.views import *
|
|
|
from att.views import *
|
|
from att.views import *
|
|
|
|
|
+from .forms import *
|
|
|
|
|
|
|
|
def welcome(request):
|
|
def welcome(request):
|
|
|
if not 'AdminId' in request.session:
|
|
if not 'AdminId' in request.session:
|
|
@@ -16,6 +17,8 @@ def welcome(request):
|
|
|
data['HeaderTitle'] = getConfig('HeaderTitle')
|
|
data['HeaderTitle'] = getConfig('HeaderTitle')
|
|
|
|
|
|
|
|
u = User.objects.get(pk=AdminId)
|
|
u = User.objects.get(pk=AdminId)
|
|
|
|
|
+ data['admin'] = u
|
|
|
|
|
+
|
|
|
a = Assegnazione.objects.filter(user=u.id)
|
|
a = Assegnazione.objects.filter(user=u.id)
|
|
|
print(len(a))
|
|
print(len(a))
|
|
|
tmplist = list()
|
|
tmplist = list()
|
|
@@ -31,6 +34,12 @@ def welcome(request):
|
|
|
print('premuto tast ritorno,logout')
|
|
print('premuto tast ritorno,logout')
|
|
|
return HttpResponseRedirect(reverse("login:start"))
|
|
return HttpResponseRedirect(reverse("login:start"))
|
|
|
|
|
|
|
|
|
|
+ if "sceltaazienda" in request.POST:
|
|
|
|
|
+ sceltaazienda = int(request.POST.get('sceltaazienda'))
|
|
|
|
|
+ print("sceltaazienda = ",request.POST.get('sceltaazienda'))
|
|
|
|
|
+ if sceltaazienda == 0: #richiesta una nuova azienda
|
|
|
|
|
+ return HttpResponseRedirect(reverse('azienda:edit'))
|
|
|
|
|
+
|
|
|
if "utenti" in request.POST:
|
|
if "utenti" in request.POST:
|
|
|
print('premuto tasto utenti')
|
|
print('premuto tasto utenti')
|
|
|
# stato premuto il tasto, tocca recuperare l'id
|
|
# stato premuto il tasto, tocca recuperare l'id
|
|
@@ -67,4 +76,41 @@ def welcome(request):
|
|
|
|
|
|
|
|
return render(request,'azienda.welcome.html',data)
|
|
return render(request,'azienda.welcome.html',data)
|
|
|
|
|
|
|
|
|
|
+def edit(request):
|
|
|
|
|
+ AdminId = request.session['AdminId']
|
|
|
|
|
+
|
|
|
|
|
+ data={}
|
|
|
|
|
+ data['HeaderTitle'] = getConfig('HeaderTitle')
|
|
|
|
|
+ data['admin' ] = User.objects.get(pk=AdminId)
|
|
|
|
|
+
|
|
|
|
|
+ if request.method == "POST":
|
|
|
|
|
+ print("Richiesta creazione nuova azienda")
|
|
|
|
|
+ nuovaazienda = formAzienda(request.POST)
|
|
|
|
|
+ if nuovaazienda.is_valid():
|
|
|
|
|
+ print("il form e' valido",request.POST)
|
|
|
|
|
+ azienda = Azienda()
|
|
|
|
|
+ azienda.nome = nuovaazienda.cleaned_data.get('nome')
|
|
|
|
|
+ azienda.mail = nuovaazienda.cleaned_data.get('mail')
|
|
|
|
|
+ azienda.partitaiva = nuovaazienda.cleaned_data.get('partitaiva')
|
|
|
|
|
+ azienda.save()
|
|
|
|
|
+ request.session['aziendaId'] = azienda.id
|
|
|
|
|
+ assegnazione = Assegnazione()
|
|
|
|
|
+ assegnazione.azienda=azienda
|
|
|
|
|
+ assegnazione.utente=User.objects.get(pk=AdminId)
|
|
|
|
|
+ assegnazione.save()
|
|
|
|
|
+ return HttpResponseRedirect(reverse('azienda:welcome'))
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("form non valido")
|
|
|
|
|
+ data['azienda'] = formAzienda(request.POST)
|
|
|
|
|
+
|
|
|
|
|
+ else: #non è un post
|
|
|
|
|
+ print("Non è un post")
|
|
|
|
|
+ formAziendaField = formAzienda()
|
|
|
|
|
+ data['azienda'] = formAziendaField
|
|
|
|
|
+
|
|
|
|
|
+ return render(request,'azienda.edit.html',data)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|