def delete(self): """ Rimuove il cliente """ if hasattr(self, "TD") and len(self.TD) > 0: self.cancellato = True session.add(self) else: if self.id_user: utente = User().getRecord(id=self.id_user) if utente: utente.delete() if posso("IP"): from promogest.modules.InfoPeso.dao.TestataInfoPeso import\ TestataInfoPeso from promogest.modules.InfoPeso.dao.ClienteGeneralita import\ ClienteGeneralita cltip = TestataInfoPeso().select(idCliente=self.id, batchSize=None) if cltip: for l in cltip: l.delete() clcg = ClienteGeneralita().select(idCliente=self.id, batchSize=None) if clcg: for l in clcg: l.delete() session.delete(self) session.commit()
def setDao(self, dao, from_other_dao=None): self.from_other_dao = from_other_dao if dao is None: # Crea un nuovo Dao vuoto self.dao = User() self.aggiornamento=False else: self.dao = User().getRecord(id=dao.id) self.aggiornamento=True self._refresh()
class AnagraficaUtentiEdit(AnagraficaEdit): """ Modifica un record dell'anagrafica degli utenti """ def __init__(self, anagrafica): AnagraficaEdit.__init__(self, anagrafica, 'Dati Utente', root='anagrafica_utenti_detail_table', path='RuoliAzioni/gui/_anagrafica_utenti_elements.glade', isModule=True) self.imgblob = None self._widgetFirstFocus = self.username_entry def draw(self, cplx=False): #Popola combobox tipi utenti fillComboboxRole(self.id_role_combobox) fillComboboxLang(self.id_language_combobox) azs = Azienda().select(batchSize = None, orderBy=Azienda.schemaa) for a in azs: self.azienda_listore.append((a.schemaa,)) self.azienda_combobox.set_model(self.azienda_listore) def setDao(self, dao, from_other_dao=None): self.from_other_dao = from_other_dao if dao is None: # Crea un nuovo Dao vuoto self.dao = User() self.aggiornamento=False else: self.dao = User().getRecord(id=dao.id) self.aggiornamento=True self._refresh() def _refresh(self): self.username_entry.set_text(self.dao.username or '') # if self.aggiornamento: # self.username_entry.set_sensitive(False) if self.dao.tipo_user =="PLAIN": self.password_entry.set_text(self.dao.password) self.confirm_password_entry.set_text(self.dao.password) self.password_entry.set_visibility(True) self.confirm_password_entry.set_visibility(True) else: self.password_entry.set_text('') self.confirm_password_entry.set_text('') self.email_entry.set_text(self.dao.email or '') self.url_entry.set_text(self.dao.photo_src or '') act = 0 if self.dao.active: act = 1 self.active_user_checkbutton.set_active(act) findComboboxRowFromId(self.id_role_combobox, self.dao.id_role) findComboboxRowFromStr(self.azienda_combobox, self.dao.schemaa_azienda,0) self.data_registrazione_label.set_text(dateToString(self.dao.registration_date)) self.ultima_modifica_label.set_text(dateToString(self.dao.last_modified)) if self.dao.id: imgBlobb = UtenteImmagine().select(idUtente = self.dao.id) if imgBlobb: try: img = ImageFile().getRecord(id=imgBlobb[0].id_immagine) fingerprint =Environment.CACHE+"/"+img.fingerprint f = open(fingerprint, "w") f.write(b64decode(img.data)) f.close() self.userlogo_image.set_from_file(fingerprint) except: self.userlogo_image.set_from_file("") # ----- Per il momento non è utilizzato ma andrà ripristinato # ---- il prima possibile # findComboboxRowFromId(self.id_language_combobox, self.dao.id_language) def saveDao(self, tipo=None): if (self.username_entry.get_text() == ''): obligatoryField(self.dialogTopLevel, self.username_entry, campo="Username") if (self.email_entry.get_text() == ''): obligatoryField(self.dialogTopLevel, self.email_entry, campo="Email") if (self.password_entry.get_text() == '') and not self.aggiornamento: obligatoryField(self.dialogTopLevel, self.password_entry, campo="Password") if (findIdFromCombobox(self.id_role_combobox) is None): obligatoryField(self.dialogTopLevel, self.id_role_combobox, campo="Ruolo") username = self.username_entry.get_text() password = self.password_entry.get_text() confirm_passowrd = self.confirm_password_entry.get_text() if password != confirm_passowrd: messageInfo(msg='Le due Password non corrispondono !!!') return passwordmd5 = hashlib.md5(username + str(password)).hexdigest() self.dao.username = username if (self.password_entry.get_text() != '') or (self.password_entry.get_text() != '' and self.aggiornamento): if self.dao.tipo_user =="PLAIN": self.dao.password = self.password_entry.get_text() else: self.dao.password = passwordmd5 self.dao.email = self.email_entry.get_text() self.dao.photo_src = self.url_entry.get_text() self.dao.id_role = findIdFromCombobox(self.id_role_combobox) self.dao.schemaa_azienda = findStrFromCombobox(self.azienda_combobox,0) or None self.dao.last_modified = datetime.datetime.now() # self.dao.id_language = findIdFromCombobox(self.id_language_combobox) self.dao.active = self.active_user_checkbutton.get_active() if not self.aggiornamento: self.dao.registration_date = datetime.datetime.now() self.dao.persist() if self.from_other_dao: self.from_other_dao.id_user = self.dao.id #self.from_other_dao.id_user.persist() if self.imgblob: idutente = self.dao.id a = UtenteImmagine().select(idUtente=self.dao.id) if a: a=a[0] img = ImageFile().getRecord(id=a.id_immagine) else: a= UtenteImmagine() img = ImageFile() img.denominazione = "nessuno" #img.altezza img.larghezza = 200 img.fingerprint = hashlib.md5(self.imgblob).hexdigest() img.data = self.imgblob img.persist() a.id_utente = self.dao.id a.id_immagine = img.id a.persist() def on_rimuovi_foto_button_clicked(self, button): self.imgblob = "RIMUOVO" self.userlogo_image.set_from_file("") def on_filechooserbutton1_file_set(self, filechooser): #import StringIO #output = StringIO.StringIO() #image.save(output) #contents = output.getvalue() #output.close() print "LA FOTO SELEZIONATA", filechooser.get_file().get_path(), filechooser.get_file() size = 200, 200 self.photo_src= filechooser.get_filename() self.userlogo_image.set_from_file(self.photo_src) #im1 = Image.fromstring(self.photo_src) f = open(self.photo_src, "r") g = f.read() #im = Image.open(g) #im.thumbnail(size, Image.ANTIALIAS) #im.tostring(self.photo_src + ".thumbnail) self.imgblob = base64.b64encode(str(g)) f.close()