def __init__(self, model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None): """ Constructor. :param model: Model class :param session: SQLAlchemy session :param name: View name. If not set, defaults to the model name :param category: Category name :param endpoint: Endpoint name. If not set, defaults to the model name :param url: Base URL. If not set, defaults to '/admin/' + endpoint :param menu_class_name: Optional class name for the menu item. :param menu_icon_type: Optional icon. Possible icon types: - `flask_admin.consts.ICON_TYPE_GLYPH` - Bootstrap glyph icon - `flask_admin.consts.ICON_TYPE_FONT_AWESOME` - Font Awesome icon - `flask_admin.consts.ICON_TYPE_IMAGE` - Image relative to Flask static directory - `flask_admin.consts.ICON_TYPE_IMAGE_URL` - Image with full URL :param menu_icon_value: Icon glyph name or URL, depending on `menu_icon_type` setting """ self.session = session self._search_fields = None self._filter_joins = dict() self._sortable_joins = dict() if self.form_choices is None: self.form_choices = {} super(ModelView, self).__init__(model, name, category, endpoint, url, static_folder, menu_class_name=menu_class_name, menu_icon_type=menu_icon_type, menu_icon_value=menu_icon_value) self._manager = manager_of_class(self.model) # Primary key self._primary_key = self.scaffold_pk() if self._primary_key is None: raise Exception('Model %s does not have primary key.' % self.model.__name__) # Configuration if not self.column_select_related_list: self._auto_joins = self.scaffold_auto_joins() else: self._auto_joins = self.column_select_related_list
def __init__(self, model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None): """ Constructor. :param model: Model class :param session: SQLAlchemy session :param name: View name. If not set, defaults to the model name :param category: Category name :param endpoint: Endpoint name. If not set, defaults to the model name :param url: Base URL. If not set, defaults to '/admin/' + endpoint :param menu_class_name: Optional class name for the menu item. :param menu_icon_type: Optional icon. Possible icon types: - `flask_admin.consts.ICON_TYPE_GLYPH` - Bootstrap glyph icon - `flask_admin.consts.ICON_TYPE_FONT_AWESOME` - Font Awesome icon - `flask_admin.consts.ICON_TYPE_IMAGE` - Image relative to Flask static directory - `flask_admin.consts.ICON_TYPE_IMAGE_URL` - Image with full URL :param menu_icon_value: Icon glyph name or URL, depending on `menu_icon_type` setting """ self.session = session self._search_fields = None self._filter_joins = dict() self._sortable_joins = dict() if self.form_choices is None: self.form_choices = {} super(ModelView, self).__init__(model, name, category, endpoint, url, static_folder, menu_class_name=menu_class_name, menu_icon_type=menu_icon_type, menu_icon_value=menu_icon_value) self._manager = manager_of_class(self.model) # Primary key self._primary_key = self.scaffold_pk() if self._primary_key is None: raise Exception('Model %s does not have primary key.' % self.model.__name__) # Configuration if not self.column_select_related_list: self._auto_joins = self.scaffold_auto_joins() else: self._auto_joins = self.column_select_related_list
def register_descriptor(class_, key, comparator=None, parententity=None, doc=None, relationship_field=None): manager = base.manager_of_class(class_) descriptor = relationship_field.InstrumentedAttribute( class_, key, comparator=comparator, parententity=parententity, relationship_field=relationship_field) descriptor.__doc__ = doc manager.instrument_attribute(key, descriptor) return descriptor
def register_descriptor(class_, key, comparator=None, parententity=None, doc=None, relationship_field=None): manager = base.manager_of_class(class_) descriptor = relationship_field.InstrumentedAttribute( class_, key, comparator=comparator, parententity=parententity, relationship_field=relationship_field) descriptor.__doc__ = doc manager.instrument_attribute(key, descriptor) return descriptor
def __init__(self, session, identities, cls, key=None): self._session = session self._cls = cls self._identities = identities if isinstance(key, basestring): manager = manager_of_class(cls) self._key = manager[key] elif key is None: mapper = class_mapper(cls) primary_keys = mapper.primary_key assert len(primary_keys) == 1 self._key = primary_keys[0] else: self._key = key
def is_sa_mapped_class(class_: type) -> bool: """ Tell whether the object is an class mapped by SqlAlchemy, declarative or not """ return manager_of_class(class_) is not None