def register_model(model: str, cls, menu_title: str = None, menu_weight: int = 0, menu_icon: str = 'fa fas fa-tags', menu_sid: str = 'taxonomy', menu_roles: Union[str, list, tuple] = ('admin', 'dev'), menu_permissions: Union[str, list, tuple] = None): """Register a taxonomy model """ if model in _models: raise RuntimeError( "Taxonomy model '{}' is already registered".format(model)) if isinstance(cls, str): cls = util.get_module_attr(cls) if not issubclass(cls, Term): raise TypeError('Subclass of {} expected'.format(Term)) odm.register_model(model, cls) _models.append(model) if reg.get('env.type') == 'wsgi' and menu_title: menu_url = router.rule_path('odm_ui@admin_browse', {'model': model}) admin.sidebar.add_menu( menu_sid, model, menu_title, menu_url, menu_icon, weight=menu_weight, roles=menu_roles, permissions=menu_permissions, )
def register_model(model: str, cls: Union[str, ContentModelClass], title: str, menu_weight: int = 0, menu_icon: str = 'fa fa-file-text-o', menu_sid: str = 'content', replace: bool = False): """Register content model """ # Resolve class if isinstance(cls, str): cls = util.get_module_attr(cls) # type: ContentModelClass if not issubclass(cls, Content): raise TypeError('Subclass of {} expected, got {}'.format(Content, type(cls))) if not replace and is_model_registered(model): raise KeyError("Content model '{}' is already registered".format(model)) # Register ODM model odm.register_model(model, cls, replace) # Saving info about registered _content_ model _models[model] = (cls, title) if reg.get('env.type') == 'wsgi': mock = dispense(model) perms = ['odm_auth@{}.{}'.format(p, model) for p in mock.odm_auth_permissions()], admin.sidebar.add_menu( sid=menu_sid, mid=model, title=title, path=router.rule_path('odm_ui@admin_browse', {'model': model}), icon=menu_icon, weight=menu_weight, permissions=perms, replace=replace, )
def plugin_load(): from plugins import odm from . import _model # ODM models odm.register_model('content_digest_subscriber', _model.ContentDigestSubscriber)
def plugin_load(): from pytsite import reg from plugins import odm from . import _api, _model, _frm, _driver # ODM models odm.register_model('setting', _model.Setting) # Registry driver reg.set_driver(_driver.Registry(reg.get_driver()))
def plugin_load(): """Hook """ from pytsite import events from plugins import comments, odm from . import _model, _driver, _eh # Register ODM model odm.register_model('comment', _model.ODMComment) # Register comments driver comments.register_driver(_driver.ODM()) events.listen('comments@report_comment', _eh.comments_report_comment)
def plugin_load(): from pytsite import router, cleanup from plugins import odm from . import _model, _controllers, _eh # Register ODM models odm.register_model('file', _model.AnyFileODMEntity) odm.register_model('file_image', _model.ImageFileODMEntity) router.handle( _controllers.Image, '/image/resize/<int:width>/<int:height>/<p1>/<p2>/<filename>', 'file_storage_odm@image', defaults={ 'width': 0, 'height': 0 }) cleanup.on_cleanup(_eh.pytsite_cleanup)
def plugin_load(): from pytsite import lang, events from plugins import permissions, odm from . import _model, _api, _driver, _eh # Resources lang.register_package(__name__) # Permissions permissions.define_group('content_import', 'content_import@content_import') # ODM models odm.register_model('content_import', _model.ContentImport) # Event handlers events.listen('[email protected]_fields', _eh.odm_model_setup_fields) events.listen('[email protected]_indexes', _eh.odm_model_setup_indexes) # RSS import driver _api.register_driver(_driver.RSS())
def plugin_load(): from pytsite import reg, util from plugins import auth, odm from . import _driver # ODM models role_cls = reg.get('auth_storage_odm.role_odm_class', 'plugins.auth_storage_odm.ODMRole') user_cls = reg.get('auth_storage_odm.user_odm_class', 'plugins.auth_storage_odm.ODMUser') odm.register_model('role', util.get_module_attr(role_cls)) odm.register_model('user', util.get_module_attr(user_cls)) odm.register_model('follower', ODMFollower) odm.register_model('blocked_user', ODMBlockedUser) # Register storage driver auth.register_storage_driver(_driver.Storage())