def load_database(self): self.database_config = self.app.config['DATABASE'] try: self.database_name = self.database_config.pop('name') self.database_engine = self.database_config.pop('engine') except KeyError: raise ImproperlyConfigured( 'Please specify a "name" and "engine" for your database') try: self.database_class = load_class(self.database_engine) assert issubclass(self.database_class, peewee.Database) except ImportError: raise ImproperlyConfigured('Unable to import: "%s"' % self.database_engine) except AttributeError: raise ImproperlyConfigured('Database engine not found: "%s"' % self.database_engine) except AssertionError: raise ImproperlyConfigured( 'Database engine not a subclass of peewee.Database: "%s"' % self.database_engine) self.database = self.database_class(self.database_name, **self.database_config)
def del_model(name): # 删除数据库 klass = load_class('model.' + name + '.' + name) klass.drop_table() # 删除类文件 os.remove('model/' + name.capitalize() + '.py') # 删除页面文件 for file in os.listdir('templates/' + name): os.remove('templates/' + name + '/' + file) # 删除文件夹 os.removedirs('templates/' + name)
def load_database(self): self.database_config = self.app.config['DATABASE'] try: self.database_name = self.database_config.get('name') self.database_engine = self.database_config.get('engine') except KeyError: raise ImproperlyConfigured('Please specify a "name" and "engine" for your database') try: self.database_class = load_class(self.database_engine) assert issubclass(self.database_class, peewee.Database) except ImportError: raise ImproperlyConfigured('Unable to import: "%s"' % self.database_engine) except AttributeError: raise ImproperlyConfigured('Database engine not found: "%s"' % self.database_engine) except AssertionError: raise ImproperlyConfigured('Database engine not a subclass of peewee.Database: "%s"' % self.database_engine) self.database = self.database_class(self.database_name, **self.database_config)
def view(model, id): klass = load_class('model.%s.%s' % (model.capitalize(), model.capitalize())) m = klass.get(id) return render_template('%s/%s_view.html' % (model, model), model=m)