ソースを参照

petites modifs

fanch 1 年間 前
コミット
8e3ee479e7

+ 1 - 1
setup.py

@@ -29,7 +29,7 @@ def get_files(path):
 
 setup(
     name="djangotools",
-    version="0.2.1",
+    version="0.2.2",
     description="A short description of the project.",
     author="François GAUTRAIS",
     install_requires=install_requires,

+ 8 - 1
src/djangotools/apps.py

@@ -5,7 +5,14 @@ import datetime
 from django.conf import settings
 
 from djangotools.common import iter_module
+from djangotools import config
 
+class BaseDjangoToolsApp(AppConfig):
+    default = False
+    def __init__(self, app_name, app_module):
+        super().__init__(app_name, app_module)
+        if hasattr(self, "on_all_apps_ready"):
+            config.add_on_all_app_ready_callback(self.on_all_apps_ready)
 
 class DjangoToolsAppConfig(AppConfig):
     name = 'djangotools'
@@ -23,7 +30,7 @@ class DjangoToolsAppConfig(AppConfig):
         self._load_context()
         self._load_views()
 
-    def ready(self):
+    def on_all_apps_ready(self):
         if not self._is_ready:
             self._init()
         self._is_ready = True

+ 0 - 2
src/djangotools/cmdline/commands/run/__init__.py

@@ -22,13 +22,11 @@ class RunCommand(Command):
         Argument("-e", "--stderr", nargs=1, help="Crée le server dans un autre processus"),
         Argument("-b", "--bind",  help="Adresse d'écoute du serveur exemple localhost:8080", default="0.0.0.0:8000"),
         Argument("-C", "--no-cron", action="store_true", help="Ne pas lancer le cron"),
-
     ]
 
     def start_cron(self, hostname):
         self.cron = CronCommand.thread_run(CommandData(url=f"http://{hostname}"))
 
-
     def wait_cron_ends(self):
         self.cron.join()
 

+ 10 - 1
src/djangotools/config/__init__.py

@@ -31,6 +31,13 @@ def get_settings():
     return settings
 
 
+_on_all_app_ready_callback = []
+
+
+def add_on_all_app_ready_callback(fct):
+    if fct not in _on_all_app_ready_callback:
+        _on_all_app_ready_callback.append(fct)
+
 def load_app(settings_module, app_dir=None, populate=True):
     global loaded
     if loaded: return
@@ -47,4 +54,6 @@ def load_app(settings_module, app_dir=None, populate=True):
     from django.conf import settings
 
     if populate:
-        apps.populate(settings.INSTALLED_APPS)
+        apps.populate(settings.INSTALLED_APPS)
+        for fct in _on_all_app_ready_callback:
+            fct()

+ 2 - 1
src/djangotools/config/base.py

@@ -103,7 +103,8 @@ class ConfigLoader:
         elif "app_dir" in global_muodule:
             self.app_dir = Directory(global_muodule["app_dir"])
         else:
-            raise ValueError("")
+            raise ValueError("Impossible de trouver le app_dir. Merci de l'ajouter dans la config python ou "
+                             " d'utiliser la variable d'environnemnt APP_DIR")
         self.app_dir = self.app_dir.resolve()
         print(f"Utilisation de app_dir={self.app_dir}")