def sv_reflection_navbar_modules(context): """Get a list of subapps for the navbar""" key = 'sv_reflection_navbar_modules_%s' % get_key_unique(context) if not cache.get(key): app_list = [] for app in get_apps(): LOGGER.debug("Considering %s for Navbar", app.label) title = app.title_modifier(context.request) if app.navbar_enabled(context.request): index = getattr(app, 'index', None) if not index: index = '%s:index' % app.label try: reverse(index) LOGGER.debug("Module %s made it with '%s'", app.name, index) app_list.append({ 'label': app.label, 'title': title, 'index': index }) except NoReverseMatch: LOGGER.debug("View '%s' not reversable, ignoring %s", index, app.name) sorted_list = sorted(app_list, key=lambda x: x.get('label')) cache.set(key, sorted_list, 1000) return sorted_list return cache.get(key) # pragma: no cover
def ifapp(*args): """Return whether a navbar link is active or not.""" app_cache = [app.label for app in get_apps(exclude=[])] for app_label in args: if app_label in app_cache: return True return False
def get_app_labels(): """Cache all installed apps and return the list""" cache_key = 'ifapp_apps' if not cache.get(cache_key): # Make a list of all short names for all apps app_cache = [] for app in get_apps(): app_cache.append(app.label) cache.set(cache_key, app_cache, 1000) return app_cache return cache.get(cache_key) # pragma: no cover
def remap_results( self, results: Dict[callable, SearchResult]) -> Dict[str, SearchResult]: """Convert handler_functions to app_label""" re_mapped = {} app_labels = [app.label for app in get_apps(exclude=[])] for app_handler, app_results in results: for app_label in app_labels: if app_handler.__module__.replace('.', '_').startswith(app_label): # Get AppConfig so we can get App's `verbose_name` app_config = apps.get_app_config(app_label) label = app_config.verbose_name if app_results: re_mapped[label] = app_results return OrderedDict(sorted(re_mapped.items()))
def sv_reflection_admin_modules(context): """Get a list of all modules and their admin page""" key = 'sv_reflection_admin_modules_%s' % get_key_unique(context) if not cache.get(key): view_list = [] for app in get_apps(): title = app.title_modifier(context.request) url = app.admin_url_name view_list.append({ 'url': url, 'default': url == SupervisrAppConfig.admin_url_name, 'name': title, }) sorted_list = sorted(view_list, key=lambda x: x.get('name')) cache.set(key, sorted_list, 1000) return sorted_list return cache.get(key) # pragma: no cover
def sv_reflection_user_modules(context): """Get a list of modules that have custom user settings""" key = 'sv_reflection_user_modules_%s' % get_key_unique(context) if not cache.get(key): app_list = [] for app in get_apps(): if not app.name.startswith('supervisr'): continue view = app.view_user_settings if view is not None: app_list.append({ 'title': app.title_modifier(context.request), 'view': '%s:%s' % (app.label, view) }) sorted_list = sorted(app_list, key=lambda x: x.get('title')) cache.set(key, sorted_list, 1000) return sorted_list return cache.get(key) # pragma: no cover
def makemessages(ctx, locale='en'): """Create .po files for every supervisr app""" setup() from django.core.management.commands.makemessages import Command from supervisr.core.utils import get_apps, LogOutputWrapper # Returns list of app starting with supervisr for app in get_apps(exclude=[]): # Get apps.py file from class app_file = inspect.getfile(app.__class__) # Get app basedir and change to it app_basedir = os.path.dirname(app_file) os.chdir(app_basedir) # Create locale dir in case it doesnt exist os.makedirs('locale', exist_ok=True) LOGGER.info("Building %s", app.__class__.__name__) builder = Command(stdout=LogOutputWrapper()) builder.handle( verbosity=1, settings=None, pythonpath=None, traceback=None, no_color=False, locale=locale.split(','), exclude=[], domain='django', all=False, extensions=None, symlinks=False, ignore_patterns=[], use_default_ignore_patterns=True, no_wrap=False, no_location=False, add_location=None, no_obsolete=False, keep_pot=False, )
for _count in range(len(mod_parts) - 1, 0, -1): path = '.'.join(mod_parts[:-_count]) if not importlib.util.find_spec(path): LOGGER.debug( "Didn't find module '%s', not importing URLs from it.", path) return [] if importlib.util.find_spec(module) is not None: LOGGER.debug("Loaded %s (namespace=%s)", module, namespace) return [ url(mount_path, include((module, namespace), namespace=namespace)), ] return [] # Load Urls for all sub apps for app in get_apps(): # API namespace is always generated automatically api_namespace = '_'.join(app.name.split('_') + ['api']) # remove `supervisr/` for mountpath and replace _ with / mount_path = app.label.replace('supervisr_', '').replace('_', '/') # Only add if module could be loaded urlpatterns += get_patterns(r"^app/%s/" % mount_path, "%s.urls" % app.name, app.label) if django_settings.DEBUG: import debug_toolbar urlpatterns += [ url(r'^__debug__/', include(debug_toolbar.urls)), ] urlpatterns += static(django_settings.MEDIA_URL,
def _init_allowed(): from supervisr.core.utils import get_apps Setting.__ALLOWED_NAMESPACES = [x.name for x in get_apps(exclude=[])]