def ProtagonistaEvent(request): global protaform if request.method == 'POST' or bool(protaform): if request.method == 'POST': protaform = NomDataForm(request.POST) protaform.is_valid() fdict = {} try: fdict = protaform.cleaned_data except: print('Error al cleaned data Protagonista') consultaB = "SELECT * from baptisme natural join event_taula" #Comencem a crear la consulta consultaM = "SELECT * from matrimoni natural join event_taula" consultaO = "SELECT * from obituari natural join event_taula" Buit = True for e in fdict: if fdict[e]!='-' and fdict[e]!='': consultaB += " WHERE";consultaM += " WHERE";consultaO += " WHERE" Buit = False break consultaB,_= Assistant.AddParameters(fdict,consultaB) consultaO,_= Assistant.AddParameters(fdict,consultaO) consultaM, newform = Assistant.AddParametersMatrimoni(fdict,consultaM) Btable = [] if not Buit: Btable = Assistant.getTable(consultaB,'Baptisme') tableB = BatejatTable(Btable) RequestConfig(request).configure(tableB) tableB.paginate(page = request.GET.get('page',1),per_page=10) Mtable = [] if not Buit: Mtable = Assistant.getTable(consultaM,'Matrimoni') tableM = MatrimoniTable(Mtable) RequestConfig(request).configure(tableM) tableM.paginate(page = request.GET.get('page',1),per_page=10) Otable = [] if not Buit: Otable = Assistant.getTable(consultaO,'Obituari') tableO = ObituariTable(Otable) RequestConfig(request).configure(tableO) tableO.paginate(page = request.GET.get('page',1),per_page=10) protaform = NomDataForm(newform) context = {'baptismes': tableB, 'matrimoni':tableM,'obituari':tableO,'form':protaform} render(request,'tfg/general_protagonista.html',context) else: protaform = NomDataForm() tableB = BatejatTable([]) tableM = MatrimoniTable([]) tableO = ObituariTable([]) context = {'baptismes': tableB, 'matrimoni':tableM,'obituari':tableO,'form':protaform} return render(request,'tfg/general_protagonista.html',context)
def ParticipantEvent(request): global pform if request.method == 'POST' or bool(pform): if request.method == 'POST': pform = NomDataForm(request.POST) pform.is_valid() fdict = {} try: fdict = pform.cleaned_data except: print('Error al cleaned data Participant') consulta = "SELECT * from participant natural join event_taula" Buit = True for e in fdict: if fdict[e]!='-' and fdict[e]!='': consulta += " WHERE" Buit = False break consulta,newform = Assistant.AddParameters(fdict,consulta) if not Buit: partable = Assistant.getTable(consulta,'Participant') else: partable = [] table = ParticipantTable(partable) RequestConfig(request).configure(table) table.paginate(page = request.GET.get('page',1),per_page=50) pform = NomDataForm(newform) context = {'participant':table,'form':pform} render(request,'tfg/general_participant.html',context) else: pform = NomDataForm() table = ParticipantTable([]) context = {'participant':table,'form':pform} return render(request,'tfg/general_participant.html',context)
def vida(request): global vidaform if request.method == 'POST' or bool(vidaform): if request.method == 'POST': vidaform = NomDataForm(request.POST) vidaform.is_valid() fdict = {} try: fdict = vidaform.cleaned_data except: print('Error al cleaned data vida') consultaB = "";consultaM = "";consultaO = "";consultaP = "" Buit = True for e in fdict: if fdict[e]!='-' and fdict[e]!='': consultaB = "select * from baptisme natural join event_taula WHERE " consultaM = "select * from matrimoni natural join event_taula WHERE " consultaO = "select * from obituari natural join event_taula WHERE " consultaP = "select * from participant natural join event_taula WHERE " Buit = False break consultaB,_= Assistant.AddParameters(fdict,consultaB) consultaO,_= Assistant.AddParameters(fdict,consultaO) consultaM,_ = Assistant.AddParametersMatrimoni(fdict,consultaM) consultaP,newform = Assistant.AddParameters(fdict,consultaP) # newform = dict(list(newform1.items()) + list(newformData.items())) tableB=[];tableM=[];tableO=[];tableP=[] if not Buit: tableB = Assistant.getTable(consultaB,'Baptisme') tableM = Assistant.getTable(consultaM,'Matrimoni') tableO = Assistant.getTable(consultaO,'Obituari') tableP = Assistant.getTable(consultaP,'Participant') vides = Assistant.getVides(tableB,tableM,tableO,tableP) vidaform = NomDataForm(newform) context = {'form':vidaform,'vides':vides} return render(request,'tfg/general_vida.html',context) else: vidaform = NomDataForm() vides = [] context = {'form':vidaform,'vides':vides} return render(request,'tfg/general_vida.html',context)
def Obituaris(request): global oform url = request.build_absolute_uri() if request.method == 'POST' or 'cerca-obituaris' in url: if request.method == 'POST': oform = NomDataForm(request.POST) oform.is_valid() fdict = oform.cleaned_data consulta = "SELECT * from obituari natural join event_taula" #Comencem a crear la consulta Buit = True for e in fdict: if fdict[e]!='-' and fdict[e]!='': consulta += " WHERE" Buit = False break consulta,newform = Assistant.AddParameters(fdict,consulta) if not Buit: Otable = Assistant.getTable(consulta,'Obituari') else: Otable = [] tableO = ObituariTable(Otable) RequestConfig(request).configure(tableO) tableO.paginate(page = request.GET.get('page',1),per_page=20) oform = NomDataForm(newform) context = {'obituaris': tableO,'form': oform} return render(request,'tfg/base_obituaris.html',context) else: arxiutable = [] with connection.cursor() as cursor: cursor.execute("SELECT * from arxiu where nom_llibre LIKE 'O%'") arxius = cursor.fetchall() for a in arxius: arxiutable.append({'Arxiu':a[0],'Nom_Parroquia':a[1], 'Persona_B':a[2],'Persona_R':a[3]}) table = ArxiuTable(arxiutable) RequestConfig(request).configure(table) table.paginate(page = request.GET.get('page',1),per_page=25) oform = NomDataForm() context = {'obituaris': table, 'form': oform} return render(request,'tfg/base_obituaris.html',context)
def Matrimonis(request): global mform url = request.build_absolute_uri() if request.method == 'POST' or 'cerca-matrimonis' in url: if request.method == 'POST': mform = NomDataForm(request.POST) mform.is_valid() fdict = mform.cleaned_data consulta = "SELECT * from matrimoni natural join event_taula" #Comencem a crear la consulta for e in fdict: if fdict[e]!='-' and fdict[e]!='': consulta += " WHERE" break consulta,newform = Assistant.AddParametersMatrimoni(fdict,consulta) Mtable = Assistant.getTable(consulta,'Matrimoni') tableM = MatrimoniTable(Mtable) RequestConfig(request).configure(tableM) tableM.paginate(page = request.GET.get('page',1),per_page=20) mform = NomDataForm(newform) context = {'matrimonis': tableM,'form': mform} return render(request,'tfg/base_matrimonis.html',context) else: arxiutable = [] with connection.cursor() as cursor: cursor.execute("SELECT * from arxiu where nom_llibre LIKE 'M%'") arxius = cursor.fetchall() for a in arxius: arxiutable.append({'Arxiu':a[0],'Nom_Parroquia':a[1], 'Persona_B':a[2],'Persona_R':a[3]}) table = ArxiuTable(arxiutable) RequestConfig(request).configure(table) table.paginate(page = request.GET.get('page',1),per_page=25) mform = NomDataForm() context = {'matrimonis': table, 'form': mform} return render(request,'tfg/base_matrimonis.html',context)