def grabarBD(self): # comprueba si existe el órgano. Si es así lee el Id, si no... lo crea try: idOrgano= PceOrgano.get(PceOrgano.descripcion==self.organo).id_organo except PceOrgano.DoesNotExist: organo = PceOrgano.create(descripcion = self.organo, url = self.organoURL ) idOrgano= organo.id_organo # Se comprueba si existe ya una licitación con el id, si no se crea try: descLicitacion = PceExpediente.get(PceExpediente.id_licitacion ==self.id_licitacion).desc_expediente# # print("licitacion ",self.id_licitacion,"-",self.num_expediente ,"ya existe con descripcion: ",descLicitacion) # print("La nueva descripcion seria: ",self.desc_expediente) return "Licitacion "+str(self.id_licitacion)+"-"+str(self.num_expediente) +" ya existe" except PceExpediente.DoesNotExist: expedienteBD= PceExpediente.create(desc_expediente = self.desc_expediente, num_expediente = self.num_expediente, estado = self.estado, id_organo = idOrgano, importe_base = self.importe, tipo_contrato_1 = self.tiposContrato[0], tipo_contrato_2 = self.tiposContrato[1], id_ministerio = self.ministry, id_licitacion=self.id_licitacion ) # nexp = expedienteBD.save() # recorre las fechas y las graba en la tabla de fechas # ATENCION, se leen fechas solo para las nuevas ---> MAL, tiene que haber nuevas fehcas!!! # for tipoFecha in self.Fecha.iterkeys(): for tipoFecha in self.Fecha.keys(): fechaBD = PceFecha.create(fecha = self.Fecha[tipoFecha], id_licitacion = self.id_licitacion, tipo_fecha = tipoFecha ) # print(self.id_licitacion,":",tipoFecha,"-", self.Fecha[tipoFecha]) # return nexp return ""