def get(self, *args, **kwargs): self.errors = [] # перезагружаем конфигурацию приложения self.application.loadConfiguration() self.removeDBSessions() # миграция БД password = None try: connection = self.getDBSession() migrate(connection = connection) except BaseException as exception: self.errors.append(u'Ошибка при миграции БД: ' + exception.message) else: # create admin user password = hashlib.sha256(str(time.time())).hexdigest()[5:11] user = User() user.fullname = 'Admin' user.login = '******' user.password = hashlib.sha256(password).hexdigest() user.role = User.ROLE_ADMIN try: connection.merge(user) connection.commit() except BaseException as exception: self.errors.append(u'Ошибка при создани пользователя: ' + exception.message) else: self.application.isInstalled = True self.render('install/end.jinja2', {'errors': self.errors, 'admin_pass': password})
def run(self): print 'start DB migrate' try: DBSession = self.getDBSession() except OperationalError as op_error: print u'Ошибка соединения с MySQL: ' + op_error.message except BaseException as ex: print u'Исключение SQLALCHEMY: ' + ex.message else: dbutils.migrate(connection = DBSession)