def _refresh(self):
     self.denominazione_entry.set_text(self.dao.denominazione or '')
     self.spese_entry.set_text(str(self.dao.spese or 0))
     self.codice_entry.set_text(self.dao.codice or '')
     findComboboxRowFromStr(self.tipo_combobox, self.dao.tipo, 0)
     findComboboxRowFromId(self.id_aliquota_iva_ccb.combobox,
                           self.dao.id_aliquota_iva)
Exemple #2
0
    def on_button_login_clicked(self, button=None):
        """
        """
        #username = self.username_comboxentry.child.get_text()
        username = self.username_entry.get_text()
        password = self.password_entry.get_text()

        if username == '' or password == '':
            messageInfo(msg=_('Inserire nome utente e password'))
            return
        elif Environment.engine.name != "sqlite" and \
                findStrFromCombobox(self.azienda_combobox, 0) == '':
            messageInfo(msg=_("Occorre selezionare un'azienda"))
            return
        else:
            #if hasattr(self,"azienda_combobox"):
            self.azienda = findStrFromCombobox(self.azienda_combobox, 0)
            findComboboxRowFromStr(self.azienda_combobox, self.azienda, 0)
            self.azienda_combobox.get_active() != -1
            #if not self.azienda:
                #self.azienda = "AziendaPromo"

        #superati i check di login
        users = User().select(username=username,
                    password=hashlib.md5(username + password).hexdigest())
        if not users:
            users = User().select(username=str(username).strip())
            if users:
                try:
                    from promogest.lib.utils import AESCipher, ops
                    r = AESCipher(ops).decrypt(
                        users[0].password)
                    if r != password:
                        messageInfo(msg=_('Password errata'))

                except:
                    rows = []
        if len(users) == 1:
            if users[0].active == False:
                messageInfo(msg=_('Utente Presente Ma non ATTIVO'))
                return
            else:
                Environment.workingYear = str(self.anno_lavoro_spinbutton.get_value_as_int())
                oldSchema = Environment.params["schema"]
                Environment.azienda = self.azienda
                for a in self.azs:
                    if a.schemaa == self.azienda:
                        a.tipo_schemaa = "last"
                    else:
                        a.tipo_schemaa = ""
                    Environment.session.add(a)
                Environment.session.commit()
                if Environment.tipodb == "postgresql":
                    Environment.params["schema"] = self.azienda
                    Environment.fk_prefix = Environment.params["schema"] + '.'
                    if self.azienda not in Environment.meta._schemas:
                        print(" PICKLE NON VA BENE")
                        #Environment.azienda = oldSchema
                        Environment.delete_pickle()
                    # import pickle
                    # cachefile = 'orm.p'
                    # Environment.meta.create_all()
                    # with open(cachefile, 'w') as cache:
                    #     pickle.dump(Environment.meta, cache)
                    #     cache.close()
                # Lancio la funzione di generazione della dir di configurazione
                from promogest.buildEnv import set_configuration
                Environment.conf = set_configuration(Environment.azienda,
                                                     Environment.workingYear)
#                    if setconf("Feed","feed"):
#                    if True == True:
#                        thread = threading.Thread(target=self.feddretreive)
#                        thread.start()
#                        thread.join(2.3)

                files = glob.glob(Environment.tempDir+"/*")
                for f in files:
                    os.remove(f)
                Environment.params['usernameLoggedList'][0] = users[0].id
                Environment.params['usernameLoggedList'][1] =\
                                                 users[0].username
                try:
                    Environment.params['usernameLoggedList'][2] =\
                                                 users[0].id_role
                except:
                    Environment.params['usernameLoggedList'][2] = 1
                if hasAction(actionID=1):
                    self.login_window.hide()
                    Environment.windowGroup.remove(self.getTopLevel())
                    installId()
                    Environment.pg2log.info(
                        "LOGIN  id, user, role azienda: %s, %s" % (
                            repr(Environment.params['usernameLoggedList']),
                                 self.azienda))
                    checkInstallation()
                    from promogest.dao.Setconf import SetConf
                    avv = SetConf().select(key="avvii")
                    if avv:
                        avv[0].value = int(avv[0].value)+1
                        Environment.avvii = int(avv[0].value)+1
                        avv[0].persist()
                    Environment.settaggi = Environment.session.query(
                        SetConf.key,
                        SetConf.value).all()
                    Environment.pg2log.info(
                        "SETAGGI: %s" % (str(Environment.settaggi)))

                    self.importModulesFromDir('promogest/modules')
                    # ATTENZIONE!!! RIATTIVARE!!!
                    from promogest.dao.DaoOrderedImport import orderedImport
                    orderedImport()
                    def mainmain():
                        from Main import Main
                        main = Main(self.azienda,
                                    self.anagrafiche_modules,
                                    self.parametri_modules,
                                    self.anagrafiche_dirette_modules,
                                    self.frame_modules,
                                    self.permanent_frames)
                        main.getTopLevel().connect("destroy",
                                                   on_main_window_closed,
                                                   self.login_window)
                        main.show()
                    glib.idle_add(mainmain)

        else:
            messageInfo(msg=_('Nome utente o password errati, Riprova'))