Commit
This method is useful to discover files inside apps.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,9 @@ def app_cache_ready(self): | |
return self.loaded | ||
|
||
def get_apps(self): | ||
"Returns a list of all installed modules that contain models." | ||
""" | ||
Returns a list of all installed modules that contain models. | ||
""" | ||
self._populate() | ||
|
||
# Ensure the returned list is always in the same order (with new apps | ||
|
@@ -140,6 +142,23 @@ def get_apps(self): | |
apps.sort() | ||
return [elt[1] for elt in apps] | ||
|
||
def get_app_paths(self): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
aaugustin
Author
Member
|
||
""" | ||
Returns a list of paths to all installed apps. | ||
Useful for discovering files at conventional locations inside apps | ||
(static files, templates, etc.) | ||
""" | ||
self._populate() | ||
|
||
app_paths = [] | ||
for app in self.get_apps(): | ||
if hasattr(app, '__path__'): # models/__init__.py package | ||
app_paths.extend([upath(path) for path in app.__path__]) | ||
This comment has been minimized.
Sorry, something went wrong.
timgraham
Member
|
||
else: # models.py module | ||
app_paths.append(upath(app.__file__)) | ||
return app_paths | ||
|
||
def get_app(self, app_label, emptyOK=False): | ||
""" | ||
Returns the module containing the models for the given app_label. If | ||
|
@@ -260,6 +279,7 @@ def register_models(self, app_label, *models): | |
# These methods were always module level, so are kept that way for backwards | ||
# compatibility. | ||
get_apps = cache.get_apps | ||
get_app_paths = cache.get_app_paths | ||
get_app = cache.get_app | ||
get_app_errors = cache.get_app_errors | ||
get_models = cache.get_models | ||
|
This is a little confusing to me in that the paths it returns contain models.pyc or end with "/models"
I propose modifying it to return just the app paths so that callers don't have to call or.path.dirname on each path that's returned. Let me know if I'm missing something.
#1359